Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

light-jdk7u60-b09.patch 421KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279
  1. diff --git a/src/cpu/x86/vm/interp_masm_x86_32.cpp b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  2. --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp
  3. +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  4. @@ -1364,7 +1364,7 @@
  5. }
  6. // RedefineClasses() tracing support for obsolete method entry
  7. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  8. + IF_TRACE_RC4 {
  9. get_thread(rcx);
  10. get_method(rbx);
  11. call_VM_leaf(
  12. diff --git a/src/cpu/x86/vm/interp_masm_x86_64.cpp b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  13. --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp
  14. +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  15. @@ -1427,7 +1427,7 @@
  16. }
  17. // RedefineClasses() tracing support for obsolete method entry
  18. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  19. + IF_TRACE_RC4 {
  20. get_method(c_rarg1);
  21. call_VM_leaf(
  22. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  23. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  24. --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  25. +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  26. @@ -1976,7 +1976,7 @@
  27. }
  28. // RedefineClasses() tracing support for obsolete method entry
  29. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  30. + IF_TRACE_RC4 {
  31. __ movoop(rax, JNIHandles::make_local(method()));
  32. __ call_VM_leaf(
  33. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  34. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  35. --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  36. +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  37. @@ -2235,7 +2235,7 @@
  38. }
  39. // RedefineClasses() tracing support for obsolete method entry
  40. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  41. + IF_TRACE_RC4 {
  42. // protect the args we've loaded
  43. save_args(masm, total_c_args, c_arg, out_regs);
  44. __ movoop(c_rarg1, JNIHandles::make_local(method()));
  45. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  46. --- a/src/share/vm/c1/c1_Compilation.hpp
  47. +++ b/src/share/vm/c1/c1_Compilation.hpp
  48. @@ -242,8 +242,9 @@
  49. #define BAILOUT(msg) { bailout(msg); return; }
  50. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  51. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  52. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  53. +// (tw) Also checks a thread local flag that can be set to trigger compiler bailout from another thread.
  54. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  55. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  56. class InstructionMark: public StackObj {
  57. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  58. --- a/src/share/vm/ci/ciObjectFactory.cpp
  59. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  60. @@ -764,3 +764,26 @@
  61. _unloaded_instances->length(),
  62. _unloaded_klasses->length());
  63. }
  64. +
  65. +int ciObjectFactory::compare_ciobjects(ciObject** a, ciObject** b) {
  66. + oop oop1 = (*a)->get_oop();
  67. + oop oop2 = (*b)->get_oop();
  68. + return ((oop1 > oop2) ? 1 : ((oop1 == oop2) ? 0 : -1));
  69. +}
  70. +
  71. +// (DCEVM) Resoring the ciObject arrays after class redefinition
  72. +void ciObjectFactory::resort_shared_ci_objects() {
  73. + _shared_ci_objects->sort(ciObjectFactory::compare_ciobjects);
  74. +
  75. +#ifdef ASSERT
  76. + if (CIObjectFactoryVerify) {
  77. + oop last = NULL;
  78. + for (int j = 0; j < _shared_ci_objects->length(); j++) {
  79. + oop o = _shared_ci_objects->at(j)->get_oop();
  80. + assert(last < o, "out of order");
  81. + last = o;
  82. + }
  83. + }
  84. +#endif // ASSERT
  85. +}
  86. +
  87. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  88. --- a/src/share/vm/ci/ciObjectFactory.hpp
  89. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  90. @@ -88,6 +88,7 @@
  91. ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
  92. + static int compare_ciobjects(ciObject** a, ciObject** b);
  93. public:
  94. static bool is_initialized() { return _initialized; }
  95. @@ -137,6 +138,8 @@
  96. void print_contents();
  97. void print();
  98. +
  99. + static void resort_shared_ci_objects();
  100. };
  101. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  102. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  103. --- a/src/share/vm/classfile/classFileParser.cpp
  104. +++ b/src/share/vm/classfile/classFileParser.cpp
  105. @@ -795,6 +795,7 @@
  106. Handle class_loader,
  107. Handle protection_domain,
  108. Symbol* class_name,
  109. + KlassHandle old_klass,
  110. TRAPS) {
  111. ClassFileStream* cfs = stream();
  112. assert(length > 0, "only called for length>0");
  113. @@ -813,6 +814,9 @@
  114. interface_index, CHECK_(nullHandle));
  115. if (cp->tag_at(interface_index).is_klass()) {
  116. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  117. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  118. + interf = KlassHandle(THREAD, interf->newest_version());
  119. + }
  120. } else {
  121. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  122. @@ -825,6 +829,9 @@
  123. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  124. unresolved_klass, class_loader, protection_domain,
  125. false, CHECK_(nullHandle));
  126. + if (!old_klass.is_null()) {
  127. + k = k->klass_part()->newest_version();
  128. + }
  129. interf = KlassHandle(THREAD, k);
  130. }
  131. @@ -2921,8 +2928,10 @@
  132. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  133. Handle class_loader,
  134. Handle protection_domain,
  135. + KlassHandle old_klass,
  136. KlassHandle host_klass,
  137. GrowableArray<Handle>* cp_patches,
  138. + GrowableArray<Symbol*>* parsed_super_symbols,
  139. TempNewSymbol& parsed_name,
  140. bool verify,
  141. TRAPS) {
  142. @@ -2948,7 +2957,7 @@
  143. init_parsed_class_attributes();
  144. - if (JvmtiExport::should_post_class_file_load_hook()) {
  145. + if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
  146. // Get the cached class file bytes (if any) from the class that
  147. // is being redefined or retransformed. We use jvmti_thread_state()
  148. // instead of JvmtiThreadState::state_for(jt) so we don't allocate
  149. @@ -2971,10 +2980,13 @@
  150. unsigned char* ptr = cfs->buffer();
  151. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  152. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  153. + Thread::current()->set_pretend_new_universe(false);
  154. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  155. &ptr, &end_ptr,
  156. &cached_class_file_bytes,
  157. &cached_class_file_length);
  158. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  159. if (ptr != cfs->buffer()) {
  160. // JVMTI agent has modified class file data.
  161. @@ -3090,6 +3102,30 @@
  162. CHECK_(nullHandle));
  163. }
  164. + // (tw) Do not parse full class file, only get super symbols and return.
  165. + if (parsed_super_symbols != NULL) {
  166. + u2 super_class_index = cfs->get_u2_fast();
  167. +
  168. + if (super_class_index != 0) {
  169. + parsed_super_symbols->append(cp->klass_name_at(super_class_index));
  170. + }
  171. +
  172. + // Interfaces
  173. + u2 itfs_len = cfs->get_u2_fast();
  174. + objArrayHandle local_interfaces;
  175. + if (itfs_len == 0) {
  176. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  177. + } else {
  178. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_NULL);
  179. + }
  180. +
  181. + for (int i=0; i<local_interfaces->length(); i++) {
  182. + oop o = local_interfaces->obj_at(i);
  183. + parsed_super_symbols->append(((klassOop)o)->klass_part()->name());
  184. + }
  185. + return NULL;
  186. + }
  187. +
  188. klassOop preserve_this_klass; // for storing result across HandleMark
  189. // release all handles when parsing is done
  190. @@ -3130,7 +3166,11 @@
  191. // However, make sure it is not an array type.
  192. bool is_array = false;
  193. if (cp->tag_at(super_class_index).is_klass()) {
  194. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  195. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  196. + if (!old_klass.is_null()) {
  197. + resolved_klass = resolved_klass->klass_part()->newest_version();
  198. + }
  199. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  200. if (_need_verify)
  201. is_array = super_klass->oop_is_array();
  202. } else if (_need_verify) {
  203. @@ -3148,7 +3188,7 @@
  204. if (itfs_len == 0) {
  205. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  206. } else {
  207. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  208. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  209. }
  210. u2 java_fields_count = 0;
  211. @@ -3202,7 +3242,9 @@
  212. protection_domain,
  213. true,
  214. CHECK_(nullHandle));
  215. -
  216. + if (!old_klass.is_null()) {
  217. + k = k->klass_part()->newest_version();
  218. + }
  219. KlassHandle kh (THREAD, k);
  220. super_klass = instanceKlassHandle(THREAD, kh());
  221. }
  222. @@ -3591,6 +3633,19 @@
  223. rt = REF_NONE;
  224. } else {
  225. rt = super_klass->reference_type();
  226. +
  227. + // (tw) With class redefinition, it can also happen that special classes are loaded.
  228. + if (name == vmSymbols::java_lang_ref_Reference()) {
  229. + rt = REF_OTHER;
  230. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  231. + rt = REF_SOFT;
  232. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  233. + rt = REF_WEAK;
  234. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  235. + rt = REF_FINAL;
  236. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  237. + rt = REF_PHANTOM;
  238. + }
  239. }
  240. // We can now create the basic klassOop for this klass
  241. @@ -3599,6 +3654,7 @@
  242. total_oop_map_count,
  243. access_flags,
  244. rt, host_klass,
  245. + old_klass,
  246. CHECK_(nullHandle));
  247. instanceKlassHandle this_klass (THREAD, ik);
  248. @@ -3691,7 +3747,7 @@
  249. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  250. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  251. - set_precomputed_flags(this_klass);
  252. + set_precomputed_flags(this_klass, old_klass);
  253. // reinitialize modifiers, using the InnerClasses attribute
  254. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  255. @@ -3711,6 +3767,10 @@
  256. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  257. }
  258. + if (rt == REF_OTHER) {
  259. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  260. + }
  261. +
  262. // Allocate mirror and initialize static fields
  263. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  264. @@ -3856,7 +3916,7 @@
  265. }
  266. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  267. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  268. klassOop super = k->super();
  269. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  270. @@ -3864,7 +3924,9 @@
  271. if (!_has_empty_finalizer) {
  272. if (_has_finalizer ||
  273. (super != NULL && super->klass_part()->has_finalizer())) {
  274. - k->set_has_finalizer();
  275. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  276. + k->set_has_finalizer();
  277. + }
  278. }
  279. }
  280. @@ -3880,7 +3942,7 @@
  281. // Check if this klass supports the java.lang.Cloneable interface
  282. if (SystemDictionary::Cloneable_klass_loaded()) {
  283. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  284. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  285. k->set_is_cloneable();
  286. }
  287. }
  288. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  289. --- a/src/share/vm/classfile/classFileParser.hpp
  290. +++ b/src/share/vm/classfile/classFileParser.hpp
  291. @@ -151,6 +151,7 @@
  292. Handle class_loader,
  293. Handle protection_domain,
  294. Symbol* class_name,
  295. + KlassHandle old_klass,
  296. TRAPS);
  297. // Field parsing
  298. @@ -237,7 +238,7 @@
  299. unsigned int nonstatic_oop_map_count,
  300. int* nonstatic_oop_offsets,
  301. unsigned int* nonstatic_oop_counts);
  302. - void set_precomputed_flags(instanceKlassHandle k);
  303. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  304. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  305. objArrayHandle local_ifs, TRAPS);
  306. @@ -349,17 +350,20 @@
  307. instanceKlassHandle parseClassFile(Symbol* name,
  308. Handle class_loader,
  309. Handle protection_domain,
  310. + KlassHandle old_klass,
  311. TempNewSymbol& parsed_name,
  312. bool verify,
  313. TRAPS) {
  314. KlassHandle no_host_klass;
  315. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  316. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
  317. }
  318. instanceKlassHandle parseClassFile(Symbol* name,
  319. Handle class_loader,
  320. Handle protection_domain,
  321. + KlassHandle old_klass,
  322. KlassHandle host_klass,
  323. GrowableArray<Handle>* cp_patches,
  324. + GrowableArray<Symbol*>* parsed_super_symbols,
  325. TempNewSymbol& parsed_name,
  326. bool verify,
  327. TRAPS);
  328. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  329. --- a/src/share/vm/classfile/classLoader.cpp
  330. +++ b/src/share/vm/classfile/classLoader.cpp
  331. @@ -915,6 +915,7 @@
  332. instanceKlassHandle result = parser.parseClassFile(h_name,
  333. class_loader,
  334. protection_domain,
  335. + KlassHandle(),
  336. parsed_name,
  337. false,
  338. CHECK_(h));
  339. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  340. --- a/src/share/vm/classfile/dictionary.cpp
  341. +++ b/src/share/vm/classfile/dictionary.cpp
  342. @@ -144,87 +144,10 @@
  343. probe = *p;
  344. klassOop e = probe->klass();
  345. oop class_loader = probe->loader();
  346. -
  347. instanceKlass* ik = instanceKlass::cast(e);
  348. - if (ik->previous_versions() != NULL) {
  349. - // This klass has previous versions so see what we can cleanup
  350. - // while it is safe to do so.
  351. -
  352. - int gc_count = 0; // leave debugging breadcrumbs
  353. - int live_count = 0;
  354. -
  355. - // RC_TRACE macro has an embedded ResourceMark
  356. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  357. - ik->external_name(), ik->previous_versions()->length()));
  358. -
  359. - for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  360. - // check the previous versions array for GC'ed weak refs
  361. - PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
  362. - jobject cp_ref = pv_node->prev_constant_pool();
  363. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  364. - if (cp_ref == NULL) {
  365. - delete pv_node;
  366. - ik->previous_versions()->remove_at(i);
  367. - // Since we are traversing the array backwards, we don't have to
  368. - // do anything special with the index.
  369. - continue; // robustness
  370. - }
  371. -
  372. - constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  373. - if (pvcp == NULL) {
  374. - // this entry has been GC'ed so remove it
  375. - delete pv_node;
  376. - ik->previous_versions()->remove_at(i);
  377. - // Since we are traversing the array backwards, we don't have to
  378. - // do anything special with the index.
  379. - gc_count++;
  380. - continue;
  381. - } else {
  382. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  383. - if (is_alive->do_object_b(pvcp)) {
  384. - live_count++;
  385. - } else {
  386. - guarantee(false, "sanity check");
  387. - }
  388. - }
  389. -
  390. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  391. - if (method_refs != NULL) {
  392. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  393. - method_refs->length()));
  394. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  395. - jweak method_ref = method_refs->at(j);
  396. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  397. - if (method_ref == NULL) {
  398. - method_refs->remove_at(j);
  399. - // Since we are traversing the array backwards, we don't have to
  400. - // do anything special with the index.
  401. - continue; // robustness
  402. - }
  403. -
  404. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  405. - if (method == NULL) {
  406. - // this method entry has been GC'ed so remove it
  407. - JNIHandles::destroy_weak_global(method_ref);
  408. - method_refs->remove_at(j);
  409. - } else {
  410. - // RC_TRACE macro has an embedded ResourceMark
  411. - RC_TRACE(0x00000200,
  412. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  413. - method->name()->as_C_string(),
  414. - method->signature()->as_C_string(), j, i));
  415. - }
  416. - }
  417. - }
  418. - }
  419. - assert(ik->previous_versions()->length() == live_count, "sanity check");
  420. - RC_TRACE(0x00000200,
  421. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  422. - gc_count));
  423. - }
  424. -
  425. +
  426. // Non-unloadable classes were handled in always_strong_oops_do
  427. - if (!is_strongly_reachable(class_loader, e)) {
  428. + if (!ik->is_redefining() && !is_strongly_reachable(class_loader, e)) {
  429. // Entry was not visited in phase1 (negated test from phase1)
  430. assert(class_loader != NULL, "unloading entry with null class loader");
  431. oop k_def_class_loader = ik->class_loader();
  432. @@ -326,6 +249,7 @@
  433. }
  434. }
  435. +
  436. // Added for initialize_itable_for_klass to handle exceptions
  437. // Just the classes from defining class loaders
  438. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  439. @@ -433,6 +357,33 @@
  440. add_entry(index, entry);
  441. }
  442. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  443. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  444. +
  445. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  446. + bool found = false;
  447. + for (int index = 0; index < table_size(); index++) {
  448. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  449. + if (entry->klass() == old_class()) {
  450. + entry->set_literal(k());
  451. + found = true;
  452. + }
  453. + }
  454. + }
  455. +
  456. + return found;
  457. +}
  458. +
  459. +// (tw) Undo previous updates to the system dictionary
  460. +void Dictionary::rollback_redefinition() {
  461. + for (int index = 0; index < table_size(); index++) {
  462. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  463. + if (entry->klass()->klass_part()->is_redefining()) {
  464. + entry->set_literal(entry->klass()->klass_part()->old_version());
  465. + }
  466. + }
  467. + }
  468. +}
  469. // This routine does not lock the system dictionary.
  470. //
  471. @@ -459,12 +410,21 @@
  472. return NULL;
  473. }
  474. +klassOop Dictionary::intercept_for_version(klassOop k) {
  475. + if (k == NULL) return k;
  476. +
  477. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  478. + return k->klass_part()->old_version();
  479. + }
  480. +
  481. + return k;
  482. +}
  483. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  484. Handle loader, Handle protection_domain, TRAPS) {
  485. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  486. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  487. - return entry->klass();
  488. + return intercept_for_version(entry->klass());
  489. } else {
  490. return NULL;
  491. }
  492. @@ -477,7 +437,7 @@
  493. assert (index == index_for(name, loader), "incorrect index?");
  494. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  495. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  496. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  497. }
  498. @@ -489,7 +449,7 @@
  499. assert (index == index_for(name, Handle()), "incorrect index?");
  500. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  501. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  502. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  503. }
  504. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  505. --- a/src/share/vm/classfile/dictionary.hpp
  506. +++ b/src/share/vm/classfile/dictionary.hpp
  507. @@ -73,6 +73,10 @@
  508. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  509. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  510. +
  511. + void rollback_redefinition();
  512. +
  513. klassOop find_class(int index, unsigned int hash,
  514. Symbol* name, Handle loader);
  515. @@ -105,6 +109,7 @@
  516. bool do_unloading(BoolObjectClosure* is_alive);
  517. // Protection domains
  518. + static klassOop intercept_for_version(klassOop k);
  519. klassOop find(int index, unsigned int hash, Symbol* name,
  520. Handle loader, Handle protection_domain, TRAPS);
  521. bool is_valid_protection_domain(int index, unsigned int hash,
  522. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  523. --- a/src/share/vm/classfile/javaClasses.cpp
  524. +++ b/src/share/vm/classfile/javaClasses.cpp
  525. @@ -621,6 +621,10 @@
  526. assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  527. klassOop k = klassOop(java_class->obj_field(_klass_offset));
  528. assert(k == NULL || k->is_klass(), "type check");
  529. + // Necessary to make old verifier work.
  530. + if (Thread::current()->pretend_new_universe()) {
  531. + k = k->klass_part()->newest_version();
  532. + }
  533. return k;
  534. }
  535. @@ -1541,6 +1545,7 @@
  536. skip_throwableInit_check = true;
  537. }
  538. }
  539. + method = method->newest_version();
  540. if (method->is_hidden()) {
  541. if (skip_hidden) continue;
  542. }
  543. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  544. --- a/src/share/vm/classfile/javaClasses.hpp
  545. +++ b/src/share/vm/classfile/javaClasses.hpp
  546. @@ -213,6 +213,7 @@
  547. class java_lang_Class : AllStatic {
  548. friend class VMStructs;
  549. + friend class VM_RedefineClasses;
  550. private:
  551. // The fake offsets are added by the class loader when java.lang.Class is loaded
  552. @@ -248,7 +249,7 @@
  553. static void print_signature(oop java_class, outputStream *st);
  554. // Testing
  555. static bool is_instance(oop obj) {
  556. - return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
  557. + return obj != NULL && (obj->klass()->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version());
  558. }
  559. static bool is_primitive(oop java_class);
  560. static BasicType primitive_type(oop java_class);
  561. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  562. --- a/src/share/vm/classfile/loaderConstraints.cpp
  563. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  564. @@ -449,7 +449,7 @@
  565. if (k != NULL) {
  566. // We found the class in the system dictionary, so we should
  567. // make sure that the klassOop matches what we already have.
  568. - guarantee(k == probe->klass(), "klass should be in dictionary");
  569. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  570. } else {
  571. // If we don't find the class in the system dictionary, it
  572. // has to be in the placeholders table.
  573. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  574. --- a/src/share/vm/classfile/systemDictionary.cpp
  575. +++ b/src/share/vm/classfile/systemDictionary.cpp
  576. @@ -157,6 +157,7 @@
  577. // can return a null klass
  578. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  579. }
  580. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  581. return klass;
  582. }
  583. @@ -199,7 +200,7 @@
  584. // Forwards to resolve_instance_class_or_null
  585. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  586. - assert(!THREAD->is_Compiler_thread(),
  587. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  588. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  589. class_name->as_C_string(),
  590. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  591. @@ -961,8 +962,10 @@
  592. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  593. class_loader,
  594. protection_domain,
  595. + KlassHandle(),
  596. host_klass,
  597. cp_patches,
  598. + NULL,
  599. parsed_name,
  600. true,
  601. THREAD);
  602. @@ -1022,7 +1025,15 @@
  603. Handle protection_domain,
  604. ClassFileStream* st,
  605. bool verify,
  606. + KlassHandle old_class,
  607. TRAPS) {
  608. +
  609. + bool redefine_classes_locked = false;
  610. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  611. + Thread::current()->redefine_classes_mutex()->lock();
  612. + redefine_classes_locked = true;
  613. + }
  614. +
  615. // Classloaders that support parallelism, e.g. bootstrap classloader,
  616. // or all classloaders with UnsyncloadClass do not acquire lock here
  617. bool DoObjectLock = true;
  618. @@ -1050,9 +1061,14 @@
  619. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  620. class_loader,
  621. protection_domain,
  622. + old_class,
  623. parsed_name,
  624. verify,
  625. THREAD);
  626. + if (!old_class.is_null() && !k.is_null()) {
  627. + k->set_redefining(true);
  628. + k->set_old_version(old_class());
  629. + }
  630. const char* pkg = "java/";
  631. if (!HAS_PENDING_EXCEPTION &&
  632. @@ -1087,13 +1103,18 @@
  633. // Add class just loaded
  634. // If a class loader supports parallel classloading handle parallel define requests
  635. // find_or_define_instance_class may return a different instanceKlass
  636. - if (is_parallelCapable(class_loader)) {
  637. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  638. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  639. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  640. } else {
  641. - define_instance_class(k, THREAD);
  642. + define_instance_class(k, old_class, THREAD);
  643. }
  644. }
  645. + if (redefine_classes_locked) {
  646. + Thread::current()->redefine_classes_mutex()->unlock();
  647. + }
  648. +
  649. // If parsing the class file or define_instance_class failed, we
  650. // need to remove the placeholder added on our behalf. But we
  651. // must make sure parsed_name is valid first (it won't be if we had
  652. @@ -1122,7 +1143,7 @@
  653. MutexLocker mu(SystemDictionary_lock, THREAD);
  654. klassOop check = find_class(parsed_name, class_loader);
  655. - assert(check == k(), "should be present in the dictionary");
  656. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  657. klassOop check2 = find_class(h_name, h_loader);
  658. assert(check == check2, "name inconsistancy in SystemDictionary");
  659. @@ -1349,7 +1370,11 @@
  660. }
  661. }
  662. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  663. +void SystemDictionary::rollback_redefinition() {
  664. + dictionary()->rollback_redefinition();
  665. +}
  666. +
  667. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  668. Handle class_loader_h(THREAD, k->class_loader());
  669. @@ -1376,13 +1401,23 @@
  670. Symbol* name_h = k->name();
  671. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  672. int d_index = dictionary()->hash_to_index(d_hash);
  673. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  674. +
  675. + // (tw) Update version of the klassOop in the system dictionary
  676. + // TODO: Check for thread safety!
  677. + if (!old_class.is_null()) {
  678. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  679. + assert (ok, "must have found old class and updated!");
  680. + }
  681. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  682. +
  683. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  684. // Register class just loaded with class loader (placed in Vector)
  685. // Note we do this before updating the dictionary, as this can
  686. // fail with an OutOfMemoryError (if it does, we will *not* put this
  687. // class in the dictionary and will not update the class hierarchy).
  688. - if (k->class_loader() != NULL) {
  689. + // (tw) Only register if not redefining a class.
  690. + if (k->class_loader() != NULL && old_class.is_null()) {
  691. methodHandle m(THREAD, Universe::loader_addClass_method());
  692. JavaValue result(T_VOID);
  693. JavaCallArguments args(class_loader_h);
  694. @@ -1408,8 +1443,9 @@
  695. }
  696. k->eager_initialize(THREAD);
  697. + // (tw) Only notify jvmti if not redefining a class.
  698. // notify jvmti
  699. - if (JvmtiExport::should_post_class_load()) {
  700. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  701. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  702. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  703. @@ -1482,7 +1518,7 @@
  704. }
  705. }
  706. - define_instance_class(k, THREAD);
  707. + define_instance_class(k, KlassHandle(), THREAD);
  708. Handle linkage_exception = Handle(); // null handle
  709. @@ -1613,6 +1649,14 @@
  710. Universe::flush_dependents_on(k);
  711. }
  712. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  713. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  714. + assert(k.not_null(), "just checking");
  715. +
  716. + k->remove_from_sibling_list();
  717. +
  718. + // TODO (tw): Remove from interfaces.
  719. +}
  720. // ----------------------------------------------------------------------------
  721. // GC support
  722. @@ -1870,9 +1914,12 @@
  723. // Preload ref klasses and set reference types
  724. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  725. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  726. +
  727. + // (tw) This is now done in parseClassFile in order to support class redefinition
  728. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  729. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  730. + // TODO(tw): Check that the following is also not necessary?
  731. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  732. instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
  733. instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
  734. @@ -1956,7 +2003,7 @@
  735. // also holds array classes
  736. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  737. - if ((defining == true) || (k() != check)) {
  738. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  739. linkage_error = "loader (instance of %s): attempted duplicate class "
  740. "definition for name: \"%s\"";
  741. } else {
  742. @@ -2616,8 +2663,10 @@
  743. name = find_placeholder(class_name, class_loader);
  744. }
  745. }
  746. - guarantee(probe != NULL || name != NULL,
  747. - "Loaded klasses should be in SystemDictionary");
  748. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  749. + guarantee(probe != NULL &&
  750. + (!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(),
  751. + "Loaded klasses should be in SystemDictionary");
  752. }
  753. // utility function for posting class load event
  754. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  755. --- a/src/share/vm/classfile/systemDictionary.hpp
  756. +++ b/src/share/vm/classfile/systemDictionary.hpp
  757. @@ -269,7 +269,7 @@
  758. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  759. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  760. Handle protection_domain,
  761. - ClassFileStream* st, bool verify, TRAPS);
  762. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  763. // Lookup an already loaded class. If not found NULL is returned.
  764. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  765. @@ -344,6 +344,8 @@
  766. // System loader lock
  767. static oop system_loader_lock() { return _system_loader_lock_obj; }
  768. + // Remove link to hierarchy
  769. + static void remove_from_hierarchy(instanceKlassHandle k);
  770. private:
  771. // Traverses preloaded oops: various system classes. These are
  772. // guaranteed to be in the perm gen.
  773. @@ -416,6 +418,8 @@
  774. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  775. }
  776. + static void rollback_redefinition();
  777. +
  778. public:
  779. #define WK_KLASS_DECLARE(name, symbol, option) \
  780. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  781. @@ -597,7 +601,7 @@
  782. // after waiting, but before reentering SystemDictionary_lock
  783. // to preserve lock order semantics.
  784. static void double_lock_wait(Handle lockObject, TRAPS);
  785. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  786. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  787. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  788. Handle class_loader,
  789. instanceKlassHandle k, TRAPS);
  790. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  791. --- a/src/share/vm/classfile/verifier.cpp
  792. +++ b/src/share/vm/classfile/verifier.cpp
  793. @@ -106,7 +106,7 @@
  794. return !need_verify;
  795. }
  796. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  797. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  798. HandleMark hm;
  799. ResourceMark rm(THREAD);
  800. @@ -117,6 +117,7 @@
  801. const char* klassName = klass->external_name();
  802. bool can_failover = FailOverToOldVerifier &&
  803. + may_use_old_verifier &&
  804. klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  805. // If the class should be verified, first see if we can use the split
  806. @@ -138,6 +139,7 @@
  807. tty->print_cr(
  808. "Fail over class verification to old verifier for: %s", klassName);
  809. }
  810. + assert(may_use_old_verifier, "");
  811. exception_name = inference_verify(
  812. klass, message_buffer, message_buffer_len, THREAD);
  813. }
  814. @@ -145,6 +147,7 @@
  815. exception_message = split_verifier.exception_message();
  816. }
  817. } else {
  818. + assert(may_use_old_verifier, "");
  819. exception_name = inference_verify(
  820. klass, message_buffer, message_buffer_len, THREAD);
  821. }
  822. @@ -210,7 +213,7 @@
  823. // NOTE: this is called too early in the bootstrapping process to be
  824. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  825. (refl_magic_klass == NULL ||
  826. - !klass->is_subtype_of(refl_magic_klass) ||
  827. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  828. VerifyReflectionBytecodes)
  829. );
  830. }
  831. @@ -517,7 +520,7 @@
  832. ClassVerifier::ClassVerifier(
  833. instanceKlassHandle klass, TRAPS)
  834. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  835. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  836. _this_type = VerificationType::reference_type(klass->name());
  837. // Create list to hold symbols in reference area.
  838. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  839. @@ -547,7 +550,7 @@
  840. _klass->external_name());
  841. }
  842. - objArrayHandle methods(THREAD, _klass->methods());
  843. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  844. int num_methods = methods->length();
  845. for (int index = 0; index < num_methods; index++) {
  846. @@ -2444,7 +2447,8 @@
  847. VerificationType stack_object_type =
  848. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  849. if (current_type() != stack_object_type) {
  850. - assert(cp->cache() == NULL, "not rewritten yet");
  851. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  852. + //assert(cp->cache() == NULL, "not rewritten yet");
  853. Symbol* ref_class_name =
  854. cp->klass_name_at(cp->klass_ref_index_at(index));
  855. // See the comments in verify_field_instructions() for
  856. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  857. --- a/src/share/vm/classfile/verifier.hpp
  858. +++ b/src/share/vm/classfile/verifier.hpp
  859. @@ -47,7 +47,7 @@
  860. * Otherwise, no exception is thrown and the return indicates the
  861. * error.
  862. */
  863. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  864. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  865. // Return false if the class is loaded by the bootstrap loader,
  866. // or if defineClass was called requesting skipping verification
  867. @@ -256,7 +256,10 @@
  868. ErrorContext _error_context; // contains information about an error
  869. +public:
  870. void verify_method(methodHandle method, TRAPS);
  871. +
  872. +private:
  873. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  874. void verify_exception_handler_table(u4 code_length, char* code_data,
  875. int& min, int& max, TRAPS);
  876. @@ -329,6 +332,7 @@
  877. VerificationType object_type() const;
  878. + instanceKlassHandle _klass_to_verify;
  879. instanceKlassHandle _klass; // the class being verified
  880. methodHandle _method; // current method being verified
  881. VerificationType _this_type; // the verification type of the current class
  882. diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
  883. --- a/src/share/vm/code/nmethod.cpp
  884. +++ b/src/share/vm/code/nmethod.cpp
  885. @@ -2083,15 +2083,14 @@
  886. methodOop method = deps.method_argument(0);
  887. for (int j = 0; j < dependee_methods->length(); j++) {
  888. if ((methodOop) dependee_methods->obj_at(j) == method) {
  889. - // RC_TRACE macro has an embedded ResourceMark
  890. - RC_TRACE(0x01000000,
  891. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  892. + ResourceMark rm(Thread::current());
  893. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  894. _method->method_holder()->klass_part()->external_name(),
  895. _method->name()->as_C_string(),
  896. _method->signature()->as_C_string(), compile_id(),
  897. method->method_holder()->klass_part()->external_name(),
  898. method->name()->as_C_string(),
  899. - method->signature()->as_C_string()));
  900. + method->signature()->as_C_string());
  901. if (TraceDependencies || LogCompilation)
  902. deps.log_dependency(dependee);
  903. return true;
  904. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  905. --- a/src/share/vm/compiler/compileBroker.cpp
  906. +++ b/src/share/vm/compiler/compileBroker.cpp
  907. @@ -1592,6 +1592,9 @@
  908. // Never compile a method if breakpoints are present in it
  909. if (method()->number_of_breakpoints() == 0) {
  910. + // (tw) Obtain a compilation lock. Class redefinition requires that there is no compilation in parallel.
  911. + thread->compilation_mutex()->lock();
  912. + thread->set_should_bailout(false);
  913. // Compile the method.
  914. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  915. #ifdef COMPILER1
  916. @@ -1615,6 +1618,7 @@
  917. // After compilation is disabled, remove remaining methods from queue
  918. method->clear_queued_for_compilation();
  919. }
  920. + thread->compilation_mutex()->unlock();
  921. }
  922. }
  923. }
  924. @@ -1780,7 +1784,11 @@
  925. //assert(false, "compiler should always document failure");
  926. // The compiler elected, without comment, not to register a result.
  927. // Do not attempt further compilations of this method.
  928. - ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
  929. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  930. + ci_env.record_failure("compile externally aborted");
  931. + } else {
  932. + ci_env.record_method_not_compilable("compile failed");
  933. + }
  934. }
  935. // Copy this bit to the enclosing block:
  936. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  937. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  938. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  939. @@ -162,6 +162,13 @@
  940. }
  941. }
  942. +
  943. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  944. + CompactPoint* cp, HeapWord* compact_top) {
  945. + ShouldNotReachHere();
  946. + return NULL;
  947. +}
  948. +
  949. // Like CompactibleSpace forward() but always calls cross_threshold() to
  950. // update the block offset table. Removed initialize_threshold call because
  951. // CFLS does not use a block offset array for contiguous spaces.
  952. @@ -2118,7 +2125,7 @@
  953. // Support for compaction
  954. void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
  955. - SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
  956. + SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
  957. // prepare_for_compaction() uses the space between live objects
  958. // so that later phase can skip dead space quickly. So verification
  959. // of the free lists doesn't work after.
  960. @@ -2139,7 +2146,7 @@
  961. }
  962. void CompactibleFreeListSpace::compact() {
  963. - SCAN_AND_COMPACT(obj_size);
  964. + SCAN_AND_COMPACT(obj_size, false);
  965. }
  966. // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
  967. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  968. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  969. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  970. @@ -149,6 +149,7 @@
  971. // Support for compacting cms
  972. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  973. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  974. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  975. // Initialization helpers.
  976. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  977. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  978. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  979. @@ -32,6 +32,8 @@
  980. #include "oops/objArrayKlass.inline.hpp"
  981. #include "oops/oop.inline.hpp"
  982. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  983. +
  984. Stack<oop, mtGC> MarkSweep::_marking_stack;
  985. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  986. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  987. @@ -357,3 +359,97 @@
  988. }
  989. #endif
  990. +
  991. +// (tw) Copy the rescued objects to their destination address after compaction.
  992. +void MarkSweep::copy_rescued_objects_back() {
  993. +
  994. + if (_rescued_oops != NULL) {
  995. +
  996. + for (int i=0; i<_rescued_oops->length(); i++) {
  997. + oop rescued_obj = _rescued_oops->at(i);
  998. +
  999. + int size = rescued_obj->size();
  1000. + oop new_obj = rescued_obj->forwardee();
  1001. +
  1002. + assert(rescued_obj->blueprint()->new_version() != NULL, "just checking");
  1003. +
  1004. + if (rescued_obj->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1005. + MarkSweep::update_fields(rescued_obj, new_obj);
  1006. + } else {
  1007. + rescued_obj->set_klass_no_check(rescued_obj->blueprint()->new_version());
  1008. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1009. + }
  1010. +
  1011. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1012. +
  1013. + new_obj->init_mark();
  1014. + assert(new_obj->is_oop(), "must be a valid oop");
  1015. + }
  1016. + _rescued_oops->clear();
  1017. + _rescued_oops = NULL;
  1018. + }
  1019. +}
  1020. +
  1021. +// (tw) Update instances of a class whose fields changed.
  1022. +void MarkSweep::update_fields(oop q, oop new_location) {
  1023. +
  1024. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1025. +
  1026. + klassOop old_klass_oop = q->klass();
  1027. + klassOop new_klass_oop = q->blueprint()->new_version();
  1028. +
  1029. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1030. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1031. +
  1032. + int size = q->size_given_klass(old_klass);
  1033. + int new_size = q->size_given_klass(new_klass);
  1034. +
  1035. + oop tmp_obj = q;
  1036. +
  1037. + // Save object somewhere, there is an overlap in fields
  1038. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1039. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1040. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1041. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1042. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1043. + }
  1044. + }
  1045. +
  1046. + tmp_obj->set_klass_no_check(new_klass_oop);
  1047. + int *cur = new_klass_oop->klass_part()->update_information();
  1048. + assert(cur != NULL, "just checking");
  1049. + MarkSweep::update_fields(new_location, tmp_obj, cur);
  1050. +
  1051. + if (tmp_obj != q) {
  1052. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1053. + }
  1054. +}
  1055. +
  1056. +void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
  1057. + assert(cur != NULL, "just checking");
  1058. + char* to = (char*)new_location;
  1059. + while (*cur != 0) {
  1060. + int size = *cur;
  1061. + if (size > 0) {
  1062. + cur++;
  1063. + int offset = *cur;
  1064. + HeapWord* from = (HeapWord*)(((char *)tmp_obj) + offset);
  1065. + if (size == HeapWordSize) {
  1066. + *((HeapWord*)to) = *from;
  1067. + } else if (size == HeapWordSize * 2) {
  1068. + *((HeapWord*)to) = *from;
  1069. + *(((HeapWord*)to) + 1) = *(from + 1);
  1070. + } else {
  1071. + Copy::conjoint_jbytes(from, to, size);
  1072. + }
  1073. + to += size;
  1074. + cur++;
  1075. + } else {
  1076. + assert(size < 0, "");
  1077. + int skip = -*cur;
  1078. + Copy::fill_to_bytes(to, skip, 0);
  1079. + to += skip;
  1080. + cur++;
  1081. + }
  1082. + }
  1083. +}
  1084. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1085. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1086. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1087. @@ -117,8 +117,12 @@
  1088. friend class AdjustPointerClosure;
  1089. friend class KeepAliveClosure;
  1090. friend class VM_MarkSweep;
  1091. + friend class GenMarkSweep;
  1092. friend void marksweep_init();
  1093. +public:
  1094. + static GrowableArray<oop>* _rescued_oops;
  1095. +
  1096. //
  1097. // Vars
  1098. //
  1099. @@ -208,6 +212,9 @@
  1100. template <class T> static inline void mark_and_push(T* p);
  1101. static inline void push_objarray(oop obj, size_t index);
  1102. + static void copy_rescued_objects_back();
  1103. + static void update_fields(oop q, oop new_location);
  1104. + static void update_fields(oop new_location, oop tmp_obj, int *cur);
  1105. static void follow_stack(); // Empty marking stack.
  1106. static void preserve_mark(oop p, markOop mark);
  1107. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1108. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1109. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1110. @@ -402,7 +402,7 @@
  1111. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1112. assert(h_exception->is_oop(), "just checking");
  1113. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1114. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1115. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1116. if (ExitVMOnVerifyError) vm_exit(-1);
  1117. ShouldNotReachHere();
  1118. }
  1119. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1120. --- a/src/share/vm/interpreter/linkResolver.cpp
  1121. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1122. @@ -153,8 +153,8 @@
  1123. // Klass resolution
  1124. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1125. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1126. - sel_klass->as_klassOop(),
  1127. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1128. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1129. true)) {
  1130. ResourceMark rm(THREAD);
  1131. Exceptions::fthrow(
  1132. @@ -338,7 +338,7 @@
  1133. // We'll check for the method name first, as that's most likely
  1134. // to be false (so we'll short-circuit out of these tests).
  1135. if (sel_method->name() == vmSymbols::clone_name() &&
  1136. - sel_klass() == SystemDictionary::Object_klass() &&
  1137. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1138. resolved_klass->oop_is_array()) {
  1139. // We need to change "protected" to "public".
  1140. assert(flags.is_protected(), "clone not protected?");
  1141. @@ -634,7 +634,7 @@
  1142. }
  1143. // Final fields can only be accessed from its own class.
  1144. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1145. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1146. THROW(vmSymbols::java_lang_IllegalAccessError());
  1147. }
  1148. @@ -839,7 +839,7 @@
  1149. bool check_access, bool check_null_and_abstract, TRAPS) {
  1150. methodHandle resolved_method;
  1151. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1152. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1153. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1154. }
  1155. // throws linktime exceptions
  1156. @@ -869,6 +869,7 @@
  1157. KlassHandle resolved_klass,
  1158. Handle recv,
  1159. KlassHandle recv_klass,
  1160. + KlassHandle current_klass,
  1161. bool check_null_and_abstract,
  1162. TRAPS) {
  1163. @@ -917,6 +918,9 @@
  1164. // recv_klass might be an arrayKlassOop but all vtables start at
  1165. // the same place. The cast is to avoid virtual call and assertion.
  1166. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1167. +
  1168. + // (tw) Check that the receiver is a subtype of the holder of the resolved method.
  1169. + assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
  1170. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  1171. }
  1172. }
  1173. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  1174. --- a/src/share/vm/interpreter/linkResolver.hpp
  1175. +++ b/src/share/vm/interpreter/linkResolver.hpp
  1176. @@ -110,7 +110,8 @@
  1177. // It does all necessary link-time checks & throws exceptions if necessary.
  1178. class LinkResolver: AllStatic {
  1179. - private:
  1180. +private:
  1181. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  1182. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1183. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1184. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1185. @@ -133,7 +134,7 @@
  1186. static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
  1187. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  1188. - 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);
  1189. + 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);
  1190. 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);
  1191. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  1192. diff --git a/src/share/vm/interpreter/oopMapCache.cpp b/src/share/vm/interpreter/oopMapCache.cpp
  1193. --- a/src/share/vm/interpreter/oopMapCache.cpp
  1194. +++ b/src/share/vm/interpreter/oopMapCache.cpp
  1195. @@ -536,9 +536,9 @@
  1196. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  1197. // Cache entry is occupied by an old redefined method and we don't want
  1198. // to pin it down so flush the entry.
  1199. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  1200. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  1201. _array[i].method()->name()->as_C_string(),
  1202. - _array[i].method()->signature()->as_C_string(), i));
  1203. + _array[i].method()->signature()->as_C_string(), i);
  1204. _array[i].flush();
  1205. }
  1206. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  1207. --- a/src/share/vm/memory/genMarkSweep.cpp
  1208. +++ b/src/share/vm/memory/genMarkSweep.cpp
  1209. @@ -421,6 +421,7 @@
  1210. // in the same order in phase2, phase3 and phase4. We don't quite do that
  1211. // here (perm_gen first rather than last), so we tell the validate code
  1212. // to use a higher index (saved from phase2) when verifying perm_gen.
  1213. + assert(_rescued_oops == NULL, "must be empty before processing");
  1214. GenCollectedHeap* gch = GenCollectedHeap::heap();
  1215. Generation* pg = gch->perm_gen();
  1216. @@ -433,10 +434,14 @@
  1217. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  1218. + MarkSweep::copy_rescued_objects_back();
  1219. +
  1220. GenCompactClosure blk;
  1221. gch->generation_iterate(&blk, true);
  1222. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  1223. + MarkSweep::copy_rescued_objects_back();
  1224. +
  1225. pg->post_compact(); // Shared spaces verification.
  1226. }
  1227. diff --git a/src/share/vm/memory/iterator.hpp b/src/share/vm/memory/iterator.hpp
  1228. --- a/src/share/vm/memory/iterator.hpp
  1229. +++ b/src/share/vm/memory/iterator.hpp
  1230. @@ -101,6 +101,12 @@
  1231. #endif
  1232. };
  1233. +class OopClosureNoHeader : public OopClosure {
  1234. +public:
  1235. + // If "true", invoke on header klass field.
  1236. + bool do_header() { return false; } // Note that this is non-virtual.
  1237. +};
  1238. +
  1239. // ObjectClosure is used for iterating through an object space
  1240. class ObjectClosure : public Closure {
  1241. diff --git a/src/share/vm/memory/oopFactory.cpp b/src/share/vm/memory/oopFactory.cpp
  1242. --- a/src/share/vm/memory/oopFactory.cpp
  1243. +++ b/src/share/vm/memory/oopFactory.cpp
  1244. @@ -129,11 +129,11 @@
  1245. unsigned int nonstatic_oop_map_count,
  1246. AccessFlags access_flags,
  1247. ReferenceType rt,
  1248. - KlassHandle host_klass, TRAPS) {
  1249. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  1250. instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
  1251. return ikk->allocate_instance_klass(name, vtable_len, itable_len,
  1252. static_field_size, nonstatic_oop_map_count,
  1253. - access_flags, rt, host_klass, CHECK_NULL);
  1254. + access_flags, rt, host_klass, old_klass, CHECK_NULL);
  1255. }
  1256. diff --git a/src/share/vm/memory/oopFactory.hpp b/src/share/vm/memory/oopFactory.hpp
  1257. --- a/src/share/vm/memory/oopFactory.hpp
  1258. +++ b/src/share/vm/memory/oopFactory.hpp
  1259. @@ -80,7 +80,7 @@
  1260. unsigned int nonstatic_oop_map_count,
  1261. AccessFlags access_flags,
  1262. ReferenceType rt,
  1263. - KlassHandle host_klass, TRAPS);
  1264. + KlassHandle host_klass, KlassHandle old_klass, TRAPS);
  1265. // Methods
  1266. private:
  1267. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  1268. --- a/src/share/vm/memory/space.cpp
  1269. +++ b/src/share/vm/memory/space.cpp
  1270. @@ -378,9 +378,8 @@
  1271. _compaction_top = bottom();
  1272. }
  1273. -HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1274. - CompactPoint* cp, HeapWord* compact_top) {
  1275. - // q is alive
  1276. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  1277. +HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
  1278. // First check if we should switch compaction space
  1279. assert(this == cp->space, "'this' should be current compaction space.");
  1280. size_t compaction_max_size = pointer_delta(end(), compact_top);
  1281. @@ -400,8 +399,15 @@
  1282. compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  1283. }
  1284. + return compact_top;
  1285. +}
  1286. +
  1287. +HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1288. + CompactPoint* cp, HeapWord* compact_top) {
  1289. + compact_top = forward_compact_top(size, cp, compact_top);
  1290. +
  1291. // store the forwarding pointer into the mark word
  1292. - if ((HeapWord*)q != compact_top) {
  1293. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  1294. q->forward_to(oop(compact_top));
  1295. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  1296. } else {
  1297. @@ -423,6 +429,58 @@
  1298. return compact_top;
  1299. }
  1300. +// Compute the forward sizes and leave out objects whose position could
  1301. +// possibly overlap other objects.
  1302. +HeapWord* CompactibleSpace::forward_with_rescue(oop q, size_t size,
  1303. + CompactPoint* cp, HeapWord* compact_top) {
  1304. + size_t forward_size = size;
  1305. +
  1306. + // (DCEVM) There is a new version of the class of q => different size
  1307. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1308. +
  1309. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1310. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1311. + forward_size = new_size;
  1312. + }
  1313. +
  1314. + compact_top = forward_compact_top(forward_size, cp, compact_top);
  1315. +
  1316. + if (must_rescue(oop(q), oop(compact_top))) {
  1317. + if (MarkSweep::_rescued_oops == NULL) {
  1318. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1319. + }
  1320. + MarkSweep::_rescued_oops->append(oop(q));
  1321. + return compact_top;
  1322. + }
  1323. +
  1324. + return forward(q, forward_size, cp, compact_top);
  1325. +}
  1326. +
  1327. +// Compute the forwarding addresses for the objects that need to be rescued.
  1328. +HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
  1329. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  1330. + if (MarkSweep::_rescued_oops != NULL) {
  1331. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  1332. + oop q = MarkSweep::_rescued_oops->at(i);
  1333. +
  1334. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  1335. + size_t size = block_size((HeapWord*)q);
  1336. +
  1337. + // (tw) There is a new version of the class of q => different size
  1338. + if (oop(q)->blueprint()->new_version() != NULL) {
  1339. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1340. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1341. + size = new_size;
  1342. + }
  1343. +
  1344. + compact_top = cp->space->forward(oop(q), size, cp, compact_top);
  1345. + assert(compact_top <= end(), "must not write over end of space!");
  1346. + }
  1347. + MarkSweep::_rescued_oops->clear();
  1348. + MarkSweep::_rescued_oops = NULL;
  1349. + }
  1350. + return compact_top;
  1351. +}
  1352. bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1353. HeapWord* q, size_t deadlength) {
  1354. @@ -444,12 +502,17 @@
  1355. #define adjust_obj_size(s) s
  1356. void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  1357. - SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
  1358. + SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
  1359. }
  1360. // Faster object search.
  1361. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  1362. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  1363. + if (!Universe::is_redefining_gc_run()) {
  1364. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
  1365. + } else {
  1366. + // Redefinition run
  1367. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
  1368. + }
  1369. }
  1370. void Space::adjust_pointers() {
  1371. @@ -490,6 +553,111 @@
  1372. assert(q == t, "just checking");
  1373. }
  1374. +
  1375. +#ifdef ASSERT
  1376. +
  1377. +int CompactibleSpace::space_index(oop obj) {
  1378. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  1379. +
  1380. + if (heap->is_in_permanent(obj)) {
  1381. + return -1;
  1382. + }
  1383. +
  1384. + int index = 0;
  1385. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1386. + Generation* gen = heap->get_gen(i);
  1387. + CompactibleSpace* space = gen->first_compaction_space();
  1388. + while (space != NULL) {
  1389. + if (space->is_in_reserved(obj)) {
  1390. + return index;
  1391. + }
  1392. + space = space->next_compaction_space();
  1393. + index++;
  1394. + }
  1395. + }
  1396. +
  1397. + tty->print_cr("could not compute space_index for %08xh", obj);
  1398. + index = 0;
  1399. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1400. + Generation* gen = heap->get_gen(i);
  1401. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  1402. +
  1403. + CompactibleSpace* space = gen->first_compaction_space();
  1404. + while (space != NULL) {
  1405. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  1406. + space = space->next_compaction_space();
  1407. + index++;
  1408. + }
  1409. + }
  1410. +
  1411. + ShouldNotReachHere();
  1412. + return 0;
  1413. +}
  1414. +#endif
  1415. +
  1416. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  1417. + // Only redefined objects can have the need to be rescued.
  1418. + if (oop(old_obj)->blueprint()->new_version() == NULL) return false;
  1419. +
  1420. + if (old_obj->is_perm()) {
  1421. + // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
  1422. + return true;
  1423. + }
  1424. +
  1425. + int new_size = old_obj->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  1426. + int original_size = old_obj->size();
  1427. +
  1428. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  1429. + bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
  1430. + bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
  1431. + if (old_in_tenured == new_in_tenured) {
  1432. + // Rescue if object may overlap with a higher memory address.
  1433. + bool overlap = (old_obj + original_size < new_obj + new_size);
  1434. + if (old_in_tenured) {
  1435. + // Old and new address are in same space, so just compare the address.
  1436. + // Must rescue if object moves towards the top of the space.
  1437. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  1438. + } else {
  1439. + // In the new generation, eden is located before the from space, so a
  1440. + // simple pointer comparison is sufficient.
  1441. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1442. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1443. + assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  1444. + }
  1445. + return overlap;
  1446. +
  1447. + } else {
  1448. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  1449. + if (tenured_gen->is_in_reserved(new_obj)) {
  1450. + // Must never rescue when moving from the new into the old generation.
  1451. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1452. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  1453. + return false;
  1454. +
  1455. + } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
  1456. + // Must always rescue when moving from the old into the new generation.
  1457. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1458. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  1459. + return true;
  1460. + }
  1461. + }
  1462. +}
  1463. +
  1464. +oop CompactibleSpace::rescue(oop old_obj) {
  1465. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  1466. +
  1467. + int size = old_obj->size();
  1468. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1469. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  1470. +
  1471. + if (MarkSweep::_rescued_oops == NULL) {
  1472. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1473. + }
  1474. +
  1475. + MarkSweep::_rescued_oops->append(rescued_obj);
  1476. + return rescued_obj;
  1477. +}
  1478. +
  1479. void CompactibleSpace::adjust_pointers() {
  1480. // Check first is there is any work to do.
  1481. if (used() == 0) {
  1482. @@ -500,7 +668,13 @@
  1483. }
  1484. void CompactibleSpace::compact() {
  1485. - SCAN_AND_COMPACT(obj_size);
  1486. +
  1487. + if(!Universe::is_redefining_gc_run()) {
  1488. + SCAN_AND_COMPACT(obj_size, false);
  1489. + } else {
  1490. + // Redefinition run
  1491. + SCAN_AND_COMPACT(obj_size, true)
  1492. + }
  1493. }
  1494. void Space::print_short() const { print_short_on(tty); }
  1495. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  1496. --- a/src/share/vm/memory/space.hpp
  1497. +++ b/src/share/vm/memory/space.hpp
  1498. @@ -445,6 +445,9 @@
  1499. // indicates when the next such action should be taken.
  1500. virtual void prepare_for_compaction(CompactPoint* cp);
  1501. // MarkSweep support phase3
  1502. + DEBUG_ONLY(int space_index(oop obj));
  1503. + bool must_rescue(oop old_obj, oop new_obj);
  1504. + oop rescue(oop old_obj);
  1505. virtual void adjust_pointers();
  1506. // MarkSweep support phase4
  1507. virtual void compact();
  1508. @@ -474,6 +477,15 @@
  1509. // accordingly".
  1510. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  1511. HeapWord* compact_top);
  1512. + // (DCEVM) same as forwad, but can rescue objects. Invoked only during
  1513. + // redefinition runs
  1514. + HeapWord* forward_with_rescue(oop q, size_t size, CompactPoint* cp,
  1515. + HeapWord* compact_top);
  1516. +
  1517. + HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
  1518. +
  1519. + // (tw) Compute new compact top without actually forwarding the object.
  1520. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1521. // Return a size with adjusments as required of the space.
  1522. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  1523. @@ -504,7 +516,7 @@
  1524. size_t word_len);
  1525. };
  1526. -#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
  1527. +#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
  1528. /* Compute the new addresses for the live objects and store it in the mark \
  1529. * Used by universe::mark_sweep_phase2() \
  1530. */ \
  1531. @@ -564,7 +576,17 @@
  1532. Prefetch::write(q, interval); \
  1533. /* size_t size = oop(q)->size(); changing this for cms for perm gen */\
  1534. size_t size = block_size(q); \
  1535. - compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1536. + if (redefinition_run) { \
  1537. + compact_top = cp->space->forward_with_rescue(oop(q), size, \
  1538. + cp, compact_top); \
  1539. + if (q < first_dead && oop(q)->is_gc_marked()) { \
  1540. + /* Was moved (otherwise, forward would reset mark), \
  1541. + set first_dead to here */ \
  1542. + first_dead = q; \
  1543. + } \
  1544. + } else { \
  1545. + compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1546. + } \
  1547. q += size; \
  1548. end_of_live = q; \
  1549. } else { \
  1550. @@ -613,6 +635,8 @@
  1551. } \
  1552. } \
  1553. \
  1554. + if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
  1555. + \
  1556. assert(q == t, "just checking"); \
  1557. if (liveRange != NULL) { \
  1558. liveRange->set_end(q); \
  1559. @@ -665,13 +689,8 @@
  1560. q += size; \
  1561. } \
  1562. \
  1563. - if (_first_dead == t) { \
  1564. - q = t; \
  1565. - } else { \
  1566. - /* $$$ This is funky. Using this to read the previously written \
  1567. - * LiveRange. See also use below. */ \
  1568. - q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
  1569. - } \
  1570. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1571. + q = _first_dead; \
  1572. } \
  1573. \
  1574. const intx interval = PrefetchScanIntervalInBytes; \
  1575. @@ -702,7 +721,7 @@
  1576. assert(q == t, "just checking"); \
  1577. }
  1578. -#define SCAN_AND_COMPACT(obj_size) { \
  1579. +#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
  1580. /* Copy all live objects to their new location \
  1581. * Used by MarkSweep::mark_sweep_phase4() */ \
  1582. \
  1583. @@ -728,12 +747,8 @@
  1584. } \
  1585. ) /* debug_only */ \
  1586. \
  1587. - if (_first_dead == t) { \
  1588. - q = t; \
  1589. - } else { \
  1590. - /* $$$ Funky */ \
  1591. - q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
  1592. - } \
  1593. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1594. + q = _first_dead; \
  1595. } \
  1596. \
  1597. const intx scan_interval = PrefetchScanIntervalInBytes; \
  1598. @@ -752,13 +767,36 @@
  1599. size_t size = obj_size(q); \
  1600. HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
  1601. \
  1602. + if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
  1603. + oop dest_obj = rescue(oop(q)); \
  1604. + debug_only(Copy::fill_to_words(q, size, 0)); \
  1605. + q += size; \
  1606. + continue; \
  1607. + } \
  1608. + \
  1609. /* prefetch beyond compaction_top */ \
  1610. Prefetch::write(compaction_top, copy_interval); \
  1611. \
  1612. /* copy object and reinit its mark */ \
  1613. VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, \
  1614. compaction_top)); \
  1615. - assert(q != compaction_top, "everything in this pass should be moving"); \
  1616. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, \
  1617. + "everything in this pass should be moving"); \
  1618. + if (redefinition_run && oop(q)->blueprint()->new_version() != NULL) { \
  1619. + klassOop new_version = oop(q)->blueprint()->new_version(); \
  1620. + if (new_version->klass_part()->update_information() == NULL) { \
  1621. + Copy::aligned_conjoint_words(q, compaction_top, size); \
  1622. + oop(compaction_top)->set_klass_no_check(new_version); \
  1623. + } else { \
  1624. + MarkSweep::update_fields(oop(q), oop(compaction_top)); \
  1625. + } \
  1626. + oop(compaction_top)->init_mark(); \
  1627. + assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1628. + \
  1629. + debug_only(prev_q = q); \
  1630. + q += size; \
  1631. + continue; \
  1632. + } \
  1633. Copy::aligned_conjoint_words(q, compaction_top, size); \
  1634. oop(compaction_top)->init_mark(); \
  1635. assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1636. diff --git a/src/share/vm/memory/specialized_oop_closures.hpp b/src/share/vm/memory/specialized_oop_closures.hpp
  1637. --- a/src/share/vm/memory/specialized_oop_closures.hpp
  1638. +++ b/src/share/vm/memory/specialized_oop_closures.hpp
  1639. @@ -37,6 +37,7 @@
  1640. // Forward declarations.
  1641. class OopClosure;
  1642. +class OopClosureNoHeader;
  1643. class OopsInGenClosure;
  1644. // DefNew
  1645. class ScanClosure;
  1646. @@ -74,6 +75,7 @@
  1647. #endif
  1648. #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
  1649. + f(OopClosureNoHeader,_v) \
  1650. f(ScanClosure,_nv) \
  1651. f(FastScanClosure,_nv) \
  1652. f(FilteringClosure,_nv)
  1653. @@ -132,6 +134,7 @@
  1654. #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
  1655. f(OopClosure,_v) \
  1656. + f(OopClosureNoHeader,_v) \
  1657. SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
  1658. #endif // SERIALGC
  1659. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  1660. --- a/src/share/vm/memory/universe.cpp
  1661. +++ b/src/share/vm/memory/universe.cpp
  1662. @@ -100,6 +100,8 @@
  1663. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  1664. #endif
  1665. +bool Universe::_is_redefining_gc_run = false;
  1666. +
  1667. // Known objects
  1668. klassOop Universe::_boolArrayKlassObj = NULL;
  1669. klassOop Universe::_byteArrayKlassObj = NULL;
  1670. @@ -204,6 +206,42 @@
  1671. f(systemObjArrayKlassObj());
  1672. }
  1673. +// (tw) This method should iterate all pointers that are not within heap objects.
  1674. +void Universe::root_oops_do(OopClosure *oopClosure) {
  1675. +
  1676. + class AlwaysTrueClosure: public BoolObjectClosure {
  1677. + public:
  1678. + void do_object(oop p) { ShouldNotReachHere(); }
  1679. + bool do_object_b(oop p) { return true; }
  1680. + };
  1681. + AlwaysTrueClosure always_true;
  1682. +
  1683. + Universe::oops_do(oopClosure);
  1684. +// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
  1685. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  1686. + Threads::oops_do(oopClosure, NULL);
  1687. + ObjectSynchronizer::oops_do(oopClosure);
  1688. + FlatProfiler::oops_do(oopClosure);
  1689. + JvmtiExport::oops_do(oopClosure);
  1690. +
  1691. + // Now adjust pointers in remaining weak roots. (All of which should
  1692. + // have been cleared if they pointed to non-surviving objects.)
  1693. + // Global (weak) JNI handles
  1694. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  1695. +
  1696. + CodeCache::oops_do(oopClosure);
  1697. + StringTable::oops_do(oopClosure);
  1698. +
  1699. + // (tw) TODO: Check if this is correct?
  1700. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  1701. + //Management::oops_do(oopClosure);
  1702. + //ref_processor()->weak_oops_do(&oopClosure);
  1703. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  1704. +
  1705. + // SO_AllClasses
  1706. + SystemDictionary::oops_do(oopClosure);
  1707. +}
  1708. +
  1709. void Universe::oops_do(OopClosure* f, bool do_all) {
  1710. f->do_oop((oop*) &_int_mirror);
  1711. @@ -1599,10 +1637,9 @@
  1712. }
  1713. // RC_TRACE macro has an embedded ResourceMark
  1714. - RC_TRACE(0x00000100,
  1715. - ("add: %s(%s): adding prev version ref for cached method @%d",
  1716. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  1717. method->name()->as_C_string(), method->signature()->as_C_string(),
  1718. - _prev_methods->length()));
  1719. + _prev_methods->length());
  1720. methodHandle method_h(method);
  1721. jweak method_ref = JNIHandles::make_weak_global(method_h);
  1722. @@ -1629,9 +1666,8 @@
  1723. JNIHandles::destroy_weak_global(method_ref);
  1724. _prev_methods->remove_at(i);
  1725. } else {
  1726. - // RC_TRACE macro has an embedded ResourceMark
  1727. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  1728. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  1729. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  1730. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  1731. }
  1732. }
  1733. } // end add_previous_version()
  1734. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  1735. --- a/src/share/vm/memory/universe.hpp
  1736. +++ b/src/share/vm/memory/universe.hpp
  1737. @@ -127,6 +127,8 @@
  1738. friend class SystemDictionary;
  1739. friend class VMStructs;
  1740. friend class CompactingPermGenGen;
  1741. + friend class Space;
  1742. + friend class ContiguousSpace;
  1743. friend class VM_PopulateDumpSharedSpace;
  1744. friend jint universe_init();
  1745. @@ -258,7 +260,18 @@
  1746. static void compute_verify_oop_data();
  1747. + static bool _is_redefining_gc_run;
  1748. +
  1749. public:
  1750. +
  1751. + static bool is_redefining_gc_run() {
  1752. + return _is_redefining_gc_run;
  1753. + }
  1754. +
  1755. + static void set_redefining_gc_run(bool b) {
  1756. + _is_redefining_gc_run = b;
  1757. + }
  1758. +
  1759. // Known classes in the VM
  1760. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  1761. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  1762. @@ -403,6 +416,8 @@
  1763. // Iteration
  1764. + static void root_oops_do(OopClosure *f);
  1765. +
  1766. // Apply "f" to the addresses of all the direct heap pointers maintained
  1767. // as static fields of "Universe".
  1768. static void oops_do(OopClosure* f, bool do_all = false);
  1769. @@ -419,6 +434,7 @@
  1770. // Debugging
  1771. static bool verify_in_progress() { return _verify_in_progress; }
  1772. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  1773. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  1774. static void verify(const char* prefix, bool silent = VerifySilently) {
  1775. verify(VerifyOption_Default, prefix, silent);
  1776. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  1777. --- a/src/share/vm/oops/cpCacheOop.cpp
  1778. +++ b/src/share/vm/oops/cpCacheOop.cpp
  1779. @@ -40,6 +40,11 @@
  1780. void ConstantPoolCacheEntry::initialize_entry(int index) {
  1781. assert(0 < index && index < 0x10000, "sanity check");
  1782. _indices = index;
  1783. +// (DCEVM) Should put something else to force JVM to fail if these invalid entries are accessed!
  1784. +//#ifdef ASSERT
  1785. + _f1 = NULL;
  1786. + _f2 = 0;
  1787. +//#endif
  1788. assert(constant_pool_index() == index, "");
  1789. }
  1790. @@ -162,7 +167,8 @@
  1791. int vtable_index) {
  1792. assert(!is_secondary_entry(), "");
  1793. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  1794. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1795. + // (tw) No longer valid assert
  1796. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1797. int byte_no = -1;
  1798. bool change_to_virtual = false;
  1799. @@ -516,116 +522,6 @@
  1800. }
  1801. #endif // SERIALGC
  1802. -// RedefineClasses() API support:
  1803. -// If this constantPoolCacheEntry refers to old_method then update it
  1804. -// to refer to new_method.
  1805. -bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  1806. - methodOop new_method, bool * trace_name_printed) {
  1807. -
  1808. - if (is_vfinal()) {
  1809. - // virtual and final so _f2 contains method ptr instead of vtable index
  1810. - if (f2_as_vfinal_method() == old_method) {
  1811. - // match old_method so need an update
  1812. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  1813. - _f2 = (intptr_t)new_method;
  1814. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1815. - if (!(*trace_name_printed)) {
  1816. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1817. - RC_TRACE_MESG(("adjust: name=%s",
  1818. - Klass::cast(old_method->method_holder())->external_name()));
  1819. - *trace_name_printed = true;
  1820. - }
  1821. - // RC_TRACE macro has an embedded ResourceMark
  1822. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  1823. - new_method->name()->as_C_string(),
  1824. - new_method->signature()->as_C_string()));
  1825. - }
  1826. -
  1827. - return true;
  1828. - }
  1829. -
  1830. - // f1() is not used with virtual entries so bail out
  1831. - return false;
  1832. - }
  1833. -
  1834. - if ((oop)_f1 == NULL) {
  1835. - // NULL f1() means this is a virtual entry so bail out
  1836. - // We are assuming that the vtable index does not need change.
  1837. - return false;
  1838. - }
  1839. -
  1840. - if ((oop)_f1 == old_method) {
  1841. - _f1 = new_method;
  1842. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1843. - if (!(*trace_name_printed)) {
  1844. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1845. - RC_TRACE_MESG(("adjust: name=%s",
  1846. - Klass::cast(old_method->method_holder())->external_name()));
  1847. - *trace_name_printed = true;
  1848. - }
  1849. - // RC_TRACE macro has an embedded ResourceMark
  1850. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  1851. - new_method->name()->as_C_string(),
  1852. - new_method->signature()->as_C_string()));
  1853. - }
  1854. -
  1855. - return true;
  1856. - }
  1857. -
  1858. - return false;
  1859. -}
  1860. -
  1861. -// a constant pool cache entry should never contain old or obsolete methods
  1862. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  1863. - if (is_vfinal()) {
  1864. - // virtual and final so _f2 contains method ptr instead of vtable index
  1865. - methodOop m = (methodOop)_f2;
  1866. - // Return false if _f2 refers to an old or an obsolete method.
  1867. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  1868. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  1869. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  1870. - // _f1 == NULL || !_f1->is_method() are OK here
  1871. - return true;
  1872. - }
  1873. -
  1874. - methodOop m = (methodOop)_f1;
  1875. - // return false if _f1 refers to an old or an obsolete method
  1876. - return (!m->is_old() && !m->is_obsolete());
  1877. -}
  1878. -
  1879. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  1880. - if (!is_method_entry()) {
  1881. - // not a method entry so not interesting by default
  1882. - return false;
  1883. - }
  1884. -
  1885. - methodOop m = NULL;
  1886. - if (is_vfinal()) {
  1887. - // virtual and final so _f2 contains method ptr instead of vtable index
  1888. - m = f2_as_vfinal_method();
  1889. - } else if (is_f1_null()) {
  1890. - // NULL _f1 means this is a virtual entry so also not interesting
  1891. - return false;
  1892. - } else {
  1893. - oop f1 = _f1; // _f1 is volatile
  1894. - if (!f1->is_method()) {
  1895. - // _f1 can also contain a klassOop for an interface
  1896. - return false;
  1897. - }
  1898. - m = f1_as_method();
  1899. - }
  1900. -
  1901. - assert(m != NULL && m->is_method(), "sanity check");
  1902. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  1903. - // robustness for above sanity checks or method is not in
  1904. - // the interesting class
  1905. - return false;
  1906. - }
  1907. -
  1908. - // the method is in the interesting class so the entry is interesting
  1909. - return true;
  1910. -}
  1911. -
  1912. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  1913. // print separator
  1914. if (index == 0) st->print_cr(" -------------");
  1915. @@ -663,60 +559,12 @@
  1916. }
  1917. }
  1918. -// RedefineClasses() API support:
  1919. -// If any entry of this constantPoolCache points to any of
  1920. -// old_methods, replace it with the corresponding new_method.
  1921. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  1922. - int methods_length, bool * trace_name_printed) {
  1923. -
  1924. - if (methods_length == 0) {
  1925. - // nothing to do if there are no methods
  1926. - return;
  1927. - }
  1928. -
  1929. - // get shorthand for the interesting class
  1930. - klassOop old_holder = old_methods[0]->method_holder();
  1931. +void constantPoolCacheOopDesc::adjust_entries() {
  1932. for (int i = 0; i < length(); i++) {
  1933. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  1934. - // skip uninteresting methods
  1935. - continue;
  1936. - }
  1937. -
  1938. - // The constantPoolCache contains entries for several different
  1939. - // things, but we only care about methods. In fact, we only care
  1940. - // about methods in the same class as the one that contains the
  1941. - // old_methods. At this point, we have an interesting entry.
  1942. -
  1943. - for (int j = 0; j < methods_length; j++) {
  1944. - methodOop old_method = old_methods[j];
  1945. - methodOop new_method = new_methods[j];
  1946. -
  1947. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  1948. - trace_name_printed)) {
  1949. - // current old_method matched this entry and we updated it so
  1950. - // break out and get to the next interesting entry if there one
  1951. - break;
  1952. - }
  1953. - }
  1954. + if (!entry_at(i)->is_secondary_entry()) {
  1955. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  1956. + }
  1957. }
  1958. }
  1959. -// the constant pool cache should never contain old or obsolete methods
  1960. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  1961. - for (int i = 1; i < length(); i++) {
  1962. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  1963. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  1964. - return false;
  1965. - }
  1966. - }
  1967. - return true;
  1968. -}
  1969. -
  1970. -void constantPoolCacheOopDesc::dump_cache() {
  1971. - for (int i = 1; i < length(); i++) {
  1972. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  1973. - entry_at(i)->print(tty, i);
  1974. - }
  1975. - }
  1976. -}
  1977. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  1978. --- a/src/share/vm/oops/cpCacheOop.hpp
  1979. +++ b/src/share/vm/oops/cpCacheOop.hpp
  1980. @@ -355,17 +355,6 @@
  1981. void update_pointers();
  1982. - // RedefineClasses() API support:
  1983. - // If this constantPoolCacheEntry refers to old_method then update it
  1984. - // to refer to new_method.
  1985. - // trace_name_printed is set to true if the current call has
  1986. - // printed the klass name so that other routines in the adjust_*
  1987. - // group don't print the klass name.
  1988. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  1989. - bool * trace_name_printed);
  1990. - bool check_no_old_or_obsolete_entries();
  1991. - bool is_interesting_method_entry(klassOop k);
  1992. -
  1993. // Debugging & Printing
  1994. void print (outputStream* st, int index) const;
  1995. void verify(outputStream* st) const;
  1996. @@ -485,16 +474,8 @@
  1997. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  1998. }
  1999. - // RedefineClasses() API support:
  2000. - // If any entry of this constantPoolCache points to any of
  2001. - // old_methods, replace it with the corresponding new_method.
  2002. - // trace_name_printed is set to true if the current call has
  2003. - // printed the klass name so that other routines in the adjust_*
  2004. - // group don't print the klass name.
  2005. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  2006. - int methods_length, bool * trace_name_printed);
  2007. - bool check_no_old_or_obsolete_entries();
  2008. - void dump_cache();
  2009. + // (tw) Clear references to methods and fields from this cache.
  2010. + void adjust_entries();
  2011. };
  2012. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  2013. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  2014. --- a/src/share/vm/oops/instanceKlass.cpp
  2015. +++ b/src/share/vm/oops/instanceKlass.cpp
  2016. @@ -255,7 +255,7 @@
  2017. // 1) Verify the bytecodes
  2018. Verifier::Mode mode =
  2019. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  2020. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  2021. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  2022. }
  2023. @@ -362,7 +362,13 @@
  2024. jt->get_thread_stat()->perf_recursion_counts_addr(),
  2025. jt->get_thread_stat()->perf_timers_addr(),
  2026. PerfClassTraceTime::CLASS_VERIFY);
  2027. + if (this_oop->is_redefining()) {
  2028. + Thread::current()->set_pretend_new_universe(true);
  2029. + }
  2030. bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  2031. + if (this_oop->is_redefining()) {
  2032. + Thread::current()->set_pretend_new_universe(false);
  2033. + }
  2034. if (!verify_ok) {
  2035. return false;
  2036. }
  2037. @@ -400,7 +406,8 @@
  2038. }
  2039. #endif
  2040. this_oop->set_init_state(linked);
  2041. - if (JvmtiExport::should_post_class_prepare()) {
  2042. + // (tw) Must check for old version in order to prevent infinite loops.
  2043. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  2044. Thread *thread = THREAD;
  2045. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  2046. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  2047. @@ -454,7 +461,9 @@
  2048. // If we were to use wait() instead of waitInterruptibly() then
  2049. // we might end up throwing IE from link/symbol resolution sites
  2050. // that aren't expected to throw. This would wreak havoc. See 6320309.
  2051. - while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
  2052. + // (tw) Wait also for the old class version to be fully initialized.
  2053. + while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
  2054. + || (this_oop->old_version() != NULL && ((instanceKlass*)this_oop->old_version()->klass_part())->is_being_initialized())) {
  2055. wait = true;
  2056. ol.waitUninterruptibly(CHECK);
  2057. }
  2058. @@ -673,6 +682,18 @@
  2059. return false;
  2060. }
  2061. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  2062. + k = k->klass_part()->newest_version();
  2063. + if (this->newest_version() == k) return true;
  2064. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  2065. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  2066. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  2067. + return true;
  2068. + }
  2069. + }
  2070. + return false;
  2071. +}
  2072. +
  2073. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  2074. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  2075. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  2076. @@ -949,6 +970,18 @@
  2077. }
  2078. }
  2079. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  2080. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  2081. + for (int i=0; i<values.length(); i++) {
  2082. + arr[i] = values.at(i);
  2083. + }
  2084. + set_update_information(arr);
  2085. +}
  2086. +
  2087. +void instanceKlass::clear_update_information() {
  2088. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  2089. + set_update_information(NULL);
  2090. +}
  2091. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  2092. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  2093. @@ -1368,6 +1401,20 @@
  2094. return id;
  2095. }
  2096. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  2097. + size_t idnum = (size_t)method->method_idnum();
  2098. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  2099. + size_t length; // length assigned as debugging crumb
  2100. + jmethodID id = NULL;
  2101. + if (jmeths != NULL && // If there is a cache
  2102. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  2103. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  2104. + return true;
  2105. + }
  2106. +
  2107. + return false;
  2108. +}
  2109. +
  2110. // Cache an itable index
  2111. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  2112. @@ -1527,6 +1574,13 @@
  2113. last = b;
  2114. b = b->next();
  2115. }
  2116. +
  2117. + // (tw) Hack as dependencies get wrong version of klassOop
  2118. + if(this->old_version() != NULL) {
  2119. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  2120. + return;
  2121. + }
  2122. +
  2123. #ifdef ASSERT
  2124. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  2125. nm->print();
  2126. @@ -1933,16 +1987,6 @@
  2127. assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2128. }
  2129. - // deallocate information about previous versions
  2130. - if (_previous_versions != NULL) {
  2131. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2132. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2133. - delete pv_node;
  2134. - }
  2135. - delete _previous_versions;
  2136. - _previous_versions = NULL;
  2137. - }
  2138. -
  2139. // deallocate the cached class file
  2140. if (_cached_class_file_bytes != NULL) {
  2141. os::free(_cached_class_file_bytes, mtClass);
  2142. @@ -2580,275 +2624,10 @@
  2143. }
  2144. #endif
  2145. -
  2146. -// RedefineClasses() support for previous versions:
  2147. -
  2148. -// Add an information node that contains weak references to the
  2149. -// interesting parts of the previous version of the_class.
  2150. -// This is also where we clean out any unused weak references.
  2151. -// Note that while we delete nodes from the _previous_versions
  2152. -// array, we never delete the array itself until the klass is
  2153. -// unloaded. The has_been_redefined() query depends on that fact.
  2154. -//
  2155. -void instanceKlass::add_previous_version(instanceKlassHandle ikh,
  2156. - BitMap* emcp_methods, int emcp_method_count) {
  2157. - assert(Thread::current()->is_VM_thread(),
  2158. - "only VMThread can add previous versions");
  2159. -
  2160. - if (_previous_versions == NULL) {
  2161. - // This is the first previous version so make some space.
  2162. - // Start with 2 elements under the assumption that the class
  2163. - // won't be redefined much.
  2164. - _previous_versions = new (ResourceObj::C_HEAP, mtClass)
  2165. - GrowableArray<PreviousVersionNode *>(2, true);
  2166. - }
  2167. -
  2168. - // RC_TRACE macro has an embedded ResourceMark
  2169. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  2170. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  2171. - constantPoolHandle cp_h(ikh->constants());
  2172. - jobject cp_ref;
  2173. - if (cp_h->is_shared()) {
  2174. - // a shared ConstantPool requires a regular reference; a weak
  2175. - // reference would be collectible
  2176. - cp_ref = JNIHandles::make_global(cp_h);
  2177. - } else {
  2178. - cp_ref = JNIHandles::make_weak_global(cp_h);
  2179. - }
  2180. - PreviousVersionNode * pv_node = NULL;
  2181. - objArrayOop old_methods = ikh->methods();
  2182. -
  2183. - if (emcp_method_count == 0) {
  2184. - // non-shared ConstantPool gets a weak reference
  2185. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  2186. - RC_TRACE(0x00000400,
  2187. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  2188. - } else {
  2189. - int local_count = 0;
  2190. - GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass)
  2191. - GrowableArray<jweak>(emcp_method_count, true);
  2192. - for (int i = 0; i < old_methods->length(); i++) {
  2193. - if (emcp_methods->at(i)) {
  2194. - // this old method is EMCP so save a weak ref
  2195. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2196. - methodHandle old_method_h(old_method);
  2197. - jweak method_ref = JNIHandles::make_weak_global(old_method_h);
  2198. - method_refs->append(method_ref);
  2199. - if (++local_count >= emcp_method_count) {
  2200. - // no more EMCP methods so bail out now
  2201. - break;
  2202. - }
  2203. - }
  2204. - }
  2205. - // non-shared ConstantPool gets a weak reference
  2206. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs);
  2207. - }
  2208. -
  2209. - _previous_versions->append(pv_node);
  2210. -
  2211. - // Using weak references allows the interesting parts of previous
  2212. - // classes to be GC'ed when they are no longer needed. Since the
  2213. - // caller is the VMThread and we are at a safepoint, this is a good
  2214. - // time to clear out unused weak references.
  2215. -
  2216. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  2217. - _previous_versions->length()));
  2218. -
  2219. - // skip the last entry since we just added it
  2220. - for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  2221. - // check the previous versions array for a GC'ed weak refs
  2222. - pv_node = _previous_versions->at(i);
  2223. - cp_ref = pv_node->prev_constant_pool();
  2224. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2225. - if (cp_ref == NULL) {
  2226. - delete pv_node;
  2227. - _previous_versions->remove_at(i);
  2228. - // Since we are traversing the array backwards, we don't have to
  2229. - // do anything special with the index.
  2230. - continue; // robustness
  2231. - }
  2232. -
  2233. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2234. - if (cp == NULL) {
  2235. - // this entry has been GC'ed so remove it
  2236. - delete pv_node;
  2237. - _previous_versions->remove_at(i);
  2238. - // Since we are traversing the array backwards, we don't have to
  2239. - // do anything special with the index.
  2240. - continue;
  2241. - } else {
  2242. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  2243. - }
  2244. -
  2245. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2246. - if (method_refs != NULL) {
  2247. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  2248. - method_refs->length()));
  2249. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  2250. - jweak method_ref = method_refs->at(j);
  2251. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2252. - if (method_ref == NULL) {
  2253. - method_refs->remove_at(j);
  2254. - // Since we are traversing the array backwards, we don't have to
  2255. - // do anything special with the index.
  2256. - continue; // robustness
  2257. - }
  2258. -
  2259. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2260. - if (method == NULL || emcp_method_count == 0) {
  2261. - // This method entry has been GC'ed or the current
  2262. - // RedefineClasses() call has made all methods obsolete
  2263. - // so remove it.
  2264. - JNIHandles::destroy_weak_global(method_ref);
  2265. - method_refs->remove_at(j);
  2266. - } else {
  2267. - // RC_TRACE macro has an embedded ResourceMark
  2268. - RC_TRACE(0x00000400,
  2269. - ("add: %s(%s): previous method @%d in version @%d is alive",
  2270. - method->name()->as_C_string(), method->signature()->as_C_string(),
  2271. - j, i));
  2272. - }
  2273. - }
  2274. - }
  2275. - }
  2276. -
  2277. - int obsolete_method_count = old_methods->length() - emcp_method_count;
  2278. -
  2279. - if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  2280. - _previous_versions->length() > 1) {
  2281. - // We have a mix of obsolete and EMCP methods. If there is more
  2282. - // than the previous version that we just added, then we have to
  2283. - // clear out any matching EMCP method entries the hard way.
  2284. - int local_count = 0;
  2285. - for (int i = 0; i < old_methods->length(); i++) {
  2286. - if (!emcp_methods->at(i)) {
  2287. - // only obsolete methods are interesting
  2288. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2289. - Symbol* m_name = old_method->name();
  2290. - Symbol* m_signature = old_method->signature();
  2291. -
  2292. - // skip the last entry since we just added it
  2293. - for (int j = _previous_versions->length() - 2; j >= 0; j--) {
  2294. - // check the previous versions array for a GC'ed weak refs
  2295. - pv_node = _previous_versions->at(j);
  2296. - cp_ref = pv_node->prev_constant_pool();
  2297. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2298. - if (cp_ref == NULL) {
  2299. - delete pv_node;
  2300. - _previous_versions->remove_at(j);
  2301. - // Since we are traversing the array backwards, we don't have to
  2302. - // do anything special with the index.
  2303. - continue; // robustness
  2304. - }
  2305. -
  2306. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2307. - if (cp == NULL) {
  2308. - // this entry has been GC'ed so remove it
  2309. - delete pv_node;
  2310. - _previous_versions->remove_at(j);
  2311. - // Since we are traversing the array backwards, we don't have to
  2312. - // do anything special with the index.
  2313. - continue;
  2314. - }
  2315. -
  2316. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2317. - if (method_refs == NULL) {
  2318. - // We have run into a PreviousVersion generation where
  2319. - // all methods were made obsolete during that generation's
  2320. - // RedefineClasses() operation. At the time of that
  2321. - // operation, all EMCP methods were flushed so we don't
  2322. - // have to go back any further.
  2323. - //
  2324. - // A NULL method_refs is different than an empty method_refs.
  2325. - // We cannot infer any optimizations about older generations
  2326. - // from an empty method_refs for the current generation.
  2327. - break;
  2328. - }
  2329. -
  2330. - for (int k = method_refs->length() - 1; k >= 0; k--) {
  2331. - jweak method_ref = method_refs->at(k);
  2332. - assert(method_ref != NULL,
  2333. - "weak method ref was unexpectedly cleared");
  2334. - if (method_ref == NULL) {
  2335. - method_refs->remove_at(k);
  2336. - // Since we are traversing the array backwards, we don't
  2337. - // have to do anything special with the index.
  2338. - continue; // robustness
  2339. - }
  2340. -
  2341. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2342. - if (method == NULL) {
  2343. - // this method entry has been GC'ed so skip it
  2344. - JNIHandles::destroy_weak_global(method_ref);
  2345. - method_refs->remove_at(k);
  2346. - continue;
  2347. - }
  2348. -
  2349. - if (method->name() == m_name &&
  2350. - method->signature() == m_signature) {
  2351. - // The current RedefineClasses() call has made all EMCP
  2352. - // versions of this method obsolete so mark it as obsolete
  2353. - // and remove the weak ref.
  2354. - RC_TRACE(0x00000400,
  2355. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  2356. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  2357. -
  2358. - method->set_is_obsolete();
  2359. - JNIHandles::destroy_weak_global(method_ref);
  2360. - method_refs->remove_at(k);
  2361. - break;
  2362. - }
  2363. - }
  2364. -
  2365. - // The previous loop may not find a matching EMCP method, but
  2366. - // that doesn't mean that we can optimize and not go any
  2367. - // further back in the PreviousVersion generations. The EMCP
  2368. - // method for this generation could have already been GC'ed,
  2369. - // but there still may be an older EMCP method that has not
  2370. - // been GC'ed.
  2371. - }
  2372. -
  2373. - if (++local_count >= obsolete_method_count) {
  2374. - // no more obsolete methods so bail out now
  2375. - break;
  2376. - }
  2377. - }
  2378. - }
  2379. - }
  2380. -} // end add_previous_version()
  2381. -
  2382. -
  2383. // Determine if instanceKlass has a previous version.
  2384. bool instanceKlass::has_previous_version() const {
  2385. - if (_previous_versions == NULL) {
  2386. - // no previous versions array so answer is easy
  2387. - return false;
  2388. - }
  2389. -
  2390. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2391. - // Check the previous versions array for an info node that hasn't
  2392. - // been GC'ed
  2393. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2394. -
  2395. - jobject cp_ref = pv_node->prev_constant_pool();
  2396. - assert(cp_ref != NULL, "cp reference was unexpectedly cleared");
  2397. - if (cp_ref == NULL) {
  2398. - continue; // robustness
  2399. - }
  2400. -
  2401. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2402. - if (cp != NULL) {
  2403. - // we have at least one previous version
  2404. - return true;
  2405. - }
  2406. -
  2407. - // We don't have to check the method refs. If the constant pool has
  2408. - // been GC'ed then so have the methods.
  2409. - }
  2410. -
  2411. - // all of the underlying nodes' info has been GC'ed
  2412. - return false;
  2413. -} // end has_previous_version()
  2414. + return _old_version != NULL;
  2415. +}
  2416. methodOop instanceKlass::method_with_idnum(int idnum) {
  2417. methodOop m = NULL;
  2418. @@ -2889,153 +2668,3 @@
  2419. } // if no array and idnum isn't included there is nothing to do
  2420. }
  2421. -// Construct a PreviousVersionNode entry for the array hung off
  2422. -// the instanceKlass.
  2423. -PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool,
  2424. - bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) {
  2425. -
  2426. - _prev_constant_pool = prev_constant_pool;
  2427. - _prev_cp_is_weak = prev_cp_is_weak;
  2428. - _prev_EMCP_methods = prev_EMCP_methods;
  2429. -}
  2430. -
  2431. -
  2432. -// Destroy a PreviousVersionNode
  2433. -PreviousVersionNode::~PreviousVersionNode() {
  2434. - if (_prev_constant_pool != NULL) {
  2435. - if (_prev_cp_is_weak) {
  2436. - JNIHandles::destroy_weak_global(_prev_constant_pool);
  2437. - } else {
  2438. - JNIHandles::destroy_global(_prev_constant_pool);
  2439. - }
  2440. - }
  2441. -
  2442. - if (_prev_EMCP_methods != NULL) {
  2443. - for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) {
  2444. - jweak method_ref = _prev_EMCP_methods->at(i);
  2445. - if (method_ref != NULL) {
  2446. - JNIHandles::destroy_weak_global(method_ref);
  2447. - }
  2448. - }
  2449. - delete _prev_EMCP_methods;
  2450. - }
  2451. -}
  2452. -
  2453. -
  2454. -// Construct a PreviousVersionInfo entry
  2455. -PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) {
  2456. - _prev_constant_pool_handle = constantPoolHandle(); // NULL handle
  2457. - _prev_EMCP_method_handles = NULL;
  2458. -
  2459. - jobject cp_ref = pv_node->prev_constant_pool();
  2460. - assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared");
  2461. - if (cp_ref == NULL) {
  2462. - return; // robustness
  2463. - }
  2464. -
  2465. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2466. - if (cp == NULL) {
  2467. - // Weak reference has been GC'ed. Since the constant pool has been
  2468. - // GC'ed, the methods have also been GC'ed.
  2469. - return;
  2470. - }
  2471. -
  2472. - // make the constantPoolOop safe to return
  2473. - _prev_constant_pool_handle = constantPoolHandle(cp);
  2474. -
  2475. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2476. - if (method_refs == NULL) {
  2477. - // the instanceKlass did not have any EMCP methods
  2478. - return;
  2479. - }
  2480. -
  2481. - _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10);
  2482. -
  2483. - int n_methods = method_refs->length();
  2484. - for (int i = 0; i < n_methods; i++) {
  2485. - jweak method_ref = method_refs->at(i);
  2486. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2487. - if (method_ref == NULL) {
  2488. - continue; // robustness
  2489. - }
  2490. -
  2491. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2492. - if (method == NULL) {
  2493. - // this entry has been GC'ed so skip it
  2494. - continue;
  2495. - }
  2496. -
  2497. - // make the methodOop safe to return
  2498. - _prev_EMCP_method_handles->append(methodHandle(method));
  2499. - }
  2500. -}
  2501. -
  2502. -
  2503. -// Destroy a PreviousVersionInfo
  2504. -PreviousVersionInfo::~PreviousVersionInfo() {
  2505. - // Since _prev_EMCP_method_handles is not C-heap allocated, we
  2506. - // don't have to delete it.
  2507. -}
  2508. -
  2509. -
  2510. -// Construct a helper for walking the previous versions array
  2511. -PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) {
  2512. - _previous_versions = ik->previous_versions();
  2513. - _current_index = 0;
  2514. - // _hm needs no initialization
  2515. - _current_p = NULL;
  2516. -}
  2517. -
  2518. -
  2519. -// Destroy a PreviousVersionWalker
  2520. -PreviousVersionWalker::~PreviousVersionWalker() {
  2521. - // Delete the current info just in case the caller didn't walk to
  2522. - // the end of the previous versions list. No harm if _current_p is
  2523. - // already NULL.
  2524. - delete _current_p;
  2525. -
  2526. - // When _hm is destroyed, all the Handles returned in
  2527. - // PreviousVersionInfo objects will be destroyed.
  2528. - // Also, after this destructor is finished it will be
  2529. - // safe to delete the GrowableArray allocated in the
  2530. - // PreviousVersionInfo objects.
  2531. -}
  2532. -
  2533. -
  2534. -// Return the interesting information for the next previous version
  2535. -// of the klass. Returns NULL if there are no more previous versions.
  2536. -PreviousVersionInfo* PreviousVersionWalker::next_previous_version() {
  2537. - if (_previous_versions == NULL) {
  2538. - // no previous versions so nothing to return
  2539. - return NULL;
  2540. - }
  2541. -
  2542. - delete _current_p; // cleanup the previous info for the caller
  2543. - _current_p = NULL; // reset to NULL so we don't delete same object twice
  2544. -
  2545. - int length = _previous_versions->length();
  2546. -
  2547. - while (_current_index < length) {
  2548. - PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
  2549. - PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass)
  2550. - PreviousVersionInfo(pv_node);
  2551. -
  2552. - constantPoolHandle cp_h = pv_info->prev_constant_pool_handle();
  2553. - if (cp_h.is_null()) {
  2554. - delete pv_info;
  2555. -
  2556. - // The underlying node's info has been GC'ed so try the next one.
  2557. - // We don't have to check the methods. If the constant pool has
  2558. - // GC'ed then so have the methods.
  2559. - continue;
  2560. - }
  2561. -
  2562. - // Found a node with non GC'ed info so return it. The caller will
  2563. - // need to delete pv_info when they are done with it.
  2564. - _current_p = pv_info;
  2565. - return pv_info;
  2566. - }
  2567. -
  2568. - // all of the underlying nodes' info has been GC'ed
  2569. - return NULL;
  2570. -} // end next_previous_version()
  2571. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  2572. --- a/src/share/vm/oops/instanceKlass.hpp
  2573. +++ b/src/share/vm/oops/instanceKlass.hpp
  2574. @@ -273,9 +273,6 @@
  2575. nmethodBucket* _dependencies; // list of dependent nmethods
  2576. nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
  2577. BreakpointInfo* _breakpoints; // bpt lists, managed by methodOop
  2578. - // Array of interesting part(s) of the previous version(s) of this
  2579. - // instanceKlass. See PreviousVersionWalker below.
  2580. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2581. // JVMTI fields can be moved to their own structure - see 6315920
  2582. unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH
  2583. jint _cached_class_file_len; // JVMTI: length of above
  2584. @@ -573,20 +570,11 @@
  2585. _nonstatic_oop_map_size = words;
  2586. }
  2587. - // RedefineClasses() support for previous versions:
  2588. - void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
  2589. - int emcp_method_count);
  2590. // If the _previous_versions array is non-NULL, then this klass
  2591. // has been redefined at least once even if we aren't currently
  2592. // tracking a previous version.
  2593. - bool has_been_redefined() const { return _previous_versions != NULL; }
  2594. + bool has_been_redefined() const { return _old_version != NULL; }
  2595. bool has_previous_version() const;
  2596. - void init_previous_versions() {
  2597. - _previous_versions = NULL;
  2598. - }
  2599. - GrowableArray<PreviousVersionNode *>* previous_versions() const {
  2600. - return _previous_versions;
  2601. - }
  2602. // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
  2603. void set_cached_class_file(unsigned char *class_file_bytes,
  2604. @@ -631,6 +619,7 @@
  2605. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  2606. size_t *length_p, jmethodID* id_p);
  2607. jmethodID jmethod_id_or_null(methodOop method);
  2608. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  2609. // cached itable index support
  2610. void set_cached_itable_index(size_t idnum, int index);
  2611. @@ -713,6 +702,7 @@
  2612. // subclass/subinterface checks
  2613. bool implements_interface(klassOop k) const;
  2614. + bool implements_interface_any_version(klassOop k) const;
  2615. // Access to the implementor of an interface.
  2616. klassOop implementor() const
  2617. @@ -762,6 +752,9 @@
  2618. void do_local_static_fields(FieldClosure* cl);
  2619. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  2620. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  2621. + void store_update_information(GrowableArray<int> &values);
  2622. + void clear_update_information();
  2623. +
  2624. void methods_do(void f(methodOop method));
  2625. void array_klasses_do(void f(klassOop k));
  2626. @@ -897,7 +890,6 @@
  2627. ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
  2628. #endif // !SERIALGC
  2629. -private:
  2630. // initialization state
  2631. #ifdef ASSERT
  2632. void set_init_state(ClassState state);
  2633. @@ -1065,106 +1057,6 @@
  2634. void verify(klassOop holder);
  2635. };
  2636. -
  2637. -// If breakpoints are more numerous than just JVMTI breakpoints,
  2638. -// consider compressing this data structure.
  2639. -// It is currently a simple linked list defined in methodOop.hpp.
  2640. -
  2641. -class BreakpointInfo;
  2642. -
  2643. -
  2644. -// A collection point for interesting information about the previous
  2645. -// version(s) of an instanceKlass. This class uses weak references to
  2646. -// the information so that the information may be collected as needed
  2647. -// by the system. If the information is shared, then a regular
  2648. -// reference must be used because a weak reference would be seen as
  2649. -// collectible. A GrowableArray of PreviousVersionNodes is attached
  2650. -// to the instanceKlass as needed. See PreviousVersionWalker below.
  2651. -class PreviousVersionNode : public CHeapObj<mtClass> {
  2652. - private:
  2653. - // A shared ConstantPool is never collected so we'll always have
  2654. - // a reference to it so we can update items in the cache. We'll
  2655. - // have a weak reference to a non-shared ConstantPool until all
  2656. - // of the methods (EMCP or obsolete) have been collected; the
  2657. - // non-shared ConstantPool becomes collectible at that point.
  2658. - jobject _prev_constant_pool; // regular or weak reference
  2659. - bool _prev_cp_is_weak; // true if not a shared ConstantPool
  2660. -
  2661. - // If the previous version of the instanceKlass doesn't have any
  2662. - // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
  2663. - // EMCP methods have been collected, then _prev_EMCP_methods can
  2664. - // have a length of zero.
  2665. - GrowableArray<jweak>* _prev_EMCP_methods;
  2666. -
  2667. -public:
  2668. - PreviousVersionNode(jobject prev_constant_pool, bool prev_cp_is_weak,
  2669. - GrowableArray<jweak>* prev_EMCP_methods);
  2670. - ~PreviousVersionNode();
  2671. - jobject prev_constant_pool() const {
  2672. - return _prev_constant_pool;
  2673. - }
  2674. - GrowableArray<jweak>* prev_EMCP_methods() const {
  2675. - return _prev_EMCP_methods;
  2676. - }
  2677. -};
  2678. -
  2679. -
  2680. -// A Handle-ized version of PreviousVersionNode.
  2681. -class PreviousVersionInfo : public ResourceObj {
  2682. - private:
  2683. - constantPoolHandle _prev_constant_pool_handle;
  2684. - // If the previous version of the instanceKlass doesn't have any
  2685. - // EMCP methods, then _prev_EMCP_methods will be NULL. Since the
  2686. - // methods cannot be collected while we hold a handle,
  2687. - // _prev_EMCP_methods should never have a length of zero.
  2688. - GrowableArray<methodHandle>* _prev_EMCP_method_handles;
  2689. -
  2690. -public:
  2691. - PreviousVersionInfo(PreviousVersionNode *pv_node);
  2692. - ~PreviousVersionInfo();
  2693. - constantPoolHandle prev_constant_pool_handle() const {
  2694. - return _prev_constant_pool_handle;
  2695. - }
  2696. - GrowableArray<methodHandle>* prev_EMCP_method_handles() const {
  2697. - return _prev_EMCP_method_handles;
  2698. - }
  2699. -};
  2700. -
  2701. -
  2702. -// Helper object for walking previous versions. This helper cleans up
  2703. -// the Handles that it allocates when the helper object is destroyed.
  2704. -// The PreviousVersionInfo object returned by next_previous_version()
  2705. -// is only valid until a subsequent call to next_previous_version() or
  2706. -// the helper object is destroyed.
  2707. -class PreviousVersionWalker : public StackObj {
  2708. - private:
  2709. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2710. - int _current_index;
  2711. - // Fields for cleaning up when we are done walking the previous versions:
  2712. - // A HandleMark for the PreviousVersionInfo handles:
  2713. - HandleMark _hm;
  2714. -
  2715. - // It would be nice to have a ResourceMark field in this helper also,
  2716. - // but the ResourceMark code says to be careful to delete handles held
  2717. - // in GrowableArrays _before_ deleting the GrowableArray. Since we
  2718. - // can't guarantee the order in which the fields are destroyed, we
  2719. - // have to let the creator of the PreviousVersionWalker object do
  2720. - // the right thing. Also, adding a ResourceMark here causes an
  2721. - // include loop.
  2722. -
  2723. - // A pointer to the current info object so we can handle the deletes.
  2724. - PreviousVersionInfo * _current_p;
  2725. -
  2726. - public:
  2727. - PreviousVersionWalker(instanceKlass *ik);
  2728. - ~PreviousVersionWalker();
  2729. -
  2730. - // Return the interesting information for the next previous version
  2731. - // of the klass. Returns NULL if there are no more previous versions.
  2732. - PreviousVersionInfo* next_previous_version();
  2733. -};
  2734. -
  2735. -
  2736. //
  2737. // nmethodBucket is used to record dependent nmethods for
  2738. // deoptimization. nmethod dependencies are actually <klass, method>
  2739. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  2740. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  2741. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  2742. @@ -358,7 +358,7 @@
  2743. unsigned nonstatic_oop_map_count,
  2744. AccessFlags access_flags,
  2745. ReferenceType rt,
  2746. - KlassHandle host_klass, TRAPS) {
  2747. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  2748. const int nonstatic_oop_map_size =
  2749. instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count);
  2750. @@ -435,7 +435,6 @@
  2751. ik->set_jni_ids(NULL);
  2752. ik->set_osr_nmethods_head(NULL);
  2753. ik->set_breakpoints(NULL);
  2754. - ik->init_previous_versions();
  2755. ik->set_generic_signature(NULL);
  2756. ik->release_set_methods_jmethod_ids(NULL);
  2757. ik->release_set_methods_cached_itable_indices(NULL);
  2758. @@ -480,6 +479,28 @@
  2759. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  2760. klassKlass::oop_print_on(obj, st);
  2761. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  2762. +
  2763. + st->print(BULLET"revision: %d", ik->revision_number());
  2764. +
  2765. + if (ik->new_version() != NULL) {
  2766. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  2767. + }
  2768. +
  2769. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  2770. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  2771. + }
  2772. +
  2773. + if (ik->old_version() != NULL) {
  2774. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  2775. + }
  2776. +
  2777. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  2778. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  2779. + }
  2780. +
  2781. + st->cr();
  2782. +
  2783. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  2784. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  2785. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  2786. @@ -537,26 +558,6 @@
  2787. st->cr();
  2788. }
  2789. - {
  2790. - ResourceMark rm;
  2791. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  2792. - // contain a GrowableArray of handles. We have to clean up the
  2793. - // GrowableArray _after_ the PreviousVersionWalker destructor
  2794. - // has destroyed the handles.
  2795. - {
  2796. - bool have_pv = false;
  2797. - PreviousVersionWalker pvw(ik);
  2798. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  2799. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  2800. - if (!have_pv)
  2801. - st->print(BULLET"previous version: ");
  2802. - have_pv = true;
  2803. - pv_info->prev_constant_pool_handle()()->print_value_on(st);
  2804. - }
  2805. - if (have_pv) st->cr();
  2806. - } // pvw is cleaned up
  2807. - } // rm is cleaned up
  2808. -
  2809. if (ik->generic_signature() != NULL) {
  2810. st->print(BULLET"generic signature: ");
  2811. ik->generic_signature()->print_value_on(st);
  2812. @@ -663,7 +664,7 @@
  2813. }
  2814. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  2815. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  2816. - guarantee(sib->super() == super, "siblings should have same superklass");
  2817. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  2818. sib = sib->next_sibling();
  2819. }
  2820. diff --git a/src/share/vm/oops/instanceKlassKlass.hpp b/src/share/vm/oops/instanceKlassKlass.hpp
  2821. --- a/src/share/vm/oops/instanceKlassKlass.hpp
  2822. +++ b/src/share/vm/oops/instanceKlassKlass.hpp
  2823. @@ -50,6 +50,7 @@
  2824. AccessFlags access_flags,
  2825. ReferenceType rt,
  2826. KlassHandle host_klass,
  2827. + KlassHandle old_klass,
  2828. TRAPS);
  2829. // Casting from klassOop
  2830. diff --git a/src/share/vm/oops/instanceMirrorKlass.cpp b/src/share/vm/oops/instanceMirrorKlass.cpp
  2831. --- a/src/share/vm/oops/instanceMirrorKlass.cpp
  2832. +++ b/src/share/vm/oops/instanceMirrorKlass.cpp
  2833. @@ -156,6 +156,13 @@
  2834. assert_is_in_closed_subset)
  2835. }
  2836. +void instanceMirrorKlass::oop_fields_iterate(oop obj, OopClosure* blk) {
  2837. + InstanceMirrorKlass_OOP_ITERATE( \
  2838. + start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
  2839. + blk->do_oop(p), \
  2840. + assert_is_in_closed_subset)
  2841. +}
  2842. +
  2843. #ifndef SERIALGC
  2844. void instanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm,
  2845. oop obj) {
  2846. diff --git a/src/share/vm/oops/instanceMirrorKlass.hpp b/src/share/vm/oops/instanceMirrorKlass.hpp
  2847. --- a/src/share/vm/oops/instanceMirrorKlass.hpp
  2848. +++ b/src/share/vm/oops/instanceMirrorKlass.hpp
  2849. @@ -79,6 +79,9 @@
  2850. DEFINE_ALLOCATE_PERMANENT(instanceMirrorKlass);
  2851. instanceOop allocate_instance(KlassHandle k, TRAPS);
  2852. + // Class redefinition, iterate static fields
  2853. + static void oop_fields_iterate(oop obj, OopClosure* blk);
  2854. +
  2855. // Garbage collection
  2856. int oop_adjust_pointers(oop obj);
  2857. void oop_follow_contents(oop obj);
  2858. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  2859. --- a/src/share/vm/oops/instanceRefKlass.cpp
  2860. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  2861. @@ -455,10 +455,13 @@
  2862. instanceKlass* ik = instanceKlass::cast(k);
  2863. // Check that we have the right class
  2864. - debug_only(static bool first_time = true);
  2865. - assert(k == SystemDictionary::Reference_klass() && first_time,
  2866. - "Invalid update of maps");
  2867. - debug_only(first_time = false);
  2868. +
  2869. + // (tw) Asserts no longer valid for class redefinition
  2870. + // debug_only(static bool first_time = true);
  2871. +
  2872. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  2873. + // "Invalid update of maps");
  2874. + //debug_only(first_time = false);
  2875. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  2876. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  2877. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  2878. --- a/src/share/vm/oops/klass.cpp
  2879. +++ b/src/share/vm/oops/klass.cpp
  2880. @@ -161,6 +161,13 @@
  2881. kl->set_alloc_size(0);
  2882. TRACE_INIT_ID(kl);
  2883. + kl->set_redefinition_flags(Klass::NoRedefinition);
  2884. + kl->set_redefining(false);
  2885. + kl->set_new_version(NULL);
  2886. + kl->set_old_version(NULL);
  2887. + kl->set_redefinition_index(-1);
  2888. + kl->set_revision_number(-1);
  2889. +
  2890. kl->set_prototype_header(markOopDesc::prototype());
  2891. kl->set_biased_lock_revocation_count(0);
  2892. kl->set_last_biased_lock_bulk_revocation_time(0);
  2893. @@ -232,7 +239,7 @@
  2894. set_super(NULL);
  2895. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  2896. assert(super_depth() == 0, "Object must already be initialized properly");
  2897. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  2898. + } else if (k != super() || k->klass_part()->super() == NULL) {
  2899. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  2900. "initialize this only once to a non-trivial value");
  2901. set_super(k);
  2902. @@ -385,7 +392,7 @@
  2903. void Klass::remove_from_sibling_list() {
  2904. // remove receiver from sibling list
  2905. instanceKlass* super = superklass();
  2906. - assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
  2907. + assert(super != NULL || as_klassOop()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version(), "should have super");
  2908. if (super == NULL) return; // special case: class Object
  2909. if (super->subklass() == this) {
  2910. // first subklass
  2911. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  2912. --- a/src/share/vm/oops/klass.hpp
  2913. +++ b/src/share/vm/oops/klass.hpp
  2914. @@ -170,6 +170,7 @@
  2915. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  2916. };
  2917. +template<class L, class R> class Pair;
  2918. class Klass : public Klass_vtbl {
  2919. friend class VMStructs;
  2920. @@ -222,6 +223,31 @@
  2921. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  2922. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  2923. + // (tw) Different class redefinition flags of code evolution.
  2924. + enum RedefinitionFlags {
  2925. +
  2926. + // This class is not redefined at all!
  2927. + NoRedefinition,
  2928. +
  2929. + // There are changes to the class meta data.
  2930. + ModifyClass = 1,
  2931. +
  2932. + // The size of the class meta data changes.
  2933. + ModifyClassSize = ModifyClass << 1,
  2934. +
  2935. + // There are change to the instance format.
  2936. + ModifyInstances = ModifyClassSize << 1,
  2937. +
  2938. + // The size of instances changes.
  2939. + ModifyInstanceSize = ModifyInstances << 1,
  2940. +
  2941. + // A super type of this class is removed.
  2942. + RemoveSuperType = ModifyInstanceSize << 1,
  2943. +
  2944. + // This class has been marked as an affected class.
  2945. + MarkedAsAffected = RemoveSuperType << 1
  2946. + };
  2947. +
  2948. protected:
  2949. //
  2950. // The oop block. All oop fields must be declared here and only oop fields
  2951. @@ -241,6 +267,10 @@
  2952. oop _java_mirror;
  2953. // Superclass
  2954. klassOop _super;
  2955. + // Old class
  2956. + klassOop _old_version;
  2957. + // New class
  2958. + klassOop _new_version;
  2959. // First subclass (NULL if none); _subklass->next_sibling() is next one
  2960. klassOop _subklass;
  2961. // Sibling link (or NULL); links all subklasses of a klass
  2962. @@ -253,6 +283,16 @@
  2963. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  2964. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  2965. + // (tw) Non-oop fields for enhanced class redefinition
  2966. + jint _revision_number; // The revision number for redefined classes
  2967. + jint _redefinition_index; // Index of this class when performing the redefinition
  2968. + bool _subtype_changed;
  2969. + int _redefinition_flags; // Level of class redefinition
  2970. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  2971. + bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
  2972. + int * _update_information; // Update information
  2973. + bool _is_redefining;
  2974. +
  2975. #ifndef PRODUCT
  2976. int _verify_count; // to avoid redundant verifies
  2977. #endif
  2978. @@ -301,6 +341,75 @@
  2979. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  2980. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  2981. + // BEGIN class redefinition utilities
  2982. +
  2983. + // double links between new and old version of a class
  2984. + klassOop old_version() const { return _old_version; }
  2985. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  2986. + klassOop new_version() const { return _new_version; }
  2987. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  2988. +
  2989. + // A subtype of this class is no longer a subtype
  2990. + bool has_subtype_changed() const { return _subtype_changed; }
  2991. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  2992. + _subtype_changed = b; }
  2993. + // state of being redefined
  2994. + int redefinition_index() const { return _redefinition_index; }
  2995. + void set_redefinition_index(int index) { _redefinition_index = index; }
  2996. + void set_redefining(bool b) { _is_redefining = b; }
  2997. + bool is_redefining() const { return _is_redefining; }
  2998. + int redefinition_flags() const { return _redefinition_flags; }
  2999. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3000. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3001. + void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
  3002. + void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
  3003. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3004. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3005. +
  3006. + // update information
  3007. + int *update_information() const { return _update_information; }
  3008. + void set_update_information(int *info) { _update_information = info; }
  3009. +
  3010. + bool is_same_or_older_version(klassOop klass) const {
  3011. + if (Klass::cast(klass) == this) { return true; }
  3012. + else if (_old_version == NULL) { return false; }
  3013. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3014. + }
  3015. +
  3016. + // Revision number for redefined classes, -1 for originally loaded classes
  3017. + jint revision_number() const {
  3018. + return _revision_number;
  3019. + }
  3020. +
  3021. + bool was_redefined() const {
  3022. + return _revision_number != -1;
  3023. + }
  3024. +
  3025. + void set_revision_number(jint number) {
  3026. + _revision_number = number;
  3027. + }
  3028. +
  3029. + klassOop oldest_version() const {
  3030. + if (_old_version == NULL) { return this->as_klassOop(); }
  3031. + else { return _old_version->klass_part()->oldest_version(); };
  3032. + }
  3033. +
  3034. + klassOop newest_version() const {
  3035. + if (_new_version == NULL) { return this->as_klassOop(); }
  3036. + else { return _new_version->klass_part()->newest_version(); };
  3037. + }
  3038. +
  3039. + klassOop active_version() const {
  3040. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3041. + else { return _new_version->klass_part()->active_version(); };
  3042. + }
  3043. +
  3044. + bool is_newest_version() const {
  3045. + return _new_version == NULL;
  3046. + }
  3047. +
  3048. + // END class redefinition utilities
  3049. +
  3050. objArrayOop secondary_supers() const { return _secondary_supers; }
  3051. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3052. @@ -361,6 +470,8 @@
  3053. void set_next_sibling(klassOop s);
  3054. oop* adr_super() const { return (oop*)&_super; }
  3055. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3056. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3057. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3058. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3059. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3060. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3061. --- a/src/share/vm/oops/klassKlass.cpp
  3062. +++ b/src/share/vm/oops/klassKlass.cpp
  3063. @@ -68,6 +68,8 @@
  3064. Klass* k = Klass::cast(klassOop(obj));
  3065. // If we are alive it is valid to keep our superclass and subtype caches alive
  3066. MarkSweep::mark_and_push(k->adr_super());
  3067. + MarkSweep::mark_and_push(k->adr_old_version());
  3068. + MarkSweep::mark_and_push(k->adr_new_version());
  3069. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3070. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3071. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3072. @@ -87,6 +89,8 @@
  3073. Klass* k = Klass::cast(klassOop(obj));
  3074. // If we are alive it is valid to keep our superclass and subtype caches alive
  3075. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3076. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3077. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3078. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3079. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3080. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3081. @@ -106,6 +110,8 @@
  3082. int size = oop_size(obj);
  3083. Klass* k = Klass::cast(klassOop(obj));
  3084. blk->do_oop(k->adr_super());
  3085. + blk->do_oop(k->adr_old_version());
  3086. + blk->do_oop(k->adr_new_version());
  3087. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3088. blk->do_oop(k->adr_primary_supers()+i);
  3089. blk->do_oop(k->adr_secondary_super_cache());
  3090. @@ -134,6 +140,10 @@
  3091. oop* adr;
  3092. adr = k->adr_super();
  3093. if (mr.contains(adr)) blk->do_oop(adr);
  3094. + adr = k->adr_old_version();
  3095. + if (mr.contains(adr)) blk->do_oop(adr);
  3096. + adr = k->adr_new_version();
  3097. + if (mr.contains(adr)) blk->do_oop(adr);
  3098. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3099. adr = k->adr_primary_supers()+i;
  3100. if (mr.contains(adr)) blk->do_oop(adr);
  3101. @@ -167,6 +177,8 @@
  3102. Klass* k = Klass::cast(klassOop(obj));
  3103. MarkSweep::adjust_pointer(k->adr_super());
  3104. + MarkSweep::adjust_pointer(k->adr_new_version());
  3105. + MarkSweep::adjust_pointer(k->adr_old_version());
  3106. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3107. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3108. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3109. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  3110. --- a/src/share/vm/oops/klassVtable.cpp
  3111. +++ b/src/share/vm/oops/klassVtable.cpp
  3112. @@ -628,17 +628,13 @@
  3113. if (unchecked_method_at(index) == old_method) {
  3114. put_method_at(new_method, index);
  3115. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3116. + IF_TRACE_RC4 {
  3117. if (!(*trace_name_printed)) {
  3118. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3119. - RC_TRACE_MESG(("adjust: name=%s",
  3120. - Klass::cast(old_method->method_holder())->external_name()));
  3121. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3122. *trace_name_printed = true;
  3123. }
  3124. - // RC_TRACE macro has an embedded ResourceMark
  3125. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  3126. - new_method->name()->as_C_string(),
  3127. - new_method->signature()->as_C_string()));
  3128. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  3129. + new_method->signature()->as_C_string());
  3130. }
  3131. // cannot 'break' here; see for-loop comment above.
  3132. }
  3133. @@ -1008,17 +1004,13 @@
  3134. if (ime->method() == old_method) {
  3135. ime->initialize(new_method);
  3136. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3137. + IF_TRACE_RC4 {
  3138. if (!(*trace_name_printed)) {
  3139. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3140. - RC_TRACE_MESG(("adjust: name=%s",
  3141. - Klass::cast(old_method->method_holder())->external_name()));
  3142. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3143. *trace_name_printed = true;
  3144. }
  3145. - // RC_TRACE macro has an embedded ResourceMark
  3146. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  3147. - new_method->name()->as_C_string(),
  3148. - new_method->signature()->as_C_string()));
  3149. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  3150. + new_method->signature()->as_C_string());
  3151. }
  3152. // cannot 'break' here; see for-loop comment above.
  3153. }
  3154. @@ -1241,6 +1233,7 @@
  3155. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  3156. vtableEntry* vte = &vt->table()[index];
  3157. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  3158. if (vte->method()->name() != table()[index].method()->name() ||
  3159. vte->method()->signature() != table()[index].method()->signature()) {
  3160. fatal("mismatched name/signature of vtable entries");
  3161. @@ -1260,6 +1253,8 @@
  3162. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3163. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  3164. + // (tw) TODO: Check: Does not hold?
  3165. + if (method() != NULL) {
  3166. assert(method() != NULL, "must have set method");
  3167. method()->verify();
  3168. // we sub_type, because it could be a miranda method
  3169. @@ -1267,7 +1262,13 @@
  3170. #ifndef PRODUCT
  3171. print();
  3172. #endif
  3173. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  3174. + klassOop first_klass = vt->klass()();
  3175. + klassOop second_klass = method()->method_holder();
  3176. + // (tw) the following fatal does not work for old versions of classes
  3177. + if (first_klass->klass_part()->is_newest_version()) {
  3178. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  3179. + }
  3180. + }
  3181. }
  3182. }
  3183. @@ -1275,8 +1276,8 @@
  3184. void vtableEntry::print() {
  3185. ResourceMark rm;
  3186. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  3187. if (Verbose) {
  3188. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  3189. tty->print("m %#lx ", (address)method());
  3190. }
  3191. }
  3192. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  3193. --- a/src/share/vm/oops/methodKlass.cpp
  3194. +++ b/src/share/vm/oops/methodKlass.cpp
  3195. @@ -93,6 +93,9 @@
  3196. m->set_adapter_entry(NULL);
  3197. m->clear_code(); // from_c/from_i get set to c2i/i2i
  3198. + m->set_new_version(NULL);
  3199. + m->set_old_version(NULL);
  3200. +
  3201. if (access_flags.is_native()) {
  3202. m->clear_native_function();
  3203. m->set_signature_handler(NULL);
  3204. @@ -122,6 +125,8 @@
  3205. // Performance tweak: We skip iterating over the klass pointer since we
  3206. // know that Universe::methodKlassObj never moves.
  3207. MarkSweep::mark_and_push(m->adr_constMethod());
  3208. + MarkSweep::mark_and_push(m->adr_new_version());
  3209. + MarkSweep::mark_and_push(m->adr_old_version());
  3210. if (m->method_data() != NULL) {
  3211. MarkSweep::mark_and_push(m->adr_method_data());
  3212. }
  3213. @@ -135,6 +140,8 @@
  3214. // Performance tweak: We skip iterating over the klass pointer since we
  3215. // know that Universe::methodKlassObj never moves.
  3216. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  3217. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  3218. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  3219. #ifdef COMPILER2
  3220. if (m->method_data() != NULL) {
  3221. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  3222. @@ -152,6 +159,8 @@
  3223. // Performance tweak: We skip iterating over the klass pointer since we
  3224. // know that Universe::methodKlassObj never moves
  3225. blk->do_oop(m->adr_constMethod());
  3226. + blk->do_oop(m->adr_new_version());
  3227. + blk->do_oop(m->adr_old_version());
  3228. if (m->method_data() != NULL) {
  3229. blk->do_oop(m->adr_method_data());
  3230. }
  3231. @@ -170,6 +179,10 @@
  3232. oop* adr;
  3233. adr = m->adr_constMethod();
  3234. if (mr.contains(adr)) blk->do_oop(adr);
  3235. + adr = m->adr_new_version();
  3236. + if (mr.contains(adr)) blk->do_oop(adr);
  3237. + adr = m->adr_old_version();
  3238. + if (mr.contains(adr)) blk->do_oop(adr);
  3239. if (m->method_data() != NULL) {
  3240. adr = m->adr_method_data();
  3241. if (mr.contains(adr)) blk->do_oop(adr);
  3242. @@ -187,6 +200,8 @@
  3243. // Performance tweak: We skip iterating over the klass pointer since we
  3244. // know that Universe::methodKlassObj never moves.
  3245. MarkSweep::adjust_pointer(m->adr_constMethod());
  3246. + MarkSweep::adjust_pointer(m->adr_new_version());
  3247. + MarkSweep::adjust_pointer(m->adr_old_version());
  3248. if (m->method_data() != NULL) {
  3249. MarkSweep::adjust_pointer(m->adr_method_data());
  3250. }
  3251. @@ -202,6 +217,8 @@
  3252. assert(obj->is_method(), "should be method");
  3253. methodOop m = methodOop(obj);
  3254. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  3255. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  3256. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  3257. #ifdef COMPILER2
  3258. if (m->method_data() != NULL) {
  3259. PSParallelCompact::adjust_pointer(m->adr_method_data());
  3260. @@ -222,7 +239,18 @@
  3261. methodOop m = methodOop(obj);
  3262. // get the effect of PrintOopAddress, always, for methods:
  3263. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  3264. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  3265. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  3266. +
  3267. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  3268. + st->print(" (old)");
  3269. + }
  3270. + st->cr();
  3271. +
  3272. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  3273. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  3274. + st->print_cr(" - new version: "INTPTR_FORMAT, (address)m->new_version());
  3275. + st->print_cr(" - old version: "INTPTR_FORMAT, (address)m->old_version());
  3276. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  3277. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  3278. m->constants()->print_value_on(st); st->cr();
  3279. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  3280. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  3281. --- a/src/share/vm/oops/methodOop.cpp
  3282. +++ b/src/share/vm/oops/methodOop.cpp
  3283. @@ -1061,6 +1061,8 @@
  3284. // Reset correct method/const method, method size, and parameter info
  3285. newm->set_constMethod(newcm);
  3286. + newm->set_new_version(newm->new_version());
  3287. + newm->set_old_version(newm->old_version());
  3288. newm->constMethod()->set_code_size(new_code_length);
  3289. newm->constMethod()->set_constMethod_size(new_const_method_size);
  3290. newm->set_method_size(new_method_size);
  3291. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  3292. --- a/src/share/vm/oops/methodOop.hpp
  3293. +++ b/src/share/vm/oops/methodOop.hpp
  3294. @@ -114,6 +114,10 @@
  3295. AccessFlags _access_flags; // Access flags
  3296. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  3297. // note: can have vtables with >2**16 elements (because of inheritance)
  3298. + // (tw) Newer version of method available?
  3299. + methodOop _new_version;
  3300. + methodOop _old_version;
  3301. +
  3302. #ifdef CC_INTERP
  3303. int _result_index; // C++ interpreter needs for converting results to/from stack
  3304. #endif
  3305. @@ -175,6 +179,29 @@
  3306. int name_index() const { return constMethod()->name_index(); }
  3307. void set_name_index(int index) { constMethod()->set_name_index(index); }
  3308. + methodOop new_version() const {return _new_version; }
  3309. + void set_new_version(methodOop m) { _new_version = m; }
  3310. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  3311. +
  3312. + methodOop old_version() const {return _old_version; };
  3313. + void set_old_version(methodOop m) {
  3314. + if (m == NULL) {
  3315. + _old_version = NULL;
  3316. + return;
  3317. + }
  3318. +
  3319. + assert(_old_version == NULL, "may only be set once");
  3320. + assert(this->code_size() == m->code_size(), "must have same code length");
  3321. + _old_version = m;
  3322. + }
  3323. +
  3324. + methodOop oldest_version() const {
  3325. + if(_old_version == NULL) return (methodOop)this;
  3326. + else {
  3327. + return old_version()->oldest_version();
  3328. + }
  3329. + }
  3330. +
  3331. // signature
  3332. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  3333. int signature_index() const { return constMethod()->signature_index(); }
  3334. @@ -734,6 +761,8 @@
  3335. // Garbage collection support
  3336. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  3337. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3338. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3339. oop* adr_method_data() const { return (oop*)&_method_data; }
  3340. };
  3341. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  3342. --- a/src/share/vm/oops/oop.hpp
  3343. +++ b/src/share/vm/oops/oop.hpp
  3344. @@ -95,6 +95,7 @@
  3345. narrowOop* compressed_klass_addr();
  3346. void set_klass(klassOop k);
  3347. + void set_klass_no_check(klassOop k);
  3348. // For klass field compression
  3349. int klass_gap() const;
  3350. @@ -135,6 +136,7 @@
  3351. bool is_array() const;
  3352. bool is_objArray() const;
  3353. bool is_klass() const;
  3354. + bool is_instanceKlass() const;
  3355. bool is_thread() const;
  3356. bool is_method() const;
  3357. bool is_constMethod() const;
  3358. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  3359. --- a/src/share/vm/oops/oop.inline.hpp
  3360. +++ b/src/share/vm/oops/oop.inline.hpp
  3361. @@ -123,6 +123,14 @@
  3362. }
  3363. }
  3364. +inline void oopDesc::set_klass_no_check(klassOop k) {
  3365. + if (UseCompressedOops) {
  3366. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  3367. + } else {
  3368. + oop_store_without_check(klass_addr(), (oop) k);
  3369. + }
  3370. +}
  3371. +
  3372. inline int oopDesc::klass_gap() const {
  3373. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  3374. }
  3375. @@ -156,6 +164,7 @@
  3376. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  3377. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  3378. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  3379. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  3380. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  3381. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  3382. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  3383. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  3384. --- a/src/share/vm/prims/jni.cpp
  3385. +++ b/src/share/vm/prims/jni.cpp
  3386. @@ -406,7 +406,7 @@
  3387. }
  3388. }
  3389. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3390. - Handle(), &st, true,
  3391. + Handle(), &st, true, KlassHandle(),
  3392. CHECK_NULL);
  3393. if (TraceClassResolution && k != NULL) {
  3394. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  3395. --- a/src/share/vm/prims/jvm.cpp
  3396. +++ b/src/share/vm/prims/jvm.cpp
  3397. @@ -872,7 +872,7 @@
  3398. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  3399. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3400. protection_domain, &st,
  3401. - verify != 0,
  3402. + verify != 0, KlassHandle(),
  3403. CHECK_NULL);
  3404. if (TraceClassResolution && k != NULL) {
  3405. diff --git a/src/share/vm/prims/jvm_misc.hpp b/src/share/vm/prims/jvm_misc.hpp
  3406. --- a/src/share/vm/prims/jvm_misc.hpp
  3407. +++ b/src/share/vm/prims/jvm_misc.hpp
  3408. @@ -84,6 +84,7 @@
  3409. (JNIEnv *env, jobject obj, jfieldID fieldID);
  3410. }
  3411. +// TODO(tw): Check if we need to "unquicken" because of class redefinition.
  3412. void quicken_jni_functions();
  3413. address jni_GetBooleanField_addr();
  3414. address jni_GetByteField_addr();
  3415. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  3416. --- a/src/share/vm/prims/jvmtiEnv.cpp
  3417. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  3418. @@ -290,7 +290,10 @@
  3419. class_definitions[index].klass = jcls;
  3420. }
  3421. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  3422. - VMThread::execute(&op);
  3423. + {
  3424. + MutexLocker sd_mutex(RedefineClasses_lock);
  3425. + VMThread::execute(&op);
  3426. + }
  3427. return (op.check_error());
  3428. } /* end RetransformClasses */
  3429. @@ -299,9 +302,12 @@
  3430. // class_definitions - pre-checked for NULL
  3431. jvmtiError
  3432. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  3433. -//TODO: add locking
  3434. +
  3435. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  3436. - VMThread::execute(&op);
  3437. + {
  3438. + MutexLocker sd_mutex(RedefineClasses_lock);
  3439. + VMThread::execute(&op);
  3440. + }
  3441. return (op.check_error());
  3442. } /* end RedefineClasses */
  3443. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  3444. --- a/src/share/vm/prims/jvmtiExport.cpp
  3445. +++ b/src/share/vm/prims/jvmtiExport.cpp
  3446. @@ -2296,7 +2296,7 @@
  3447. // iterate over any code blob descriptors collected and post a
  3448. // DYNAMIC_CODE_GENERATED event to the profiler.
  3449. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  3450. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  3451. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  3452. // iterate over any code blob descriptors that we collected
  3453. if (_code_blobs != NULL) {
  3454. for (int i=0; i<_code_blobs->length(); i++) {
  3455. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  3456. --- a/src/share/vm/prims/jvmtiImpl.cpp
  3457. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  3458. @@ -284,60 +284,11 @@
  3459. }
  3460. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  3461. - ((methodOopDesc*)_method->*meth_act)(_bci);
  3462. -
  3463. - // add/remove breakpoint to/from versions of the method that
  3464. - // are EMCP. Directly or transitively obsolete methods are
  3465. - // not saved in the PreviousVersionInfo.
  3466. - Thread *thread = Thread::current();
  3467. - instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder());
  3468. - Symbol* m_name = _method->name();
  3469. - Symbol* m_signature = _method->signature();
  3470. -
  3471. - {
  3472. - ResourceMark rm(thread);
  3473. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  3474. - // contain a GrowableArray of handles. We have to clean up the
  3475. - // GrowableArray _after_ the PreviousVersionWalker destructor
  3476. - // has destroyed the handles.
  3477. - {
  3478. - // search previous versions if they exist
  3479. - PreviousVersionWalker pvw((instanceKlass *)ikh()->klass_part());
  3480. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  3481. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  3482. - GrowableArray<methodHandle>* methods =
  3483. - pv_info->prev_EMCP_method_handles();
  3484. -
  3485. - if (methods == NULL) {
  3486. - // We have run into a PreviousVersion generation where
  3487. - // all methods were made obsolete during that generation's
  3488. - // RedefineClasses() operation. At the time of that
  3489. - // operation, all EMCP methods were flushed so we don't
  3490. - // have to go back any further.
  3491. - //
  3492. - // A NULL methods array is different than an empty methods
  3493. - // array. We cannot infer any optimizations about older
  3494. - // generations from an empty methods array for the current
  3495. - // generation.
  3496. - break;
  3497. - }
  3498. -
  3499. - for (int i = methods->length() - 1; i >= 0; i--) {
  3500. - methodHandle method = methods->at(i);
  3501. - if (method->name() == m_name && method->signature() == m_signature) {
  3502. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  3503. - meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  3504. - method->name()->as_C_string(),
  3505. - method->signature()->as_C_string()));
  3506. - assert(!method->is_obsolete(), "only EMCP methods here");
  3507. -
  3508. - ((methodOopDesc*)method()->*meth_act)(_bci);
  3509. - break;
  3510. - }
  3511. - }
  3512. - }
  3513. - } // pvw is cleaned up
  3514. - } // rm is cleaned up
  3515. + methodOop method = _method;
  3516. + while (method != NULL) {
  3517. + ((methodOopDesc*)method->*meth_act)(_bci);
  3518. + method = method->old_version();
  3519. + }
  3520. }
  3521. void JvmtiBreakpoint::set() {
  3522. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3523. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3524. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3525. @@ -1,5 +1,5 @@
  3526. /*
  3527. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  3528. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  3529. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3530. *
  3531. * This code is free software; you can redistribute it and/or modify it
  3532. @@ -35,546 +35,58 @@
  3533. #include "prims/jvmtiImpl.hpp"
  3534. #include "prims/jvmtiRedefineClasses.hpp"
  3535. #include "prims/methodComparator.hpp"
  3536. -#include "prims/methodHandles.hpp"
  3537. #include "runtime/deoptimization.hpp"
  3538. #include "runtime/relocator.hpp"
  3539. #include "utilities/bitMap.inline.hpp"
  3540. +#include "prims/jvmtiClassFileReconstituter.hpp"
  3541. +#include "compiler/compileBroker.hpp"
  3542. +#include "oops/instanceMirrorKlass.hpp"
  3543. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  3544. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  3545. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  3546. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  3547. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  3548. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  3549. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  3550. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  3551. +int* VM_RedefineClasses::_deleted_methods = NULL;
  3552. +int* VM_RedefineClasses::_added_methods = NULL;
  3553. int VM_RedefineClasses::_matching_methods_length = 0;
  3554. int VM_RedefineClasses::_deleted_methods_length = 0;
  3555. int VM_RedefineClasses::_added_methods_length = 0;
  3556. -klassOop VM_RedefineClasses::_the_class_oop = NULL;
  3557. +GrowableArray<instanceKlassHandle>* VM_RedefineClasses::_affected_klasses = NULL;
  3558. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  3559. - const jvmtiClassDefinition *class_defs,
  3560. - JvmtiClassLoadKind class_load_kind) {
  3561. +// Holds the revision number of the current class redefinition
  3562. +int VM_RedefineClasses::_revision_number = -1;
  3563. +
  3564. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  3565. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
  3566. + RC_TIMER_START(_timer_total);
  3567. _class_count = class_count;
  3568. _class_defs = class_defs;
  3569. _class_load_kind = class_load_kind;
  3570. - _res = JVMTI_ERROR_NONE;
  3571. + _result = JVMTI_ERROR_NONE;
  3572. }
  3573. -bool VM_RedefineClasses::doit_prologue() {
  3574. - if (_class_count == 0) {
  3575. - _res = JVMTI_ERROR_NONE;
  3576. - return false;
  3577. - }
  3578. - if (_class_defs == NULL) {
  3579. - _res = JVMTI_ERROR_NULL_POINTER;
  3580. - return false;
  3581. - }
  3582. - for (int i = 0; i < _class_count; i++) {
  3583. - if (_class_defs[i].klass == NULL) {
  3584. - _res = JVMTI_ERROR_INVALID_CLASS;
  3585. - return false;
  3586. - }
  3587. - if (_class_defs[i].class_byte_count == 0) {
  3588. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3589. - return false;
  3590. - }
  3591. - if (_class_defs[i].class_bytes == NULL) {
  3592. - _res = JVMTI_ERROR_NULL_POINTER;
  3593. - return false;
  3594. - }
  3595. - }
  3596. +VM_RedefineClasses::~VM_RedefineClasses() {
  3597. + unlock_threads();
  3598. + RC_TIMER_STOP(_timer_total);
  3599. - // Start timer after all the sanity checks; not quite accurate, but
  3600. - // better than adding a bunch of stop() calls.
  3601. - RC_TIMER_START(_timer_vm_op_prologue);
  3602. -
  3603. - // We first load new class versions in the prologue, because somewhere down the
  3604. - // call chain it is required that the current thread is a Java thread.
  3605. - _res = load_new_class_versions(Thread::current());
  3606. - if (_res != JVMTI_ERROR_NONE) {
  3607. - // Free os::malloc allocated memory in load_new_class_version.
  3608. - os::free(_scratch_classes);
  3609. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3610. - return false;
  3611. - }
  3612. -
  3613. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3614. - return true;
  3615. -}
  3616. -
  3617. -void VM_RedefineClasses::doit() {
  3618. - Thread *thread = Thread::current();
  3619. -
  3620. - if (UseSharedSpaces) {
  3621. - // Sharing is enabled so we remap the shared readonly space to
  3622. - // shared readwrite, private just in case we need to redefine
  3623. - // a shared class. We do the remap during the doit() phase of
  3624. - // the safepoint to be safer.
  3625. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  3626. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  3627. - ("failed to remap shared readonly space to readwrite, private"));
  3628. - _res = JVMTI_ERROR_INTERNAL;
  3629. - return;
  3630. - }
  3631. - }
  3632. -
  3633. - for (int i = 0; i < _class_count; i++) {
  3634. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  3635. - }
  3636. - // Disable any dependent concurrent compilations
  3637. - SystemDictionary::notice_modification();
  3638. -
  3639. - // Set flag indicating that some invariants are no longer true.
  3640. - // See jvmtiExport.hpp for detailed explanation.
  3641. - JvmtiExport::set_has_redefined_a_class();
  3642. -
  3643. -// check_class() is optionally called for product bits, but is
  3644. -// always called for non-product bits.
  3645. -#ifdef PRODUCT
  3646. - if (RC_TRACE_ENABLED(0x00004000)) {
  3647. -#endif
  3648. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  3649. - SystemDictionary::classes_do(check_class, thread);
  3650. -#ifdef PRODUCT
  3651. - }
  3652. -#endif
  3653. -}
  3654. -
  3655. -void VM_RedefineClasses::doit_epilogue() {
  3656. - // Free os::malloc allocated memory.
  3657. - // The memory allocated in redefine will be free'ed in next VM operation.
  3658. - os::free(_scratch_classes);
  3659. -
  3660. - if (RC_TRACE_ENABLED(0x00000004)) {
  3661. - // Used to have separate timers for "doit" and "all", but the timer
  3662. - // overhead skewed the measurements.
  3663. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  3664. - _timer_rsc_phase2.milliseconds();
  3665. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  3666. -
  3667. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  3668. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  3669. - _timer_vm_op_prologue.milliseconds(), doit_time));
  3670. - RC_TRACE(0x00000004,
  3671. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  3672. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  3673. + if (TimeRedefineClasses) {
  3674. + tty->print_cr("");
  3675. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  3676. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  3677. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  3678. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  3679. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  3680. + tty->print_cr("Timing Heap Iteration: %d", _timer_heap_iteration.milliseconds());
  3681. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  3682. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  3683. + tty->print_cr("------------------------------------------------------------------");
  3684. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  3685. + tty->print_cr("");
  3686. }
  3687. }
  3688. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  3689. - // classes for primitives cannot be redefined
  3690. - if (java_lang_Class::is_primitive(klass_mirror)) {
  3691. - return false;
  3692. - }
  3693. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  3694. - // classes for arrays cannot be redefined
  3695. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  3696. - return false;
  3697. - }
  3698. - return true;
  3699. -}
  3700. -
  3701. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  3702. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  3703. -// direct CP entries, there is just the current entry to append. For
  3704. -// indirect and double-indirect CP entries, there are zero or more
  3705. -// referenced CP entries along with the current entry to append.
  3706. -// Indirect and double-indirect CP entries are handled by recursive
  3707. -// calls to append_entry() as needed. The referenced CP entries are
  3708. -// always appended to *merge_cp_p before the referee CP entry. These
  3709. -// referenced CP entries may already exist in *merge_cp_p in which case
  3710. -// there is nothing extra to append and only the current entry is
  3711. -// appended.
  3712. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  3713. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  3714. - TRAPS) {
  3715. -
  3716. - // append is different depending on entry tag type
  3717. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3718. -
  3719. - // The old verifier is implemented outside the VM. It loads classes,
  3720. - // but does not resolve constant pool entries directly so we never
  3721. - // see Class entries here with the old verifier. Similarly the old
  3722. - // verifier does not like Class entries in the input constant pool.
  3723. - // The split-verifier is implemented in the VM so it can optionally
  3724. - // and directly resolve constant pool entries to load classes. The
  3725. - // split-verifier can accept either Class entries or UnresolvedClass
  3726. - // entries in the input constant pool. We revert the appended copy
  3727. - // back to UnresolvedClass so that either verifier will be happy
  3728. - // with the constant pool entry.
  3729. - case JVM_CONSTANT_Class:
  3730. - {
  3731. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  3732. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  3733. - scratch_cp->klass_name_at(scratch_i));
  3734. -
  3735. - if (scratch_i != *merge_cp_length_p) {
  3736. - // The new entry in *merge_cp_p is at a different index than
  3737. - // the new entry in scratch_cp so we need to map the index values.
  3738. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3739. - }
  3740. - (*merge_cp_length_p)++;
  3741. - } break;
  3742. -
  3743. - // these are direct CP entries so they can be directly appended,
  3744. - // but double and long take two constant pool entries
  3745. - case JVM_CONSTANT_Double: // fall through
  3746. - case JVM_CONSTANT_Long:
  3747. - {
  3748. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  3749. - THREAD);
  3750. -
  3751. - if (scratch_i != *merge_cp_length_p) {
  3752. - // The new entry in *merge_cp_p is at a different index than
  3753. - // the new entry in scratch_cp so we need to map the index values.
  3754. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3755. - }
  3756. - (*merge_cp_length_p) += 2;
  3757. - } break;
  3758. -
  3759. - // these are direct CP entries so they can be directly appended
  3760. - case JVM_CONSTANT_Float: // fall through
  3761. - case JVM_CONSTANT_Integer: // fall through
  3762. - case JVM_CONSTANT_Utf8: // fall through
  3763. -
  3764. - // This was an indirect CP entry, but it has been changed into
  3765. - // an interned string so this entry can be directly appended.
  3766. - case JVM_CONSTANT_String: // fall through
  3767. -
  3768. - // These were indirect CP entries, but they have been changed into
  3769. - // Symbol*s so these entries can be directly appended.
  3770. - case JVM_CONSTANT_UnresolvedClass: // fall through
  3771. - case JVM_CONSTANT_UnresolvedString:
  3772. - {
  3773. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  3774. - THREAD);
  3775. -
  3776. - if (scratch_i != *merge_cp_length_p) {
  3777. - // The new entry in *merge_cp_p is at a different index than
  3778. - // the new entry in scratch_cp so we need to map the index values.
  3779. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3780. - }
  3781. - (*merge_cp_length_p)++;
  3782. - } break;
  3783. -
  3784. - // this is an indirect CP entry so it needs special handling
  3785. - case JVM_CONSTANT_NameAndType:
  3786. - {
  3787. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  3788. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  3789. - merge_cp_length_p, THREAD);
  3790. -
  3791. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  3792. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  3793. - merge_cp_p, merge_cp_length_p,
  3794. - THREAD);
  3795. -
  3796. - // If the referenced entries already exist in *merge_cp_p, then
  3797. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  3798. - // In that case, all we are appending is the current entry.
  3799. - if (new_name_ref_i != name_ref_i) {
  3800. - RC_TRACE(0x00080000,
  3801. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  3802. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  3803. - }
  3804. - if (new_signature_ref_i != signature_ref_i) {
  3805. - RC_TRACE(0x00080000,
  3806. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  3807. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  3808. - }
  3809. -
  3810. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  3811. - new_name_ref_i, new_signature_ref_i);
  3812. - if (scratch_i != *merge_cp_length_p) {
  3813. - // The new entry in *merge_cp_p is at a different index than
  3814. - // the new entry in scratch_cp so we need to map the index values.
  3815. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3816. - }
  3817. - (*merge_cp_length_p)++;
  3818. - } break;
  3819. -
  3820. - // this is a double-indirect CP entry so it needs special handling
  3821. - case JVM_CONSTANT_Fieldref: // fall through
  3822. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  3823. - case JVM_CONSTANT_Methodref:
  3824. - {
  3825. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  3826. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  3827. - merge_cp_p, merge_cp_length_p, THREAD);
  3828. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  3829. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  3830. - merge_cp_p, merge_cp_length_p, THREAD);
  3831. -
  3832. - const char *entry_name;
  3833. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3834. - case JVM_CONSTANT_Fieldref:
  3835. - entry_name = "Fieldref";
  3836. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  3837. - new_name_and_type_ref_i);
  3838. - break;
  3839. - case JVM_CONSTANT_InterfaceMethodref:
  3840. - entry_name = "IFMethodref";
  3841. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  3842. - new_klass_ref_i, new_name_and_type_ref_i);
  3843. - break;
  3844. - case JVM_CONSTANT_Methodref:
  3845. - entry_name = "Methodref";
  3846. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  3847. - new_name_and_type_ref_i);
  3848. - break;
  3849. - default:
  3850. - guarantee(false, "bad switch");
  3851. - break;
  3852. - }
  3853. -
  3854. - if (klass_ref_i != new_klass_ref_i) {
  3855. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  3856. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  3857. - }
  3858. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  3859. - RC_TRACE(0x00080000,
  3860. - ("%s entry@%d name_and_type_index changed: %d to %d",
  3861. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  3862. - new_name_and_type_ref_i));
  3863. - }
  3864. -
  3865. - if (scratch_i != *merge_cp_length_p) {
  3866. - // The new entry in *merge_cp_p is at a different index than
  3867. - // the new entry in scratch_cp so we need to map the index values.
  3868. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3869. - }
  3870. - (*merge_cp_length_p)++;
  3871. - } break;
  3872. -
  3873. - // this is an indirect CP entry so it needs special handling
  3874. - case JVM_CONSTANT_MethodType:
  3875. - {
  3876. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  3877. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  3878. - merge_cp_length_p, THREAD);
  3879. - if (new_ref_i != ref_i) {
  3880. - RC_TRACE(0x00080000,
  3881. - ("MethodType entry@%d ref_index change: %d to %d",
  3882. - *merge_cp_length_p, ref_i, new_ref_i));
  3883. - }
  3884. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  3885. - if (scratch_i != *merge_cp_length_p) {
  3886. - // The new entry in *merge_cp_p is at a different index than
  3887. - // the new entry in scratch_cp so we need to map the index values.
  3888. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3889. - }
  3890. - (*merge_cp_length_p)++;
  3891. - } break;
  3892. -
  3893. - // this is an indirect CP entry so it needs special handling
  3894. - case JVM_CONSTANT_MethodHandle:
  3895. - {
  3896. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  3897. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  3898. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  3899. - merge_cp_length_p, THREAD);
  3900. - if (new_ref_i != ref_i) {
  3901. - RC_TRACE(0x00080000,
  3902. - ("MethodHandle entry@%d ref_index change: %d to %d",
  3903. - *merge_cp_length_p, ref_i, new_ref_i));
  3904. - }
  3905. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  3906. - if (scratch_i != *merge_cp_length_p) {
  3907. - // The new entry in *merge_cp_p is at a different index than
  3908. - // the new entry in scratch_cp so we need to map the index values.
  3909. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3910. - }
  3911. - (*merge_cp_length_p)++;
  3912. - } break;
  3913. -
  3914. - // this is an indirect CP entry so it needs special handling
  3915. - case JVM_CONSTANT_InvokeDynamic:
  3916. - {
  3917. - // Index of the bootstrap specifier in the operands array
  3918. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  3919. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  3920. - merge_cp_length_p, THREAD);
  3921. - // The bootstrap method NameAndType_info index
  3922. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  3923. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  3924. - merge_cp_length_p, THREAD);
  3925. - if (new_bs_i != old_bs_i) {
  3926. - RC_TRACE(0x00080000,
  3927. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  3928. - *merge_cp_length_p, old_bs_i, new_bs_i));
  3929. - }
  3930. - if (new_ref_i != old_ref_i) {
  3931. - RC_TRACE(0x00080000,
  3932. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  3933. - *merge_cp_length_p, old_ref_i, new_ref_i));
  3934. - }
  3935. -
  3936. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  3937. - if (scratch_i != *merge_cp_length_p) {
  3938. - // The new entry in *merge_cp_p is at a different index than
  3939. - // the new entry in scratch_cp so we need to map the index values.
  3940. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3941. - }
  3942. - (*merge_cp_length_p)++;
  3943. - } break;
  3944. -
  3945. - // At this stage, Class or UnresolvedClass could be here, but not
  3946. - // ClassIndex
  3947. - case JVM_CONSTANT_ClassIndex: // fall through
  3948. -
  3949. - // Invalid is used as the tag for the second constant pool entry
  3950. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  3951. - // not be seen by itself.
  3952. - case JVM_CONSTANT_Invalid: // fall through
  3953. -
  3954. - // At this stage, String or UnresolvedString could be here, but not
  3955. - // StringIndex
  3956. - case JVM_CONSTANT_StringIndex: // fall through
  3957. -
  3958. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  3959. - // here
  3960. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  3961. -
  3962. - default:
  3963. - {
  3964. - // leave a breadcrumb
  3965. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  3966. - ShouldNotReachHere();
  3967. - } break;
  3968. - } // end switch tag value
  3969. -} // end append_entry()
  3970. -
  3971. -
  3972. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  3973. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  3974. -
  3975. - int new_ref_i = ref_i;
  3976. - bool match = (ref_i < *merge_cp_length_p) &&
  3977. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  3978. -
  3979. - if (!match) {
  3980. - // forward reference in *merge_cp_p or not a direct match
  3981. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  3982. - if (found_i != 0) {
  3983. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  3984. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  3985. - new_ref_i = found_i;
  3986. - map_index(scratch_cp, ref_i, found_i);
  3987. - } else {
  3988. - // no match found so we have to append this entry to *merge_cp_p
  3989. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  3990. - // The above call to append_entry() can only append one entry
  3991. - // so the post call query of *merge_cp_length_p is only for
  3992. - // the sake of consistency.
  3993. - new_ref_i = *merge_cp_length_p - 1;
  3994. - }
  3995. - }
  3996. -
  3997. - return new_ref_i;
  3998. -} // end find_or_append_indirect_entry()
  3999. -
  4000. -
  4001. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  4002. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  4003. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  4004. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  4005. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  4006. -
  4007. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  4008. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  4009. - merge_cp_length_p, THREAD);
  4010. - if (new_ref_i != old_ref_i) {
  4011. - RC_TRACE(0x00080000,
  4012. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  4013. - _operands_cur_length, old_ref_i, new_ref_i));
  4014. - }
  4015. -
  4016. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  4017. - int new_bs_i = _operands_cur_length;
  4018. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  4019. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  4020. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  4021. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  4022. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  4023. -
  4024. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  4025. - merge_ops->short_at_put(new_base++, new_ref_i);
  4026. - merge_ops->short_at_put(new_base++, argc);
  4027. -
  4028. - for (int i = 0; i < argc; i++) {
  4029. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  4030. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  4031. - merge_cp_length_p, THREAD);
  4032. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  4033. - if (new_arg_ref_i != old_arg_ref_i) {
  4034. - RC_TRACE(0x00080000,
  4035. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  4036. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  4037. - }
  4038. - }
  4039. - if (old_bs_i != _operands_cur_length) {
  4040. - // The bootstrap specifier in *merge_cp_p is at a different index than
  4041. - // that in scratch_cp so we need to map the index values.
  4042. - map_operand_index(old_bs_i, new_bs_i);
  4043. - }
  4044. - _operands_cur_length++;
  4045. -} // end append_operand()
  4046. -
  4047. -
  4048. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  4049. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  4050. -
  4051. - int new_bs_i = old_bs_i; // bootstrap specifier index
  4052. - bool match = (old_bs_i < _operands_cur_length) &&
  4053. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  4054. -
  4055. - if (!match) {
  4056. - // forward reference in *merge_cp_p or not a direct match
  4057. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  4058. - _operands_cur_length, THREAD);
  4059. - if (found_i != -1) {
  4060. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  4061. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  4062. - new_bs_i = found_i;
  4063. - map_operand_index(old_bs_i, found_i);
  4064. - } else {
  4065. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  4066. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  4067. - new_bs_i = _operands_cur_length - 1;
  4068. - }
  4069. - }
  4070. - return new_bs_i;
  4071. -} // end find_or_append_operand()
  4072. -
  4073. -
  4074. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  4075. - if (merge_cp->operands() == NULL) {
  4076. - return;
  4077. - }
  4078. - // Shrink the merge_cp operands
  4079. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  4080. -
  4081. - if (RC_TRACE_ENABLED(0x00040000)) {
  4082. - // don't want to loop unless we are tracing
  4083. - int count = 0;
  4084. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  4085. - int value = _operands_index_map_p->at(i);
  4086. - if (value != -1) {
  4087. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  4088. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  4089. - count++;
  4090. - }
  4091. - }
  4092. - }
  4093. - // Clean-up
  4094. - _operands_index_map_p = NULL;
  4095. - _operands_cur_length = 0;
  4096. - _operands_index_map_count = 0;
  4097. -} // end finalize_operands_merge()
  4098. -
  4099. -
  4100. void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  4101. typeArrayOop save;
  4102. @@ -591,20 +103,604 @@
  4103. scratch_class->set_method_default_annotations_of(j, save);
  4104. }
  4105. +void VM_RedefineClasses::add_affected_klasses( klassOop klass )
  4106. +{
  4107. + assert(!_affected_klasses->contains(klass), "must not occur more than once!");
  4108. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  4109. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4110. - instanceKlassHandle the_class,
  4111. - instanceKlassHandle scratch_class) {
  4112. + Klass* k = klass->klass_part();
  4113. +
  4114. + if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4115. + _affected_klasses->append(klass);
  4116. + return;
  4117. + }
  4118. +
  4119. + for (juint i = 0; i < k->super_depth(); i++) {
  4120. + klassOop primary_oop = k->primary_super_of_depth(i);
  4121. + // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
  4122. + if (primary_oop == NULL) break;
  4123. + Klass* primary = Klass::cast(primary_oop);
  4124. + if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4125. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  4126. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  4127. + _affected_klasses->append(klass);
  4128. + return;
  4129. + }
  4130. + }
  4131. +
  4132. + // Check secondary supers
  4133. + int cnt = k->secondary_supers()->length();
  4134. + for (int i = 0; i < cnt; i++) {
  4135. + Klass* secondary = Klass::cast((klassOop) k->secondary_supers()->obj_at(i));
  4136. + if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4137. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  4138. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  4139. + _affected_klasses->append(klass);
  4140. + return;
  4141. + }
  4142. + }
  4143. +}
  4144. +
  4145. +
  4146. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4147. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes() {
  4148. +
  4149. + assert(_affected_klasses, "");
  4150. + for (int i = 0; i < _class_count; i++) {
  4151. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4152. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4153. + klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
  4154. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4155. + }
  4156. +
  4157. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4158. + SystemDictionary::classes_do(VM_RedefineClasses::add_affected_klasses);
  4159. + TRACE_RC1("%d classes affected", _affected_klasses->length());
  4160. +
  4161. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4162. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
  4163. + IF_TRACE_RC2 {
  4164. + TRACE_RC2("Redefine order: ");
  4165. + for (int i = 0; i < _affected_klasses->length(); i++) {
  4166. + TRACE_RC2("%s", _affected_klasses->at(i)->name()->as_C_string());
  4167. + }
  4168. + }
  4169. +
  4170. + return result;
  4171. +}
  4172. +
  4173. +// Searches for the class bytes of the given class and returns them as a byte array.
  4174. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4175. +
  4176. + *not_changed = false;
  4177. +
  4178. + // Search for the index in the redefinition array that corresponds to the current class
  4179. + int j;
  4180. + for (j=0; j<_class_count; j++) {
  4181. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4182. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4183. + if (the_class_oop == the_class()) {
  4184. + break;
  4185. + }
  4186. + }
  4187. +
  4188. + if (j == _class_count) {
  4189. +
  4190. + *not_changed = true;
  4191. +
  4192. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4193. + // so the user did not specify a different bytecode for that class.
  4194. +
  4195. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4196. + // not cached, we need to reconstitute the class file from VM representation
  4197. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4198. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4199. +
  4200. + JvmtiClassFileReconstituter reconstituter(the_class);
  4201. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4202. + return reconstituter.get_error();
  4203. + }
  4204. +
  4205. + *class_byte_count = (jint)reconstituter.class_file_size();
  4206. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4207. +
  4208. + TRACE_RC3("Reconstituted class bytes");
  4209. +
  4210. + } else {
  4211. +
  4212. + // it is cached, get it from the cache
  4213. + *class_byte_count = the_class->get_cached_class_file_len();
  4214. + *class_bytes = the_class->get_cached_class_file_bytes();
  4215. +
  4216. +
  4217. + TRACE_RC3("Retrieved cached class bytes");
  4218. + }
  4219. +
  4220. + } else {
  4221. +
  4222. + // Redefine with bytecodes at index j
  4223. + *class_bytes = _class_defs[j].class_bytes;
  4224. + *class_byte_count = _class_defs[j].class_byte_count;
  4225. + }
  4226. +
  4227. + return JVMTI_ERROR_NONE;
  4228. +}
  4229. +
  4230. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4231. +bool VM_RedefineClasses::doit_prologue() {
  4232. +
  4233. + _revision_number++;
  4234. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  4235. + lock_threads();
  4236. +
  4237. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4238. + RC_TIMER_START(_timer_prologue);
  4239. +
  4240. + if (!check_arguments()) {
  4241. + RC_TIMER_STOP(_timer_prologue);
  4242. + return false;
  4243. + }
  4244. +
  4245. + // We first load new class versions in the prologue, because somewhere down the
  4246. + // call chain it is required that the current thread is a Java thread.
  4247. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4248. +
  4249. + assert(_affected_klasses == NULL, "");
  4250. + _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
  4251. +
  4252. +
  4253. + _result = load_new_class_versions(Thread::current());
  4254. +
  4255. + TRACE_RC1("Loaded new class versions!");
  4256. + if (_result != JVMTI_ERROR_NONE) {
  4257. + TRACE_RC1("error occured: %d!", _result);
  4258. + delete _new_classes;
  4259. + _new_classes = NULL;
  4260. + delete _affected_klasses;
  4261. + _affected_klasses = NULL;
  4262. + RC_TIMER_STOP(_timer_prologue);
  4263. + return false;
  4264. + }
  4265. +
  4266. + TRACE_RC2("nearly finished");
  4267. + VM_GC_Operation::doit_prologue();
  4268. + RC_TIMER_STOP(_timer_prologue);
  4269. + TRACE_RC2("doit_prologue finished!");
  4270. + return true;
  4271. +}
  4272. +
  4273. +// Checks basic properties of the arguments of the redefinition command.
  4274. +jvmtiError VM_RedefineClasses::check_arguments_error() {
  4275. + if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
  4276. + for (int i = 0; i < _class_count; i++) {
  4277. + if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
  4278. + if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4279. + if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
  4280. + }
  4281. + return JVMTI_ERROR_NONE;
  4282. +}
  4283. +
  4284. +// Returns false and sets an result error code if the redefinition should be aborted.
  4285. +bool VM_RedefineClasses::check_arguments() {
  4286. + jvmtiError error = check_arguments_error();
  4287. + if (error != JVMTI_ERROR_NONE || _class_count == 0) {
  4288. + _result = error;
  4289. + return false;
  4290. + }
  4291. + return true;
  4292. +}
  4293. +
  4294. +jvmtiError VM_RedefineClasses::check_exception() const {
  4295. + Thread* THREAD = Thread::current();
  4296. + if (HAS_PENDING_EXCEPTION) {
  4297. +
  4298. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4299. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  4300. + if (TraceRedefineClasses >= 1) {
  4301. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4302. + tty->print_cr("");
  4303. + }
  4304. + CLEAR_PENDING_EXCEPTION;
  4305. +
  4306. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4307. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4308. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4309. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4310. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4311. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4312. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4313. + // The message will be "XXX (wrong name: YYY)"
  4314. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4315. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4316. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4317. + } else {
  4318. + // Just in case more exceptions can be thrown..
  4319. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4320. + }
  4321. + }
  4322. +
  4323. + return JVMTI_ERROR_NONE;
  4324. +}
  4325. +
  4326. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4327. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4328. +
  4329. + ResourceMark rm(THREAD);
  4330. +
  4331. + TRACE_RC1("===================================================================");
  4332. + TRACE_RC1("redefinition started by thread \"%s\"", THREAD->name());
  4333. + TRACE_RC1("load new class versions (%d)", _class_count);
  4334. +
  4335. + // Retrieve an array of all classes that need to be redefined
  4336. + jvmtiError err = find_sorted_affected_classes();
  4337. + if (err != JVMTI_ERROR_NONE) {
  4338. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  4339. + return err;
  4340. + }
  4341. +
  4342. +
  4343. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4344. +
  4345. + _max_redefinition_flags = Klass::NoRedefinition;
  4346. + jvmtiError result = JVMTI_ERROR_NONE;
  4347. +
  4348. + for (int i=0; i<_affected_klasses->length(); i++) {
  4349. + TRACE_RC2("Processing affected class %d of %d", i+1, _affected_klasses->length());
  4350. +
  4351. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4352. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  4353. +
  4354. + the_class->link_class(THREAD);
  4355. + result = check_exception();
  4356. + if (result != JVMTI_ERROR_NONE) break;
  4357. +
  4358. + // Find new class bytes
  4359. + const unsigned char* class_bytes;
  4360. + jint class_byte_count;
  4361. + jvmtiError error;
  4362. + jboolean not_changed;
  4363. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4364. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  4365. + result = error;
  4366. + break;
  4367. + }
  4368. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4369. +
  4370. +
  4371. + // Set redefined class handle in JvmtiThreadState class.
  4372. + // This redefined class is sent to agent event handler for class file
  4373. + // load hook event.
  4374. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4375. +
  4376. + TRACE_RC2("Before resolving from stream");
  4377. +
  4378. + RC_TIMER_STOP(_timer_prologue);
  4379. + RC_TIMER_START(_timer_class_loading);
  4380. +
  4381. +
  4382. + // Parse the stream.
  4383. + Handle the_class_loader(THREAD, the_class->class_loader());
  4384. + Handle protection_domain(THREAD, the_class->protection_domain());
  4385. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4386. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class->name(),
  4387. + the_class_loader,
  4388. + protection_domain,
  4389. + &st,
  4390. + true,
  4391. + the_class,
  4392. + THREAD));
  4393. +
  4394. + RC_TIMER_STOP(_timer_class_loading);
  4395. + RC_TIMER_START(_timer_prologue);
  4396. +
  4397. + TRACE_RC2("After resolving class from stream!");
  4398. + // Clear class_being_redefined just to be sure.
  4399. + state->clear_class_being_redefined();
  4400. +
  4401. + result = check_exception();
  4402. + if (result != JVMTI_ERROR_NONE) break;
  4403. +
  4404. + not_changed = false;
  4405. +
  4406. +#ifdef ASSERT
  4407. +
  4408. + assert(new_class() != NULL, "Class could not be loaded!");
  4409. + assert(new_class() != the_class(), "must be different");
  4410. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4411. +
  4412. +
  4413. + objArrayOop k_interfaces = new_class->local_interfaces();
  4414. + for (int j=0; j<k_interfaces->length(); j++) {
  4415. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4416. + }
  4417. +
  4418. + if (!THREAD->is_Compiler_thread()) {
  4419. +
  4420. + TRACE_RC2("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT, the_class->name()->as_C_string(), the_class->class_loader(), the_class->protection_domain());
  4421. + // If we are on the compiler thread, we must not try to resolve a class.
  4422. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4423. +
  4424. + if (systemLookup != NULL) {
  4425. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4426. +
  4427. +
  4428. + Klass *subklass = new_class()->klass_part()->subklass();
  4429. + while (subklass != NULL) {
  4430. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4431. + subklass = subklass->next_sibling();
  4432. + }
  4433. + } else {
  4434. + // This can happen for reflection generated classes.. ?
  4435. + CLEAR_PENDING_EXCEPTION;
  4436. + }
  4437. + }
  4438. +
  4439. +#endif
  4440. +
  4441. + IF_TRACE_RC1 {
  4442. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4443. + 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());
  4444. + }
  4445. + }
  4446. +
  4447. + // Set the new version of the class
  4448. + new_class->set_revision_number(_revision_number);
  4449. + new_class->set_redefinition_index(i);
  4450. + the_class->set_new_version(new_class());
  4451. + _new_classes->append(new_class);
  4452. +
  4453. + assert(new_class->new_version() == NULL, "");
  4454. +
  4455. + int redefinition_flags = Klass::NoRedefinition;
  4456. +
  4457. + if (not_changed) {
  4458. + redefinition_flags = Klass::NoRedefinition;
  4459. + } else if (AllowAdvancedClassRedefinition) {
  4460. + redefinition_flags = calculate_redefinition_flags(new_class);
  4461. + if (redefinition_flags >= Klass::RemoveSuperType) {
  4462. + TRACE_RC1("Remove super type is not allowed");
  4463. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4464. + break;
  4465. + }
  4466. + } else {
  4467. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4468. + if (allowed != JVMTI_ERROR_NONE) {
  4469. + TRACE_RC1("Error redefinition not allowed!");
  4470. + result = allowed;
  4471. + break;
  4472. + }
  4473. + redefinition_flags = Klass::ModifyClass;
  4474. + }
  4475. +
  4476. + if (new_class->super() != NULL) {
  4477. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4478. + }
  4479. +
  4480. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4481. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4482. + }
  4483. +
  4484. + new_class->set_redefinition_flags(redefinition_flags);
  4485. +
  4486. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4487. +
  4488. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4489. + // TODO: Check if watch access flags of static fields are updated correctly.
  4490. + calculate_instance_update_information(_new_classes->at(i)());
  4491. + } else {
  4492. + // Fields were not changed, transfer special flags only
  4493. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4494. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4495. +
  4496. + JavaFieldStream old_fs(the_class);
  4497. + JavaFieldStream new_fs(new_class);
  4498. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4499. + AccessFlags flags = new_fs.access_flags();
  4500. + flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
  4501. + flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
  4502. + new_fs.set_access_flags(flags);
  4503. + }
  4504. + }
  4505. +
  4506. + IF_TRACE_RC3 {
  4507. + if (new_class->super() != NULL) {
  4508. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  4509. + }
  4510. + }
  4511. +
  4512. +#ifdef ASSERT
  4513. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4514. +
  4515. + the_class->vtable()->verify(tty);
  4516. + new_class->vtable()->verify(tty);
  4517. +#endif
  4518. +
  4519. + TRACE_RC2("Verification done!");
  4520. +
  4521. + if (i == _affected_klasses->length() - 1) {
  4522. +
  4523. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4524. +
  4525. + for (int j=0; j<_affected_klasses->length(); j++) {
  4526. +
  4527. + klassOop initial_klass = _affected_klasses->at(j)();
  4528. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4529. + Klass *cur_klass = initial_subklass;
  4530. + while(cur_klass != NULL) {
  4531. +
  4532. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
  4533. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4534. + if (!_affected_klasses->contains(handle)) {
  4535. +
  4536. + int k = i + 1;
  4537. + for (; k<_affected_klasses->length(); k++) {
  4538. + if (_affected_klasses->at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4539. + break;
  4540. + }
  4541. + }
  4542. + _affected_klasses->insert_before(k, handle);
  4543. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  4544. + }
  4545. + }
  4546. +
  4547. + cur_klass = cur_klass->next_sibling();
  4548. + }
  4549. + }
  4550. +
  4551. + int new_count = _affected_klasses->length() - 1 - i;
  4552. + if (new_count != 0) {
  4553. +
  4554. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  4555. + }
  4556. + }
  4557. + }
  4558. +
  4559. + if (result != JVMTI_ERROR_NONE) {
  4560. + rollback();
  4561. + return result;
  4562. + }
  4563. +
  4564. + RC_TIMER_STOP(_timer_prologue);
  4565. + RC_TIMER_START(_timer_class_linking);
  4566. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4567. + for (int i=0; i<_affected_klasses->length(); i++) {
  4568. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4569. + instanceKlassHandle new_class(the_class->new_version());
  4570. +
  4571. + TRACE_RC2("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string());
  4572. + new_class->link_class(THREAD);
  4573. +
  4574. + result = check_exception();
  4575. + if (result != JVMTI_ERROR_NONE) break;
  4576. + }
  4577. + RC_TIMER_STOP(_timer_class_linking);
  4578. + RC_TIMER_START(_timer_prologue);
  4579. +
  4580. + if (result != JVMTI_ERROR_NONE) {
  4581. + rollback();
  4582. + return result;
  4583. + }
  4584. +
  4585. + TRACE_RC2("All classes loaded!");
  4586. +
  4587. +#ifdef ASSERT
  4588. + for (int i=0; i<_affected_klasses->length(); i++) {
  4589. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4590. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4591. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  4592. + assert(new_version->new_version() == NULL, "Must be newest version");
  4593. +
  4594. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  4595. + new_version()->print();
  4596. + new_version->super()->print();
  4597. + }
  4598. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  4599. + }
  4600. +
  4601. + SystemDictionary::classes_do(check_class, THREAD);
  4602. +
  4603. +#endif
  4604. +
  4605. + TRACE_RC1("Finished verification!");
  4606. + return JVMTI_ERROR_NONE;
  4607. +}
  4608. +
  4609. +void VM_RedefineClasses::lock_threads() {
  4610. +
  4611. + RC_TIMER_START(_timer_wait_for_locks);
  4612. +
  4613. +
  4614. + JavaThread *javaThread = Threads::first();
  4615. + while (javaThread != NULL) {
  4616. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4617. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4618. + compilerThread->set_should_bailout(true);
  4619. + }
  4620. + javaThread = javaThread->next();
  4621. + }
  4622. +
  4623. + int cnt = 0;
  4624. + javaThread = Threads::first();
  4625. + while (javaThread != NULL) {
  4626. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4627. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4628. + compilerThread->compilation_mutex()->lock();
  4629. + cnt++;
  4630. + }
  4631. + javaThread = javaThread->next();
  4632. + }
  4633. +
  4634. + TRACE_RC2("Locked %d compiler threads", cnt);
  4635. +
  4636. + cnt = 0;
  4637. + javaThread = Threads::first();
  4638. + while (javaThread != NULL) {
  4639. + if (javaThread != Thread::current()) {
  4640. + javaThread->redefine_classes_mutex()->lock();
  4641. + cnt++;
  4642. + }
  4643. + javaThread = javaThread->next();
  4644. + }
  4645. +
  4646. +
  4647. + TRACE_RC2("Locked %d threads", cnt);
  4648. +
  4649. + RC_TIMER_STOP(_timer_wait_for_locks);
  4650. +}
  4651. +
  4652. +void VM_RedefineClasses::unlock_threads() {
  4653. +
  4654. + int cnt = 0;
  4655. + JavaThread *javaThread = Threads::first();
  4656. + Thread *thread = Thread::current();
  4657. + while (javaThread != NULL) {
  4658. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4659. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4660. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  4661. + compilerThread->compilation_mutex()->unlock();
  4662. + cnt++;
  4663. + }
  4664. + }
  4665. + javaThread = javaThread->next();
  4666. + }
  4667. +
  4668. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  4669. +
  4670. + cnt = 0;
  4671. + javaThread = Threads::first();
  4672. + while (javaThread != NULL) {
  4673. + if (javaThread != Thread::current()) {
  4674. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  4675. + javaThread->redefine_classes_mutex()->unlock();
  4676. + cnt++;
  4677. + }
  4678. + }
  4679. + javaThread = javaThread->next();
  4680. + }
  4681. +
  4682. + TRACE_RC2("Unlocked %d threads", cnt);
  4683. +}
  4684. +
  4685. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  4686. +
  4687. +
  4688. +
  4689. + // Compatibility mode => check for unsupported modification
  4690. +
  4691. +
  4692. + assert(scratch_class->old_version() != NULL, "must have old version");
  4693. + instanceKlassHandle the_class(scratch_class->old_version());
  4694. +
  4695. int i;
  4696. // Check superclasses, or rather their names, since superclasses themselves can be
  4697. // requested to replace.
  4698. // Check for NULL superclass first since this might be java.lang.Object
  4699. if (the_class->super() != scratch_class->super() &&
  4700. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  4701. - Klass::cast(the_class->super())->name() !=
  4702. - Klass::cast(scratch_class->super())->name())) {
  4703. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4704. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  4705. + Klass::cast(the_class->super())->name() !=
  4706. + Klass::cast(scratch_class->super())->name())) {
  4707. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4708. }
  4709. // Check if the number, names and order of directly implemented interfaces are the same.
  4710. @@ -622,8 +718,8 @@
  4711. }
  4712. for (i = 0; i < n_intfs; i++) {
  4713. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  4714. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4715. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4716. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4717. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4718. }
  4719. }
  4720. @@ -772,12 +868,8 @@
  4721. idnum_owner->set_method_idnum(new_num);
  4722. }
  4723. k_new_method->set_method_idnum(old_num);
  4724. - swap_all_method_annotations(old_num, new_num, scratch_class);
  4725. }
  4726. }
  4727. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  4728. - k_new_method->name_and_sig_as_C_string(), ni,
  4729. - k_old_method->name_and_sig_as_C_string(), oi));
  4730. // advance to next pair of methods
  4731. ++oi;
  4732. ++ni;
  4733. @@ -786,11 +878,11 @@
  4734. // method added, see if it is OK
  4735. new_flags = (jushort) k_new_method->access_flags().get_flags();
  4736. if ((new_flags & JVM_ACC_PRIVATE) == 0
  4737. - // hack: private should be treated as final, but alas
  4738. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4739. - ) {
  4740. - // new methods must be private
  4741. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4742. + // hack: private should be treated as final, but alas
  4743. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4744. + ) {
  4745. + // new methods must be private
  4746. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4747. }
  4748. {
  4749. u2 num = the_class->next_method_idnum();
  4750. @@ -805,24 +897,19 @@
  4751. idnum_owner->set_method_idnum(new_num);
  4752. }
  4753. k_new_method->set_method_idnum(num);
  4754. - swap_all_method_annotations(new_num, num, scratch_class);
  4755. }
  4756. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  4757. - k_new_method->name_and_sig_as_C_string(), ni));
  4758. ++ni; // advance to next new method
  4759. break;
  4760. case deleted:
  4761. // method deleted, see if it is OK
  4762. old_flags = (jushort) k_old_method->access_flags().get_flags();
  4763. if ((old_flags & JVM_ACC_PRIVATE) == 0
  4764. - // hack: private should be treated as final, but alas
  4765. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4766. - ) {
  4767. - // deleted methods must be private
  4768. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4769. + // hack: private should be treated as final, but alas
  4770. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4771. + ) {
  4772. + // deleted methods must be private
  4773. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4774. }
  4775. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  4776. - k_old_method->name_and_sig_as_C_string(), oi));
  4777. ++oi; // advance to next old method
  4778. break;
  4779. default:
  4780. @@ -833,2119 +920,1332 @@
  4781. return JVMTI_ERROR_NONE;
  4782. }
  4783. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  4784. -// Find new constant pool index value for old constant pool index value
  4785. -// by seaching the index map. Returns zero (0) if there is no mapped
  4786. -// value for the old constant pool index.
  4787. -int VM_RedefineClasses::find_new_index(int old_index) {
  4788. - if (_index_map_count == 0) {
  4789. - // map is empty so nothing can be found
  4790. - return 0;
  4791. + int result = Klass::NoRedefinition;
  4792. +
  4793. +
  4794. +
  4795. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  4796. +
  4797. + assert(new_class->old_version() != NULL, "must have old version");
  4798. + instanceKlassHandle the_class(new_class->old_version());
  4799. +
  4800. + // Check whether class is in the error init state.
  4801. + if (the_class->is_in_error_state()) {
  4802. + // TBD #5057930: special error code is needed in 1.6
  4803. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  4804. }
  4805. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  4806. - // The old_index is out of range so it is not mapped. This should
  4807. - // not happen in regular constant pool merging use, but it can
  4808. - // happen if a corrupt annotation is processed.
  4809. - return 0;
  4810. + int i;
  4811. +
  4812. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4813. + // Check superclasses
  4814. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  4815. + if (the_class->super() != new_class->super()) {
  4816. + // Super class changed
  4817. +
  4818. + klassOop cur_klass = the_class->super();
  4819. + while (cur_klass != NULL) {
  4820. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  4821. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  4822. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  4823. +
  4824. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  4825. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  4826. + cur_klass->klass_part()->set_subtype_changed(true);
  4827. + }
  4828. + }
  4829. +
  4830. + cur_klass = cur_klass->klass_part()->super();
  4831. + }
  4832. +
  4833. + cur_klass = new_class->super();
  4834. + while (cur_klass != NULL) {
  4835. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  4836. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  4837. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  4838. + }
  4839. + cur_klass = cur_klass->klass_part()->super();
  4840. + }
  4841. }
  4842. - int value = _index_map_p->at(old_index);
  4843. - if (value == -1) {
  4844. - // the old_index is not mapped
  4845. - return 0;
  4846. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4847. + // Check interfaces
  4848. +
  4849. + // Interfaces removed?
  4850. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  4851. + for (i = 0; i<old_interfaces->length(); i++) {
  4852. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  4853. + if (!new_class->implements_interface_any_version(old_interface())) {
  4854. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  4855. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  4856. +
  4857. + if (!old_interface->has_subtype_changed()) {
  4858. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  4859. + old_interface->set_subtype_changed(true);
  4860. + }
  4861. + }
  4862. }
  4863. - return value;
  4864. -} // end find_new_index()
  4865. -
  4866. -
  4867. -// Find new bootstrap specifier index value for old bootstrap specifier index
  4868. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  4869. -// value for the old bootstrap specifier index.
  4870. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  4871. - if (_operands_index_map_count == 0) {
  4872. - // map is empty so nothing can be found
  4873. - return -1;
  4874. + // Interfaces added?
  4875. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  4876. + for (i = 0; i<new_interfaces->length(); i++) {
  4877. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  4878. + result = result | Klass::ModifyClass;
  4879. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  4880. + }
  4881. }
  4882. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  4883. - // The old_index is out of range so it is not mapped.
  4884. - // This should not happen in regular constant pool merging use.
  4885. - return -1;
  4886. +
  4887. + // Check whether class modifiers are the same.
  4888. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  4889. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  4890. + if (old_flags != new_flags) {
  4891. + // TODO (tw): Can this have any effects?
  4892. + }
  4893. +
  4894. + // Check if the number, names, types and order of fields declared in these classes
  4895. + // are the same.
  4896. + JavaFieldStream old_fs(the_class);
  4897. + JavaFieldStream new_fs(new_class);
  4898. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4899. + // access
  4900. + old_flags = old_fs.access_flags().as_short();
  4901. + new_flags = new_fs.access_flags().as_short();
  4902. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  4903. + // TODO (tw) can this have any effect?
  4904. + }
  4905. + // offset
  4906. + if (old_fs.offset() != new_fs.offset()) {
  4907. + result = result | Klass::ModifyInstances;
  4908. + }
  4909. + // name and signature
  4910. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  4911. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  4912. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  4913. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  4914. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  4915. + result = result | Klass::ModifyInstances;
  4916. + }
  4917. }
  4918. - int value = _operands_index_map_p->at(old_index);
  4919. -
  4920. - return value;
  4921. -} // end find_new_operand_index()
  4922. -
  4923. -
  4924. -// Returns true if the current mismatch is due to a resolved/unresolved
  4925. -// class pair. Otherwise, returns false.
  4926. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  4927. - int index1, constantPoolHandle cp2, int index2) {
  4928. -
  4929. - jbyte t1 = cp1->tag_at(index1).value();
  4930. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  4931. - return false; // wrong entry type; not our special case
  4932. + // If both streams aren't done then we have a differing number of
  4933. + // fields.
  4934. + if (!old_fs.done() || !new_fs.done()) {
  4935. + result = result | Klass::ModifyInstances;
  4936. }
  4937. - jbyte t2 = cp2->tag_at(index2).value();
  4938. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  4939. - return false; // wrong entry type; not our special case
  4940. - }
  4941. + // Do a parallel walk through the old and new methods. Detect
  4942. + // cases where they match (exist in both), have been added in
  4943. + // the new methods, or have been deleted (exist only in the
  4944. + // old methods). The class file parser places methods in order
  4945. + // by method name, but does not order overloaded methods by
  4946. + // signature. In order to determine what fate befell the methods,
  4947. + // this code places the overloaded new methods that have matching
  4948. + // old methods in the same order as the old methods and places
  4949. + // new overloaded methods at the end of overloaded methods of
  4950. + // that name. The code for this order normalization is adapted
  4951. + // from the algorithm used in instanceKlass::find_method().
  4952. + // Since we are swapping out of order entries as we find them,
  4953. + // we only have to search forward through the overloaded methods.
  4954. + // Methods which are added and have the same name as an existing
  4955. + // method (but different signature) will be put at the end of
  4956. + // the methods with that name, and the name mismatch code will
  4957. + // handle them.
  4958. + objArrayHandle k_old_methods(the_class->methods());
  4959. + objArrayHandle k_new_methods(new_class->methods());
  4960. + int n_old_methods = k_old_methods->length();
  4961. + int n_new_methods = k_new_methods->length();
  4962. - if (t1 == t2) {
  4963. - return false; // not a mismatch; not our special case
  4964. - }
  4965. + int ni = 0;
  4966. + int oi = 0;
  4967. + while (true) {
  4968. + methodOop k_old_method;
  4969. + methodOop k_new_method;
  4970. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  4971. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  4972. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  4973. - if (strcmp(s1, s2) != 0) {
  4974. - return false; // strings don't match; not our special case
  4975. - }
  4976. + if (oi >= n_old_methods) {
  4977. + if (ni >= n_new_methods) {
  4978. + break; // we've looked at everything, done
  4979. + }
  4980. + // New method at the end
  4981. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4982. + method_was = added;
  4983. + } else if (ni >= n_new_methods) {
  4984. + // Old method, at the end, is deleted
  4985. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4986. + method_was = deleted;
  4987. + } else {
  4988. + // There are more methods in both the old and new lists
  4989. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4990. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4991. + if (k_old_method->name() != k_new_method->name()) {
  4992. + // Methods are sorted by method name, so a mismatch means added
  4993. + // or deleted
  4994. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  4995. + method_was = added;
  4996. + } else {
  4997. + method_was = deleted;
  4998. + }
  4999. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5000. + // Both the name and signature match
  5001. + method_was = matched;
  5002. + } else {
  5003. + // The name matches, but the signature doesn't, which means we have to
  5004. + // search forward through the new overloaded methods.
  5005. + int nj; // outside the loop for post-loop check
  5006. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5007. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5008. + if (k_old_method->name() != m->name()) {
  5009. + // reached another method name so no more overloaded methods
  5010. + method_was = deleted;
  5011. + break;
  5012. + }
  5013. + if (k_old_method->signature() == m->signature()) {
  5014. + // found a match so swap the methods
  5015. + k_new_methods->obj_at_put(ni, m);
  5016. + k_new_methods->obj_at_put(nj, k_new_method);
  5017. + k_new_method = m;
  5018. + method_was = matched;
  5019. + break;
  5020. + }
  5021. + }
  5022. - return true; // made it through the gauntlet; this is our special case
  5023. -} // end is_unresolved_class_mismatch()
  5024. -
  5025. -
  5026. -// Returns true if the current mismatch is due to a resolved/unresolved
  5027. -// string pair. Otherwise, returns false.
  5028. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5029. - int index1, constantPoolHandle cp2, int index2) {
  5030. -
  5031. - jbyte t1 = cp1->tag_at(index1).value();
  5032. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5033. - return false; // wrong entry type; not our special case
  5034. - }
  5035. -
  5036. - jbyte t2 = cp2->tag_at(index2).value();
  5037. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5038. - return false; // wrong entry type; not our special case
  5039. - }
  5040. -
  5041. - if (t1 == t2) {
  5042. - return false; // not a mismatch; not our special case
  5043. - }
  5044. -
  5045. - char *s1 = cp1->string_at_noresolve(index1);
  5046. - char *s2 = cp2->string_at_noresolve(index2);
  5047. - if (strcmp(s1, s2) != 0) {
  5048. - return false; // strings don't match; not our special case
  5049. - }
  5050. -
  5051. - return true; // made it through the gauntlet; this is our special case
  5052. -} // end is_unresolved_string_mismatch()
  5053. -
  5054. -
  5055. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5056. - // For consistency allocate memory using os::malloc wrapper.
  5057. - _scratch_classes = (instanceKlassHandle *)
  5058. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5059. - if (_scratch_classes == NULL) {
  5060. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5061. - }
  5062. -
  5063. - ResourceMark rm(THREAD);
  5064. -
  5065. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5066. - // state can only be NULL if the current thread is exiting which
  5067. - // should not happen since we're trying to do a RedefineClasses
  5068. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5069. - for (int i = 0; i < _class_count; i++) {
  5070. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5071. - // classes for primitives cannot be redefined
  5072. - if (!is_modifiable_class(mirror)) {
  5073. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5074. - }
  5075. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5076. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5077. - Symbol* the_class_sym = the_class->name();
  5078. -
  5079. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5080. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5081. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5082. - the_class->external_name(), _class_load_kind,
  5083. - os::available_memory() >> 10));
  5084. -
  5085. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5086. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5087. -
  5088. - // Parse the stream.
  5089. - Handle the_class_loader(THREAD, the_class->class_loader());
  5090. - Handle protection_domain(THREAD, the_class->protection_domain());
  5091. - // Set redefined class handle in JvmtiThreadState class.
  5092. - // This redefined class is sent to agent event handler for class file
  5093. - // load hook event.
  5094. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5095. -
  5096. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5097. - the_class_loader,
  5098. - protection_domain,
  5099. - &st,
  5100. - THREAD);
  5101. - // Clear class_being_redefined just to be sure.
  5102. - state->clear_class_being_redefined();
  5103. -
  5104. - // TODO: if this is retransform, and nothing changed we can skip it
  5105. -
  5106. - instanceKlassHandle scratch_class (THREAD, k);
  5107. -
  5108. - if (HAS_PENDING_EXCEPTION) {
  5109. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5110. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5111. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5112. - ex_name->as_C_string()));
  5113. - CLEAR_PENDING_EXCEPTION;
  5114. -
  5115. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5116. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5117. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5118. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5119. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5120. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5121. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5122. - // The message will be "XXX (wrong name: YYY)"
  5123. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5124. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5125. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5126. - } else { // Just in case more exceptions can be thrown..
  5127. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5128. - }
  5129. - }
  5130. -
  5131. - // Ensure class is linked before redefine
  5132. - if (!the_class->is_linked()) {
  5133. - the_class->link_class(THREAD);
  5134. - if (HAS_PENDING_EXCEPTION) {
  5135. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5136. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5137. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5138. - ex_name->as_C_string()));
  5139. - CLEAR_PENDING_EXCEPTION;
  5140. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5141. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5142. - } else {
  5143. - return JVMTI_ERROR_INTERNAL;
  5144. + if (nj >= n_new_methods) {
  5145. + // reached the end without a match; so method was deleted
  5146. + method_was = deleted;
  5147. }
  5148. }
  5149. }
  5150. - // Do the validity checks in compare_and_normalize_class_versions()
  5151. - // before verifying the byte codes. By doing these checks first, we
  5152. - // limit the number of functions that require redirection from
  5153. - // the_class to scratch_class. In particular, we don't have to
  5154. - // modify JNI GetSuperclass() and thus won't change its performance.
  5155. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5156. - scratch_class);
  5157. - if (res != JVMTI_ERROR_NONE) {
  5158. - return res;
  5159. + switch (method_was) {
  5160. + case matched:
  5161. + // methods match, be sure modifiers do too
  5162. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5163. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5164. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  5165. + // (tw) Can this have any effects? Probably yes on vtables?
  5166. + result = result | Klass::ModifyClass;
  5167. + }
  5168. + {
  5169. + u2 new_num = k_new_method->method_idnum();
  5170. + u2 old_num = k_old_method->method_idnum();
  5171. + if (new_num != old_num) {
  5172. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  5173. + if (idnum_owner != NULL) {
  5174. + // There is already a method assigned this idnum -- switch them
  5175. + idnum_owner->set_method_idnum(new_num);
  5176. + }
  5177. + k_new_method->set_method_idnum(old_num);
  5178. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  5179. + swap_all_method_annotations(old_num, new_num, new_class);
  5180. + }
  5181. + }
  5182. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  5183. + k_new_method->name_and_sig_as_C_string(), ni,
  5184. + k_old_method->name_and_sig_as_C_string(), oi);
  5185. + // advance to next pair of methods
  5186. + ++oi;
  5187. + ++ni;
  5188. + break;
  5189. + case added:
  5190. + // method added, see if it is OK
  5191. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5192. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5193. + // hack: private should be treated as final, but alas
  5194. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5195. + ) {
  5196. + // new methods must be private
  5197. + result = result | Klass::ModifyClass;
  5198. + }
  5199. + {
  5200. + u2 num = the_class->next_method_idnum();
  5201. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5202. + // cannot add any more methods
  5203. + result = result | Klass::ModifyClass;
  5204. + }
  5205. + u2 new_num = k_new_method->method_idnum();
  5206. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5207. + if (idnum_owner != NULL) {
  5208. + // There is already a method assigned this idnum -- switch them
  5209. + idnum_owner->set_method_idnum(new_num);
  5210. + }
  5211. + k_new_method->set_method_idnum(num);
  5212. + swap_all_method_annotations(new_num, num, new_class);
  5213. + }
  5214. + TRACE_RC1("Method added: new: %s [%d]",
  5215. + k_new_method->name_and_sig_as_C_string(), ni);
  5216. + ++ni; // advance to next new method
  5217. + break;
  5218. + case deleted:
  5219. + // method deleted, see if it is OK
  5220. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5221. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5222. + // hack: private should be treated as final, but alas
  5223. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5224. + ) {
  5225. + // deleted methods must be private
  5226. + result = result | Klass::ModifyClass;
  5227. + }
  5228. + TRACE_RC1("Method deleted: old: %s [%d]",
  5229. + k_old_method->name_and_sig_as_C_string(), oi);
  5230. + ++oi; // advance to next old method
  5231. + break;
  5232. + default:
  5233. + ShouldNotReachHere();
  5234. + }
  5235. + }
  5236. +
  5237. + if (new_class()->size() != new_class->old_version()->size()) {
  5238. + result |= Klass::ModifyClassSize;
  5239. + }
  5240. +
  5241. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  5242. + result |= Klass::ModifyInstanceSize;
  5243. + }
  5244. +
  5245. + // (tw) Check method bodies to be able to return NoChange?
  5246. + return result;
  5247. +}
  5248. +
  5249. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  5250. +
  5251. + class CalculateFieldUpdates : public FieldClosure {
  5252. +
  5253. + private:
  5254. + instanceKlass* _old_ik;
  5255. + GrowableArray<int> _update_info;
  5256. + int _position;
  5257. + bool _copy_backwards;
  5258. +
  5259. + public:
  5260. +
  5261. + bool does_copy_backwards() {
  5262. + return _copy_backwards;
  5263. }
  5264. - // verify what the caller passed us
  5265. - {
  5266. - // The bug 6214132 caused the verification to fail.
  5267. - // Information about the_class and scratch_class is temporarily
  5268. - // recorded into jvmtiThreadState. This data is used to redirect
  5269. - // the_class to scratch_class in the JVM_* functions called by the
  5270. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5271. - // description.
  5272. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5273. - Verifier::verify(
  5274. - scratch_class, Verifier::ThrowException, true, THREAD);
  5275. + CalculateFieldUpdates(instanceKlass* old_ik) :
  5276. + _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
  5277. + _update_info.append(_position);
  5278. + _update_info.append(0);
  5279. }
  5280. - if (HAS_PENDING_EXCEPTION) {
  5281. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5282. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5283. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5284. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5285. - CLEAR_PENDING_EXCEPTION;
  5286. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5287. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5288. + GrowableArray<int> &finish() {
  5289. + _update_info.append(0);
  5290. + return _update_info;
  5291. + }
  5292. +
  5293. + void do_field(fieldDescriptor* fd) {
  5294. + int alignment = fd->offset() - _position;
  5295. + if (alignment > 0) {
  5296. + // This field was aligned, so we need to make sure that we fill the gap
  5297. + fill(alignment);
  5298. + }
  5299. +
  5300. + assert(_position == fd->offset(), "must be correct offset!");
  5301. +
  5302. + fieldDescriptor old_fd;
  5303. + if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
  5304. + // Found field in the old class, copy
  5305. + copy(old_fd.offset(), type2aelembytes(fd->field_type()));
  5306. +
  5307. + if (old_fd.offset() < fd->offset()) {
  5308. + _copy_backwards = true;
  5309. + }
  5310. +
  5311. + // Transfer special flags
  5312. + fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
  5313. + fd->set_is_field_access_watched(old_fd.is_field_access_watched());
  5314. } else {
  5315. - // tell the caller the bytecodes are bad
  5316. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5317. + // New field, fill
  5318. + fill(type2aelembytes(fd->field_type()));
  5319. }
  5320. }
  5321. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5322. - if (res != JVMTI_ERROR_NONE) {
  5323. - return res;
  5324. + private:
  5325. +
  5326. + void fill(int size) {
  5327. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
  5328. + (*_update_info.adr_at(_update_info.length() - 1)) -= size;
  5329. + } else {
  5330. + _update_info.append(-size);
  5331. + }
  5332. + _position += size;
  5333. }
  5334. - if (VerifyMergedCPBytecodes) {
  5335. - // verify what we have done during constant pool merging
  5336. - {
  5337. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5338. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  5339. + void copy(int offset, int size) {
  5340. + int prev_end = -1;
  5341. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
  5342. + prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
  5343. }
  5344. - if (HAS_PENDING_EXCEPTION) {
  5345. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5346. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5347. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5348. - ("verify_byte_codes post merge-CP exception: '%s'",
  5349. - ex_name->as_C_string()));
  5350. - CLEAR_PENDING_EXCEPTION;
  5351. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5352. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5353. - } else {
  5354. - // tell the caller that constant pool merging screwed up
  5355. - return JVMTI_ERROR_INTERNAL;
  5356. + if (prev_end == offset) {
  5357. + (*_update_info.adr_at(_update_info.length() - 2)) += size;
  5358. + } else {
  5359. + _update_info.append(size);
  5360. + _update_info.append(offset);
  5361. + }
  5362. +
  5363. + _position += size;
  5364. + }
  5365. + };
  5366. +
  5367. + instanceKlass* ik = instanceKlass::cast(new_version);
  5368. + instanceKlass* old_ik = instanceKlass::cast(new_version->klass_part()->old_version());
  5369. + CalculateFieldUpdates cl(old_ik);
  5370. + ik->do_nonstatic_fields(&cl);
  5371. +
  5372. + GrowableArray<int> result = cl.finish();
  5373. + ik->store_update_information(result);
  5374. + ik->set_copying_backwards(cl.does_copy_backwards());
  5375. +
  5376. + IF_TRACE_RC2 {
  5377. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  5378. + if (cl.does_copy_backwards()) {
  5379. + TRACE_RC2("\tDoes copy backwards!");
  5380. + }
  5381. + for (int i=0; i<result.length(); i++) {
  5382. + int curNum = result.at(i);
  5383. + if (curNum < 0) {
  5384. + TRACE_RC2("\t%d CLEAN", curNum);
  5385. + } else if (curNum > 0) {
  5386. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  5387. + i++;
  5388. + } else {
  5389. + TRACE_RC2("\tEND");
  5390. + }
  5391. + }
  5392. + }
  5393. +}
  5394. +
  5395. +void VM_RedefineClasses::rollback() {
  5396. + TRACE_RC1("Rolling back redefinition!");
  5397. + SystemDictionary::rollback_redefinition();
  5398. +
  5399. + TRACE_RC1("After rolling back system dictionary!");
  5400. + for (int i=0; i<_new_classes->length(); i++) {
  5401. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  5402. + }
  5403. +
  5404. + for (int i=0; i<_new_classes->length(); i++) {
  5405. + instanceKlassHandle new_class = _new_classes->at(i);
  5406. + new_class->set_redefining(false);
  5407. + new_class->old_version()->klass_part()->set_new_version(NULL);
  5408. + new_class->set_old_version(NULL);
  5409. + }
  5410. +
  5411. +}
  5412. +
  5413. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  5414. + markOop first_mark = first->mark();
  5415. + markOop second_mark = second->mark();
  5416. + first->set_mark(second_mark);
  5417. + second->set_mark(first_mark);
  5418. +}
  5419. +
  5420. +
  5421. +class FieldCopier : public FieldClosure {
  5422. + public:
  5423. + void do_field(fieldDescriptor* fd) {
  5424. + instanceKlass* cur = instanceKlass::cast(fd->field_holder());
  5425. + oop cur_oop = cur->java_mirror();
  5426. +
  5427. + instanceKlass* old = instanceKlass::cast(cur->old_version());
  5428. + oop old_oop = old->java_mirror();
  5429. +
  5430. + fieldDescriptor result;
  5431. + bool found = old->find_local_field(fd->name(), fd->signature(), &result);
  5432. + if (found && result.is_static()) {
  5433. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d",
  5434. + fd->name()->as_C_string(), result.offset(), fd->offset());
  5435. + memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
  5436. + old_oop->obj_field_addr<HeapWord>(result.offset()),
  5437. + type2aelembytes(fd->field_type()));
  5438. +
  5439. + // Static fields may have references to java.lang.Class
  5440. + if (fd->field_type() == T_OBJECT) {
  5441. + oop oop = cur_oop->obj_field(fd->offset());
  5442. + if (oop != NULL && oop->is_instanceMirror()) {
  5443. + klassOop klass = java_lang_Class::as_klassOop(oop);
  5444. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  5445. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  5446. + if (klass->klass_part()->new_version() != NULL) {
  5447. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  5448. +
  5449. + cur_oop->obj_field_put(fd->offset(), oop);
  5450. + }
  5451. + }
  5452. }
  5453. }
  5454. }
  5455. + }
  5456. +};
  5457. - Rewriter::rewrite(scratch_class, THREAD);
  5458. - if (!HAS_PENDING_EXCEPTION) {
  5459. - Rewriter::relocate_and_link(scratch_class, THREAD);
  5460. +void VM_RedefineClasses::mark_as_scavengable(nmethod* nm) {
  5461. + if (!nm->on_scavenge_root_list()) {
  5462. + CodeCache::add_scavenge_root_nmethod(nm);
  5463. + }
  5464. +}
  5465. +
  5466. +struct StoreBarrier {
  5467. + template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
  5468. +};
  5469. +
  5470. +struct StoreNoBarrier {
  5471. + template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
  5472. +};
  5473. +
  5474. +template <class S>
  5475. +class ChangePointersOopClosure : public OopClosureNoHeader {
  5476. + // Forward pointers to instanceKlass and mirror class to new versions
  5477. + template <class T>
  5478. + inline void do_oop_work(T* p) {
  5479. + oop oop = oopDesc::load_decode_heap_oop(p);
  5480. + if (oop == NULL) {
  5481. + return;
  5482. }
  5483. - if (HAS_PENDING_EXCEPTION) {
  5484. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5485. - CLEAR_PENDING_EXCEPTION;
  5486. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5487. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5488. - } else {
  5489. - return JVMTI_ERROR_INTERNAL;
  5490. + if (oop->is_instanceKlass()) {
  5491. + klassOop klass = (klassOop) oop;
  5492. + if (klass->klass_part()->new_version() != NULL) {
  5493. + oop = klass->klass_part()->new_version();
  5494. + S::oop_store(p, oop);
  5495. + }
  5496. + } else if (oop->is_instanceMirror()) {
  5497. + klassOop klass = java_lang_Class::as_klassOop(oop);
  5498. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  5499. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  5500. + if (klass->klass_part()->new_version() != NULL) {
  5501. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  5502. + S::oop_store(p, oop);
  5503. + }
  5504. + }
  5505. + }
  5506. + }
  5507. +
  5508. + virtual void do_oop(oop* o) {
  5509. + do_oop_work(o);
  5510. + }
  5511. +
  5512. + virtual void do_oop(narrowOop* o) {
  5513. + do_oop_work(o);
  5514. + }
  5515. +};
  5516. +
  5517. +void VM_RedefineClasses::doit() {
  5518. + Thread *thread = Thread::current();
  5519. +
  5520. + TRACE_RC1("Entering doit!");
  5521. +
  5522. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  5523. +
  5524. + if (UseSharedSpaces) {
  5525. + // Sharing is enabled so we remap the shared readonly space to
  5526. + // shared readwrite, private just in case we need to redefine
  5527. + // a shared class. We do the remap during the doit() phase of
  5528. + // the safepoint to be safer.
  5529. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  5530. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  5531. + _result = JVMTI_ERROR_INTERNAL;
  5532. + return;
  5533. + }
  5534. + }
  5535. +
  5536. + RC_TIMER_START(_timer_prepare_redefinition);
  5537. + for (int i = 0; i < _new_classes->length(); i++) {
  5538. + redefine_single_class(_new_classes->at(i), thread);
  5539. + }
  5540. +
  5541. + // Deoptimize all compiled code that depends on this class
  5542. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  5543. +
  5544. + // Adjust constantpool caches and vtables for all classes
  5545. + // that reference methods of the evolved class.
  5546. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  5547. +
  5548. + RC_TIMER_STOP(_timer_prepare_redefinition);
  5549. + RC_TIMER_START(_timer_heap_iteration);
  5550. +
  5551. + class ChangePointersObjectClosure : public ObjectClosure {
  5552. +
  5553. + private:
  5554. +
  5555. + OopClosureNoHeader *_closure;
  5556. + bool _needs_instance_update;
  5557. + oop _tmp_obj;
  5558. + int _tmp_obj_size;
  5559. +
  5560. + public:
  5561. + ChangePointersObjectClosure(OopClosureNoHeader *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
  5562. +
  5563. + bool needs_instance_update() {
  5564. + return _needs_instance_update;
  5565. + }
  5566. +
  5567. + void copy_to_tmp(oop o) {
  5568. + int size = o->size();
  5569. + if (_tmp_obj_size < size) {
  5570. + _tmp_obj_size = size;
  5571. + _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  5572. + }
  5573. + Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
  5574. + }
  5575. +
  5576. + virtual void do_object(oop obj) {
  5577. + if (obj->is_instanceKlass()) return;
  5578. + if (obj->is_instanceMirror()) {
  5579. + // static fields may have references to old java.lang.Class instances, update them
  5580. + // at the same time, we don't want to update other oops in the java.lang.Class
  5581. + // Causes SIGSEGV?
  5582. + //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
  5583. + } else {
  5584. + obj->oop_iterate(_closure);
  5585. + }
  5586. +
  5587. + // Update method handles
  5588. + // FIXME: should we also update fields?
  5589. + if (java_lang_invoke_MemberName::is_instance(obj)) {
  5590. + oop target = java_lang_invoke_MemberName::vmtarget(obj);
  5591. + if (target != NULL && target->is_method()) {
  5592. + methodOop m = (methodOop) target;
  5593. + klassOop holder = m->method_holder();
  5594. + if (!holder->klass_part()->is_newest_version()) {
  5595. + // Let's try to re-resolve method
  5596. + klassOop newest = holder->klass_part()->newest_version();
  5597. + methodOop new_method = instanceKlass::cast(newest)->find_method(m->name(), m->signature());
  5598. + java_lang_invoke_MemberName::set_vmtarget(obj, new_method);
  5599. + }
  5600. + }
  5601. + }
  5602. +
  5603. + if (obj->blueprint()->new_version() != NULL) {
  5604. + Klass* new_klass = obj->blueprint()->new_version()->klass_part();
  5605. + if (obj->is_perm()) {
  5606. + _needs_instance_update = true;
  5607. + } else if(new_klass->update_information() != NULL) {
  5608. + int size_diff = obj->size() - obj->size_given_klass(new_klass);
  5609. +
  5610. + // Either new size is bigger or gap is to small to be filled
  5611. + if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
  5612. + // We need an instance update => set back to old klass
  5613. + _needs_instance_update = true;
  5614. + } else {
  5615. + oop src = obj;
  5616. + if (new_klass->is_copying_backwards()) {
  5617. + copy_to_tmp(obj);
  5618. + src = _tmp_obj;
  5619. + }
  5620. + src->set_klass_no_check(obj->blueprint()->new_version());
  5621. + MarkSweep::update_fields(obj, src, new_klass->update_information());
  5622. +
  5623. + if (size_diff > 0) {
  5624. + HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
  5625. + CollectedHeap::fill_with_object(dead_space, size_diff);
  5626. + }
  5627. + }
  5628. + } else {
  5629. + obj->set_klass_no_check(obj->blueprint()->new_version());
  5630. + }
  5631. + }
  5632. + }
  5633. + };
  5634. +
  5635. + ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
  5636. + ChangePointersOopClosure<StoreBarrier> oopClosure;
  5637. + ChangePointersObjectClosure objectClosure(&oopClosure);
  5638. +
  5639. + {
  5640. + // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
  5641. + // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
  5642. + // mark such nmethod's as "scavengable".
  5643. + // For now, mark all nmethod's as scavengable that are not scavengable already
  5644. + if (ScavengeRootsInCode) {
  5645. + CodeCache::nmethods_do(mark_as_scavengable);
  5646. + }
  5647. +
  5648. + SharedHeap::heap()->gc_prologue(true);
  5649. + Universe::heap()->object_iterate(&objectClosure);
  5650. + Universe::root_oops_do(&oopClosureNoBarrier);
  5651. + SharedHeap::heap()->gc_epilogue(false);
  5652. + }
  5653. +
  5654. +
  5655. + for (int i=0; i<_new_classes->length(); i++) {
  5656. + klassOop cur_oop = _new_classes->at(i)();
  5657. + instanceKlass* cur = instanceKlass::cast(cur_oop);
  5658. + klassOop old_oop = cur->old_version();
  5659. + instanceKlass* old = instanceKlass::cast(old_oop);
  5660. +
  5661. + // Swap marks to have same hashcodes
  5662. + swap_marks(cur_oop, old_oop);
  5663. + swap_marks(cur->java_mirror(), old->java_mirror());
  5664. +
  5665. + // Revert pool holder for old version of klass (it was updated by one of ours closure!)
  5666. + old->constants()->set_pool_holder(old_oop);
  5667. +
  5668. +
  5669. + if (old->array_klasses() != NULL) {
  5670. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  5671. + assert(cur->array_klasses() == NULL, "just checking");
  5672. + cur->set_array_klasses(old->array_klasses());
  5673. + }
  5674. +
  5675. + // Initialize the new class! Special static initialization that does not execute the
  5676. + // static constructor but copies static field values from the old class if name
  5677. + // and signature of a static field match.
  5678. + FieldCopier copier;
  5679. + cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
  5680. + old->set_java_mirror(cur->java_mirror());
  5681. +
  5682. + // Transfer init state
  5683. + instanceKlass::ClassState state = old->init_state();
  5684. + if (state > instanceKlass::linked) {
  5685. + cur->set_init_state(state);
  5686. }
  5687. }
  5688. - _scratch_classes[i] = scratch_class;
  5689. + RC_TIMER_STOP(_timer_heap_iteration);
  5690. + RC_TIMER_START(_timer_redefinition);
  5691. + if (objectClosure.needs_instance_update()){
  5692. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5693. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5694. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  5695. - the_class->external_name(), os::available_memory() >> 10));
  5696. + // Do a full garbage collection to update the instance sizes accordingly
  5697. + TRACE_RC1("Before performing full GC!");
  5698. + Universe::set_redefining_gc_run(true);
  5699. + notify_gc_begin(true);
  5700. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  5701. + notify_gc_end();
  5702. + Universe::set_redefining_gc_run(false);
  5703. + TRACE_RC1("GC done!");
  5704. }
  5705. - return JVMTI_ERROR_NONE;
  5706. + // Unmark klassOops as "redefining"
  5707. + for (int i=0; i<_new_classes->length(); i++) {
  5708. + klassOop cur_klass = _new_classes->at(i)();
  5709. + instanceKlass* cur = (instanceKlass*)cur_klass->klass_part();
  5710. + cur->set_redefining(false);
  5711. + cur->clear_update_information();
  5712. + }
  5713. +
  5714. + // Disable any dependent concurrent compilations
  5715. + SystemDictionary::notice_modification();
  5716. +
  5717. + // Set flag indicating that some invariants are no longer true.
  5718. + // See jvmtiExport.hpp for detailed explanation.
  5719. + JvmtiExport::set_has_redefined_a_class();
  5720. +
  5721. + // Clean up caches in the compiler interface and compiler threads
  5722. + ciObjectFactory::resort_shared_ci_objects();
  5723. +
  5724. +#ifdef ASSERT
  5725. +
  5726. + // Universe::verify();
  5727. + // JNIHandles::verify();
  5728. +
  5729. + SystemDictionary::classes_do(check_class, thread);
  5730. +#endif
  5731. +
  5732. + RC_TIMER_STOP(_timer_redefinition);
  5733. +
  5734. + if (TraceRedefineClasses > 0) {
  5735. + tty->flush();
  5736. + }
  5737. }
  5738. +void VM_RedefineClasses::doit_epilogue() {
  5739. -// Map old_index to new_index as needed. scratch_cp is only needed
  5740. -// for RC_TRACE() calls.
  5741. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  5742. - int old_index, int new_index) {
  5743. - if (find_new_index(old_index) != 0) {
  5744. - // old_index is already mapped
  5745. - return;
  5746. + RC_TIMER_START(_timer_vm_op_epilogue);
  5747. +
  5748. + //unlock_threads();
  5749. +
  5750. + ResourceMark mark;
  5751. +
  5752. + VM_GC_Operation::doit_epilogue();
  5753. + TRACE_RC1("GC Operation epilogue finished! ");
  5754. +
  5755. + // Free the array of scratch classes
  5756. + delete _new_classes;
  5757. + _new_classes = NULL;
  5758. +
  5759. + // Free the array of affected classes
  5760. + delete _affected_klasses;
  5761. + _affected_klasses = NULL;
  5762. +
  5763. + TRACE_RC1("Redefinition finished!");
  5764. +
  5765. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  5766. +}
  5767. +
  5768. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  5769. + // classes for primitives cannot be redefined
  5770. + if (java_lang_Class::is_primitive(klass_mirror)) {
  5771. + return false;
  5772. }
  5773. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  5774. + // classes for arrays cannot be redefined
  5775. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  5776. + return false;
  5777. + }
  5778. + return true;
  5779. +}
  5780. - if (old_index == new_index) {
  5781. - // no mapping is needed
  5782. - return;
  5783. +#ifdef ASSERT
  5784. +
  5785. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  5786. + klassOop k_oop = k_oop_latest;
  5787. + while (k_oop != NULL) {
  5788. +
  5789. + instanceKlassHandle k_handle(THREAD, k_oop);
  5790. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  5791. + k_oop = k_oop->klass_part()->old_version();
  5792. }
  5793. +}
  5794. - _index_map_p->at_put(old_index, new_index);
  5795. - _index_map_count++;
  5796. +#endif
  5797. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  5798. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  5799. -} // end map_index()
  5800. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  5801. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  5802. +// do that, they assume that cache entry is resolved already.
  5803. +void VM_RedefineClasses::unpatch_bytecode(methodOop method) {
  5804. + RawBytecodeStream bcs(method);
  5805. + Bytecodes::Code code;
  5806. + Bytecodes::Code java_code;
  5807. + while (!bcs.is_last_bytecode()) {
  5808. + code = bcs.raw_next();
  5809. + address bcp = bcs.bcp();
  5810. -
  5811. -// Map old_index to new_index as needed.
  5812. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  5813. - if (find_new_operand_index(old_index) != -1) {
  5814. - // old_index is already mapped
  5815. - return;
  5816. - }
  5817. -
  5818. - if (old_index == new_index) {
  5819. - // no mapping is needed
  5820. - return;
  5821. - }
  5822. -
  5823. - _operands_index_map_p->at_put(old_index, new_index);
  5824. - _operands_index_map_count++;
  5825. -
  5826. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  5827. -} // end map_index()
  5828. -
  5829. -
  5830. -// Merge old_cp and scratch_cp and return the results of the merge via
  5831. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  5832. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  5833. -// in *merge_cp_p. Also creates a map of indices from entries in
  5834. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  5835. -// entries are only created for entries in scratch_cp that occupy a
  5836. -// different location in *merged_cp_p.
  5837. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  5838. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  5839. - int *merge_cp_length_p, TRAPS) {
  5840. -
  5841. - if (merge_cp_p == NULL) {
  5842. - assert(false, "caller must provide scatch constantPool");
  5843. - return false; // robustness
  5844. - }
  5845. - if (merge_cp_length_p == NULL) {
  5846. - assert(false, "caller must provide scatch CP length");
  5847. - return false; // robustness
  5848. - }
  5849. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  5850. - // but the caller might be smart so make sure we have at least
  5851. - // the minimum.
  5852. - if ((*merge_cp_p)->length() < old_cp->length()) {
  5853. - assert(false, "merge area too small");
  5854. - return false; // robustness
  5855. - }
  5856. -
  5857. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5858. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  5859. - scratch_cp->length()));
  5860. -
  5861. - {
  5862. - // Pass 0:
  5863. - // The old_cp is copied to *merge_cp_p; this means that any code
  5864. - // using old_cp does not have to change. This work looks like a
  5865. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  5866. - // handle one special case:
  5867. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  5868. - // This will make verification happy.
  5869. -
  5870. - int old_i; // index into old_cp
  5871. -
  5872. - // index zero (0) is not used in constantPools
  5873. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  5874. - // leave debugging crumb
  5875. - jbyte old_tag = old_cp->tag_at(old_i).value();
  5876. - switch (old_tag) {
  5877. - case JVM_CONSTANT_Class:
  5878. - case JVM_CONSTANT_UnresolvedClass:
  5879. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5880. - // May be resolving while calling this so do the same for
  5881. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  5882. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  5883. - old_cp->klass_name_at(old_i));
  5884. - break;
  5885. -
  5886. - case JVM_CONSTANT_Double:
  5887. - case JVM_CONSTANT_Long:
  5888. - // just copy the entry to *merge_cp_p, but double and long take
  5889. - // two constant pool entries
  5890. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5891. - old_i++;
  5892. - break;
  5893. -
  5894. - default:
  5895. - // just copy the entry to *merge_cp_p
  5896. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5897. - break;
  5898. + if (code == Bytecodes::_breakpoint) {
  5899. + int bci = method->bci_from(bcp);
  5900. + code = method->orig_bytecode_at(bci);
  5901. + java_code = Bytecodes::java_code(code);
  5902. + if (code != java_code &&
  5903. + (java_code == Bytecodes::_getfield ||
  5904. + java_code == Bytecodes::_putfield ||
  5905. + java_code == Bytecodes::_aload_0)) {
  5906. + // Let breakpoint table handling unpatch bytecode
  5907. + method->set_orig_bytecode_at(bci, java_code);
  5908. }
  5909. - } // end for each old_cp entry
  5910. -
  5911. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  5912. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  5913. -
  5914. - // We don't need to sanity check that *merge_cp_length_p is within
  5915. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  5916. - (*merge_cp_length_p) = old_i;
  5917. - }
  5918. -
  5919. - // merge_cp_len should be the same as old_cp->length() at this point
  5920. - // so this trace message is really a "warm-and-breathing" message.
  5921. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5922. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  5923. -
  5924. - int scratch_i; // index into scratch_cp
  5925. - {
  5926. - // Pass 1a:
  5927. - // Compare scratch_cp entries to the old_cp entries that we have
  5928. - // already copied to *merge_cp_p. In this pass, we are eliminating
  5929. - // exact duplicates (matching entry at same index) so we only
  5930. - // compare entries in the common indice range.
  5931. - int increment = 1;
  5932. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  5933. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  5934. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5935. - case JVM_CONSTANT_Double:
  5936. - case JVM_CONSTANT_Long:
  5937. - // double and long take two constant pool entries
  5938. - increment = 2;
  5939. - break;
  5940. -
  5941. - default:
  5942. - increment = 1;
  5943. - break;
  5944. - }
  5945. -
  5946. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  5947. - scratch_i, CHECK_0);
  5948. - if (match) {
  5949. - // found a match at the same index so nothing more to do
  5950. - continue;
  5951. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  5952. - *merge_cp_p, scratch_i)) {
  5953. - // The mismatch in compare_entry_to() above is because of a
  5954. - // resolved versus unresolved class entry at the same index
  5955. - // with the same string value. Since Pass 0 reverted any
  5956. - // class entries to unresolved class entries in *merge_cp_p,
  5957. - // we go with the unresolved class entry.
  5958. - continue;
  5959. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  5960. - *merge_cp_p, scratch_i)) {
  5961. - // The mismatch in compare_entry_to() above is because of a
  5962. - // resolved versus unresolved string entry at the same index
  5963. - // with the same string value. We can live with whichever
  5964. - // happens to be at scratch_i in *merge_cp_p.
  5965. - continue;
  5966. - }
  5967. -
  5968. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  5969. - CHECK_0);
  5970. - if (found_i != 0) {
  5971. - guarantee(found_i != scratch_i,
  5972. - "compare_entry_to() and find_matching_entry() do not agree");
  5973. -
  5974. - // Found a matching entry somewhere else in *merge_cp_p so
  5975. - // just need a mapping entry.
  5976. - map_index(scratch_cp, scratch_i, found_i);
  5977. - continue;
  5978. - }
  5979. -
  5980. - // The find_matching_entry() call above could fail to find a match
  5981. - // due to a resolved versus unresolved class or string entry situation
  5982. - // like we solved above with the is_unresolved_*_mismatch() calls.
  5983. - // However, we would have to call is_unresolved_*_mismatch() over
  5984. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  5985. - // worth the time.
  5986. -
  5987. - // No match found so we have to append this entry and any unique
  5988. - // referenced entries to *merge_cp_p.
  5989. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5990. - CHECK_0);
  5991. - }
  5992. - }
  5993. -
  5994. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5995. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5996. - *merge_cp_length_p, scratch_i, _index_map_count));
  5997. -
  5998. - if (scratch_i < scratch_cp->length()) {
  5999. - // Pass 1b:
  6000. - // old_cp is smaller than scratch_cp so there are entries in
  6001. - // scratch_cp that we have not yet processed. We take care of
  6002. - // those now.
  6003. - int increment = 1;
  6004. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6005. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6006. - case JVM_CONSTANT_Double:
  6007. - case JVM_CONSTANT_Long:
  6008. - // double and long take two constant pool entries
  6009. - increment = 2;
  6010. - break;
  6011. -
  6012. - default:
  6013. - increment = 1;
  6014. - break;
  6015. - }
  6016. -
  6017. - int found_i =
  6018. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6019. - if (found_i != 0) {
  6020. - // Found a matching entry somewhere else in *merge_cp_p so
  6021. - // just need a mapping entry.
  6022. - map_index(scratch_cp, scratch_i, found_i);
  6023. - continue;
  6024. - }
  6025. -
  6026. - // No match found so we have to append this entry and any unique
  6027. - // referenced entries to *merge_cp_p.
  6028. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6029. - CHECK_0);
  6030. - }
  6031. -
  6032. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6033. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6034. - *merge_cp_length_p, scratch_i, _index_map_count));
  6035. - }
  6036. - finalize_operands_merge(*merge_cp_p, THREAD);
  6037. -
  6038. - return true;
  6039. -} // end merge_constant_pools()
  6040. -
  6041. -
  6042. -// Merge constant pools between the_class and scratch_class and
  6043. -// potentially rewrite bytecodes in scratch_class to use the merged
  6044. -// constant pool.
  6045. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6046. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6047. - TRAPS) {
  6048. - // worst case merged constant pool length is old and new combined
  6049. - int merge_cp_length = the_class->constants()->length()
  6050. - + scratch_class->constants()->length();
  6051. -
  6052. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6053. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6054. -
  6055. - // Constant pools are not easily reused so we allocate a new one
  6056. - // each time.
  6057. - // merge_cp is created unsafe for concurrent GC processing. It
  6058. - // should be marked safe before discarding it. Even though
  6059. - // garbage, if it crosses a card boundary, it may be scanned
  6060. - // in order to find the start of the first complete object on the card.
  6061. - constantPoolHandle merge_cp(THREAD,
  6062. - oopFactory::new_constantPool(merge_cp_length,
  6063. - oopDesc::IsUnsafeConc,
  6064. - THREAD));
  6065. - int orig_length = old_cp->orig_length();
  6066. - if (orig_length == 0) {
  6067. - // This old_cp is an actual original constant pool. We save
  6068. - // the original length in the merged constant pool so that
  6069. - // merge_constant_pools() can be more efficient. If a constant
  6070. - // pool has a non-zero orig_length() value, then that constant
  6071. - // pool was created by a merge operation in RedefineClasses.
  6072. - merge_cp->set_orig_length(old_cp->length());
  6073. - } else {
  6074. - // This old_cp is a merged constant pool from a previous
  6075. - // RedefineClasses() calls so just copy the orig_length()
  6076. - // value.
  6077. - merge_cp->set_orig_length(old_cp->orig_length());
  6078. - }
  6079. -
  6080. - ResourceMark rm(THREAD);
  6081. - _index_map_count = 0;
  6082. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6083. -
  6084. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6085. - _operands_index_map_count = 0;
  6086. - _operands_index_map_p = new intArray(
  6087. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6088. -
  6089. - // reference to the cp holder is needed for copy_operands()
  6090. - merge_cp->set_pool_holder(scratch_class());
  6091. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6092. - &merge_cp_length, THREAD);
  6093. - merge_cp->set_pool_holder(NULL);
  6094. -
  6095. - if (!result) {
  6096. - // The merge can fail due to memory allocation failure or due
  6097. - // to robustness checks.
  6098. - return JVMTI_ERROR_INTERNAL;
  6099. - }
  6100. -
  6101. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6102. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6103. -
  6104. - if (_index_map_count == 0) {
  6105. - // there is nothing to map between the new and merged constant pools
  6106. -
  6107. - if (old_cp->length() == scratch_cp->length()) {
  6108. - // The old and new constant pools are the same length and the
  6109. - // index map is empty. This means that the three constant pools
  6110. - // are equivalent (but not the same). Unfortunately, the new
  6111. - // constant pool has not gone through link resolution nor have
  6112. - // the new class bytecodes gone through constant pool cache
  6113. - // rewriting so we can't use the old constant pool with the new
  6114. - // class.
  6115. -
  6116. - merge_cp()->set_is_conc_safe(true);
  6117. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6118. - } else if (old_cp->length() < scratch_cp->length()) {
  6119. - // The old constant pool has fewer entries than the new constant
  6120. - // pool and the index map is empty. This means the new constant
  6121. - // pool is a superset of the old constant pool. However, the old
  6122. - // class bytecodes have already gone through constant pool cache
  6123. - // rewriting so we can't use the new constant pool with the old
  6124. - // class.
  6125. -
  6126. - merge_cp()->set_is_conc_safe(true);
  6127. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6128. } else {
  6129. - // The old constant pool has more entries than the new constant
  6130. - // pool and the index map is empty. This means that both the old
  6131. - // and merged constant pools are supersets of the new constant
  6132. - // pool.
  6133. -
  6134. - // Replace the new constant pool with a shrunken copy of the
  6135. - // merged constant pool; the previous new constant pool will
  6136. - // get GCed.
  6137. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6138. - THREAD);
  6139. - // drop local ref to the merged constant pool
  6140. - merge_cp()->set_is_conc_safe(true);
  6141. - merge_cp = constantPoolHandle();
  6142. - }
  6143. - } else {
  6144. - if (RC_TRACE_ENABLED(0x00040000)) {
  6145. - // don't want to loop unless we are tracing
  6146. - int count = 0;
  6147. - for (int i = 1; i < _index_map_p->length(); i++) {
  6148. - int value = _index_map_p->at(i);
  6149. -
  6150. - if (value != -1) {
  6151. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6152. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6153. - count++;
  6154. - }
  6155. + java_code = Bytecodes::java_code(code);
  6156. + if (code != java_code &&
  6157. + (java_code == Bytecodes::_getfield ||
  6158. + java_code == Bytecodes::_putfield ||
  6159. + java_code == Bytecodes::_aload_0)) {
  6160. + *bcp = java_code;
  6161. }
  6162. }
  6163. - // We have entries mapped between the new and merged constant pools
  6164. - // so we have to rewrite some constant pool references.
  6165. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6166. - return JVMTI_ERROR_INTERNAL;
  6167. - }
  6168. -
  6169. - // Replace the new constant pool with a shrunken copy of the
  6170. - // merged constant pool so now the rewritten bytecodes have
  6171. - // valid references; the previous new constant pool will get
  6172. - // GCed.
  6173. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6174. - THREAD);
  6175. - merge_cp()->set_is_conc_safe(true);
  6176. - }
  6177. - assert(old_cp()->is_conc_safe(), "Just checking");
  6178. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6179. -
  6180. - return JVMTI_ERROR_NONE;
  6181. -} // end merge_cp_and_rewrite()
  6182. -
  6183. -
  6184. -// Rewrite constant pool references in klass scratch_class.
  6185. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6186. - TRAPS) {
  6187. -
  6188. - // rewrite constant pool references in the methods:
  6189. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6190. - // propagate failure back to caller
  6191. - return false;
  6192. - }
  6193. -
  6194. - // rewrite constant pool references in the class_annotations:
  6195. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6196. - // propagate failure back to caller
  6197. - return false;
  6198. - }
  6199. -
  6200. - // rewrite constant pool references in the fields_annotations:
  6201. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6202. - // propagate failure back to caller
  6203. - return false;
  6204. - }
  6205. -
  6206. - // rewrite constant pool references in the methods_annotations:
  6207. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6208. - // propagate failure back to caller
  6209. - return false;
  6210. - }
  6211. -
  6212. - // rewrite constant pool references in the methods_parameter_annotations:
  6213. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6214. - THREAD)) {
  6215. - // propagate failure back to caller
  6216. - return false;
  6217. - }
  6218. -
  6219. - // rewrite constant pool references in the methods_default_annotations:
  6220. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6221. - THREAD)) {
  6222. - // propagate failure back to caller
  6223. - return false;
  6224. - }
  6225. -
  6226. - return true;
  6227. -} // end rewrite_cp_refs()
  6228. -
  6229. -
  6230. -// Rewrite constant pool references in the methods.
  6231. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6232. - instanceKlassHandle scratch_class, TRAPS) {
  6233. -
  6234. - objArrayHandle methods(THREAD, scratch_class->methods());
  6235. -
  6236. - if (methods.is_null() || methods->length() == 0) {
  6237. - // no methods so nothing to do
  6238. - return true;
  6239. - }
  6240. -
  6241. - // rewrite constant pool references in the methods:
  6242. - for (int i = methods->length() - 1; i >= 0; i--) {
  6243. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  6244. - methodHandle new_method;
  6245. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  6246. - if (!new_method.is_null()) {
  6247. - // the method has been replaced so save the new method version
  6248. - methods->obj_at_put(i, new_method());
  6249. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  6250. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  6251. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  6252. + assert(code2 == Bytecodes::_fast_igetfield ||
  6253. + code2 == Bytecodes::_fast_agetfield ||
  6254. + code2 == Bytecodes::_fast_fgetfield, "");
  6255. + *(bcp + 1) = Bytecodes::java_code(code2);
  6256. }
  6257. }
  6258. -
  6259. - return true;
  6260. }
  6261. -
  6262. -// Rewrite constant pool references in the specific method. This code
  6263. -// was adapted from Rewriter::rewrite_method().
  6264. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  6265. - methodHandle *new_method_p, TRAPS) {
  6266. -
  6267. - *new_method_p = methodHandle(); // default is no new method
  6268. -
  6269. - // We cache a pointer to the bytecodes here in code_base. If GC
  6270. - // moves the methodOop, then the bytecodes will also move which
  6271. - // will likely cause a crash. We create a No_Safepoint_Verifier
  6272. - // object to detect whether we pass a possible safepoint in this
  6273. - // code block.
  6274. - No_Safepoint_Verifier nsv;
  6275. -
  6276. - // Bytecodes and their length
  6277. - address code_base = method->code_base();
  6278. - int code_length = method->code_size();
  6279. -
  6280. - int bc_length;
  6281. - for (int bci = 0; bci < code_length; bci += bc_length) {
  6282. - address bcp = code_base + bci;
  6283. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  6284. -
  6285. - bc_length = Bytecodes::length_for(c);
  6286. - if (bc_length == 0) {
  6287. - // More complicated bytecodes report a length of zero so
  6288. - // we have to try again a slightly different way.
  6289. - bc_length = Bytecodes::length_at(method(), bcp);
  6290. - }
  6291. -
  6292. - assert(bc_length != 0, "impossible bytecode length");
  6293. -
  6294. - switch (c) {
  6295. - case Bytecodes::_ldc:
  6296. - {
  6297. - int cp_index = *(bcp + 1);
  6298. - int new_index = find_new_index(cp_index);
  6299. -
  6300. - if (StressLdcRewrite && new_index == 0) {
  6301. - // If we are stressing ldc -> ldc_w rewriting, then we
  6302. - // always need a new_index value.
  6303. - new_index = cp_index;
  6304. - }
  6305. - if (new_index != 0) {
  6306. - // the original index is mapped so we have more work to do
  6307. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  6308. - // The new value can still use ldc instead of ldc_w
  6309. - // unless we are trying to stress ldc -> ldc_w rewriting
  6310. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6311. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6312. - bcp, cp_index, new_index));
  6313. - *(bcp + 1) = new_index;
  6314. - } else {
  6315. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6316. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  6317. - Bytecodes::name(c), bcp, cp_index, new_index));
  6318. - // the new value needs ldc_w instead of ldc
  6319. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  6320. - bcp = (address)inst_buffer;
  6321. - // construct new instruction sequence
  6322. - *bcp = Bytecodes::_ldc_w;
  6323. - bcp++;
  6324. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  6325. - // See comment below for difference between put_Java_u2()
  6326. - // and put_native_u2().
  6327. - Bytes::put_Java_u2(bcp, new_index);
  6328. -
  6329. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  6330. - methodHandle m;
  6331. - {
  6332. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  6333. -
  6334. - // ldc is 2 bytes and ldc_w is 3 bytes
  6335. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  6336. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  6337. - guarantee(false, "insert_space_at() failed");
  6338. - }
  6339. - }
  6340. -
  6341. - // return the new method so that the caller can update
  6342. - // the containing class
  6343. - *new_method_p = method = m;
  6344. - // switch our bytecode processing loop from the old method
  6345. - // to the new method
  6346. - code_base = method->code_base();
  6347. - code_length = method->code_size();
  6348. - bcp = code_base + bci;
  6349. - c = (Bytecodes::Code)(*bcp);
  6350. - bc_length = Bytecodes::length_for(c);
  6351. - assert(bc_length != 0, "sanity check");
  6352. - } // end we need ldc_w instead of ldc
  6353. - } // end if there is a mapped index
  6354. - } break;
  6355. -
  6356. - // these bytecodes have a two-byte constant pool index
  6357. - case Bytecodes::_anewarray : // fall through
  6358. - case Bytecodes::_checkcast : // fall through
  6359. - case Bytecodes::_getfield : // fall through
  6360. - case Bytecodes::_getstatic : // fall through
  6361. - case Bytecodes::_instanceof : // fall through
  6362. - case Bytecodes::_invokedynamic : // fall through
  6363. - case Bytecodes::_invokeinterface: // fall through
  6364. - case Bytecodes::_invokespecial : // fall through
  6365. - case Bytecodes::_invokestatic : // fall through
  6366. - case Bytecodes::_invokevirtual : // fall through
  6367. - case Bytecodes::_ldc_w : // fall through
  6368. - case Bytecodes::_ldc2_w : // fall through
  6369. - case Bytecodes::_multianewarray : // fall through
  6370. - case Bytecodes::_new : // fall through
  6371. - case Bytecodes::_putfield : // fall through
  6372. - case Bytecodes::_putstatic :
  6373. - {
  6374. - address p = bcp + 1;
  6375. - int cp_index = Bytes::get_Java_u2(p);
  6376. - int new_index = find_new_index(cp_index);
  6377. - if (new_index != 0) {
  6378. - // the original index is mapped so update w/ new value
  6379. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6380. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6381. - bcp, cp_index, new_index));
  6382. - // Rewriter::rewrite_method() uses put_native_u2() in this
  6383. - // situation because it is reusing the constant pool index
  6384. - // location for a native index into the constantPoolCache.
  6385. - // Since we are updating the constant pool index prior to
  6386. - // verification and constantPoolCache initialization, we
  6387. - // need to keep the new index in Java byte order.
  6388. - Bytes::put_Java_u2(p, new_index);
  6389. - }
  6390. - } break;
  6391. - }
  6392. - } // end for each bytecode
  6393. -} // end rewrite_cp_refs_in_method()
  6394. -
  6395. -
  6396. -// Rewrite constant pool references in the class_annotations field.
  6397. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  6398. - instanceKlassHandle scratch_class, TRAPS) {
  6399. -
  6400. - typeArrayHandle class_annotations(THREAD,
  6401. - scratch_class->class_annotations());
  6402. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  6403. - // no class_annotations so nothing to do
  6404. - return true;
  6405. - }
  6406. -
  6407. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6408. - ("class_annotations length=%d", class_annotations->length()));
  6409. -
  6410. - int byte_i = 0; // byte index into class_annotations
  6411. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  6412. - THREAD);
  6413. -}
  6414. -
  6415. -
  6416. -// Rewrite constant pool references in an annotations typeArray. This
  6417. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  6418. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  6419. -//
  6420. -// annotations_typeArray {
  6421. -// u2 num_annotations;
  6422. -// annotation annotations[num_annotations];
  6423. -// }
  6424. -//
  6425. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  6426. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6427. -
  6428. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6429. - // not enough room for num_annotations field
  6430. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6431. - ("length() is too small for num_annotations field"));
  6432. - return false;
  6433. - }
  6434. -
  6435. - u2 num_annotations = Bytes::get_Java_u2((address)
  6436. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6437. - byte_i_ref += 2;
  6438. -
  6439. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6440. - ("num_annotations=%d", num_annotations));
  6441. -
  6442. - int calc_num_annotations = 0;
  6443. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  6444. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6445. - byte_i_ref, THREAD)) {
  6446. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6447. - ("bad annotation_struct at %d", calc_num_annotations));
  6448. - // propagate failure back to caller
  6449. - return false;
  6450. - }
  6451. - }
  6452. - assert(num_annotations == calc_num_annotations, "sanity check");
  6453. -
  6454. - return true;
  6455. -} // end rewrite_cp_refs_in_annotations_typeArray()
  6456. -
  6457. -
  6458. -// Rewrite constant pool references in the annotation struct portion of
  6459. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  6460. -// the 2nd-edition of the VM spec:
  6461. -//
  6462. -// struct annotation {
  6463. -// u2 type_index;
  6464. -// u2 num_element_value_pairs;
  6465. -// {
  6466. -// u2 element_name_index;
  6467. -// element_value value;
  6468. -// } element_value_pairs[num_element_value_pairs];
  6469. -// }
  6470. -//
  6471. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  6472. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6473. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  6474. - // not enough room for smallest annotation_struct
  6475. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6476. - ("length() is too small for annotation_struct"));
  6477. - return false;
  6478. - }
  6479. -
  6480. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  6481. - byte_i_ref, "mapped old type_index=%d", THREAD);
  6482. -
  6483. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  6484. - annotations_typeArray->byte_at_addr(
  6485. - byte_i_ref));
  6486. - byte_i_ref += 2;
  6487. -
  6488. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6489. - ("type_index=%d num_element_value_pairs=%d", type_index,
  6490. - num_element_value_pairs));
  6491. -
  6492. - int calc_num_element_value_pairs = 0;
  6493. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  6494. - calc_num_element_value_pairs++) {
  6495. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6496. - // not enough room for another element_name_index, let alone
  6497. - // the rest of another component
  6498. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6499. - ("length() is too small for element_name_index"));
  6500. - return false;
  6501. - }
  6502. -
  6503. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  6504. - annotations_typeArray, byte_i_ref,
  6505. - "mapped old element_name_index=%d", THREAD);
  6506. -
  6507. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6508. - ("element_name_index=%d", element_name_index));
  6509. -
  6510. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  6511. - byte_i_ref, THREAD)) {
  6512. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6513. - ("bad element_value at %d", calc_num_element_value_pairs));
  6514. - // propagate failure back to caller
  6515. - return false;
  6516. - }
  6517. - } // end for each component
  6518. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  6519. - "sanity check");
  6520. -
  6521. - return true;
  6522. -} // end rewrite_cp_refs_in_annotation_struct()
  6523. -
  6524. -
  6525. -// Rewrite a constant pool reference at the current position in
  6526. -// annotations_typeArray if needed. Returns the original constant
  6527. -// pool reference if a rewrite was not needed or the new constant
  6528. -// pool reference if a rewrite was needed.
  6529. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  6530. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  6531. - const char * trace_mesg, TRAPS) {
  6532. -
  6533. - address cp_index_addr = (address)
  6534. - annotations_typeArray->byte_at_addr(byte_i_ref);
  6535. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  6536. - u2 new_cp_index = find_new_index(old_cp_index);
  6537. - if (new_cp_index != 0) {
  6538. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  6539. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  6540. - old_cp_index = new_cp_index;
  6541. - }
  6542. - byte_i_ref += 2;
  6543. - return old_cp_index;
  6544. -}
  6545. -
  6546. -
  6547. -// Rewrite constant pool references in the element_value portion of an
  6548. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  6549. -// the 2nd-edition of the VM spec:
  6550. -//
  6551. -// struct element_value {
  6552. -// u1 tag;
  6553. -// union {
  6554. -// u2 const_value_index;
  6555. -// {
  6556. -// u2 type_name_index;
  6557. -// u2 const_name_index;
  6558. -// } enum_const_value;
  6559. -// u2 class_info_index;
  6560. -// annotation annotation_value;
  6561. -// struct {
  6562. -// u2 num_values;
  6563. -// element_value values[num_values];
  6564. -// } array_value;
  6565. -// } value;
  6566. -// }
  6567. -//
  6568. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  6569. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6570. -
  6571. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  6572. - // not enough room for a tag let alone the rest of an element_value
  6573. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6574. - ("length() is too small for a tag"));
  6575. - return false;
  6576. - }
  6577. -
  6578. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  6579. - byte_i_ref++;
  6580. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  6581. -
  6582. - switch (tag) {
  6583. - // These BaseType tag values are from Table 4.2 in VM spec:
  6584. - case 'B': // byte
  6585. - case 'C': // char
  6586. - case 'D': // double
  6587. - case 'F': // float
  6588. - case 'I': // int
  6589. - case 'J': // long
  6590. - case 'S': // short
  6591. - case 'Z': // boolean
  6592. -
  6593. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  6594. - // the VM spec:
  6595. - case 's':
  6596. - {
  6597. - // For the above tag values (including the BaseType values),
  6598. - // value.const_value_index is right union field.
  6599. -
  6600. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6601. - // not enough room for a const_value_index
  6602. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6603. - ("length() is too small for a const_value_index"));
  6604. - return false;
  6605. - }
  6606. -
  6607. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  6608. - annotations_typeArray, byte_i_ref,
  6609. - "mapped old const_value_index=%d", THREAD);
  6610. -
  6611. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6612. - ("const_value_index=%d", const_value_index));
  6613. - } break;
  6614. -
  6615. - case 'e':
  6616. - {
  6617. - // for the above tag value, value.enum_const_value is right union field
  6618. -
  6619. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  6620. - // not enough room for a enum_const_value
  6621. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6622. - ("length() is too small for a enum_const_value"));
  6623. - return false;
  6624. - }
  6625. -
  6626. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  6627. - annotations_typeArray, byte_i_ref,
  6628. - "mapped old type_name_index=%d", THREAD);
  6629. -
  6630. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  6631. - annotations_typeArray, byte_i_ref,
  6632. - "mapped old const_name_index=%d", THREAD);
  6633. -
  6634. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6635. - ("type_name_index=%d const_name_index=%d", type_name_index,
  6636. - const_name_index));
  6637. - } break;
  6638. -
  6639. - case 'c':
  6640. - {
  6641. - // for the above tag value, value.class_info_index is right union field
  6642. -
  6643. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6644. - // not enough room for a class_info_index
  6645. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6646. - ("length() is too small for a class_info_index"));
  6647. - return false;
  6648. - }
  6649. -
  6650. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  6651. - annotations_typeArray, byte_i_ref,
  6652. - "mapped old class_info_index=%d", THREAD);
  6653. -
  6654. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6655. - ("class_info_index=%d", class_info_index));
  6656. - } break;
  6657. -
  6658. - case '@':
  6659. - // For the above tag value, value.attr_value is the right union
  6660. - // field. This is a nested annotation.
  6661. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6662. - byte_i_ref, THREAD)) {
  6663. - // propagate failure back to caller
  6664. - return false;
  6665. - }
  6666. - break;
  6667. -
  6668. - case '[':
  6669. - {
  6670. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6671. - // not enough room for a num_values field
  6672. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6673. - ("length() is too small for a num_values field"));
  6674. - return false;
  6675. - }
  6676. -
  6677. - // For the above tag value, value.array_value is the right union
  6678. - // field. This is an array of nested element_value.
  6679. - u2 num_values = Bytes::get_Java_u2((address)
  6680. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6681. - byte_i_ref += 2;
  6682. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  6683. -
  6684. - int calc_num_values = 0;
  6685. - for (; calc_num_values < num_values; calc_num_values++) {
  6686. - if (!rewrite_cp_refs_in_element_value(
  6687. - annotations_typeArray, byte_i_ref, THREAD)) {
  6688. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6689. - ("bad nested element_value at %d", calc_num_values));
  6690. - // propagate failure back to caller
  6691. - return false;
  6692. - }
  6693. - }
  6694. - assert(num_values == calc_num_values, "sanity check");
  6695. - } break;
  6696. -
  6697. - default:
  6698. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  6699. - return false;
  6700. - } // end decode tag field
  6701. -
  6702. - return true;
  6703. -} // end rewrite_cp_refs_in_element_value()
  6704. -
  6705. -
  6706. -// Rewrite constant pool references in a fields_annotations field.
  6707. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  6708. - instanceKlassHandle scratch_class, TRAPS) {
  6709. -
  6710. - objArrayHandle fields_annotations(THREAD,
  6711. - scratch_class->fields_annotations());
  6712. -
  6713. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  6714. - // no fields_annotations so nothing to do
  6715. - return true;
  6716. - }
  6717. -
  6718. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6719. - ("fields_annotations length=%d", fields_annotations->length()));
  6720. -
  6721. - for (int i = 0; i < fields_annotations->length(); i++) {
  6722. - typeArrayHandle field_annotations(THREAD,
  6723. - (typeArrayOop)fields_annotations->obj_at(i));
  6724. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  6725. - // this field does not have any annotations so skip it
  6726. - continue;
  6727. - }
  6728. -
  6729. - int byte_i = 0; // byte index into field_annotations
  6730. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  6731. - THREAD)) {
  6732. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6733. - ("bad field_annotations at %d", i));
  6734. - // propagate failure back to caller
  6735. - return false;
  6736. - }
  6737. - }
  6738. -
  6739. - return true;
  6740. -} // end rewrite_cp_refs_in_fields_annotations()
  6741. -
  6742. -
  6743. -// Rewrite constant pool references in a methods_annotations field.
  6744. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  6745. - instanceKlassHandle scratch_class, TRAPS) {
  6746. -
  6747. - objArrayHandle methods_annotations(THREAD,
  6748. - scratch_class->methods_annotations());
  6749. -
  6750. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  6751. - // no methods_annotations so nothing to do
  6752. - return true;
  6753. - }
  6754. -
  6755. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6756. - ("methods_annotations length=%d", methods_annotations->length()));
  6757. -
  6758. - for (int i = 0; i < methods_annotations->length(); i++) {
  6759. - typeArrayHandle method_annotations(THREAD,
  6760. - (typeArrayOop)methods_annotations->obj_at(i));
  6761. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  6762. - // this method does not have any annotations so skip it
  6763. - continue;
  6764. - }
  6765. -
  6766. - int byte_i = 0; // byte index into method_annotations
  6767. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  6768. - THREAD)) {
  6769. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6770. - ("bad method_annotations at %d", i));
  6771. - // propagate failure back to caller
  6772. - return false;
  6773. - }
  6774. - }
  6775. -
  6776. - return true;
  6777. -} // end rewrite_cp_refs_in_methods_annotations()
  6778. -
  6779. -
  6780. -// Rewrite constant pool references in a methods_parameter_annotations
  6781. -// field. This "structure" is adapted from the
  6782. -// RuntimeVisibleParameterAnnotations_attribute described in section
  6783. -// 4.8.17 of the 2nd-edition of the VM spec:
  6784. -//
  6785. -// methods_parameter_annotations_typeArray {
  6786. -// u1 num_parameters;
  6787. -// {
  6788. -// u2 num_annotations;
  6789. -// annotation annotations[num_annotations];
  6790. -// } parameter_annotations[num_parameters];
  6791. -// }
  6792. -//
  6793. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  6794. - instanceKlassHandle scratch_class, TRAPS) {
  6795. -
  6796. - objArrayHandle methods_parameter_annotations(THREAD,
  6797. - scratch_class->methods_parameter_annotations());
  6798. -
  6799. - if (methods_parameter_annotations.is_null()
  6800. - || methods_parameter_annotations->length() == 0) {
  6801. - // no methods_parameter_annotations so nothing to do
  6802. - return true;
  6803. - }
  6804. -
  6805. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6806. - ("methods_parameter_annotations length=%d",
  6807. - methods_parameter_annotations->length()));
  6808. -
  6809. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  6810. - typeArrayHandle method_parameter_annotations(THREAD,
  6811. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  6812. - if (method_parameter_annotations.is_null()
  6813. - || method_parameter_annotations->length() == 0) {
  6814. - // this method does not have any parameter annotations so skip it
  6815. - continue;
  6816. - }
  6817. -
  6818. - if (method_parameter_annotations->length() < 1) {
  6819. - // not enough room for a num_parameters field
  6820. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6821. - ("length() is too small for a num_parameters field at %d", i));
  6822. - return false;
  6823. - }
  6824. -
  6825. - int byte_i = 0; // byte index into method_parameter_annotations
  6826. -
  6827. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  6828. - byte_i++;
  6829. -
  6830. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6831. - ("num_parameters=%d", num_parameters));
  6832. -
  6833. - int calc_num_parameters = 0;
  6834. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  6835. - if (!rewrite_cp_refs_in_annotations_typeArray(
  6836. - method_parameter_annotations, byte_i, THREAD)) {
  6837. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6838. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  6839. - // propagate failure back to caller
  6840. - return false;
  6841. - }
  6842. - }
  6843. - assert(num_parameters == calc_num_parameters, "sanity check");
  6844. - }
  6845. -
  6846. - return true;
  6847. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  6848. -
  6849. -
  6850. -// Rewrite constant pool references in a methods_default_annotations
  6851. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  6852. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  6853. -//
  6854. -// methods_default_annotations_typeArray {
  6855. -// element_value default_value;
  6856. -// }
  6857. -//
  6858. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  6859. - instanceKlassHandle scratch_class, TRAPS) {
  6860. -
  6861. - objArrayHandle methods_default_annotations(THREAD,
  6862. - scratch_class->methods_default_annotations());
  6863. -
  6864. - if (methods_default_annotations.is_null()
  6865. - || methods_default_annotations->length() == 0) {
  6866. - // no methods_default_annotations so nothing to do
  6867. - return true;
  6868. - }
  6869. -
  6870. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6871. - ("methods_default_annotations length=%d",
  6872. - methods_default_annotations->length()));
  6873. -
  6874. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  6875. - typeArrayHandle method_default_annotations(THREAD,
  6876. - (typeArrayOop)methods_default_annotations->obj_at(i));
  6877. - if (method_default_annotations.is_null()
  6878. - || method_default_annotations->length() == 0) {
  6879. - // this method does not have any default annotations so skip it
  6880. - continue;
  6881. - }
  6882. -
  6883. - int byte_i = 0; // byte index into method_default_annotations
  6884. -
  6885. - if (!rewrite_cp_refs_in_element_value(
  6886. - method_default_annotations, byte_i, THREAD)) {
  6887. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6888. - ("bad default element_value at %d", i));
  6889. - // propagate failure back to caller
  6890. - return false;
  6891. - }
  6892. - }
  6893. -
  6894. - return true;
  6895. -} // end rewrite_cp_refs_in_methods_default_annotations()
  6896. -
  6897. -
  6898. -// Rewrite constant pool references in the method's stackmap table.
  6899. -// These "structures" are adapted from the StackMapTable_attribute that
  6900. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  6901. -// (dated 2005.10.26):
  6902. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6903. -//
  6904. -// stack_map {
  6905. -// u2 number_of_entries;
  6906. -// stack_map_frame entries[number_of_entries];
  6907. -// }
  6908. -//
  6909. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  6910. - methodHandle method, TRAPS) {
  6911. -
  6912. - if (!method->has_stackmap_table()) {
  6913. - return;
  6914. - }
  6915. -
  6916. - typeArrayOop stackmap_data = method->stackmap_data();
  6917. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  6918. - address stackmap_end = stackmap_p + stackmap_data->length();
  6919. -
  6920. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  6921. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  6922. - stackmap_p += 2;
  6923. -
  6924. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6925. - ("number_of_entries=%u", number_of_entries));
  6926. -
  6927. - // walk through each stack_map_frame
  6928. - u2 calc_number_of_entries = 0;
  6929. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  6930. - // The stack_map_frame structure is a u1 frame_type followed by
  6931. - // 0 or more bytes of data:
  6932. - //
  6933. - // union stack_map_frame {
  6934. - // same_frame;
  6935. - // same_locals_1_stack_item_frame;
  6936. - // same_locals_1_stack_item_frame_extended;
  6937. - // chop_frame;
  6938. - // same_frame_extended;
  6939. - // append_frame;
  6940. - // full_frame;
  6941. - // }
  6942. -
  6943. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  6944. - // The Linux compiler does not like frame_type to be u1 or u2. It
  6945. - // issues the following warning for the first if-statement below:
  6946. - //
  6947. - // "warning: comparison is always true due to limited range of data type"
  6948. - //
  6949. - u4 frame_type = *stackmap_p;
  6950. - stackmap_p++;
  6951. -
  6952. - // same_frame {
  6953. - // u1 frame_type = SAME; /* 0-63 */
  6954. - // }
  6955. - if (frame_type >= 0 && frame_type <= 63) {
  6956. - // nothing more to do for same_frame
  6957. - }
  6958. -
  6959. - // same_locals_1_stack_item_frame {
  6960. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  6961. - // verification_type_info stack[1];
  6962. - // }
  6963. - else if (frame_type >= 64 && frame_type <= 127) {
  6964. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6965. - calc_number_of_entries, frame_type, THREAD);
  6966. - }
  6967. -
  6968. - // reserved for future use
  6969. - else if (frame_type >= 128 && frame_type <= 246) {
  6970. - // nothing more to do for reserved frame_types
  6971. - }
  6972. -
  6973. - // same_locals_1_stack_item_frame_extended {
  6974. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  6975. - // u2 offset_delta;
  6976. - // verification_type_info stack[1];
  6977. - // }
  6978. - else if (frame_type == 247) {
  6979. - stackmap_p += 2;
  6980. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6981. - calc_number_of_entries, frame_type, THREAD);
  6982. - }
  6983. -
  6984. - // chop_frame {
  6985. - // u1 frame_type = CHOP; /* 248-250 */
  6986. - // u2 offset_delta;
  6987. - // }
  6988. - else if (frame_type >= 248 && frame_type <= 250) {
  6989. - stackmap_p += 2;
  6990. - }
  6991. -
  6992. - // same_frame_extended {
  6993. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  6994. - // u2 offset_delta;
  6995. - // }
  6996. - else if (frame_type == 251) {
  6997. - stackmap_p += 2;
  6998. - }
  6999. -
  7000. - // append_frame {
  7001. - // u1 frame_type = APPEND; /* 252-254 */
  7002. - // u2 offset_delta;
  7003. - // verification_type_info locals[frame_type - 251];
  7004. - // }
  7005. - else if (frame_type >= 252 && frame_type <= 254) {
  7006. - assert(stackmap_p + 2 <= stackmap_end,
  7007. - "no room for offset_delta");
  7008. - stackmap_p += 2;
  7009. - u1 len = frame_type - 251;
  7010. - for (u1 i = 0; i < len; i++) {
  7011. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7012. - calc_number_of_entries, frame_type, THREAD);
  7013. - }
  7014. - }
  7015. -
  7016. - // full_frame {
  7017. - // u1 frame_type = FULL_FRAME; /* 255 */
  7018. - // u2 offset_delta;
  7019. - // u2 number_of_locals;
  7020. - // verification_type_info locals[number_of_locals];
  7021. - // u2 number_of_stack_items;
  7022. - // verification_type_info stack[number_of_stack_items];
  7023. - // }
  7024. - else if (frame_type == 255) {
  7025. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  7026. - "no room for smallest full_frame");
  7027. - stackmap_p += 2;
  7028. -
  7029. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  7030. - stackmap_p += 2;
  7031. -
  7032. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  7033. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7034. - calc_number_of_entries, frame_type, THREAD);
  7035. - }
  7036. -
  7037. - // Use the largest size for the number_of_stack_items, but only get
  7038. - // the right number of bytes.
  7039. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  7040. - stackmap_p += 2;
  7041. -
  7042. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  7043. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7044. - calc_number_of_entries, frame_type, THREAD);
  7045. - }
  7046. - }
  7047. - } // end while there is a stack_map_frame
  7048. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  7049. -} // end rewrite_cp_refs_in_stack_map_table()
  7050. -
  7051. -
  7052. -// Rewrite constant pool references in the verification type info
  7053. -// portion of the method's stackmap table. These "structures" are
  7054. -// adapted from the StackMapTable_attribute that is described in
  7055. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  7056. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  7057. -//
  7058. -// The verification_type_info structure is a u1 tag followed by 0 or
  7059. -// more bytes of data:
  7060. -//
  7061. -// union verification_type_info {
  7062. -// Top_variable_info;
  7063. -// Integer_variable_info;
  7064. -// Float_variable_info;
  7065. -// Long_variable_info;
  7066. -// Double_variable_info;
  7067. -// Null_variable_info;
  7068. -// UninitializedThis_variable_info;
  7069. -// Object_variable_info;
  7070. -// Uninitialized_variable_info;
  7071. -// }
  7072. -//
  7073. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  7074. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  7075. - u1 frame_type, TRAPS) {
  7076. -
  7077. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  7078. - u1 tag = *stackmap_p_ref;
  7079. - stackmap_p_ref++;
  7080. -
  7081. - switch (tag) {
  7082. - // Top_variable_info {
  7083. - // u1 tag = ITEM_Top; /* 0 */
  7084. - // }
  7085. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  7086. - case 0: // fall through
  7087. -
  7088. - // Integer_variable_info {
  7089. - // u1 tag = ITEM_Integer; /* 1 */
  7090. - // }
  7091. - case ITEM_Integer: // fall through
  7092. -
  7093. - // Float_variable_info {
  7094. - // u1 tag = ITEM_Float; /* 2 */
  7095. - // }
  7096. - case ITEM_Float: // fall through
  7097. -
  7098. - // Double_variable_info {
  7099. - // u1 tag = ITEM_Double; /* 3 */
  7100. - // }
  7101. - case ITEM_Double: // fall through
  7102. -
  7103. - // Long_variable_info {
  7104. - // u1 tag = ITEM_Long; /* 4 */
  7105. - // }
  7106. - case ITEM_Long: // fall through
  7107. -
  7108. - // Null_variable_info {
  7109. - // u1 tag = ITEM_Null; /* 5 */
  7110. - // }
  7111. - case ITEM_Null: // fall through
  7112. -
  7113. - // UninitializedThis_variable_info {
  7114. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  7115. - // }
  7116. - case ITEM_UninitializedThis:
  7117. - // nothing more to do for the above tag types
  7118. - break;
  7119. -
  7120. - // Object_variable_info {
  7121. - // u1 tag = ITEM_Object; /* 7 */
  7122. - // u2 cpool_index;
  7123. - // }
  7124. - case ITEM_Object:
  7125. - {
  7126. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  7127. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  7128. - u2 new_cp_index = find_new_index(cpool_index);
  7129. - if (new_cp_index != 0) {
  7130. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7131. - ("mapped old cpool_index=%d", cpool_index));
  7132. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  7133. - cpool_index = new_cp_index;
  7134. - }
  7135. - stackmap_p_ref += 2;
  7136. -
  7137. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7138. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  7139. - frame_type, cpool_index));
  7140. - } break;
  7141. -
  7142. - // Uninitialized_variable_info {
  7143. - // u1 tag = ITEM_Uninitialized; /* 8 */
  7144. - // u2 offset;
  7145. - // }
  7146. - case ITEM_Uninitialized:
  7147. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  7148. - stackmap_p_ref += 2;
  7149. - break;
  7150. -
  7151. - default:
  7152. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7153. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  7154. - ShouldNotReachHere();
  7155. - break;
  7156. - } // end switch (tag)
  7157. -} // end rewrite_cp_refs_in_verification_type_info()
  7158. -
  7159. -
  7160. -// Change the constant pool associated with klass scratch_class to
  7161. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  7162. -// are copied from scratch_cp to a smaller constant pool and the
  7163. -// smaller constant pool is associated with scratch_class.
  7164. -void VM_RedefineClasses::set_new_constant_pool(
  7165. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  7166. - int scratch_cp_length, TRAPS) {
  7167. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  7168. -
  7169. - // scratch_cp is a merged constant pool and has enough space for a
  7170. - // worst case merge situation. We want to associate the minimum
  7171. - // sized constant pool with the klass to save space.
  7172. - constantPoolHandle smaller_cp(THREAD,
  7173. - oopFactory::new_constantPool(scratch_cp_length,
  7174. - oopDesc::IsUnsafeConc,
  7175. - THREAD));
  7176. - // preserve orig_length() value in the smaller copy
  7177. - int orig_length = scratch_cp->orig_length();
  7178. - assert(orig_length != 0, "sanity check");
  7179. - smaller_cp->set_orig_length(orig_length);
  7180. -
  7181. - // attach klass to new constant pool
  7182. - // reference to the cp holder is needed for copy_operands()
  7183. - smaller_cp->set_pool_holder(scratch_class());
  7184. -
  7185. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  7186. - scratch_cp = smaller_cp;
  7187. - smaller_cp()->set_is_conc_safe(true);
  7188. -
  7189. - // attach new constant pool to klass
  7190. - scratch_class->set_constants(scratch_cp());
  7191. -
  7192. - int i; // for portability
  7193. -
  7194. - // update each field in klass to use new constant pool indices as needed
  7195. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  7196. - jshort cur_index = fs.name_index();
  7197. - jshort new_index = find_new_index(cur_index);
  7198. - if (new_index != 0) {
  7199. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7200. - ("field-name_index change: %d to %d", cur_index, new_index));
  7201. - fs.set_name_index(new_index);
  7202. - }
  7203. - cur_index = fs.signature_index();
  7204. - new_index = find_new_index(cur_index);
  7205. - if (new_index != 0) {
  7206. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7207. - ("field-signature_index change: %d to %d", cur_index, new_index));
  7208. - fs.set_signature_index(new_index);
  7209. - }
  7210. - cur_index = fs.initval_index();
  7211. - new_index = find_new_index(cur_index);
  7212. - if (new_index != 0) {
  7213. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7214. - ("field-initval_index change: %d to %d", cur_index, new_index));
  7215. - fs.set_initval_index(new_index);
  7216. - }
  7217. - cur_index = fs.generic_signature_index();
  7218. - new_index = find_new_index(cur_index);
  7219. - if (new_index != 0) {
  7220. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7221. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  7222. - fs.set_generic_signature_index(new_index);
  7223. - }
  7224. - } // end for each field
  7225. -
  7226. - // Update constant pool indices in the inner classes info to use
  7227. - // new constant indices as needed. The inner classes info is a
  7228. - // quadruple:
  7229. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  7230. - InnerClassesIterator iter(scratch_class);
  7231. - for (; !iter.done(); iter.next()) {
  7232. - int cur_index = iter.inner_class_info_index();
  7233. - if (cur_index == 0) {
  7234. - continue; // JVM spec. allows null inner class refs so skip it
  7235. - }
  7236. - int new_index = find_new_index(cur_index);
  7237. - if (new_index != 0) {
  7238. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7239. - ("inner_class_info change: %d to %d", cur_index, new_index));
  7240. - iter.set_inner_class_info_index(new_index);
  7241. - }
  7242. - cur_index = iter.outer_class_info_index();
  7243. - new_index = find_new_index(cur_index);
  7244. - if (new_index != 0) {
  7245. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7246. - ("outer_class_info change: %d to %d", cur_index, new_index));
  7247. - iter.set_outer_class_info_index(new_index);
  7248. - }
  7249. - cur_index = iter.inner_name_index();
  7250. - new_index = find_new_index(cur_index);
  7251. - if (new_index != 0) {
  7252. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7253. - ("inner_name change: %d to %d", cur_index, new_index));
  7254. - iter.set_inner_name_index(new_index);
  7255. - }
  7256. - } // end for each inner class
  7257. -
  7258. - // Attach each method in klass to the new constant pool and update
  7259. - // to use new constant pool indices as needed:
  7260. - objArrayHandle methods(THREAD, scratch_class->methods());
  7261. - for (i = methods->length() - 1; i >= 0; i--) {
  7262. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7263. - method->set_constants(scratch_cp());
  7264. -
  7265. - int new_index = find_new_index(method->name_index());
  7266. - if (new_index != 0) {
  7267. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7268. - ("method-name_index change: %d to %d", method->name_index(),
  7269. - new_index));
  7270. - method->set_name_index(new_index);
  7271. - }
  7272. - new_index = find_new_index(method->signature_index());
  7273. - if (new_index != 0) {
  7274. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7275. - ("method-signature_index change: %d to %d",
  7276. - method->signature_index(), new_index));
  7277. - method->set_signature_index(new_index);
  7278. - }
  7279. - new_index = find_new_index(method->generic_signature_index());
  7280. - if (new_index != 0) {
  7281. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7282. - ("method-generic_signature_index change: %d to %d",
  7283. - method->generic_signature_index(), new_index));
  7284. - method->set_generic_signature_index(new_index);
  7285. - }
  7286. -
  7287. - // Update constant pool indices in the method's checked exception
  7288. - // table to use new constant indices as needed.
  7289. - int cext_length = method->checked_exceptions_length();
  7290. - if (cext_length > 0) {
  7291. - CheckedExceptionElement * cext_table =
  7292. - method->checked_exceptions_start();
  7293. - for (int j = 0; j < cext_length; j++) {
  7294. - int cur_index = cext_table[j].class_cp_index;
  7295. - int new_index = find_new_index(cur_index);
  7296. - if (new_index != 0) {
  7297. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7298. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  7299. - cext_table[j].class_cp_index = (u2)new_index;
  7300. - }
  7301. - } // end for each checked exception table entry
  7302. - } // end if there are checked exception table entries
  7303. -
  7304. - // Update each catch type index in the method's exception table
  7305. - // to use new constant pool indices as needed. The exception table
  7306. - // holds quadruple entries of the form:
  7307. - // (beg_bci, end_bci, handler_bci, klass_index)
  7308. -
  7309. - ExceptionTable ex_table(method());
  7310. - int ext_length = ex_table.length();
  7311. -
  7312. - for (int j = 0; j < ext_length; j ++) {
  7313. - int cur_index = ex_table.catch_type_index(j);
  7314. - int new_index = find_new_index(cur_index);
  7315. - if (new_index != 0) {
  7316. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7317. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  7318. - ex_table.set_catch_type_index(j, new_index);
  7319. - }
  7320. - } // end for each exception table entry
  7321. -
  7322. - // Update constant pool indices in the method's local variable
  7323. - // table to use new constant indices as needed. The local variable
  7324. - // table hold sextuple entries of the form:
  7325. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  7326. - int lvt_length = method->localvariable_table_length();
  7327. - if (lvt_length > 0) {
  7328. - LocalVariableTableElement * lv_table =
  7329. - method->localvariable_table_start();
  7330. - for (int j = 0; j < lvt_length; j++) {
  7331. - int cur_index = lv_table[j].name_cp_index;
  7332. - int new_index = find_new_index(cur_index);
  7333. - if (new_index != 0) {
  7334. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7335. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  7336. - lv_table[j].name_cp_index = (u2)new_index;
  7337. - }
  7338. - cur_index = lv_table[j].descriptor_cp_index;
  7339. - new_index = find_new_index(cur_index);
  7340. - if (new_index != 0) {
  7341. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7342. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  7343. - new_index));
  7344. - lv_table[j].descriptor_cp_index = (u2)new_index;
  7345. - }
  7346. - cur_index = lv_table[j].signature_cp_index;
  7347. - new_index = find_new_index(cur_index);
  7348. - if (new_index != 0) {
  7349. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7350. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  7351. - lv_table[j].signature_cp_index = (u2)new_index;
  7352. - }
  7353. - } // end for each local variable table entry
  7354. - } // end if there are local variable table entries
  7355. -
  7356. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  7357. - } // end for each method
  7358. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7359. -} // end set_new_constant_pool()
  7360. -
  7361. -
  7362. -// Unevolving classes may point to methods of the_class directly
  7363. +// Unevolving classes may point to old methods directly
  7364. // from their constant pool caches, itables, and/or vtables. We
  7365. // use the SystemDictionary::classes_do() facility and this helper
  7366. -// to fix up these pointers.
  7367. +// to fix up these pointers. Additional field offsets and vtable indices
  7368. +// in the constant pool cache entries are fixed.
  7369. //
  7370. // Note: We currently don't support updating the vtable in
  7371. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7372. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  7373. - oop initiating_loader, TRAPS) {
  7374. - Klass *k = k_oop->klass_part();
  7375. - if (k->oop_is_instance()) {
  7376. - HandleMark hm(THREAD);
  7377. - instanceKlass *ik = (instanceKlass *) k;
  7378. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7379. + klassOop k_oop = k_oop_latest;
  7380. + while (k_oop != NULL) {
  7381. + Klass *k = k_oop->klass_part();
  7382. + if (k->oop_is_instance()) {
  7383. + HandleMark hm(THREAD);
  7384. + instanceKlass *ik = (instanceKlass *) k;
  7385. - // HotSpot specific optimization! HotSpot does not currently
  7386. - // support delegation from the bootstrap class loader to a
  7387. - // user-defined class loader. This means that if the bootstrap
  7388. - // class loader is the initiating class loader, then it will also
  7389. - // be the defining class loader. This also means that classes
  7390. - // loaded by the bootstrap class loader cannot refer to classes
  7391. - // loaded by a user-defined class loader. Note: a user-defined
  7392. - // class loader can delegate to the bootstrap class loader.
  7393. - //
  7394. - // If the current class being redefined has a user-defined class
  7395. - // loader as its defining class loader, then we can skip all
  7396. - // classes loaded by the bootstrap class loader.
  7397. - bool is_user_defined =
  7398. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  7399. - if (is_user_defined && ik->class_loader() == NULL) {
  7400. - return;
  7401. - }
  7402. + constantPoolHandle other_cp;
  7403. + constantPoolCacheOop cp_cache;
  7404. - // This is a very busy routine. We don't want too much tracing
  7405. - // printed out.
  7406. - bool trace_name_printed = false;
  7407. + other_cp = constantPoolHandle(ik->constants());
  7408. - // Very noisy: only enable this call if you are trying to determine
  7409. - // that a specific class gets found by this routine.
  7410. - // RC_TRACE macro has an embedded ResourceMark
  7411. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  7412. - // ("adjust check: name=%s", ik->external_name()));
  7413. - // trace_name_printed = true;
  7414. + for (int i=0; i<other_cp->length(); i++) {
  7415. + if (other_cp->tag_at(i).is_klass()) {
  7416. + klassOop klass = other_cp->klass_at(i, THREAD);
  7417. + if (klass->klass_part()->new_version() != NULL) {
  7418. - // Fix the vtable embedded in the_class and subclasses of the_class,
  7419. - // if one exists. We discard scratch_class and we don't keep an
  7420. - // instanceKlass around to hold obsolete methods so we don't have
  7421. - // any other instanceKlass embedded vtables to update. The vtable
  7422. - // holds the methodOops for virtual (but not final) methods.
  7423. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  7424. - // ik->vtable() creates a wrapper object; rm cleans it up
  7425. - ResourceMark rm(THREAD);
  7426. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  7427. - _matching_new_methods,
  7428. - _matching_methods_length,
  7429. - &trace_name_printed);
  7430. - }
  7431. + // (tw) TODO: check why/if this is necessary
  7432. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  7433. + }
  7434. + klass = other_cp->klass_at(i, THREAD);
  7435. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  7436. + }
  7437. + }
  7438. - // If the current class has an itable and we are either redefining an
  7439. - // interface or if the current class is a subclass of the_class, then
  7440. - // we potentially have to fix the itable. If we are redefining an
  7441. - // interface, then we have to call adjust_method_entries() for
  7442. - // every instanceKlass that has an itable since there isn't a
  7443. - // subclass relationship between an interface and an instanceKlass.
  7444. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  7445. - || ik->is_subclass_of(_the_class_oop))) {
  7446. - // ik->itable() creates a wrapper object; rm cleans it up
  7447. - ResourceMark rm(THREAD);
  7448. - ik->itable()->adjust_method_entries(_matching_old_methods,
  7449. - _matching_new_methods,
  7450. - _matching_methods_length,
  7451. - &trace_name_printed);
  7452. - }
  7453. + cp_cache = other_cp->cache();
  7454. - // The constant pools in other classes (other_cp) can refer to
  7455. - // methods in the_class. We have to update method information in
  7456. - // other_cp's cache. If other_cp has a previous version, then we
  7457. - // have to repeat the process for each previous version. The
  7458. - // constant pool cache holds the methodOops for non-virtual
  7459. - // methods and for virtual, final methods.
  7460. - //
  7461. - // Special case: if the current class is the_class, then new_cp
  7462. - // has already been attached to the_class and old_cp has already
  7463. - // been added as a previous version. The new_cp doesn't have any
  7464. - // cached references to old methods so it doesn't need to be
  7465. - // updated. We can simply start with the previous version(s) in
  7466. - // that case.
  7467. - constantPoolHandle other_cp;
  7468. - constantPoolCacheOop cp_cache;
  7469. + if (cp_cache != NULL) {
  7470. + cp_cache->adjust_entries();
  7471. + }
  7472. - if (k_oop != _the_class_oop) {
  7473. - // this klass' constant pool cache may need adjustment
  7474. - other_cp = constantPoolHandle(ik->constants());
  7475. - cp_cache = other_cp->cache();
  7476. - if (cp_cache != NULL) {
  7477. - cp_cache->adjust_method_entries(_matching_old_methods,
  7478. - _matching_new_methods,
  7479. - _matching_methods_length,
  7480. - &trace_name_printed);
  7481. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
  7482. + if (RewriteBytecodes) {
  7483. + ik->methods_do(unpatch_bytecode);
  7484. }
  7485. }
  7486. - {
  7487. - ResourceMark rm(THREAD);
  7488. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  7489. - // contain a GrowableArray of handles. We have to clean up the
  7490. - // GrowableArray _after_ the PreviousVersionWalker destructor
  7491. - // has destroyed the handles.
  7492. - {
  7493. - // the previous versions' constant pool caches may need adjustment
  7494. - PreviousVersionWalker pvw(ik);
  7495. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  7496. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  7497. - other_cp = pv_info->prev_constant_pool_handle();
  7498. - cp_cache = other_cp->cache();
  7499. - if (cp_cache != NULL) {
  7500. - cp_cache->adjust_method_entries(_matching_old_methods,
  7501. - _matching_new_methods,
  7502. - _matching_methods_length,
  7503. - &trace_name_printed);
  7504. - }
  7505. - }
  7506. - } // pvw is cleaned up
  7507. - } // rm is cleaned up
  7508. + k_oop = k_oop->klass_part()->old_version();
  7509. }
  7510. }
  7511. void VM_RedefineClasses::update_jmethod_ids() {
  7512. for (int j = 0; j < _matching_methods_length; ++j) {
  7513. - methodOop old_method = _matching_old_methods[j];
  7514. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7515. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  7516. +
  7517. jmethodID jmid = old_method->find_jmethod_id_or_null();
  7518. + if (old_method->new_version() != NULL && jmid == NULL) {
  7519. + // (tw) Have to create jmethodID in this case
  7520. + jmid = old_method->jmethod_id();
  7521. + }
  7522. +
  7523. if (jmid != NULL) {
  7524. // There is a jmethodID, change it to point to the new method
  7525. - methodHandle new_method_h(_matching_new_methods[j]);
  7526. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  7527. + if (old_method->new_version() == NULL) {
  7528. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  7529. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  7530. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  7531. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  7532. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7533. + } else {
  7534. + jmethodID mid = new_method_h->jmethod_id();
  7535. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  7536. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  7537. + }
  7538. JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7539. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  7540. - "should be replaced");
  7541. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  7542. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  7543. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  7544. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  7545. +
  7546. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7547. }
  7548. }
  7549. }
  7550. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  7551. - BitMap *emcp_methods, int * emcp_method_count_p) {
  7552. - *emcp_method_count_p = 0;
  7553. - int obsolete_count = 0;
  7554. - int old_index = 0;
  7555. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7556. - methodOop old_method = _matching_old_methods[j];
  7557. - methodOop new_method = _matching_new_methods[j];
  7558. - methodOop old_array_method;
  7559. - // Maintain an old_index into the _old_methods array by skipping
  7560. - // deleted methods
  7561. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7562. - != old_method) {
  7563. - ++old_index;
  7564. +// Deoptimize all compiled code that depends on this class.
  7565. +//
  7566. +// If the can_redefine_classes capability is obtained in the onload
  7567. +// phase then the compiler has recorded all dependencies from startup.
  7568. +// In that case we need only deoptimize and throw away all compiled code
  7569. +// that depends on the class.
  7570. +//
  7571. +// If can_redefine_classes is obtained sometime after the onload
  7572. +// phase then the dependency information may be incomplete. In that case
  7573. +// the first call to RedefineClasses causes all compiled code to be
  7574. +// thrown away. As can_redefine_classes has been obtained then
  7575. +// all future compilations will record dependencies so second and
  7576. +// subsequent calls to RedefineClasses need only throw away code
  7577. +// that depends on the class.
  7578. +//
  7579. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  7580. + assert_locked_or_safepoint(Compile_lock);
  7581. +
  7582. + // All dependencies have been recorded from startup or this is a second or
  7583. + // subsequent use of RedefineClasses
  7584. +
  7585. + // For now deopt all
  7586. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  7587. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  7588. + Universe::flush_evol_dependents_on(k_h);
  7589. + } else {
  7590. + CodeCache::mark_all_nmethods_for_deoptimization();
  7591. +
  7592. + ResourceMark rm(THREAD);
  7593. + DeoptimizationMarker dm;
  7594. +
  7595. + // Deoptimize all activations depending on marked nmethods
  7596. + Deoptimization::deoptimize_dependents();
  7597. +
  7598. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  7599. + CodeCache::make_marked_nmethods_not_entrant();
  7600. +
  7601. + // From now on we know that the dependency information is complete
  7602. + JvmtiExport::set_all_dependencies_are_recorded(true);
  7603. + }
  7604. +}
  7605. +
  7606. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7607. + methodOop old_method;
  7608. + methodOop new_method;
  7609. +
  7610. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7611. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7612. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  7613. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7614. +
  7615. + _matching_methods_length = 0;
  7616. + _deleted_methods_length = 0;
  7617. + _added_methods_length = 0;
  7618. +
  7619. + int nj = 0;
  7620. + int oj = 0;
  7621. + while (true) {
  7622. + if (oj >= _old_methods->length()) {
  7623. + if (nj >= _new_methods->length()) {
  7624. + break; // we've looked at everything, done
  7625. + }
  7626. + // New method at the end
  7627. + new_method = (methodOop) _new_methods->obj_at(nj);
  7628. + _added_methods[_added_methods_length++] = nj;
  7629. + ++nj;
  7630. + } else if (nj >= _new_methods->length()) {
  7631. + // Old method, at the end, is deleted
  7632. + old_method = (methodOop) _old_methods->obj_at(oj);
  7633. + _deleted_methods[_deleted_methods_length++] = oj;
  7634. + ++oj;
  7635. + } else {
  7636. + old_method = (methodOop) _old_methods->obj_at(oj);
  7637. + new_method = (methodOop) _new_methods->obj_at(nj);
  7638. + if (old_method->name() == new_method->name()) {
  7639. + if (old_method->signature() == new_method->signature()) {
  7640. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  7641. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  7642. + ++nj;
  7643. + ++oj;
  7644. + } else {
  7645. + // added overloaded have already been moved to the end,
  7646. + // so this is a deleted overloaded method
  7647. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7648. + ++oj;
  7649. + }
  7650. + } else { // names don't match
  7651. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  7652. + // new method
  7653. + _added_methods[_added_methods_length++] = nj;//new_method;
  7654. + ++nj;
  7655. + } else {
  7656. + // deleted method
  7657. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7658. + ++oj;
  7659. + }
  7660. + }
  7661. }
  7662. + }
  7663. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  7664. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  7665. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  7666. +}
  7667. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7668. - // The EMCP definition from JSR-163 requires the bytecodes to be
  7669. - // the same with the exception of constant pool indices which may
  7670. - // differ. However, the constants referred to by those indices
  7671. - // must be the same.
  7672. - //
  7673. - // We use methods_EMCP() for comparison since constant pool
  7674. - // merging can remove duplicate constant pool entries that were
  7675. - // present in the old method and removed from the rewritten new
  7676. - // method. A faster binary comparison function would consider the
  7677. - // old and new methods to be different when they are actually
  7678. - // EMCP.
  7679. - //
  7680. - // The old and new methods are EMCP and you would think that we
  7681. - // could get rid of one of them here and now and save some space.
  7682. - // However, the concept of EMCP only considers the bytecodes and
  7683. - // the constant pool entries in the comparison. Other things,
  7684. - // e.g., the line number table (LNT) or the local variable table
  7685. - // (LVT) don't count in the comparison. So the new (and EMCP)
  7686. - // method can have a new LNT that we need so we can't just
  7687. - // overwrite the new method with the old method.
  7688. - //
  7689. - // When this routine is called, we have already attached the new
  7690. - // methods to the_class so the old methods are effectively
  7691. - // overwritten. However, if an old method is still executing,
  7692. - // then the old method cannot be collected until sometime after
  7693. - // the old method call has returned. So the overwriting of old
  7694. - // methods by new methods will save us space except for those
  7695. - // (hopefully few) old methods that are still executing.
  7696. - //
  7697. - // A method refers to a constMethodOop and this presents another
  7698. - // possible avenue to space savings. The constMethodOop in the
  7699. - // new method contains possibly new attributes (LNT, LVT, etc).
  7700. - // At first glance, it seems possible to save space by replacing
  7701. - // the constMethodOop in the old method with the constMethodOop
  7702. - // from the new method. The old and new methods would share the
  7703. - // same constMethodOop and we would save the space occupied by
  7704. - // the old constMethodOop. However, the constMethodOop contains
  7705. - // a back reference to the containing method. Sharing the
  7706. - // constMethodOop between two methods could lead to confusion in
  7707. - // the code that uses the back reference. This would lead to
  7708. - // brittle code that could be broken in non-obvious ways now or
  7709. - // in the future.
  7710. - //
  7711. - // Another possibility is to copy the constMethodOop from the new
  7712. - // method to the old method and then overwrite the new method with
  7713. - // the old method. Since the constMethodOop contains the bytecodes
  7714. - // for the method embedded in the oop, this option would change
  7715. - // the bytecodes out from under any threads executing the old
  7716. - // method and make the thread's bcp invalid. Since EMCP requires
  7717. - // that the bytecodes be the same modulo constant pool indices, it
  7718. - // is straight forward to compute the correct new bcp in the new
  7719. - // constMethodOop from the old bcp in the old constMethodOop. The
  7720. - // time consuming part would be searching all the frames in all
  7721. - // of the threads to find all of the calls to the old method.
  7722. - //
  7723. - // It looks like we will have to live with the limited savings
  7724. - // that we get from effectively overwriting the old methods
  7725. - // when the new methods are attached to the_class.
  7726. - // track which methods are EMCP for add_previous_version() call
  7727. - emcp_methods->set_bit(old_index);
  7728. - (*emcp_method_count_p)++;
  7729. - // An EMCP method is _not_ obsolete. An obsolete method has a
  7730. - // different jmethodID than the current method. An EMCP method
  7731. - // has the same jmethodID as the current method. Having the
  7732. - // same jmethodID for all EMCP versions of a method allows for
  7733. - // a consistent view of the EMCP methods regardless of which
  7734. - // EMCP method you happen to have in hand. For example, a
  7735. - // breakpoint set in one EMCP method will work for all EMCP
  7736. - // versions of the method including the current one.
  7737. - } else {
  7738. - // mark obsolete methods as such
  7739. +// Install the redefinition of a class:
  7740. +// - house keeping (flushing breakpoints and caches, deoptimizing
  7741. +// dependent compiled code)
  7742. +// - adjusting constant pool caches and vtables in other classes
  7743. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  7744. +
  7745. + ResourceMark rm(THREAD);
  7746. +
  7747. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7748. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7749. +
  7750. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  7751. +
  7752. +#ifndef JVMTI_KERNEL
  7753. + // Remove all breakpoints in methods of this class
  7754. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  7755. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  7756. +#endif // !JVMTI_KERNEL
  7757. +
  7758. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  7759. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  7760. + // cached and users of the cache care about each active version of
  7761. + // the method so we have to track this previous version.
  7762. + // Do this before methods get switched
  7763. + Universe::reflect_invoke_cache()->add_previous_version(
  7764. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7765. + }
  7766. +
  7767. + _old_methods = the_old_class->methods();
  7768. + _new_methods = the_new_class->methods();
  7769. + compute_added_deleted_matching_methods();
  7770. +
  7771. + // track which methods are EMCP for add_previous_version() call below
  7772. +
  7773. + // (tw) TODO: Check if we need the concept of EMCP?
  7774. + BitMap emcp_methods(_old_methods->length());
  7775. + int emcp_method_count = 0;
  7776. + emcp_methods.clear(); // clears 0..(length() - 1)
  7777. +
  7778. + // We need to mark methods as old!!
  7779. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  7780. + update_jmethod_ids();
  7781. +
  7782. + // TODO:
  7783. + transfer_old_native_function_registrations(the_old_class);
  7784. +
  7785. +
  7786. +
  7787. +#ifdef ASSERT
  7788. +
  7789. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  7790. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  7791. +
  7792. + //JNIHandles::verify();
  7793. +
  7794. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  7795. +
  7796. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  7797. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7798. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7799. +
  7800. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  7801. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  7802. + }
  7803. +
  7804. + _old_methods->verify();
  7805. + _new_methods->verify();
  7806. +
  7807. + the_new_class->vtable()->verify(tty);
  7808. + the_old_class->vtable()->verify(tty);
  7809. +
  7810. +#endif
  7811. +
  7812. + // increment the classRedefinedCount field in the_class and in any
  7813. + // direct and indirect subclasses of the_class
  7814. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  7815. +
  7816. +}
  7817. +
  7818. +
  7819. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  7820. + TRACE_RC3("Checking matching methods for EMCP");
  7821. + *emcp_method_count_p = 0;
  7822. + int obsolete_count = 0;
  7823. + int old_index = 0;
  7824. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7825. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7826. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  7827. + methodOop old_array_method;
  7828. +
  7829. + // Maintain an old_index into the _old_methods array by skipping
  7830. + // deleted methods
  7831. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7832. + != old_method) {
  7833. + ++old_index;
  7834. + }
  7835. +
  7836. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7837. + // The EMCP definition from JSR-163 requires the bytecodes to be
  7838. + // the same with the exception of constant pool indices which may
  7839. + // differ. However, the constants referred to by those indices
  7840. + // must be the same.
  7841. + //
  7842. + // We use methods_EMCP() for comparison since constant pool
  7843. + // merging can remove duplicate constant pool entries that were
  7844. + // present in the old method and removed from the rewritten new
  7845. + // method. A faster binary comparison function would consider the
  7846. + // old and new methods to be different when they are actually
  7847. + // EMCP.
  7848. +
  7849. + // track which methods are EMCP for add_previous_version() call
  7850. + emcp_methods->set_bit(old_index);
  7851. + (*emcp_method_count_p)++;
  7852. +
  7853. + // An EMCP method is _not_ obsolete. An obsolete method has a
  7854. + // different jmethodID than the current method. An EMCP method
  7855. + // has the same jmethodID as the current method. Having the
  7856. + // same jmethodID for all EMCP versions of a method allows for
  7857. + // a consistent view of the EMCP methods regardless of which
  7858. + // EMCP method you happen to have in hand. For example, a
  7859. + // breakpoint set in one EMCP method will work for all EMCP
  7860. + // versions of the method including the current one.
  7861. +
  7862. + old_method->set_new_version(new_method);
  7863. + new_method->set_old_version(old_method);
  7864. +
  7865. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  7866. +
  7867. + // Transfer breakpoints
  7868. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  7869. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  7870. + TRACE_RC2("Checking breakpoint");
  7871. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  7872. + if (bp->match(old_method)) {
  7873. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  7874. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  7875. + new_method->set_breakpoint(bp->bci());
  7876. + }
  7877. + }
  7878. + } else {
  7879. + // mark obsolete methods as such
  7880. + old_method->set_is_obsolete();
  7881. + obsolete_count++;
  7882. +
  7883. + // With tracing we try not to "yack" too much. The position of
  7884. + // this trace assumes there are fewer obsolete methods than
  7885. + // EMCP methods.
  7886. + TRACE_RC3("mark %s(%s) as obsolete",
  7887. + old_method->name()->as_C_string(),
  7888. + old_method->signature()->as_C_string());
  7889. + }
  7890. + old_method->set_is_old();
  7891. + }
  7892. + for (int i = 0; i < _deleted_methods_length; ++i) {
  7893. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  7894. +
  7895. + //assert(old_method->vtable_index() < 0,
  7896. + // "cannot delete methods with vtable entries");;
  7897. +
  7898. + // Mark all deleted methods as old and obsolete
  7899. + old_method->set_is_old();
  7900. old_method->set_is_obsolete();
  7901. - obsolete_count++;
  7902. -
  7903. - // obsolete methods need a unique idnum
  7904. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  7905. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  7906. -// u2 old_num = old_method->method_idnum();
  7907. - old_method->set_method_idnum(num);
  7908. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  7909. - }
  7910. + ++obsolete_count;
  7911. // With tracing we try not to "yack" too much. The position of
  7912. // this trace assumes there are fewer obsolete methods than
  7913. // EMCP methods.
  7914. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  7915. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  7916. old_method->name()->as_C_string(),
  7917. - old_method->signature()->as_C_string()));
  7918. + old_method->signature()->as_C_string());
  7919. }
  7920. - old_method->set_is_old();
  7921. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  7922. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  7923. +}
  7924. +
  7925. +// Increment the classRedefinedCount field in the specific instanceKlass
  7926. +// and in all direct and indirect subclasses.
  7927. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  7928. + oop class_mirror = ik->java_mirror();
  7929. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  7930. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  7931. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  7932. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  7933. +}
  7934. +
  7935. +#ifndef PRODUCT
  7936. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  7937. + Klass *k = k_oop->klass_part();
  7938. + if (k->oop_is_instance()) {
  7939. + HandleMark hm(THREAD);
  7940. + instanceKlass *ik = (instanceKlass *) k;
  7941. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  7942. +
  7943. + if (ik->vtable_length() > 0) {
  7944. + ResourceMark rm(THREAD);
  7945. + if (!ik->vtable()->check_no_old_or_obsolete_entries()) {
  7946. + TRACE_RC1("size of class: %d\n", k_oop->size());
  7947. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  7948. + assert(false, "OLD method found");
  7949. + }
  7950. +
  7951. + ik->vtable()->verify(tty, true);
  7952. + }
  7953. }
  7954. - for (int i = 0; i < _deleted_methods_length; ++i) {
  7955. - methodOop old_method = _deleted_methods[i];
  7956. +}
  7957. - assert(old_method->vtable_index() < 0,
  7958. - "cannot delete methods with vtable entries");;
  7959. +#endif
  7960. - // Mark all deleted methods as old and obsolete
  7961. - old_method->set_is_old();
  7962. - old_method->set_is_obsolete();
  7963. - ++obsolete_count;
  7964. - // With tracing we try not to "yack" too much. The position of
  7965. - // this trace assumes there are fewer obsolete methods than
  7966. - // EMCP methods.
  7967. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  7968. - old_method->name()->as_C_string(),
  7969. - old_method->signature()->as_C_string()));
  7970. +static bool match_right(void* value, Pair<klassOop, klassOop> elem) {
  7971. + return elem.right() == value;
  7972. +}
  7973. +
  7974. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS)
  7975. +{
  7976. + GrowableArray< Pair<klassOop, klassOop> > links;
  7977. +
  7978. + for (int i=0; i<class_count; i++) {
  7979. +
  7980. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  7981. + instanceKlassHandle the_class(THREAD, java_lang_Class::as_klassOop(mirror));
  7982. + Handle the_class_loader(THREAD, the_class->class_loader());
  7983. + Handle protection_domain(THREAD, the_class->protection_domain());
  7984. +
  7985. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  7986. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  7987. + ClassFileParser cfp(&st);
  7988. +
  7989. + GrowableArray<Symbol*> symbolArr;
  7990. + TempNewSymbol parsed_name;
  7991. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  7992. + cfp.parseClassFile(the_class->name(), the_class_loader, protection_domain, the_class, KlassHandle(), NULL, &symbolArr, parsed_name, false, THREAD);
  7993. +
  7994. + for (int j=0; j<symbolArr.length(); j++) {
  7995. + Symbol* sym = symbolArr.at(j);
  7996. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  7997. + klassOop super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
  7998. + if (super_klass != NULL) {
  7999. + instanceKlassHandle the_super_class(THREAD, super_klass);
  8000. + if (_affected_klasses->contains(the_super_class)) {
  8001. + TRACE_RC2("Found class to link");
  8002. + links.append(Pair<klassOop, klassOop>(super_klass, the_class()));
  8003. + }
  8004. + }
  8005. + }
  8006. +
  8007. + assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
  8008. + the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
  8009. }
  8010. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  8011. - "sanity check");
  8012. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  8013. - obsolete_count));
  8014. +
  8015. +
  8016. + TRACE_RC1("Identified links between classes! ");
  8017. +
  8018. + for (int i=0; i < _affected_klasses->length(); i++) {
  8019. + instanceKlassHandle klass = _affected_klasses->at(i);
  8020. +
  8021. + if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
  8022. + klass->clear_redefinition_flag(Klass::MarkedAsAffected);
  8023. + klassOop superKlass = klass->super();
  8024. + if (_affected_klasses->contains(superKlass)) {
  8025. + links.append(Pair<klassOop, klassOop>(superKlass, klass()));
  8026. + }
  8027. +
  8028. + objArrayOop superInterfaces = klass->local_interfaces();
  8029. + for (int j=0; j<superInterfaces->length(); j++) {
  8030. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  8031. + if (_affected_klasses->contains(interfaceKlass)) {
  8032. + links.append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  8033. + }
  8034. + }
  8035. + }
  8036. + }
  8037. +
  8038. + IF_TRACE_RC2 {
  8039. + TRACE_RC2("Identified links: ");
  8040. + for (int i=0; i<links.length(); i++) {
  8041. + TRACE_RC2("%s to %s", links.at(i).left()->klass_part()->name()->as_C_string(),
  8042. + links.at(i).right()->klass_part()->name()->as_C_string());
  8043. + }
  8044. + }
  8045. +
  8046. + for (int i = 0; i < _affected_klasses->length(); i++) {
  8047. + int j;
  8048. + for (j = i; j < _affected_klasses->length(); j++) {
  8049. + // Search for node with no incoming edges
  8050. + klassOop oop = _affected_klasses->at(j)();
  8051. + int k = links.find(oop, match_right);
  8052. + if (k == -1) break;
  8053. + }
  8054. + if (j == _affected_klasses->length()) {
  8055. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  8056. + }
  8057. +
  8058. + // Remove all links from this node
  8059. + klassOop oop = _affected_klasses->at(j)();
  8060. + int k = 0;
  8061. + while (k < links.length()) {
  8062. + if (links.adr_at(k)->left() == oop) {
  8063. + links.delete_at(k);
  8064. + } else {
  8065. + k++;
  8066. + }
  8067. + }
  8068. +
  8069. + // Swap node
  8070. + instanceKlassHandle tmp = _affected_klasses->at(j);
  8071. + _affected_klasses->at_put(j, _affected_klasses->at(i));
  8072. + _affected_klasses->at_put(i, tmp);
  8073. + }
  8074. +
  8075. + return JVMTI_ERROR_NONE;
  8076. }
  8077. // This internal class transfers the native function registration from old methods
  8078. @@ -2969,7 +2269,7 @@
  8079. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8080. //
  8081. class TransferNativeFunctionRegistration {
  8082. - private:
  8083. +private:
  8084. instanceKlassHandle the_class;
  8085. int prefix_count;
  8086. char** prefixes;
  8087. @@ -2982,42 +2282,42 @@
  8088. // (2) with the prefix.
  8089. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  8090. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  8091. - Symbol* signature) {
  8092. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8093. - if (name_symbol != NULL) {
  8094. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  8095. - if (method != NULL) {
  8096. - // Even if prefixed, intermediate methods must exist.
  8097. - if (method->is_native()) {
  8098. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8099. - return method;
  8100. - }
  8101. - if (depth < prefix_count) {
  8102. - // Try applying further prefixes (other than this one).
  8103. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8104. - if (method != NULL) {
  8105. - return method; // found
  8106. + Symbol* signature) {
  8107. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8108. + if (name_symbol != NULL) {
  8109. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  8110. + if (method != NULL) {
  8111. + // Even if prefixed, intermediate methods must exist.
  8112. + if (method->is_native()) {
  8113. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8114. + return method;
  8115. }
  8116. + if (depth < prefix_count) {
  8117. + // Try applying further prefixes (other than this one).
  8118. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8119. + if (method != NULL) {
  8120. + return method; // found
  8121. + }
  8122. - // Try adding this prefix to the method name and see if it matches
  8123. - // another method name.
  8124. - char* prefix = prefixes[depth];
  8125. - size_t prefix_len = strlen(prefix);
  8126. - size_t trial_len = name_len + prefix_len;
  8127. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8128. - strcpy(trial_name_str, prefix);
  8129. - strcat(trial_name_str, name_str);
  8130. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8131. - signature);
  8132. - if (method != NULL) {
  8133. - // If found along this branch, it was prefixed, mark as such
  8134. - method->set_is_prefixed_native();
  8135. - return method; // found
  8136. + // Try adding this prefix to the method name and see if it matches
  8137. + // another method name.
  8138. + char* prefix = prefixes[depth];
  8139. + size_t prefix_len = strlen(prefix);
  8140. + size_t trial_len = name_len + prefix_len;
  8141. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8142. + strcpy(trial_name_str, prefix);
  8143. + strcat(trial_name_str, name_str);
  8144. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8145. + signature);
  8146. + if (method != NULL) {
  8147. + // If found along this branch, it was prefixed, mark as such
  8148. + method->set_is_prefixed_native();
  8149. + return method; // found
  8150. + }
  8151. }
  8152. }
  8153. }
  8154. - }
  8155. - return NULL; // This whole branch bore nothing
  8156. + return NULL; // This whole branch bore nothing
  8157. }
  8158. // Return the method name with old prefixes stripped away.
  8159. @@ -3042,10 +2342,10 @@
  8160. ResourceMark rm;
  8161. char* name_str = method_name_without_prefixes(method);
  8162. return search_prefix_name_space(0, name_str, strlen(name_str),
  8163. - method->signature());
  8164. + method->signature());
  8165. }
  8166. - public:
  8167. +public:
  8168. // Construct a native method transfer processor for this class.
  8169. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  8170. @@ -3056,9 +2356,9 @@
  8171. }
  8172. // Attempt to transfer any of the old or deleted methods that are native
  8173. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  8174. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  8175. for (int j = 0; j < methods_length; j++) {
  8176. - methodOop old_method = old_methods[j];
  8177. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  8178. if (old_method->is_native() && old_method->has_native_function()) {
  8179. methodOop new_method = strip_and_search_for_new_native(old_method);
  8180. @@ -3067,7 +2367,9 @@
  8181. // Redefine does not send events (except CFLH), certainly not this
  8182. // behind the scenes re-registration.
  8183. new_method->set_native_function(old_method->native_function(),
  8184. - !methodOopDesc::native_bind_event_is_interesting);
  8185. + !methodOopDesc::native_bind_event_is_interesting);
  8186. +
  8187. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  8188. }
  8189. }
  8190. }
  8191. @@ -3075,544 +2377,8 @@
  8192. };
  8193. // Don't lose the association between a native method and its JNI function.
  8194. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  8195. - TransferNativeFunctionRegistration transfer(the_class);
  8196. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  8197. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  8198. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  8199. + TransferNativeFunctionRegistration transfer(old_klass);
  8200. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  8201. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  8202. }
  8203. -
  8204. -// Deoptimize all compiled code that depends on this class.
  8205. -//
  8206. -// If the can_redefine_classes capability is obtained in the onload
  8207. -// phase then the compiler has recorded all dependencies from startup.
  8208. -// In that case we need only deoptimize and throw away all compiled code
  8209. -// that depends on the class.
  8210. -//
  8211. -// If can_redefine_classes is obtained sometime after the onload
  8212. -// phase then the dependency information may be incomplete. In that case
  8213. -// the first call to RedefineClasses causes all compiled code to be
  8214. -// thrown away. As can_redefine_classes has been obtained then
  8215. -// all future compilations will record dependencies so second and
  8216. -// subsequent calls to RedefineClasses need only throw away code
  8217. -// that depends on the class.
  8218. -//
  8219. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  8220. - assert_locked_or_safepoint(Compile_lock);
  8221. -
  8222. - // All dependencies have been recorded from startup or this is a second or
  8223. - // subsequent use of RedefineClasses
  8224. - if (JvmtiExport::all_dependencies_are_recorded()) {
  8225. - Universe::flush_evol_dependents_on(k_h);
  8226. - } else {
  8227. - CodeCache::mark_all_nmethods_for_deoptimization();
  8228. -
  8229. - ResourceMark rm(THREAD);
  8230. - DeoptimizationMarker dm;
  8231. -
  8232. - // Deoptimize all activations depending on marked nmethods
  8233. - Deoptimization::deoptimize_dependents();
  8234. -
  8235. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  8236. - CodeCache::make_marked_nmethods_not_entrant();
  8237. -
  8238. - // From now on we know that the dependency information is complete
  8239. - JvmtiExport::set_all_dependencies_are_recorded(true);
  8240. - }
  8241. -}
  8242. -
  8243. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  8244. - methodOop old_method;
  8245. - methodOop new_method;
  8246. -
  8247. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8248. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8249. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  8250. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8251. -
  8252. - _matching_methods_length = 0;
  8253. - _deleted_methods_length = 0;
  8254. - _added_methods_length = 0;
  8255. -
  8256. - int nj = 0;
  8257. - int oj = 0;
  8258. - while (true) {
  8259. - if (oj >= _old_methods->length()) {
  8260. - if (nj >= _new_methods->length()) {
  8261. - break; // we've looked at everything, done
  8262. - }
  8263. - // New method at the end
  8264. - new_method = (methodOop) _new_methods->obj_at(nj);
  8265. - _added_methods[_added_methods_length++] = new_method;
  8266. - ++nj;
  8267. - } else if (nj >= _new_methods->length()) {
  8268. - // Old method, at the end, is deleted
  8269. - old_method = (methodOop) _old_methods->obj_at(oj);
  8270. - _deleted_methods[_deleted_methods_length++] = old_method;
  8271. - ++oj;
  8272. - } else {
  8273. - old_method = (methodOop) _old_methods->obj_at(oj);
  8274. - new_method = (methodOop) _new_methods->obj_at(nj);
  8275. - if (old_method->name() == new_method->name()) {
  8276. - if (old_method->signature() == new_method->signature()) {
  8277. - _matching_old_methods[_matching_methods_length ] = old_method;
  8278. - _matching_new_methods[_matching_methods_length++] = new_method;
  8279. - ++nj;
  8280. - ++oj;
  8281. - } else {
  8282. - // added overloaded have already been moved to the end,
  8283. - // so this is a deleted overloaded method
  8284. - _deleted_methods[_deleted_methods_length++] = old_method;
  8285. - ++oj;
  8286. - }
  8287. - } else { // names don't match
  8288. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  8289. - // new method
  8290. - _added_methods[_added_methods_length++] = new_method;
  8291. - ++nj;
  8292. - } else {
  8293. - // deleted method
  8294. - _deleted_methods[_deleted_methods_length++] = old_method;
  8295. - ++oj;
  8296. - }
  8297. - }
  8298. - }
  8299. - }
  8300. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  8301. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  8302. -}
  8303. -
  8304. -
  8305. -
  8306. -// Install the redefinition of a class:
  8307. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8308. -// dependent compiled code)
  8309. -// - replacing parts in the_class with parts from scratch_class
  8310. -// - adding a weak reference to track the obsolete but interesting
  8311. -// parts of the_class
  8312. -// - adjusting constant pool caches and vtables in other classes
  8313. -// that refer to methods in the_class. These adjustments use the
  8314. -// SystemDictionary::classes_do() facility which only allows
  8315. -// a helper method to be specified. The interesting parameters
  8316. -// that we would like to pass to the helper method are saved in
  8317. -// static global fields in the VM operation.
  8318. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  8319. - instanceKlassHandle scratch_class, TRAPS) {
  8320. -
  8321. - RC_TIMER_START(_timer_rsc_phase1);
  8322. -
  8323. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  8324. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  8325. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  8326. -
  8327. - // Remove all breakpoints in methods of this class
  8328. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  8329. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  8330. -
  8331. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  8332. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  8333. - // cached and users of the cache care about each active version of
  8334. - // the method so we have to track this previous version.
  8335. - // Do this before methods get switched
  8336. - Universe::reflect_invoke_cache()->add_previous_version(
  8337. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  8338. - }
  8339. -
  8340. - // Deoptimize all compiled code that depends on this class
  8341. - flush_dependent_code(the_class, THREAD);
  8342. -
  8343. - _old_methods = the_class->methods();
  8344. - _new_methods = scratch_class->methods();
  8345. - _the_class_oop = the_class_oop;
  8346. - compute_added_deleted_matching_methods();
  8347. - update_jmethod_ids();
  8348. -
  8349. - // Attach new constant pool to the original klass. The original
  8350. - // klass still refers to the old constant pool (for now).
  8351. - scratch_class->constants()->set_pool_holder(the_class());
  8352. -
  8353. -#if 0
  8354. - // In theory, with constant pool merging in place we should be able
  8355. - // to save space by using the new, merged constant pool in place of
  8356. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  8357. - // the klass version we are replacing now and any constant pool(s) in
  8358. - // previous versions of klass. Nice theory, doesn't work in practice.
  8359. - // When this code is enabled, even simple programs throw NullPointer
  8360. - // exceptions. I'm guessing that this is caused by some constant pool
  8361. - // cache difference between the new, merged constant pool and the
  8362. - // constant pool that was just being used by the klass. I'm keeping
  8363. - // this code around to archive the idea, but the code has to remain
  8364. - // disabled for now.
  8365. -
  8366. - // Attach each old method to the new constant pool. This can be
  8367. - // done here since we are past the bytecode verification and
  8368. - // constant pool optimization phases.
  8369. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  8370. - methodOop method = (methodOop)_old_methods->obj_at(i);
  8371. - method->set_constants(scratch_class->constants());
  8372. - }
  8373. -
  8374. - {
  8375. - // walk all previous versions of the klass
  8376. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  8377. - PreviousVersionWalker pvw(ik);
  8378. - instanceKlassHandle ikh;
  8379. - do {
  8380. - ikh = pvw.next_previous_version();
  8381. - if (!ikh.is_null()) {
  8382. - ik = ikh();
  8383. -
  8384. - // attach previous version of klass to the new constant pool
  8385. - ik->set_constants(scratch_class->constants());
  8386. -
  8387. - // Attach each method in the previous version of klass to the
  8388. - // new constant pool
  8389. - objArrayOop prev_methods = ik->methods();
  8390. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  8391. - methodOop method = (methodOop)prev_methods->obj_at(i);
  8392. - method->set_constants(scratch_class->constants());
  8393. - }
  8394. - }
  8395. - } while (!ikh.is_null());
  8396. - }
  8397. -#endif
  8398. -
  8399. - // Replace methods and constantpool
  8400. - the_class->set_methods(_new_methods);
  8401. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  8402. - // and to be able to undo operation easily.
  8403. -
  8404. - constantPoolOop old_constants = the_class->constants();
  8405. - the_class->set_constants(scratch_class->constants());
  8406. - scratch_class->set_constants(old_constants); // See the previous comment.
  8407. -#if 0
  8408. - // We are swapping the guts of "the new class" with the guts of "the
  8409. - // class". Since the old constant pool has just been attached to "the
  8410. - // new class", it seems logical to set the pool holder in the old
  8411. - // constant pool also. However, doing this will change the observable
  8412. - // class hierarchy for any old methods that are still executing. A
  8413. - // method can query the identity of its "holder" and this query uses
  8414. - // the method's constant pool link to find the holder. The change in
  8415. - // holding class from "the class" to "the new class" can confuse
  8416. - // things.
  8417. - //
  8418. - // Setting the old constant pool's holder will also cause
  8419. - // verification done during vtable initialization below to fail.
  8420. - // During vtable initialization, the vtable's class is verified to be
  8421. - // a subtype of the method's holder. The vtable's class is "the
  8422. - // class" and the method's holder is gotten from the constant pool
  8423. - // link in the method itself. For "the class"'s directly implemented
  8424. - // methods, the method holder is "the class" itself (as gotten from
  8425. - // the new constant pool). The check works fine in this case. The
  8426. - // check also works fine for methods inherited from super classes.
  8427. - //
  8428. - // Miranda methods are a little more complicated. A miranda method is
  8429. - // provided by an interface when the class implementing the interface
  8430. - // does not provide its own method. These interfaces are implemented
  8431. - // internally as an instanceKlass. These special instanceKlasses
  8432. - // share the constant pool of the class that "implements" the
  8433. - // interface. By sharing the constant pool, the method holder of a
  8434. - // miranda method is the class that "implements" the interface. In a
  8435. - // non-redefine situation, the subtype check works fine. However, if
  8436. - // the old constant pool's pool holder is modified, then the check
  8437. - // fails because there is no class hierarchy relationship between the
  8438. - // vtable's class and "the new class".
  8439. -
  8440. - old_constants->set_pool_holder(scratch_class());
  8441. -#endif
  8442. -
  8443. - // track which methods are EMCP for add_previous_version() call below
  8444. - BitMap emcp_methods(_old_methods->length());
  8445. - int emcp_method_count = 0;
  8446. - emcp_methods.clear(); // clears 0..(length() - 1)
  8447. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  8448. - transfer_old_native_function_registrations(the_class);
  8449. -
  8450. - // The class file bytes from before any retransformable agents mucked
  8451. - // with them was cached on the scratch class, move to the_class.
  8452. - // Note: we still want to do this if nothing needed caching since it
  8453. - // should get cleared in the_class too.
  8454. - if (the_class->get_cached_class_file_bytes() == 0) {
  8455. - // the_class doesn't have a cache yet so copy it
  8456. - the_class->set_cached_class_file(
  8457. - scratch_class->get_cached_class_file_bytes(),
  8458. - scratch_class->get_cached_class_file_len());
  8459. - }
  8460. -#ifndef PRODUCT
  8461. - else {
  8462. - assert(the_class->get_cached_class_file_bytes() ==
  8463. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  8464. - assert(the_class->get_cached_class_file_len() ==
  8465. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  8466. - }
  8467. -#endif
  8468. -
  8469. - // Replace inner_classes
  8470. - typeArrayOop old_inner_classes = the_class->inner_classes();
  8471. - the_class->set_inner_classes(scratch_class->inner_classes());
  8472. - scratch_class->set_inner_classes(old_inner_classes);
  8473. -
  8474. - // Initialize the vtable and interface table after
  8475. - // methods have been rewritten
  8476. - {
  8477. - ResourceMark rm(THREAD);
  8478. - // no exception should happen here since we explicitly
  8479. - // do not check loader constraints.
  8480. - // compare_and_normalize_class_versions has already checked:
  8481. - // - classloaders unchanged, signatures unchanged
  8482. - // - all instanceKlasses for redefined classes reused & contents updated
  8483. - the_class->vtable()->initialize_vtable(false, THREAD);
  8484. - the_class->itable()->initialize_itable(false, THREAD);
  8485. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  8486. - }
  8487. -
  8488. - // Leave arrays of jmethodIDs and itable index cache unchanged
  8489. -
  8490. - // Copy the "source file name" attribute from new class version
  8491. - the_class->set_source_file_name(scratch_class->source_file_name());
  8492. -
  8493. - // Copy the "source debug extension" attribute from new class version
  8494. - the_class->set_source_debug_extension(
  8495. - scratch_class->source_debug_extension(),
  8496. - scratch_class->source_debug_extension() == NULL ? 0 :
  8497. - (int)strlen(scratch_class->source_debug_extension()));
  8498. -
  8499. - // Use of javac -g could be different in the old and the new
  8500. - if (scratch_class->access_flags().has_localvariable_table() !=
  8501. - the_class->access_flags().has_localvariable_table()) {
  8502. -
  8503. - AccessFlags flags = the_class->access_flags();
  8504. - if (scratch_class->access_flags().has_localvariable_table()) {
  8505. - flags.set_has_localvariable_table();
  8506. - } else {
  8507. - flags.clear_has_localvariable_table();
  8508. - }
  8509. - the_class->set_access_flags(flags);
  8510. - }
  8511. -
  8512. - // Replace class annotation fields values
  8513. - typeArrayOop old_class_annotations = the_class->class_annotations();
  8514. - the_class->set_class_annotations(scratch_class->class_annotations());
  8515. - scratch_class->set_class_annotations(old_class_annotations);
  8516. -
  8517. - // Replace fields annotation fields values
  8518. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  8519. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  8520. - scratch_class->set_fields_annotations(old_fields_annotations);
  8521. -
  8522. - // Replace methods annotation fields values
  8523. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  8524. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  8525. - scratch_class->set_methods_annotations(old_methods_annotations);
  8526. -
  8527. - // Replace methods parameter annotation fields values
  8528. - objArrayOop old_methods_parameter_annotations =
  8529. - the_class->methods_parameter_annotations();
  8530. - the_class->set_methods_parameter_annotations(
  8531. - scratch_class->methods_parameter_annotations());
  8532. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  8533. -
  8534. - // Replace methods default annotation fields values
  8535. - objArrayOop old_methods_default_annotations =
  8536. - the_class->methods_default_annotations();
  8537. - the_class->set_methods_default_annotations(
  8538. - scratch_class->methods_default_annotations());
  8539. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  8540. -
  8541. - // Replace minor version number of class file
  8542. - u2 old_minor_version = the_class->minor_version();
  8543. - the_class->set_minor_version(scratch_class->minor_version());
  8544. - scratch_class->set_minor_version(old_minor_version);
  8545. -
  8546. - // Replace major version number of class file
  8547. - u2 old_major_version = the_class->major_version();
  8548. - the_class->set_major_version(scratch_class->major_version());
  8549. - scratch_class->set_major_version(old_major_version);
  8550. -
  8551. - // Replace CP indexes for class and name+type of enclosing method
  8552. - u2 old_class_idx = the_class->enclosing_method_class_index();
  8553. - u2 old_method_idx = the_class->enclosing_method_method_index();
  8554. - the_class->set_enclosing_method_indices(
  8555. - scratch_class->enclosing_method_class_index(),
  8556. - scratch_class->enclosing_method_method_index());
  8557. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  8558. -
  8559. - // keep track of previous versions of this class
  8560. - the_class->add_previous_version(scratch_class, &emcp_methods,
  8561. - emcp_method_count);
  8562. -
  8563. - RC_TIMER_STOP(_timer_rsc_phase1);
  8564. - RC_TIMER_START(_timer_rsc_phase2);
  8565. -
  8566. - // Adjust constantpool caches and vtables for all classes
  8567. - // that reference methods of the evolved class.
  8568. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  8569. -
  8570. - // JSR-292 support
  8571. - MemberNameTable* mnt = the_class->member_names();
  8572. - if (mnt != NULL) {
  8573. - bool trace_name_printed = false;
  8574. - mnt->adjust_method_entries(_matching_old_methods,
  8575. - _matching_new_methods,
  8576. - _matching_methods_length,
  8577. - &trace_name_printed);
  8578. - }
  8579. -
  8580. - if (the_class->oop_map_cache() != NULL) {
  8581. - // Flush references to any obsolete methods from the oop map cache
  8582. - // so that obsolete methods are not pinned.
  8583. - the_class->oop_map_cache()->flush_obsolete_entries();
  8584. - }
  8585. -
  8586. - // increment the classRedefinedCount field in the_class and in any
  8587. - // direct and indirect subclasses of the_class
  8588. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  8589. -
  8590. - // RC_TRACE macro has an embedded ResourceMark
  8591. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  8592. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  8593. - the_class->external_name(),
  8594. - java_lang_Class::classRedefinedCount(the_class_mirror),
  8595. - os::available_memory() >> 10));
  8596. -
  8597. - RC_TIMER_STOP(_timer_rsc_phase2);
  8598. -} // end redefine_single_class()
  8599. -
  8600. -
  8601. -// Increment the classRedefinedCount field in the specific instanceKlass
  8602. -// and in all direct and indirect subclasses.
  8603. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  8604. - oop class_mirror = ik->java_mirror();
  8605. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  8606. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  8607. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  8608. -
  8609. - if (class_oop != _the_class_oop) {
  8610. - // _the_class_oop count is printed at end of redefine_single_class()
  8611. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  8612. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  8613. - }
  8614. -
  8615. - for (Klass *subk = ik->subklass(); subk != NULL;
  8616. - subk = subk->next_sibling()) {
  8617. - if (subk->oop_is_instance()) {
  8618. - // Only update instanceKlasses
  8619. - instanceKlass *subik = (instanceKlass*)subk;
  8620. - // recursively do subclasses of the current subclass
  8621. - increment_class_counter(subik, THREAD);
  8622. - }
  8623. - }
  8624. -}
  8625. -
  8626. -void VM_RedefineClasses::check_class(klassOop k_oop,
  8627. - oop initiating_loader, TRAPS) {
  8628. - Klass *k = k_oop->klass_part();
  8629. - if (k->oop_is_instance()) {
  8630. - HandleMark hm(THREAD);
  8631. - instanceKlass *ik = (instanceKlass *) k;
  8632. - bool no_old_methods = true; // be optimistic
  8633. - ResourceMark rm(THREAD);
  8634. -
  8635. - // a vtable should never contain old or obsolete methods
  8636. - if (ik->vtable_length() > 0 &&
  8637. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  8638. - if (RC_TRACE_ENABLED(0x00004000)) {
  8639. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8640. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  8641. - " -- OLD or OBSOLETE method found -- class: %s",
  8642. - ik->signature_name()));
  8643. - ik->vtable()->dump_vtable();
  8644. - }
  8645. - no_old_methods = false;
  8646. - }
  8647. -
  8648. - // an itable should never contain old or obsolete methods
  8649. - if (ik->itable_length() > 0 &&
  8650. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  8651. - if (RC_TRACE_ENABLED(0x00004000)) {
  8652. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8653. - ("klassItable::check_no_old_or_obsolete_entries failure"
  8654. - " -- OLD or OBSOLETE method found -- class: %s",
  8655. - ik->signature_name()));
  8656. - ik->itable()->dump_itable();
  8657. - }
  8658. - no_old_methods = false;
  8659. - }
  8660. -
  8661. - // the constant pool cache should never contain old or obsolete methods
  8662. - if (ik->constants() != NULL &&
  8663. - ik->constants()->cache() != NULL &&
  8664. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  8665. - if (RC_TRACE_ENABLED(0x00004000)) {
  8666. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8667. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  8668. - " -- OLD or OBSOLETE method found -- class: %s",
  8669. - ik->signature_name()));
  8670. - ik->constants()->cache()->dump_cache();
  8671. - }
  8672. - no_old_methods = false;
  8673. - }
  8674. -
  8675. - if (!no_old_methods) {
  8676. - if (RC_TRACE_ENABLED(0x00004000)) {
  8677. - dump_methods();
  8678. - } else {
  8679. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  8680. - "to see more info about the following guarantee() failure.");
  8681. - }
  8682. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  8683. - }
  8684. - }
  8685. -}
  8686. -
  8687. -void VM_RedefineClasses::dump_methods() {
  8688. - int j;
  8689. - RC_TRACE(0x00004000, ("_old_methods --"));
  8690. - for (j = 0; j < _old_methods->length(); ++j) {
  8691. - methodOop m = (methodOop) _old_methods->obj_at(j);
  8692. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8693. - m->access_flags().print_on(tty);
  8694. - tty->print(" -- ");
  8695. - m->print_name(tty);
  8696. - tty->cr();
  8697. - }
  8698. - RC_TRACE(0x00004000, ("_new_methods --"));
  8699. - for (j = 0; j < _new_methods->length(); ++j) {
  8700. - methodOop m = (methodOop) _new_methods->obj_at(j);
  8701. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8702. - m->access_flags().print_on(tty);
  8703. - tty->print(" -- ");
  8704. - m->print_name(tty);
  8705. - tty->cr();
  8706. - }
  8707. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  8708. - for (j = 0; j < _matching_methods_length; ++j) {
  8709. - methodOop m = _matching_old_methods[j];
  8710. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8711. - m->access_flags().print_on(tty);
  8712. - tty->print(" -- ");
  8713. - m->print_name(tty);
  8714. - tty->cr();
  8715. - m = _matching_new_methods[j];
  8716. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  8717. - m->access_flags().print_on(tty);
  8718. - tty->cr();
  8719. - }
  8720. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  8721. - for (j = 0; j < _deleted_methods_length; ++j) {
  8722. - methodOop m = _deleted_methods[j];
  8723. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8724. - m->access_flags().print_on(tty);
  8725. - tty->print(" -- ");
  8726. - m->print_name(tty);
  8727. - tty->cr();
  8728. - }
  8729. - RC_TRACE(0x00004000, ("_added_methods --"));
  8730. - for (j = 0; j < _added_methods_length; ++j) {
  8731. - methodOop m = _added_methods[j];
  8732. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8733. - m->access_flags().print_on(tty);
  8734. - tty->print(" -- ");
  8735. - m->print_name(tty);
  8736. - tty->cr();
  8737. - }
  8738. -}
  8739. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8740. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8741. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8742. @@ -1,5 +1,5 @@
  8743. /*
  8744. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  8745. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  8746. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8747. *
  8748. * This code is free software; you can redistribute it and/or modify it
  8749. @@ -30,332 +30,29 @@
  8750. #include "memory/resourceArea.hpp"
  8751. #include "oops/objArrayKlass.hpp"
  8752. #include "oops/objArrayOop.hpp"
  8753. +#include "oops/fieldStreams.hpp"
  8754. #include "prims/jvmtiRedefineClassesTrace.hpp"
  8755. -#include "runtime/vm_operations.hpp"
  8756. +#include "gc_implementation/shared/vmGCOperations.hpp"
  8757. -// Introduction:
  8758. -//
  8759. -// The RedefineClasses() API is used to change the definition of one or
  8760. -// more classes. While the API supports redefining more than one class
  8761. -// in a single call, in general, the API is discussed in the context of
  8762. -// changing the definition of a single current class to a single new
  8763. -// class. For clarity, the current class is will always be called
  8764. -// "the_class" and the new class will always be called "scratch_class".
  8765. -//
  8766. -// The name "the_class" is used because there is only one structure
  8767. -// that represents a specific class; redefinition does not replace the
  8768. -// structure, but instead replaces parts of the structure. The name
  8769. -// "scratch_class" is used because the structure that represents the
  8770. -// new definition of a specific class is simply used to carry around
  8771. -// the parts of the new definition until they are used to replace the
  8772. -// appropriate parts in the_class. Once redefinition of a class is
  8773. -// complete, scratch_class is thrown away.
  8774. -//
  8775. -//
  8776. -// Implementation Overview:
  8777. -//
  8778. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  8779. -// does the real work. The work is split in varying degrees between
  8780. -// doit_prologue(), doit() and doit_epilogue().
  8781. -//
  8782. -// 1) doit_prologue() is called by the JavaThread on the way to a
  8783. -// safepoint. It does parameter verification and loads scratch_class
  8784. -// which involves:
  8785. -// - parsing the incoming class definition using the_class' class
  8786. -// loader and security context
  8787. -// - linking scratch_class
  8788. -// - merging constant pools and rewriting bytecodes as needed
  8789. -// for the merged constant pool
  8790. -// - verifying the bytecodes in scratch_class
  8791. -// - setting up the constant pool cache and rewriting bytecodes
  8792. -// as needed to use the cache
  8793. -// - finally, scratch_class is compared to the_class to verify
  8794. -// that it is a valid replacement class
  8795. -// - if everything is good, then scratch_class is saved in an
  8796. -// instance field in the VM operation for the doit() call
  8797. -//
  8798. -// Note: A JavaThread must do the above work.
  8799. -//
  8800. -// 2) doit() is called by the VMThread during a safepoint. It installs
  8801. -// the new class definition(s) which involves:
  8802. -// - retrieving the scratch_class from the instance field in the
  8803. -// VM operation
  8804. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8805. -// dependent compiled code)
  8806. -// - replacing parts in the_class with parts from scratch_class
  8807. -// - adding weak reference(s) to track the obsolete but interesting
  8808. -// parts of the_class
  8809. -// - adjusting constant pool caches and vtables in other classes
  8810. -// that refer to methods in the_class. These adjustments use the
  8811. -// SystemDictionary::classes_do() facility which only allows
  8812. -// a helper method to be specified. The interesting parameters
  8813. -// that we would like to pass to the helper method are saved in
  8814. -// static global fields in the VM operation.
  8815. -// - telling the SystemDictionary to notice our changes
  8816. -//
  8817. -// Note: the above work must be done by the VMThread to be safe.
  8818. -//
  8819. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  8820. -// is finished and the safepoint is done. It simply cleans up
  8821. -// memory allocated in doit_prologue() and used in doit().
  8822. -//
  8823. -//
  8824. -// Constant Pool Details:
  8825. -//
  8826. -// When the_class is redefined, we cannot just replace the constant
  8827. -// pool in the_class with the constant pool from scratch_class because
  8828. -// that could confuse obsolete methods that may still be running.
  8829. -// Instead, the constant pool from the_class, old_cp, is merged with
  8830. -// the constant pool from scratch_class, scratch_cp. The resulting
  8831. -// constant pool, merge_cp, replaces old_cp in the_class.
  8832. -//
  8833. -// The key part of any merging algorithm is the entry comparison
  8834. -// function so we have to know the types of entries in a constant pool
  8835. -// in order to merge two of them together. Constant pools can contain
  8836. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  8837. -// is not presently used so we only have to worry about the other 11
  8838. -// entry types. For the purposes of constant pool merging, it is
  8839. -// helpful to know that the 11 entry types fall into 3 different
  8840. -// subtypes: "direct", "indirect" and "double-indirect".
  8841. -//
  8842. -// Direct CP entries contain data and do not contain references to
  8843. -// other CP entries. The following are direct CP entries:
  8844. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  8845. -//
  8846. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  8847. -// and no other data. The following are indirect CP entries:
  8848. -// JVM_CONSTANT_{Class,NameAndType,String}
  8849. -//
  8850. -// Double-indirect CP entries contain two references to indirect CP
  8851. -// entries and no other data. The following are double-indirect CP
  8852. -// entries:
  8853. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  8854. -//
  8855. -// When comparing entries between two constant pools, the entry types
  8856. -// are compared first and if they match, then further comparisons are
  8857. -// made depending on the entry subtype. Comparing direct CP entries is
  8858. -// simply a matter of comparing the data associated with each entry.
  8859. -// Comparing both indirect and double-indirect CP entries requires
  8860. -// recursion.
  8861. -//
  8862. -// Fortunately, the recursive combinations are limited because indirect
  8863. -// CP entries can only refer to direct CP entries and double-indirect
  8864. -// CP entries can only refer to indirect CP entries. The following is
  8865. -// an example illustration of the deepest set of indirections needed to
  8866. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  8867. -//
  8868. -// JVM_CONSTANT_Fieldref {
  8869. -// class_index => JVM_CONSTANT_Class {
  8870. -// name_index => JVM_CONSTANT_Utf8 {
  8871. -// <data-1>
  8872. -// }
  8873. -// }
  8874. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  8875. -// name_index => JVM_CONSTANT_Utf8 {
  8876. -// <data-2>
  8877. -// }
  8878. -// descriptor_index => JVM_CONSTANT_Utf8 {
  8879. -// <data-3>
  8880. -// }
  8881. -// }
  8882. -// }
  8883. -//
  8884. -// The above illustration is not a data structure definition for any
  8885. -// computer language. The curly braces ('{' and '}') are meant to
  8886. -// delimit the context of the "fields" in the CP entry types shown.
  8887. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  8888. -// "=>", e.g., the class_index is used to indirectly reference a
  8889. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  8890. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  8891. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  8892. -// have to do a total of 5 indirections just to get to the CP entries
  8893. -// that contain the interesting pieces of data and then we have to
  8894. -// fetch the three pieces of data. This means we have to do a total of
  8895. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  8896. -// entries.
  8897. -//
  8898. -// Here is the indirection, data and dereference count for each entry
  8899. -// type:
  8900. -//
  8901. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  8902. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  8903. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  8904. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  8905. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  8906. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  8907. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  8908. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  8909. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  8910. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  8911. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  8912. -//
  8913. -// So different subtypes of CP entries require different amounts of
  8914. -// work for a proper comparison.
  8915. -//
  8916. -// Now that we've talked about the different entry types and how to
  8917. -// compare them we need to get back to merging. This is not a merge in
  8918. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  8919. -// constant pools, we copy all the entries from old_cp to merge_cp,
  8920. -// preserving entry order. Next we append all the unique entries from
  8921. -// scratch_cp to merge_cp and we track the index changes from the
  8922. -// location in scratch_cp to the possibly new location in merge_cp.
  8923. -// When we are done, any obsolete code that is still running that
  8924. -// uses old_cp should not be able to observe any difference if it
  8925. -// were to use merge_cp. As for the new code in scratch_class, it is
  8926. -// modified to use the appropriate index values in merge_cp before it
  8927. -// is used to replace the code in the_class.
  8928. -//
  8929. -// There is one small complication in copying the entries from old_cp
  8930. -// to merge_cp. Two of the CP entry types are special in that they are
  8931. -// lazily resolved. Before explaining the copying complication, we need
  8932. -// to digress into CP entry resolution.
  8933. -//
  8934. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  8935. -// the class file, but are not stored in memory as such until they are
  8936. -// resolved. The entries are not resolved unless they are used because
  8937. -// resolution is expensive. During class file parsing the entries are
  8938. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  8939. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  8940. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  8941. -// have been parsed, but the index values in the entries have not been
  8942. -// validated. After the entire constant pool has been parsed, the index
  8943. -// values can be validated and then the entries are converted into
  8944. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  8945. -// entries. During this conversion process, the UTF8 values that are
  8946. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  8947. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  8948. -// entries are modified to refer to the Symbol*s. This optimization
  8949. -// eliminates one level of indirection for those two CP entry types and
  8950. -// gets the entries ready for verification. During class file parsing
  8951. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  8952. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  8953. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  8954. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  8955. -// entries.
  8956. -//
  8957. -// Now we can get back to the copying complication. When we copy
  8958. -// entries from old_cp to merge_cp, we have to revert any
  8959. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  8960. -// or verification will fail.
  8961. -//
  8962. -// It is important to explicitly state that the merging algorithm
  8963. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  8964. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  8965. -// entries in the merge_cp. This is done both to make verification
  8966. -// happy and to avoid adding more brittleness between RedefineClasses
  8967. -// and the constant pool cache. By allowing the constant pool cache
  8968. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  8969. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  8970. -// about those algorithms in RedefineClasses.
  8971. -//
  8972. -// Appending unique entries from scratch_cp to merge_cp is straight
  8973. -// forward for direct CP entries and most indirect CP entries. For the
  8974. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  8975. -// indirect CP entry types, the presence of more than one piece of
  8976. -// interesting data makes appending the entries more complicated.
  8977. -//
  8978. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  8979. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  8980. -// If the index in scratch_cp is different than the destination index
  8981. -// in merge_cp, then the change in index value is tracked.
  8982. -//
  8983. -// Note: the above discussion for the direct CP entries also applies
  8984. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  8985. -//
  8986. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  8987. -// one data element at the end of the recursion, we know that we have
  8988. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  8989. -// unique then it is appended to merge_cp before the current entry.
  8990. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  8991. -// is updated to refer to the duplicate entry in merge_cp before it is
  8992. -// appended to merge_cp. Again, any changes in index values are tracked
  8993. -// as needed.
  8994. -//
  8995. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  8996. -// types is theoretical. Since those entry types have already been
  8997. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  8998. -// they are handled as direct CP entries.
  8999. -//
  9000. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  9001. -// data elements at the end of the recursions, we know that we have
  9002. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  9003. -// entries are appended to merge_cp before the current entry. For any
  9004. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  9005. -// updated to refer to the duplicate entry in merge_cp before it is
  9006. -// appended to merge_cp. Again, any changes in index values are tracked
  9007. -// as needed.
  9008. -//
  9009. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  9010. -// types, since there are two indirect CP entries and three data
  9011. -// elements at the end of the recursions, we know that we have between
  9012. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  9013. -// above for an example of all six entries. The uniqueness algorithm
  9014. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  9015. -// covered above. Any unique entries are appended to merge_cp before
  9016. -// the current entry. For any entries that are not unique, the current
  9017. -// entry is updated to refer to the duplicate entry in merge_cp before
  9018. -// it is appended to merge_cp. Again, any changes in index values are
  9019. -// tracked as needed.
  9020. -//
  9021. -//
  9022. -// Other Details:
  9023. -//
  9024. -// Details for other parts of RedefineClasses need to be written.
  9025. -// This is a placeholder section.
  9026. -//
  9027. -//
  9028. -// Open Issues (in no particular order):
  9029. -//
  9030. -// - How do we serialize the RedefineClasses() API without deadlocking?
  9031. -//
  9032. -// - SystemDictionary::parse_stream() was called with a NULL protection
  9033. -// domain since the initial version. This has been changed to pass
  9034. -// the_class->protection_domain(). This change has been tested with
  9035. -// all NSK tests and nothing broke, but what will adding it now break
  9036. -// in ways that we don't test?
  9037. -//
  9038. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  9039. -// (indirect) use of the Relocator class that the max instruction
  9040. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  9041. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  9042. -// what it does to the bytecodes. More investigation is needed.
  9043. -//
  9044. -// - java.lang.Object methods can be called on arrays. This is
  9045. -// implemented via the arrayKlassOop vtable which we don't
  9046. -// update. For example, if we redefine java.lang.Object.toString(),
  9047. -// then the new version of the method will not be called for array
  9048. -// objects.
  9049. -//
  9050. -// - How do we know if redefine_single_class() and the guts of
  9051. -// instanceKlass are out of sync? I don't think this can be
  9052. -// automated, but we should probably order the work in
  9053. -// redefine_single_class() to match the order of field
  9054. -// definitions in instanceKlass. We also need to add some
  9055. -// comments about keeping things in sync.
  9056. -//
  9057. -// - set_new_constant_pool() is huge and we should consider refactoring
  9058. -// it into smaller chunks of work.
  9059. -//
  9060. -// - The exception table update code in set_new_constant_pool() defines
  9061. -// const values that are also defined in a local context elsewhere.
  9062. -// The same literal values are also used in elsewhere. We need to
  9063. -// coordinate a cleanup of these constants with Runtime.
  9064. -//
  9065. +// New version that allows arbitrary changes to already loaded classes.
  9066. +class VM_RedefineClasses: public VM_GC_Operation {
  9067. + private:
  9068. -class VM_RedefineClasses: public VM_Operation {
  9069. - private:
  9070. // These static fields are needed by SystemDictionary::classes_do()
  9071. // facility and the adjust_cpool_cache_and_vtable() helper:
  9072. static objArrayOop _old_methods;
  9073. static objArrayOop _new_methods;
  9074. - static methodOop* _matching_old_methods;
  9075. - static methodOop* _matching_new_methods;
  9076. - static methodOop* _deleted_methods;
  9077. - static methodOop* _added_methods;
  9078. + static int* _matching_old_methods;
  9079. + static int* _matching_new_methods;
  9080. + static int* _deleted_methods;
  9081. + static int* _added_methods;
  9082. static int _matching_methods_length;
  9083. static int _deleted_methods_length;
  9084. static int _added_methods_length;
  9085. - static klassOop _the_class_oop;
  9086. +
  9087. + static int _revision_number;
  9088. +
  9089. + static GrowableArray<instanceKlassHandle>* _affected_klasses;
  9090. // The instance fields are used to pass information from
  9091. // doit_prologue() to doit() and doit_epilogue().
  9092. @@ -366,47 +63,28 @@
  9093. // RetransformClasses. Indicate which.
  9094. JvmtiClassLoadKind _class_load_kind;
  9095. - // _index_map_count is just an optimization for knowing if
  9096. - // _index_map_p contains any entries.
  9097. - int _index_map_count;
  9098. - intArray * _index_map_p;
  9099. -
  9100. - // _operands_index_map_count is just an optimization for knowing if
  9101. - // _operands_index_map_p contains any entries.
  9102. - int _operands_cur_length;
  9103. - int _operands_index_map_count;
  9104. - intArray * _operands_index_map_p;
  9105. -
  9106. - // ptr to _class_count scratch_classes
  9107. - instanceKlassHandle * _scratch_classes;
  9108. - jvmtiError _res;
  9109. + GrowableArray<instanceKlassHandle>* _new_classes;
  9110. + jvmtiError _result;
  9111. + int _max_redefinition_flags;
  9112. // Performance measurement support. These timers do not cover all
  9113. // the work done for JVM/TI RedefineClasses() but they do cover
  9114. // the heavy lifting.
  9115. - elapsedTimer _timer_rsc_phase1;
  9116. - elapsedTimer _timer_rsc_phase2;
  9117. - elapsedTimer _timer_vm_op_prologue;
  9118. + elapsedTimer _timer_total;
  9119. + elapsedTimer _timer_prologue;
  9120. + elapsedTimer _timer_class_linking;
  9121. + elapsedTimer _timer_class_loading;
  9122. + elapsedTimer _timer_prepare_redefinition;
  9123. + elapsedTimer _timer_wait_for_locks;
  9124. + elapsedTimer _timer_heap_iteration;
  9125. + elapsedTimer _timer_redefinition;
  9126. + elapsedTimer _timer_vm_op_epilogue;
  9127. - // These routines are roughly in call order unless otherwise noted.
  9128. -
  9129. - // Load the caller's new class definition(s) into _scratch_classes.
  9130. - // Constant pool merging work is done here as needed. Also calls
  9131. - // compare_and_normalize_class_versions() to verify the class
  9132. - // definition(s).
  9133. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  9134. + jvmtiError find_sorted_affected_classes( );
  9135. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  9136. jvmtiError load_new_class_versions(TRAPS);
  9137. - // Verify that the caller provided class definition(s) that meet
  9138. - // the restrictions of RedefineClasses. Normalize the order of
  9139. - // overloaded methods as needed.
  9140. - jvmtiError compare_and_normalize_class_versions(
  9141. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  9142. -
  9143. - // Swap annotations[i] with annotations[j]
  9144. - // Used by compare_and_normalize_class_versions() when normalizing
  9145. - // overloaded methods or changing idnum as when adding or deleting methods.
  9146. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  9147. -
  9148. // Figure out which new methods match old methods in name and signature,
  9149. // which methods have been added, and which are no longer present
  9150. void compute_added_deleted_matching_methods();
  9151. @@ -414,103 +92,71 @@
  9152. // Change jmethodIDs to point to the new methods
  9153. void update_jmethod_ids();
  9154. - // In addition to marking methods as obsolete, this routine
  9155. - // records which methods are EMCP (Equivalent Module Constant
  9156. - // Pool) in the emcp_methods BitMap and returns the number of
  9157. - // EMCP methods via emcp_method_count_p. This information is
  9158. - // used when information about the previous version of the_class
  9159. - // is squirreled away.
  9160. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  9161. - int * emcp_method_count_p);
  9162. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9163. + void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  9164. - // Unevolving classes may point to methods of the_class directly
  9165. - // from their constant pool caches, itables, and/or vtables. We
  9166. - // use the SystemDictionary::classes_do() facility and this helper
  9167. - // to fix up these pointers.
  9168. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  9169. + static void add_affected_klasses( klassOop obj );
  9170. +
  9171. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
  9172. // Install the redefinition of a class
  9173. - void redefine_single_class(jclass the_jclass,
  9174. - instanceKlassHandle scratch_class, TRAPS);
  9175. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  9176. // Increment the classRedefinedCount field in the specific instanceKlass
  9177. // and in all direct and indirect subclasses.
  9178. void increment_class_counter(instanceKlass *ik, TRAPS);
  9179. - // Support for constant pool merging (these routines are in alpha order):
  9180. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  9181. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9182. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  9183. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9184. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  9185. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  9186. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9187. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  9188. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9189. - int find_new_index(int old_index);
  9190. - int find_new_operand_index(int old_bootstrap_spec_index);
  9191. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  9192. - constantPoolHandle cp2, int index2);
  9193. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  9194. - constantPoolHandle cp2, int index2);
  9195. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  9196. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  9197. - bool merge_constant_pools(constantPoolHandle old_cp,
  9198. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  9199. - int *merge_cp_length_p, TRAPS);
  9200. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  9201. - instanceKlassHandle scratch_class, TRAPS);
  9202. - u2 rewrite_cp_ref_in_annotation_data(
  9203. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  9204. - const char * trace_mesg, TRAPS);
  9205. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  9206. - bool rewrite_cp_refs_in_annotation_struct(
  9207. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9208. - bool rewrite_cp_refs_in_annotations_typeArray(
  9209. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  9210. - bool rewrite_cp_refs_in_class_annotations(
  9211. - instanceKlassHandle scratch_class, TRAPS);
  9212. - bool rewrite_cp_refs_in_element_value(
  9213. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9214. - bool rewrite_cp_refs_in_fields_annotations(
  9215. - instanceKlassHandle scratch_class, TRAPS);
  9216. - void rewrite_cp_refs_in_method(methodHandle method,
  9217. - methodHandle * new_method_p, TRAPS);
  9218. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  9219. - bool rewrite_cp_refs_in_methods_annotations(
  9220. - instanceKlassHandle scratch_class, TRAPS);
  9221. - bool rewrite_cp_refs_in_methods_default_annotations(
  9222. - instanceKlassHandle scratch_class, TRAPS);
  9223. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  9224. - instanceKlassHandle scratch_class, TRAPS);
  9225. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  9226. - void rewrite_cp_refs_in_verification_type_info(
  9227. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  9228. - u1 frame_size, TRAPS);
  9229. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  9230. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  9231. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  9232. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  9233. - static void dump_methods();
  9234. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  9235. +
  9236. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  9237. +
  9238. + static void unpatch_bytecode(methodOop method);
  9239. +
  9240. +#ifdef ASSERT
  9241. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  9242. +#endif
  9243. +
  9244. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  9245. + void calculate_instance_update_information(klassOop new_version);
  9246. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  9247. + static void mark_as_scavengable(nmethod* nm);
  9248. +
  9249. + bool check_arguments();
  9250. + jvmtiError check_arguments_error();
  9251. public:
  9252. - VM_RedefineClasses(jint class_count,
  9253. - const jvmtiClassDefinition *class_defs,
  9254. - JvmtiClassLoadKind class_load_kind);
  9255. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  9256. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  9257. + virtual ~VM_RedefineClasses();
  9258. +
  9259. bool doit_prologue();
  9260. void doit();
  9261. void doit_epilogue();
  9262. + void rollback();
  9263. - bool allow_nested_vm_operations() const { return true; }
  9264. - jvmtiError check_error() { return _res; }
  9265. + jvmtiError check_exception() const;
  9266. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  9267. + bool skip_operation() const { return false; }
  9268. + bool allow_nested_vm_operations() const { return true; }
  9269. + jvmtiError check_error() { return _result; }
  9270. // Modifiable test must be shared between IsModifiableClass query
  9271. // and redefine implementation
  9272. static bool is_modifiable_class(oop klass_mirror);
  9273. +
  9274. + // Utility methods for transfering field access flags
  9275. +
  9276. + static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
  9277. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  9278. +
  9279. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9280. +
  9281. + void lock_threads();
  9282. + void unlock_threads();
  9283. +
  9284. + static void swap_marks(oop first, oop second);
  9285. +
  9286. };
  9287. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  9288. diff --git a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9289. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9290. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9291. @@ -1,5 +1,5 @@
  9292. /*
  9293. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  9294. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  9295. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9296. *
  9297. * This code is free software; you can redistribute it and/or modify it
  9298. @@ -22,114 +22,26 @@
  9299. *
  9300. */
  9301. -#ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9302. -#define SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9303. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  9304. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  9305. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  9306. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  9307. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  9308. -// RedefineClasses tracing support via the TraceRedefineClasses
  9309. -// option. A bit is assigned to each group of trace messages.
  9310. -// Groups of messages are individually selectable. We have to use
  9311. -// decimal values on the command line since the command option
  9312. -// parsing logic doesn't like non-decimal numerics. The HEX values
  9313. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  9314. -// the old cumulative behavior, pick the level after the one in
  9315. -// which you are interested and subtract one, e.g., 33554431 will
  9316. -// print every tracing message.
  9317. -//
  9318. -// 0x00000000 | 0 - default; no tracing messages
  9319. -// 0x00000001 | 1 - name each target class before loading, after
  9320. -// loading and after redefinition is completed
  9321. -// 0x00000002 | 2 - print info if parsing, linking or
  9322. -// verification throws an exception
  9323. -// 0x00000004 | 4 - print timer info for the VM operation
  9324. -// 0x00000008 | 8 - print subclass counter updates
  9325. -// 0x00000010 | 16 - unused
  9326. -// 0x00000020 | 32 - unused
  9327. -// 0x00000040 | 64 - unused
  9328. -// 0x00000080 | 128 - unused
  9329. -// 0x00000100 | 256 - previous class weak reference addition
  9330. -// 0x00000200 | 512 - previous class weak reference mgmt during
  9331. -// class unloading checks (GC)
  9332. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  9333. -// add previous ops (GC)
  9334. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  9335. -// 0x00001000 | 4096 - detect calls to obsolete methods
  9336. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  9337. -// 0x00004000 | 16384 - detect old/obsolete methods in metadata
  9338. -// 0x00008000 | 32768 - old/new method matching/add/delete
  9339. -// 0x00010000 | 65536 - impl details: CP size info
  9340. -// 0x00020000 | 131072 - impl details: CP merge pass info
  9341. -// 0x00040000 | 262144 - impl details: CP index maps
  9342. -// 0x00080000 | 524288 - impl details: modified CP index values
  9343. -// 0x00100000 | 1048576 - impl details: vtable updates
  9344. -// 0x00200000 | 2097152 - impl details: itable updates
  9345. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  9346. -// 0x00800000 | 8388608 - impl details: methodComparator info
  9347. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  9348. -// 0x02000000 | 33554432 - impl details: annotation updates
  9349. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  9350. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  9351. -// 0x10000000 | 268435456 - unused
  9352. -// 0x20000000 | 536870912 - unused
  9353. -// 0x40000000 | 1073741824 - unused
  9354. -// 0x80000000 | 2147483648 - unused
  9355. -//
  9356. -// Note: The ResourceMark is to cleanup resource allocated args.
  9357. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  9358. -#define RC_TRACE(level, args) \
  9359. - if ((TraceRedefineClasses & level) != 0) { \
  9360. - ResourceMark rm; \
  9361. - tty->print("RedefineClasses-0x%x: ", level); \
  9362. - tty->print_cr args; \
  9363. - } while (0)
  9364. -
  9365. -#define RC_TRACE_NO_CR(level, args) \
  9366. - if ((TraceRedefineClasses & level) != 0) { \
  9367. - ResourceMark rm; \
  9368. - tty->print("RedefineClasses-0x%x: ", level); \
  9369. - tty->print args; \
  9370. - } while (0)
  9371. -
  9372. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  9373. - if ((TraceRedefineClasses & level) != 0) { \
  9374. - ResourceMark rm(thread); \
  9375. - tty->print("RedefineClasses-0x%x: ", level); \
  9376. - tty->print_cr args; \
  9377. - } while (0)
  9378. -
  9379. -#define RC_TRACE_MESG(args) \
  9380. - { \
  9381. - ResourceMark rm; \
  9382. - tty->print("RedefineClasses: "); \
  9383. - tty->print_cr args; \
  9384. - } while (0)
  9385. -
  9386. -// Macro for checking if TraceRedefineClasses has a specific bit
  9387. -// enabled. Returns true if the bit specified by level is set.
  9388. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  9389. -
  9390. -// Macro for checking if TraceRedefineClasses has one or more bits
  9391. -// set in a range of bit values. Returns true if one or more bits
  9392. -// is set in the range from low..high inclusive. Assumes that low
  9393. -// and high are single bit values.
  9394. -//
  9395. -// ((high << 1) - 1)
  9396. -// Yields a mask that removes bits greater than the high bit value.
  9397. -// This algorithm doesn't work with highest bit.
  9398. -// ~(low - 1)
  9399. -// Yields a mask that removes bits lower than the low bit value.
  9400. -#define RC_TRACE_IN_RANGE(low, high) \
  9401. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  9402. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  9403. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  9404. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  9405. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  9406. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  9407. // Timer support macros. Only do timer operations if timer tracing
  9408. // is enabled. The "while (0)" is so we can use semi-colon at end of
  9409. // the macro.
  9410. #define RC_TIMER_START(t) \
  9411. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9412. + if (TimeRedefineClasses) { \
  9413. t.start(); \
  9414. } while (0)
  9415. #define RC_TIMER_STOP(t) \
  9416. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9417. + if (TimeRedefineClasses) { \
  9418. t.stop(); \
  9419. } while (0)
  9420. -
  9421. -#endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9422. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  9423. --- a/src/share/vm/prims/methodComparator.cpp
  9424. +++ b/src/share/vm/prims/methodComparator.cpp
  9425. @@ -42,10 +42,9 @@
  9426. if (old_method->code_size() != new_method->code_size())
  9427. return false;
  9428. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  9429. - // RC_TRACE macro has an embedded ResourceMark
  9430. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  9431. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  9432. old_method->name()->as_C_string(),
  9433. - check_stack_and_locals_size(old_method, new_method)));
  9434. + check_stack_and_locals_size(old_method, new_method));
  9435. return false;
  9436. }
  9437. @@ -114,10 +113,9 @@
  9438. // Now we can test all forward jumps
  9439. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  9440. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  9441. - RC_TRACE(0x00800000,
  9442. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9443. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9444. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  9445. - fwd_jmps.at(i*2+1)));
  9446. + fwd_jmps.at(i*2+1));
  9447. return false;
  9448. }
  9449. }
  9450. diff --git a/src/share/vm/prims/methodHandles.cpp b/src/share/vm/prims/methodHandles.cpp
  9451. --- a/src/share/vm/prims/methodHandles.cpp
  9452. +++ b/src/share/vm/prims/methodHandles.cpp
  9453. @@ -1025,34 +1025,6 @@
  9454. return found;
  9455. }
  9456. -// It is called at safepoint only
  9457. -void MemberNameTable::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  9458. - int methods_length, bool *trace_name_printed) {
  9459. - assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
  9460. - // search the MemberNameTable for uses of either obsolete or EMCP methods
  9461. - for (int j = 0; j < methods_length; j++) {
  9462. - methodOop old_method = old_methods[j];
  9463. - methodOop new_method = new_methods[j];
  9464. - oop mem_name = find_member_name_by_method(old_method);
  9465. - if (mem_name != NULL) {
  9466. - java_lang_invoke_MemberName::adjust_vmtarget(mem_name, new_method);
  9467. -
  9468. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  9469. - if (!(*trace_name_printed)) {
  9470. - // RC_TRACE_MESG macro has an embedded ResourceMark
  9471. - RC_TRACE_MESG(("adjust: name=%s",
  9472. - Klass::cast(old_method->method_holder())->external_name()));
  9473. - *trace_name_printed = true;
  9474. - }
  9475. - // RC_TRACE macro has an embedded ResourceMark
  9476. - RC_TRACE(0x00400000, ("MemberName method update: %s(%s)",
  9477. - new_method->name()->as_C_string(),
  9478. - new_method->signature()->as_C_string()));
  9479. - }
  9480. - }
  9481. - }
  9482. -}
  9483. -
  9484. //
  9485. // Here are the native methods in java.lang.invoke.MethodHandleNatives
  9486. // They are the private interface between this JVM and the HotSpot-specific
  9487. diff --git a/src/share/vm/prims/methodHandles.hpp b/src/share/vm/prims/methodHandles.hpp
  9488. --- a/src/share/vm/prims/methodHandles.hpp
  9489. +++ b/src/share/vm/prims/methodHandles.hpp
  9490. @@ -241,12 +241,6 @@
  9491. void add_member_name(int index, jweak mem_name_ref);
  9492. oop get_member_name(int index);
  9493. - public:
  9494. - // RedefineClasses() API support:
  9495. - // If a MemberName refers to old_method then update it
  9496. - // to refer to new_method.
  9497. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  9498. - int methods_length, bool *trace_name_printed);
  9499. private:
  9500. oop find_member_name_by_method(methodOop old_method);
  9501. };
  9502. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  9503. --- a/src/share/vm/runtime/arguments.cpp
  9504. +++ b/src/share/vm/runtime/arguments.cpp
  9505. @@ -54,8 +54,8 @@
  9506. #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  9507. #endif
  9508. -// Note: This is a special bug reporting site for the JVM
  9509. -#define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  9510. +// (tw) The DCE VM has its own JIRA bug tracking system.
  9511. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  9512. #define DEFAULT_JAVA_LAUNCHER "generic"
  9513. char** Arguments::_jvm_flags_array = NULL;
  9514. @@ -1831,6 +1831,16 @@
  9515. status = false;
  9516. }
  9517. + // (tw) Must use serial GC. This limitation applies because the instance size changing GC modifications
  9518. + // are only built into the mark and compact algorithm.
  9519. + if (!UseSerialGC && i >= 1) {
  9520. + //jio_fprintf(defaultStream::error_stream(),
  9521. + // "Must use the serial GC in the Dynamic Code Evolution VM\n");
  9522. + //status = false;
  9523. + } else {
  9524. + UseSerialGC = true;
  9525. + }
  9526. +
  9527. return status;
  9528. }
  9529. @@ -3258,7 +3268,7 @@
  9530. // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  9531. set_aggressive_opts_flags();
  9532. -
  9533. +#ifndef COMPILER2
  9534. // Turn off biased locking for locking debug mode flags,
  9535. // which are subtlely different from each other but neither works with
  9536. // biased locking.
  9537. @@ -3275,6 +3285,7 @@
  9538. }
  9539. UseBiasedLocking = false;
  9540. }
  9541. +#endif
  9542. #ifdef CC_INTERP
  9543. // Clear flags not supported by the C++ interpreter
  9544. diff --git a/src/share/vm/runtime/fieldDescriptor.cpp b/src/share/vm/runtime/fieldDescriptor.cpp
  9545. --- a/src/share/vm/runtime/fieldDescriptor.cpp
  9546. +++ b/src/share/vm/runtime/fieldDescriptor.cpp
  9547. @@ -92,7 +92,8 @@
  9548. instanceKlass* ik = instanceKlass::cast(k);
  9549. _cp = ik->constants();
  9550. FieldInfo* f = ik->field(index);
  9551. - assert(!f->is_internal(), "regular Java fields only");
  9552. + // (tw) do we need this?
  9553. +// assert(!f->is_internal(), "regular Java fields only");
  9554. _access_flags = accessFlags_from(f->access_flags());
  9555. guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
  9556. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  9557. --- a/src/share/vm/runtime/globals.hpp
  9558. +++ b/src/share/vm/runtime/globals.hpp
  9559. @@ -1230,6 +1230,11 @@
  9560. product(intx, TraceRedefineClasses, 0, \
  9561. "Trace level for JVMTI RedefineClasses") \
  9562. \
  9563. + product(bool, TimeRedefineClasses, false, \
  9564. + "Measure timing for JVMTI RedefineClasses") \
  9565. + \
  9566. + product(bool, AllowAdvancedClassRedefinition, true, \
  9567. + "Allow advanced class redefinition beyond swapping method bodies")\
  9568. develop(bool, StressMethodComparator, false, \
  9569. "run the MethodComparator on all loaded methods") \
  9570. \
  9571. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  9572. --- a/src/share/vm/runtime/interfaceSupport.hpp
  9573. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  9574. @@ -296,7 +296,7 @@
  9575. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  9576. // We are leaving the VM at this point and going directly to native code.
  9577. // Block, if we are in the middle of a safepoint synchronization.
  9578. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9579. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9580. thread->frame_anchor()->make_walkable(thread);
  9581. trans_and_fence(_thread_in_vm, _thread_in_native);
  9582. // Check for pending. async. exceptions or suspends.
  9583. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  9584. --- a/src/share/vm/runtime/javaCalls.cpp
  9585. +++ b/src/share/vm/runtime/javaCalls.cpp
  9586. @@ -60,7 +60,7 @@
  9587. bool clear_pending_exception = true;
  9588. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  9589. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9590. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9591. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  9592. _result = result;
  9593. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  9594. --- a/src/share/vm/runtime/jniHandles.cpp
  9595. +++ b/src/share/vm/runtime/jniHandles.cpp
  9596. @@ -112,6 +112,10 @@
  9597. }
  9598. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  9599. + if (mh->newest_version() != mh()) {
  9600. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  9601. + return (jmethodID) make_weak_global(mh_new);
  9602. + }
  9603. return (jmethodID) make_weak_global(mh);
  9604. }
  9605. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  9606. --- a/src/share/vm/runtime/mutex.cpp
  9607. +++ b/src/share/vm/runtime/mutex.cpp
  9608. @@ -1227,7 +1227,7 @@
  9609. // in increasing rank order (modulo any native ranks)
  9610. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9611. if (tmp->next() != NULL) {
  9612. - assert(tmp->rank() == Mutex::native ||
  9613. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9614. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9615. }
  9616. }
  9617. @@ -1247,7 +1247,7 @@
  9618. // in increasing rank order (modulo any native ranks)
  9619. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9620. if (tmp->next() != NULL) {
  9621. - assert(tmp->rank() == Mutex::native ||
  9622. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9623. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9624. }
  9625. }
  9626. @@ -1310,6 +1310,7 @@
  9627. // already hold Terminator_lock - may happen because of periodic safepoints
  9628. if (this->rank() != Mutex::native &&
  9629. this->rank() != Mutex::suspend_resume &&
  9630. + this->rank() != Mutex::redefine_classes &&
  9631. locks != NULL && locks->rank() <= this->rank() &&
  9632. !SafepointSynchronize::is_at_safepoint() &&
  9633. this != Interrupt_lock &&
  9634. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  9635. --- a/src/share/vm/runtime/mutex.hpp
  9636. +++ b/src/share/vm/runtime/mutex.hpp
  9637. @@ -109,7 +109,8 @@
  9638. barrier = safepoint + 1,
  9639. nonleaf = barrier + 1,
  9640. max_nonleaf = nonleaf + 900,
  9641. - native = max_nonleaf + 1
  9642. + native = max_nonleaf + 1,
  9643. + redefine_classes = native + 1
  9644. };
  9645. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  9646. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  9647. --- a/src/share/vm/runtime/mutexLocker.cpp
  9648. +++ b/src/share/vm/runtime/mutexLocker.cpp
  9649. @@ -49,6 +49,7 @@
  9650. // Consider using GCC's __read_mostly.
  9651. Mutex* Patching_lock = NULL;
  9652. +Mutex* RedefineClasses_lock = NULL;
  9653. Monitor* SystemDictionary_lock = NULL;
  9654. Mutex* PackageTable_lock = NULL;
  9655. Mutex* CompiledIC_lock = NULL;
  9656. @@ -283,6 +284,7 @@
  9657. def(Debug3_lock , Mutex , nonleaf+4, true );
  9658. def(CompileThread_lock , Monitor, nonleaf+5, false);
  9659. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  9660. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  9661. #ifdef INCLUDE_TRACE
  9662. def(JfrMsg_lock , Monitor, leaf, true);
  9663. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  9664. --- a/src/share/vm/runtime/mutexLocker.hpp
  9665. +++ b/src/share/vm/runtime/mutexLocker.hpp
  9666. @@ -43,6 +43,7 @@
  9667. // Mutexes used in the VM.
  9668. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  9669. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  9670. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  9671. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  9672. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  9673. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  9674. --- a/src/share/vm/runtime/reflection.cpp
  9675. +++ b/src/share/vm/runtime/reflection.cpp
  9676. @@ -468,7 +468,8 @@
  9677. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9678. if ( JDK_Version::is_gte_jdk14x_version()
  9679. && UseNewReflection
  9680. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9681. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9682. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9683. return true;
  9684. }
  9685. @@ -519,6 +520,12 @@
  9686. AccessFlags access,
  9687. bool classloader_only,
  9688. bool protected_restriction) {
  9689. +
  9690. + // (tw) Decide accessibility based on active version
  9691. + if (current_class != NULL) {
  9692. + current_class = current_class->klass_part()->active_version();
  9693. + }
  9694. +
  9695. // Verify that current_class can access a field of field_class, where that
  9696. // field's access bits are "access". We assume that we've already verified
  9697. // that current_class can access field_class.
  9698. @@ -560,7 +567,8 @@
  9699. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9700. if ( JDK_Version::is_gte_jdk14x_version()
  9701. && UseNewReflection
  9702. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9703. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9704. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9705. return true;
  9706. }
  9707. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  9708. --- a/src/share/vm/runtime/sharedRuntime.cpp
  9709. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  9710. @@ -603,21 +603,13 @@
  9711. //
  9712. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  9713. JavaThread* thread, methodOopDesc* method))
  9714. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  9715. + assert(TraceRedefineClasses >= 4, "wrong call");
  9716. if (method->is_obsolete()) {
  9717. // We are calling an obsolete method, but this is not necessarily
  9718. // an error. Our method could have been redefined just after we
  9719. // fetched the methodOop from the constant pool.
  9720. -
  9721. - // RC_TRACE macro has an embedded ResourceMark
  9722. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  9723. - ("calling obsolete method '%s'",
  9724. - method->name_and_sig_as_C_string()));
  9725. - if (RC_TRACE_ENABLED(0x00002000)) {
  9726. - // this option is provided to debug calls to obsolete methods
  9727. - guarantee(false, "faulting at call to an obsolete method.");
  9728. - }
  9729. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  9730. }
  9731. return 0;
  9732. JRT_END
  9733. @@ -1137,7 +1129,20 @@
  9734. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  9735. int retry_count = 0;
  9736. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  9737. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  9738. + callee_method->method_holder()->klass_part()->super() != NULL) {
  9739. +
  9740. + // (tw) If we are executing an old method, this is OK!
  9741. + {
  9742. + ResourceMark rm(thread);
  9743. + RegisterMap cbl_map(thread, false);
  9744. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  9745. +
  9746. + CodeBlob* caller_cb = caller_frame.cb();
  9747. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  9748. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  9749. + if (caller_nm->method()->is_old()) break;
  9750. + }
  9751. +
  9752. // If has a pending exception then there is no need to re-try to
  9753. // resolve this method.
  9754. // If the method has been redefined, we need to try again.
  9755. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  9756. --- a/src/share/vm/runtime/thread.cpp
  9757. +++ b/src/share/vm/runtime/thread.cpp
  9758. @@ -216,6 +216,8 @@
  9759. set_self_raw_id(0);
  9760. set_lgrp_id(-1);
  9761. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  9762. +
  9763. // allocated data structures
  9764. set_osthread(NULL);
  9765. set_resource_area(new (mtThread)ResourceArea());
  9766. @@ -249,6 +251,7 @@
  9767. omFreeProvision = 32 ;
  9768. omInUseList = NULL ;
  9769. omInUseCount = 0 ;
  9770. + _pretend_new_universe = false;
  9771. #ifdef ASSERT
  9772. _visited_for_critical_count = false;
  9773. @@ -884,6 +887,15 @@
  9774. return false;
  9775. }
  9776. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  9777. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  9778. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  9779. + return true;
  9780. + }
  9781. + }
  9782. + return false;
  9783. +}
  9784. +
  9785. #endif
  9786. @@ -1637,7 +1649,7 @@
  9787. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  9788. assert(JavaThread::current() == this, "sanity check");
  9789. - assert(!Thread::current()->owns_locks(), "sanity check");
  9790. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  9791. DTRACE_THREAD_PROBE(start, this);
  9792. @@ -3193,7 +3205,7 @@
  9793. // Create a CompilerThread
  9794. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9795. -: JavaThread(&compiler_thread_entry) {
  9796. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  9797. _env = NULL;
  9798. _log = NULL;
  9799. _task = NULL;
  9800. @@ -3201,6 +3213,7 @@
  9801. _counters = counters;
  9802. _buffer_blob = NULL;
  9803. _scanned_nmethod = NULL;
  9804. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  9805. #ifndef PRODUCT
  9806. _ideal_graph_printer = NULL;
  9807. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  9808. --- a/src/share/vm/runtime/thread.hpp
  9809. +++ b/src/share/vm/runtime/thread.hpp
  9810. @@ -202,12 +202,15 @@
  9811. public:
  9812. void enter_signal_handler() { _num_nested_signal++; }
  9813. void leave_signal_handler() { _num_nested_signal--; }
  9814. - bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9815. + bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9816. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  9817. private:
  9818. // Debug tracing
  9819. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  9820. + Mutex* _redefine_classes_mutex;
  9821. +
  9822. // Active_handles points to a block of handles
  9823. JNIHandleBlock* _active_handles;
  9824. @@ -530,10 +533,15 @@
  9825. uintptr_t _self_raw_id; // used by get_thread (mutable)
  9826. int _lgrp_id;
  9827. +
  9828. + bool _pretend_new_universe;
  9829. +
  9830. public:
  9831. // Stack overflow support
  9832. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  9833. + 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; } }
  9834. + bool pretend_new_universe() { return _pretend_new_universe; }
  9835. void set_stack_base(address base) { _stack_base = base; }
  9836. size_t stack_size() const { return _stack_size; }
  9837. void set_stack_size(size_t size) { _stack_size = size; }
  9838. @@ -570,6 +578,7 @@
  9839. void print_owned_locks() const { print_owned_locks_on(tty); }
  9840. Monitor* owned_locks() const { return _owned_locks; }
  9841. bool owns_locks() const { return owned_locks() != NULL; }
  9842. + bool owns_locks_but_redefine_classes_lock() const;
  9843. bool owns_locks_but_compiled_lock() const;
  9844. // Deadlock detection
  9845. @@ -1793,6 +1802,8 @@
  9846. CompileTask* _task;
  9847. CompileQueue* _queue;
  9848. BufferBlob* _buffer_blob;
  9849. + bool _should_bailout;
  9850. + Mutex* _compilation_mutex;
  9851. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  9852. @@ -1802,12 +1813,16 @@
  9853. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  9854. + bool should_bailout() const { return _should_bailout; }
  9855. + void set_should_bailout(bool b) { _should_bailout = false; }
  9856. +
  9857. bool is_Compiler_thread() const { return true; }
  9858. // Hide this compiler thread from external view.
  9859. bool is_hidden_from_external_view() const { return true; }
  9860. CompileQueue* queue() { return _queue; }
  9861. CompilerCounters* counters() { return _counters; }
  9862. + Mutex *compilation_mutex() { return _compilation_mutex; }
  9863. // Get/set the thread's compilation environment.
  9864. ciEnv* env() { return _env; }
  9865. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  9866. --- a/src/share/vm/runtime/vmThread.cpp
  9867. +++ b/src/share/vm/runtime/vmThread.cpp
  9868. @@ -691,6 +691,9 @@
  9869. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  9870. Thread::oops_do(f, cf);
  9871. _vm_queue->oops_do(f);
  9872. + if (_cur_vm_operation != NULL) {
  9873. + _cur_vm_operation->oops_do(f);
  9874. + }
  9875. }
  9876. //------------------------------------------------------------------------------------------------------------------
  9877. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  9878. --- a/src/share/vm/utilities/exceptions.cpp
  9879. +++ b/src/share/vm/utilities/exceptions.cpp
  9880. @@ -254,6 +254,8 @@
  9881. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  9882. assert(!thread->has_pending_exception(), "already has exception");
  9883. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  9884. + Thread::current()->set_pretend_new_universe(false);
  9885. Handle h_exception;
  9886. // Resolve exception klass
  9887. @@ -285,6 +287,7 @@
  9888. h_exception = Handle(thread, thread->pending_exception());
  9889. thread->clear_pending_exception();
  9890. }
  9891. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  9892. return h_exception;
  9893. }
  9894. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  9895. --- a/src/share/vm/utilities/growableArray.hpp
  9896. +++ b/src/share/vm/utilities/growableArray.hpp
  9897. @@ -145,6 +145,33 @@
  9898. assert(on_stack(), "fast ResourceObj path only");
  9899. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  9900. }
  9901. +
  9902. +};
  9903. +
  9904. +template<class E, class F> class Pair : public StackObj
  9905. +{
  9906. +private:
  9907. + E _left;
  9908. + F _right;
  9909. +
  9910. +public:
  9911. +
  9912. + Pair() {
  9913. +
  9914. + }
  9915. +
  9916. + Pair(E left, F right) {
  9917. + this->_left = left;
  9918. + this->_right = right;
  9919. + }
  9920. +
  9921. + E left() {
  9922. + return _left;
  9923. + }
  9924. +
  9925. + F right() {
  9926. + return _right;
  9927. + }
  9928. };
  9929. template<class E> class GrowableArray : public GenericGrowableArray {