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

light-jdk7u79-b15.patch 424KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339
  1. diff --git a/src/cpu/x86/vm/interp_masm_x86_32.cpp b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  2. index b0ebcfd..6366d68 100644
  3. --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp
  4. +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  5. @@ -1364,7 +1364,7 @@
  6. }
  7. // RedefineClasses() tracing support for obsolete method entry
  8. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  9. + IF_TRACE_RC4 {
  10. get_thread(rcx);
  11. get_method(rbx);
  12. call_VM_leaf(
  13. diff --git a/src/cpu/x86/vm/interp_masm_x86_64.cpp b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  14. index 2790c2a..c315b18 100644
  15. --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp
  16. +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  17. @@ -1427,7 +1427,7 @@
  18. }
  19. // RedefineClasses() tracing support for obsolete method entry
  20. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  21. + IF_TRACE_RC4 {
  22. get_method(c_rarg1);
  23. call_VM_leaf(
  24. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  25. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  26. index 16958cd..09d6300 100644
  27. --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  28. +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  29. @@ -1976,7 +1976,7 @@
  30. }
  31. // RedefineClasses() tracing support for obsolete method entry
  32. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  33. + IF_TRACE_RC4 {
  34. __ movoop(rax, JNIHandles::make_local(method()));
  35. __ call_VM_leaf(
  36. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  37. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  38. index 7dc4e62..86c8c95 100644
  39. --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  40. +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  41. @@ -2235,7 +2235,7 @@
  42. }
  43. // RedefineClasses() tracing support for obsolete method entry
  44. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  45. + IF_TRACE_RC4 {
  46. // protect the args we've loaded
  47. save_args(masm, total_c_args, c_arg, out_regs);
  48. __ movoop(c_rarg1, JNIHandles::make_local(method()));
  49. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  50. index 9a8ca61..83e6f54 100644
  51. --- a/src/share/vm/c1/c1_Compilation.hpp
  52. +++ b/src/share/vm/c1/c1_Compilation.hpp
  53. @@ -242,8 +242,9 @@
  54. #define BAILOUT(msg) { bailout(msg); return; }
  55. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  56. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  57. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  58. +// (tw) Also checks a thread local flag that can be set to trigger compiler bailout from another thread.
  59. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  60. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  61. class InstructionMark: public StackObj {
  62. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  63. index e0ab96b..db8e551 100644
  64. --- a/src/share/vm/ci/ciObjectFactory.cpp
  65. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  66. @@ -764,3 +764,26 @@
  67. _unloaded_instances->length(),
  68. _unloaded_klasses->length());
  69. }
  70. +
  71. +int ciObjectFactory::compare_ciobjects(ciObject** a, ciObject** b) {
  72. + oop oop1 = (*a)->get_oop();
  73. + oop oop2 = (*b)->get_oop();
  74. + return ((oop1 > oop2) ? 1 : ((oop1 == oop2) ? 0 : -1));
  75. +}
  76. +
  77. +// (DCEVM) Resoring the ciObject arrays after class redefinition
  78. +void ciObjectFactory::resort_shared_ci_objects() {
  79. + _shared_ci_objects->sort(ciObjectFactory::compare_ciobjects);
  80. +
  81. +#ifdef ASSERT
  82. + if (CIObjectFactoryVerify) {
  83. + oop last = NULL;
  84. + for (int j = 0; j < _shared_ci_objects->length(); j++) {
  85. + oop o = _shared_ci_objects->at(j)->get_oop();
  86. + assert(last < o, "out of order");
  87. + last = o;
  88. + }
  89. + }
  90. +#endif // ASSERT
  91. +}
  92. +
  93. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  94. index 26cc2c3..d99d3d6 100644
  95. --- a/src/share/vm/ci/ciObjectFactory.hpp
  96. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  97. @@ -88,6 +88,7 @@
  98. ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
  99. + static int compare_ciobjects(ciObject** a, ciObject** b);
  100. public:
  101. static bool is_initialized() { return _initialized; }
  102. @@ -137,6 +138,8 @@
  103. void print_contents();
  104. void print();
  105. +
  106. + static void resort_shared_ci_objects();
  107. };
  108. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  109. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  110. index 505bad1..4d172fd 100644
  111. --- a/src/share/vm/classfile/classFileParser.cpp
  112. +++ b/src/share/vm/classfile/classFileParser.cpp
  113. @@ -795,6 +795,7 @@
  114. Handle class_loader,
  115. Handle protection_domain,
  116. Symbol* class_name,
  117. + KlassHandle old_klass,
  118. TRAPS) {
  119. ClassFileStream* cfs = stream();
  120. assert(length > 0, "only called for length>0");
  121. @@ -813,6 +814,9 @@
  122. interface_index, CHECK_(nullHandle));
  123. if (cp->tag_at(interface_index).is_klass()) {
  124. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  125. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  126. + interf = KlassHandle(THREAD, interf->newest_version());
  127. + }
  128. } else {
  129. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  130. @@ -825,6 +829,9 @@
  131. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  132. unresolved_klass, class_loader, protection_domain,
  133. false, CHECK_(nullHandle));
  134. + if (!old_klass.is_null()) {
  135. + k = k->klass_part()->newest_version();
  136. + }
  137. interf = KlassHandle(THREAD, k);
  138. }
  139. @@ -2955,8 +2962,10 @@
  140. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  141. Handle class_loader,
  142. Handle protection_domain,
  143. + KlassHandle old_klass,
  144. KlassHandle host_klass,
  145. GrowableArray<Handle>* cp_patches,
  146. + GrowableArray<Symbol*>* parsed_super_symbols,
  147. TempNewSymbol& parsed_name,
  148. bool verify,
  149. TRAPS) {
  150. @@ -2982,7 +2991,7 @@
  151. init_parsed_class_attributes();
  152. - if (JvmtiExport::should_post_class_file_load_hook()) {
  153. + if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
  154. // Get the cached class file bytes (if any) from the class that
  155. // is being redefined or retransformed. We use jvmti_thread_state()
  156. // instead of JvmtiThreadState::state_for(jt) so we don't allocate
  157. @@ -3005,10 +3014,13 @@
  158. unsigned char* ptr = cfs->buffer();
  159. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  160. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  161. + Thread::current()->set_pretend_new_universe(false);
  162. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  163. &ptr, &end_ptr,
  164. &cached_class_file_bytes,
  165. &cached_class_file_length);
  166. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  167. if (ptr != cfs->buffer()) {
  168. // JVMTI agent has modified class file data.
  169. @@ -3124,6 +3136,30 @@
  170. CHECK_(nullHandle));
  171. }
  172. + // (tw) Do not parse full class file, only get super symbols and return.
  173. + if (parsed_super_symbols != NULL) {
  174. + u2 super_class_index = cfs->get_u2_fast();
  175. +
  176. + if (super_class_index != 0) {
  177. + parsed_super_symbols->append(cp->klass_name_at(super_class_index));
  178. + }
  179. +
  180. + // Interfaces
  181. + u2 itfs_len = cfs->get_u2_fast();
  182. + objArrayHandle local_interfaces;
  183. + if (itfs_len == 0) {
  184. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  185. + } else {
  186. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_NULL);
  187. + }
  188. +
  189. + for (int i=0; i<local_interfaces->length(); i++) {
  190. + oop o = local_interfaces->obj_at(i);
  191. + parsed_super_symbols->append(((klassOop)o)->klass_part()->name());
  192. + }
  193. + return NULL;
  194. + }
  195. +
  196. klassOop preserve_this_klass; // for storing result across HandleMark
  197. // release all handles when parsing is done
  198. @@ -3164,7 +3200,11 @@
  199. // However, make sure it is not an array type.
  200. bool is_array = false;
  201. if (cp->tag_at(super_class_index).is_klass()) {
  202. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  203. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  204. + if (!old_klass.is_null()) {
  205. + resolved_klass = resolved_klass->klass_part()->newest_version();
  206. + }
  207. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  208. if (_need_verify)
  209. is_array = super_klass->oop_is_array();
  210. } else if (_need_verify) {
  211. @@ -3182,7 +3222,7 @@
  212. if (itfs_len == 0) {
  213. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  214. } else {
  215. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  216. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  217. }
  218. u2 java_fields_count = 0;
  219. @@ -3237,7 +3277,9 @@
  220. protection_domain,
  221. true,
  222. CHECK_(nullHandle));
  223. -
  224. + if (!old_klass.is_null()) {
  225. + k = k->klass_part()->newest_version();
  226. + }
  227. KlassHandle kh (THREAD, k);
  228. super_klass = instanceKlassHandle(THREAD, kh());
  229. }
  230. @@ -3626,6 +3668,19 @@
  231. rt = REF_NONE;
  232. } else {
  233. rt = super_klass->reference_type();
  234. +
  235. + // (tw) With class redefinition, it can also happen that special classes are loaded.
  236. + if (name == vmSymbols::java_lang_ref_Reference()) {
  237. + rt = REF_OTHER;
  238. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  239. + rt = REF_SOFT;
  240. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  241. + rt = REF_WEAK;
  242. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  243. + rt = REF_FINAL;
  244. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  245. + rt = REF_PHANTOM;
  246. + }
  247. }
  248. // We can now create the basic klassOop for this klass
  249. @@ -3634,6 +3689,7 @@
  250. total_oop_map_count,
  251. access_flags,
  252. rt, host_klass,
  253. + old_klass,
  254. CHECK_(nullHandle));
  255. instanceKlassHandle this_klass (THREAD, ik);
  256. @@ -3726,7 +3782,7 @@
  257. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  258. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  259. - set_precomputed_flags(this_klass);
  260. + set_precomputed_flags(this_klass, old_klass);
  261. // reinitialize modifiers, using the InnerClasses attribute
  262. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  263. @@ -3744,6 +3800,10 @@
  264. // check that if this class is an interface then it doesn't have static methods
  265. if (this_klass->is_interface()) {
  266. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  267. + }
  268. +
  269. + if (rt == REF_OTHER) {
  270. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  271. }
  272. // Allocate mirror and initialize static fields
  273. @@ -3891,7 +3951,7 @@
  274. }
  275. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  276. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  277. klassOop super = k->super();
  278. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  279. @@ -3899,7 +3959,9 @@
  280. if (!_has_empty_finalizer) {
  281. if (_has_finalizer ||
  282. (super != NULL && super->klass_part()->has_finalizer())) {
  283. - k->set_has_finalizer();
  284. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  285. + k->set_has_finalizer();
  286. + }
  287. }
  288. }
  289. @@ -3915,7 +3977,7 @@
  290. // Check if this klass supports the java.lang.Cloneable interface
  291. if (SystemDictionary::Cloneable_klass_loaded()) {
  292. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  293. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  294. k->set_is_cloneable();
  295. }
  296. }
  297. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  298. index a95a784..ebf08b3 100644
  299. --- a/src/share/vm/classfile/classFileParser.hpp
  300. +++ b/src/share/vm/classfile/classFileParser.hpp
  301. @@ -151,6 +151,7 @@
  302. Handle class_loader,
  303. Handle protection_domain,
  304. Symbol* class_name,
  305. + KlassHandle old_klass,
  306. TRAPS);
  307. // Field parsing
  308. @@ -239,7 +240,7 @@
  309. unsigned int nonstatic_oop_map_count,
  310. int* nonstatic_oop_offsets,
  311. unsigned int* nonstatic_oop_counts);
  312. - void set_precomputed_flags(instanceKlassHandle k);
  313. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  314. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  315. objArrayHandle local_ifs, TRAPS);
  316. @@ -357,17 +358,20 @@
  317. instanceKlassHandle parseClassFile(Symbol* name,
  318. Handle class_loader,
  319. Handle protection_domain,
  320. + KlassHandle old_klass,
  321. TempNewSymbol& parsed_name,
  322. bool verify,
  323. TRAPS) {
  324. KlassHandle no_host_klass;
  325. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  326. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
  327. }
  328. instanceKlassHandle parseClassFile(Symbol* name,
  329. Handle class_loader,
  330. Handle protection_domain,
  331. + KlassHandle old_klass,
  332. KlassHandle host_klass,
  333. GrowableArray<Handle>* cp_patches,
  334. + GrowableArray<Symbol*>* parsed_super_symbols,
  335. TempNewSymbol& parsed_name,
  336. bool verify,
  337. TRAPS);
  338. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  339. index a2e61a4..450e19f 100644
  340. --- a/src/share/vm/classfile/classLoader.cpp
  341. +++ b/src/share/vm/classfile/classLoader.cpp
  342. @@ -915,6 +915,7 @@
  343. instanceKlassHandle result = parser.parseClassFile(h_name,
  344. class_loader,
  345. protection_domain,
  346. + KlassHandle(),
  347. parsed_name,
  348. false,
  349. CHECK_(h));
  350. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  351. index 78e76cc..d167c98 100644
  352. --- a/src/share/vm/classfile/dictionary.cpp
  353. +++ b/src/share/vm/classfile/dictionary.cpp
  354. @@ -144,87 +144,10 @@
  355. probe = *p;
  356. klassOop e = probe->klass();
  357. oop class_loader = probe->loader();
  358. -
  359. instanceKlass* ik = instanceKlass::cast(e);
  360. - if (ik->previous_versions() != NULL) {
  361. - // This klass has previous versions so see what we can cleanup
  362. - // while it is safe to do so.
  363. -
  364. - int gc_count = 0; // leave debugging breadcrumbs
  365. - int live_count = 0;
  366. -
  367. - // RC_TRACE macro has an embedded ResourceMark
  368. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  369. - ik->external_name(), ik->previous_versions()->length()));
  370. -
  371. - for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  372. - // check the previous versions array for GC'ed weak refs
  373. - PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
  374. - jobject cp_ref = pv_node->prev_constant_pool();
  375. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  376. - if (cp_ref == NULL) {
  377. - delete pv_node;
  378. - ik->previous_versions()->remove_at(i);
  379. - // Since we are traversing the array backwards, we don't have to
  380. - // do anything special with the index.
  381. - continue; // robustness
  382. - }
  383. -
  384. - constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  385. - if (pvcp == NULL) {
  386. - // this entry has been GC'ed so remove it
  387. - delete pv_node;
  388. - ik->previous_versions()->remove_at(i);
  389. - // Since we are traversing the array backwards, we don't have to
  390. - // do anything special with the index.
  391. - gc_count++;
  392. - continue;
  393. - } else {
  394. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  395. - if (is_alive->do_object_b(pvcp)) {
  396. - live_count++;
  397. - } else {
  398. - guarantee(false, "sanity check");
  399. - }
  400. - }
  401. -
  402. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  403. - if (method_refs != NULL) {
  404. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  405. - method_refs->length()));
  406. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  407. - jweak method_ref = method_refs->at(j);
  408. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  409. - if (method_ref == NULL) {
  410. - method_refs->remove_at(j);
  411. - // Since we are traversing the array backwards, we don't have to
  412. - // do anything special with the index.
  413. - continue; // robustness
  414. - }
  415. -
  416. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  417. - if (method == NULL) {
  418. - // this method entry has been GC'ed so remove it
  419. - JNIHandles::destroy_weak_global(method_ref);
  420. - method_refs->remove_at(j);
  421. - } else {
  422. - // RC_TRACE macro has an embedded ResourceMark
  423. - RC_TRACE(0x00000200,
  424. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  425. - method->name()->as_C_string(),
  426. - method->signature()->as_C_string(), j, i));
  427. - }
  428. - }
  429. - }
  430. - }
  431. - assert(ik->previous_versions()->length() == live_count, "sanity check");
  432. - RC_TRACE(0x00000200,
  433. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  434. - gc_count));
  435. - }
  436. -
  437. +
  438. // Non-unloadable classes were handled in always_strong_oops_do
  439. - if (!is_strongly_reachable(class_loader, e)) {
  440. + if (!ik->is_redefining() && !is_strongly_reachable(class_loader, e)) {
  441. // Entry was not visited in phase1 (negated test from phase1)
  442. assert(class_loader != NULL, "unloading entry with null class loader");
  443. oop k_def_class_loader = ik->class_loader();
  444. @@ -325,6 +248,7 @@
  445. }
  446. }
  447. }
  448. +
  449. // Added for initialize_itable_for_klass to handle exceptions
  450. // Just the classes from defining class loaders
  451. @@ -433,6 +357,33 @@
  452. add_entry(index, entry);
  453. }
  454. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  455. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  456. +
  457. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  458. + bool found = false;
  459. + for (int index = 0; index < table_size(); index++) {
  460. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  461. + if (entry->klass() == old_class()) {
  462. + entry->set_literal(k());
  463. + found = true;
  464. + }
  465. + }
  466. + }
  467. +
  468. + return found;
  469. +}
  470. +
  471. +// (tw) Undo previous updates to the system dictionary
  472. +void Dictionary::rollback_redefinition() {
  473. + for (int index = 0; index < table_size(); index++) {
  474. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  475. + if (entry->klass()->klass_part()->is_redefining()) {
  476. + entry->set_literal(entry->klass()->klass_part()->old_version());
  477. + }
  478. + }
  479. + }
  480. +}
  481. // This routine does not lock the system dictionary.
  482. //
  483. @@ -459,12 +410,21 @@
  484. return NULL;
  485. }
  486. +klassOop Dictionary::intercept_for_version(klassOop k) {
  487. + if (k == NULL) return k;
  488. +
  489. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  490. + return k->klass_part()->old_version();
  491. + }
  492. +
  493. + return k;
  494. +}
  495. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  496. Handle loader, Handle protection_domain, TRAPS) {
  497. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  498. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  499. - return entry->klass();
  500. + return intercept_for_version(entry->klass());
  501. } else {
  502. return NULL;
  503. }
  504. @@ -477,7 +437,7 @@
  505. assert (index == index_for(name, loader), "incorrect index?");
  506. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  507. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  508. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  509. }
  510. @@ -489,7 +449,7 @@
  511. assert (index == index_for(name, Handle()), "incorrect index?");
  512. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  513. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  514. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  515. }
  516. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  517. index bd33760..ea1fe3c 100644
  518. --- a/src/share/vm/classfile/dictionary.hpp
  519. +++ b/src/share/vm/classfile/dictionary.hpp
  520. @@ -73,6 +73,10 @@
  521. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  522. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  523. +
  524. + void rollback_redefinition();
  525. +
  526. klassOop find_class(int index, unsigned int hash,
  527. Symbol* name, Handle loader);
  528. @@ -105,6 +109,7 @@
  529. bool do_unloading(BoolObjectClosure* is_alive);
  530. // Protection domains
  531. + static klassOop intercept_for_version(klassOop k);
  532. klassOop find(int index, unsigned int hash, Symbol* name,
  533. Handle loader, Handle protection_domain, TRAPS);
  534. bool is_valid_protection_domain(int index, unsigned int hash,
  535. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  536. index 7dd5f1b..1ac23a9 100644
  537. --- a/src/share/vm/classfile/javaClasses.cpp
  538. +++ b/src/share/vm/classfile/javaClasses.cpp
  539. @@ -621,6 +621,10 @@
  540. assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  541. klassOop k = klassOop(java_class->obj_field(_klass_offset));
  542. assert(k == NULL || k->is_klass(), "type check");
  543. + // Necessary to make old verifier work.
  544. + if (Thread::current()->pretend_new_universe()) {
  545. + k = k->klass_part()->newest_version();
  546. + }
  547. return k;
  548. }
  549. @@ -1541,6 +1545,7 @@
  550. skip_throwableInit_check = true;
  551. }
  552. }
  553. + method = method->newest_version();
  554. if (method->is_hidden()) {
  555. if (skip_hidden) continue;
  556. }
  557. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  558. index 36d1cec..4699301 100644
  559. --- a/src/share/vm/classfile/javaClasses.hpp
  560. +++ b/src/share/vm/classfile/javaClasses.hpp
  561. @@ -213,6 +213,7 @@
  562. class java_lang_Class : AllStatic {
  563. friend class VMStructs;
  564. + friend class VM_RedefineClasses;
  565. private:
  566. // The fake offsets are added by the class loader when java.lang.Class is loaded
  567. @@ -248,7 +249,7 @@
  568. static void print_signature(oop java_class, outputStream *st);
  569. // Testing
  570. static bool is_instance(oop obj) {
  571. - return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
  572. + return obj != NULL && (obj->klass()->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version());
  573. }
  574. static bool is_primitive(oop java_class);
  575. static BasicType primitive_type(oop java_class);
  576. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  577. index 8650cd9..965cce2 100644
  578. --- a/src/share/vm/classfile/loaderConstraints.cpp
  579. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  580. @@ -449,7 +449,7 @@
  581. if (k != NULL) {
  582. // We found the class in the system dictionary, so we should
  583. // make sure that the klassOop matches what we already have.
  584. - guarantee(k == probe->klass(), "klass should be in dictionary");
  585. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  586. } else {
  587. // If we don't find the class in the system dictionary, it
  588. // has to be in the placeholders table.
  589. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  590. index 2fa221b..475aef9 100644
  591. --- a/src/share/vm/classfile/systemDictionary.cpp
  592. +++ b/src/share/vm/classfile/systemDictionary.cpp
  593. @@ -157,6 +157,7 @@
  594. // can return a null klass
  595. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  596. }
  597. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  598. return klass;
  599. }
  600. @@ -199,7 +200,7 @@
  601. // Forwards to resolve_instance_class_or_null
  602. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  603. - assert(!THREAD->is_Compiler_thread(),
  604. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  605. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  606. class_name->as_C_string(),
  607. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  608. @@ -961,8 +962,10 @@
  609. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  610. class_loader,
  611. protection_domain,
  612. + KlassHandle(),
  613. host_klass,
  614. cp_patches,
  615. + NULL,
  616. parsed_name,
  617. true,
  618. THREAD);
  619. @@ -1022,7 +1025,15 @@
  620. Handle protection_domain,
  621. ClassFileStream* st,
  622. bool verify,
  623. + KlassHandle old_class,
  624. TRAPS) {
  625. +
  626. + bool redefine_classes_locked = false;
  627. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  628. + Thread::current()->redefine_classes_mutex()->lock();
  629. + redefine_classes_locked = true;
  630. + }
  631. +
  632. // Classloaders that support parallelism, e.g. bootstrap classloader,
  633. // or all classloaders with UnsyncloadClass do not acquire lock here
  634. bool DoObjectLock = true;
  635. @@ -1050,9 +1061,14 @@
  636. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  637. class_loader,
  638. protection_domain,
  639. + old_class,
  640. parsed_name,
  641. verify,
  642. THREAD);
  643. + if (!old_class.is_null() && !k.is_null()) {
  644. + k->set_redefining(true);
  645. + k->set_old_version(old_class());
  646. + }
  647. const char* pkg = "java/";
  648. if (!HAS_PENDING_EXCEPTION &&
  649. @@ -1087,11 +1103,16 @@
  650. // Add class just loaded
  651. // If a class loader supports parallel classloading handle parallel define requests
  652. // find_or_define_instance_class may return a different instanceKlass
  653. - if (is_parallelCapable(class_loader)) {
  654. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  655. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  656. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  657. } else {
  658. - define_instance_class(k, THREAD);
  659. + define_instance_class(k, old_class, THREAD);
  660. }
  661. + }
  662. +
  663. + if (redefine_classes_locked) {
  664. + Thread::current()->redefine_classes_mutex()->unlock();
  665. }
  666. // If parsing the class file or define_instance_class failed, we
  667. @@ -1122,7 +1143,7 @@
  668. MutexLocker mu(SystemDictionary_lock, THREAD);
  669. klassOop check = find_class(parsed_name, class_loader);
  670. - assert(check == k(), "should be present in the dictionary");
  671. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  672. klassOop check2 = find_class(h_name, h_loader);
  673. assert(check == check2, "name inconsistancy in SystemDictionary");
  674. @@ -1349,7 +1370,11 @@
  675. }
  676. }
  677. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  678. +void SystemDictionary::rollback_redefinition() {
  679. + dictionary()->rollback_redefinition();
  680. +}
  681. +
  682. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  683. Handle class_loader_h(THREAD, k->class_loader());
  684. @@ -1376,13 +1401,23 @@
  685. Symbol* name_h = k->name();
  686. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  687. int d_index = dictionary()->hash_to_index(d_hash);
  688. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  689. +
  690. + // (tw) Update version of the klassOop in the system dictionary
  691. + // TODO: Check for thread safety!
  692. + if (!old_class.is_null()) {
  693. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  694. + assert (ok, "must have found old class and updated!");
  695. + }
  696. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  697. +
  698. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  699. // Register class just loaded with class loader (placed in Vector)
  700. // Note we do this before updating the dictionary, as this can
  701. // fail with an OutOfMemoryError (if it does, we will *not* put this
  702. // class in the dictionary and will not update the class hierarchy).
  703. - if (k->class_loader() != NULL) {
  704. + // (tw) Only register if not redefining a class.
  705. + if (k->class_loader() != NULL && old_class.is_null()) {
  706. methodHandle m(THREAD, Universe::loader_addClass_method());
  707. JavaValue result(T_VOID);
  708. JavaCallArguments args(class_loader_h);
  709. @@ -1408,8 +1443,9 @@
  710. }
  711. k->eager_initialize(THREAD);
  712. + // (tw) Only notify jvmti if not redefining a class.
  713. // notify jvmti
  714. - if (JvmtiExport::should_post_class_load()) {
  715. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  716. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  717. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  718. @@ -1482,7 +1518,7 @@
  719. }
  720. }
  721. - define_instance_class(k, THREAD);
  722. + define_instance_class(k, KlassHandle(), THREAD);
  723. Handle linkage_exception = Handle(); // null handle
  724. @@ -1613,6 +1649,14 @@
  725. Universe::flush_dependents_on(k);
  726. }
  727. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  728. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  729. + assert(k.not_null(), "just checking");
  730. +
  731. + k->remove_from_sibling_list();
  732. +
  733. + // TODO (tw): Remove from interfaces.
  734. +}
  735. // ----------------------------------------------------------------------------
  736. // GC support
  737. @@ -1870,9 +1914,12 @@
  738. // Preload ref klasses and set reference types
  739. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  740. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  741. +
  742. + // (tw) This is now done in parseClassFile in order to support class redefinition
  743. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  744. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
  745. + // TODO(tw): Check that the following is also not necessary?
  746. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  747. instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
  748. instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
  749. @@ -1957,7 +2004,7 @@
  750. // also holds array classes
  751. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  752. - if ((defining == true) || (k() != check)) {
  753. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  754. linkage_error = "loader (instance of %s): attempted duplicate class "
  755. "definition for name: \"%s\"";
  756. } else {
  757. @@ -2617,8 +2664,10 @@
  758. name = find_placeholder(class_name, class_loader);
  759. }
  760. }
  761. - guarantee(probe != NULL || name != NULL,
  762. - "Loaded klasses should be in SystemDictionary");
  763. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  764. + guarantee(probe != NULL &&
  765. + (!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(),
  766. + "Loaded klasses should be in SystemDictionary");
  767. }
  768. // utility function for posting class load event
  769. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  770. index 85474c5..570606f 100644
  771. --- a/src/share/vm/classfile/systemDictionary.hpp
  772. +++ b/src/share/vm/classfile/systemDictionary.hpp
  773. @@ -270,7 +270,7 @@
  774. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  775. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  776. Handle protection_domain,
  777. - ClassFileStream* st, bool verify, TRAPS);
  778. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  779. // Lookup an already loaded class. If not found NULL is returned.
  780. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  781. @@ -345,6 +345,8 @@
  782. // System loader lock
  783. static oop system_loader_lock() { return _system_loader_lock_obj; }
  784. + // Remove link to hierarchy
  785. + static void remove_from_hierarchy(instanceKlassHandle k);
  786. private:
  787. // Traverses preloaded oops: various system classes. These are
  788. // guaranteed to be in the perm gen.
  789. @@ -416,6 +418,8 @@
  790. int limit = (int)end_id + 1;
  791. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  792. }
  793. +
  794. + static void rollback_redefinition();
  795. public:
  796. #define WK_KLASS_DECLARE(name, symbol, option) \
  797. @@ -598,7 +602,7 @@
  798. // after waiting, but before reentering SystemDictionary_lock
  799. // to preserve lock order semantics.
  800. static void double_lock_wait(Handle lockObject, TRAPS);
  801. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  802. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  803. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  804. Handle class_loader,
  805. instanceKlassHandle k, TRAPS);
  806. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  807. index 49c4b2c..937f4f6 100644
  808. --- a/src/share/vm/classfile/verifier.cpp
  809. +++ b/src/share/vm/classfile/verifier.cpp
  810. @@ -106,7 +106,7 @@
  811. return !need_verify;
  812. }
  813. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  814. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  815. HandleMark hm;
  816. ResourceMark rm(THREAD);
  817. @@ -117,6 +117,7 @@
  818. const char* klassName = klass->external_name();
  819. bool can_failover = FailOverToOldVerifier &&
  820. + may_use_old_verifier &&
  821. klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  822. // If the class should be verified, first see if we can use the split
  823. @@ -138,6 +139,7 @@
  824. tty->print_cr(
  825. "Fail over class verification to old verifier for: %s", klassName);
  826. }
  827. + assert(may_use_old_verifier, "");
  828. exception_name = inference_verify(
  829. klass, message_buffer, message_buffer_len, THREAD);
  830. }
  831. @@ -145,6 +147,7 @@
  832. exception_message = split_verifier.exception_message();
  833. }
  834. } else {
  835. + assert(may_use_old_verifier, "");
  836. exception_name = inference_verify(
  837. klass, message_buffer, message_buffer_len, THREAD);
  838. }
  839. @@ -210,7 +213,7 @@
  840. // NOTE: this is called too early in the bootstrapping process to be
  841. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  842. (refl_magic_klass == NULL ||
  843. - !klass->is_subtype_of(refl_magic_klass) ||
  844. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  845. VerifyReflectionBytecodes)
  846. );
  847. }
  848. @@ -517,7 +520,7 @@
  849. ClassVerifier::ClassVerifier(
  850. instanceKlassHandle klass, TRAPS)
  851. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  852. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  853. _this_type = VerificationType::reference_type(klass->name());
  854. // Create list to hold symbols in reference area.
  855. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  856. @@ -547,7 +550,7 @@
  857. _klass->external_name());
  858. }
  859. - objArrayHandle methods(THREAD, _klass->methods());
  860. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  861. int num_methods = methods->length();
  862. for (int index = 0; index < num_methods; index++) {
  863. @@ -2668,7 +2671,8 @@
  864. VerificationType stack_object_type =
  865. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  866. if (current_type() != stack_object_type) {
  867. - assert(cp->cache() == NULL, "not rewritten yet");
  868. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  869. + //assert(cp->cache() == NULL, "not rewritten yet");
  870. Symbol* ref_class_name =
  871. cp->klass_name_at(cp->klass_ref_index_at(index));
  872. // See the comments in verify_field_instructions() for
  873. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  874. index 92c4fd2..5e8e0da 100644
  875. --- a/src/share/vm/classfile/verifier.hpp
  876. +++ b/src/share/vm/classfile/verifier.hpp
  877. @@ -48,7 +48,7 @@
  878. * Otherwise, no exception is thrown and the return indicates the
  879. * error.
  880. */
  881. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  882. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  883. // Return false if the class is loaded by the bootstrap loader,
  884. // or if defineClass was called requesting skipping verification
  885. @@ -257,7 +257,10 @@
  886. ErrorContext _error_context; // contains information about an error
  887. +public:
  888. void verify_method(methodHandle method, TRAPS);
  889. +
  890. +private:
  891. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  892. void verify_exception_handler_table(u4 code_length, char* code_data,
  893. int& min, int& max, TRAPS);
  894. @@ -341,6 +344,7 @@
  895. VerificationType object_type() const;
  896. + instanceKlassHandle _klass_to_verify;
  897. instanceKlassHandle _klass; // the class being verified
  898. methodHandle _method; // current method being verified
  899. VerificationType _this_type; // the verification type of the current class
  900. diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
  901. index dddbea2..d5918cd 100644
  902. --- a/src/share/vm/code/nmethod.cpp
  903. +++ b/src/share/vm/code/nmethod.cpp
  904. @@ -2083,15 +2083,14 @@
  905. methodOop method = deps.method_argument(0);
  906. for (int j = 0; j < dependee_methods->length(); j++) {
  907. if ((methodOop) dependee_methods->obj_at(j) == method) {
  908. - // RC_TRACE macro has an embedded ResourceMark
  909. - RC_TRACE(0x01000000,
  910. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  911. + ResourceMark rm(Thread::current());
  912. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  913. _method->method_holder()->klass_part()->external_name(),
  914. _method->name()->as_C_string(),
  915. _method->signature()->as_C_string(), compile_id(),
  916. method->method_holder()->klass_part()->external_name(),
  917. method->name()->as_C_string(),
  918. - method->signature()->as_C_string()));
  919. + method->signature()->as_C_string());
  920. if (TraceDependencies || LogCompilation)
  921. deps.log_dependency(dependee);
  922. return true;
  923. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  924. index 3e8a65a..a03c876 100644
  925. --- a/src/share/vm/compiler/compileBroker.cpp
  926. +++ b/src/share/vm/compiler/compileBroker.cpp
  927. @@ -1592,6 +1592,9 @@
  928. // Never compile a method if breakpoints are present in it
  929. if (method()->number_of_breakpoints() == 0) {
  930. + // (tw) Obtain a compilation lock. Class redefinition requires that there is no compilation in parallel.
  931. + thread->compilation_mutex()->lock();
  932. + thread->set_should_bailout(false);
  933. // Compile the method.
  934. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  935. #ifdef COMPILER1
  936. @@ -1615,6 +1618,7 @@
  937. // After compilation is disabled, remove remaining methods from queue
  938. method->clear_queued_for_compilation();
  939. }
  940. + thread->compilation_mutex()->unlock();
  941. }
  942. }
  943. }
  944. @@ -1780,7 +1784,11 @@
  945. //assert(false, "compiler should always document failure");
  946. // The compiler elected, without comment, not to register a result.
  947. // Do not attempt further compilations of this method.
  948. - ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
  949. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  950. + ci_env.record_failure("compile externally aborted");
  951. + } else {
  952. + ci_env.record_method_not_compilable("compile failed");
  953. + }
  954. }
  955. // Copy this bit to the enclosing block:
  956. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  957. index a3abd66..fb52e6f 100644
  958. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  959. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  960. @@ -162,6 +162,13 @@
  961. }
  962. }
  963. +
  964. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  965. + CompactPoint* cp, HeapWord* compact_top) {
  966. + ShouldNotReachHere();
  967. + return NULL;
  968. +}
  969. +
  970. // Like CompactibleSpace forward() but always calls cross_threshold() to
  971. // update the block offset table. Removed initialize_threshold call because
  972. // CFLS does not use a block offset array for contiguous spaces.
  973. @@ -2118,7 +2125,7 @@
  974. // Support for compaction
  975. void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
  976. - SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
  977. + SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
  978. // prepare_for_compaction() uses the space between live objects
  979. // so that later phase can skip dead space quickly. So verification
  980. // of the free lists doesn't work after.
  981. @@ -2139,7 +2146,7 @@
  982. }
  983. void CompactibleFreeListSpace::compact() {
  984. - SCAN_AND_COMPACT(obj_size);
  985. + SCAN_AND_COMPACT(obj_size, false);
  986. }
  987. // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
  988. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  989. index 24509b6..6670b73 100644
  990. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  991. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  992. @@ -149,6 +149,7 @@
  993. // Support for compacting cms
  994. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  995. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  996. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  997. // Initialization helpers.
  998. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  999. index 29841d8..d1386c7 100644
  1000. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1001. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1002. @@ -32,6 +32,8 @@
  1003. #include "oops/objArrayKlass.inline.hpp"
  1004. #include "oops/oop.inline.hpp"
  1005. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1006. +
  1007. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1008. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1009. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1010. @@ -357,3 +359,97 @@
  1011. }
  1012. #endif
  1013. +
  1014. +// (tw) Copy the rescued objects to their destination address after compaction.
  1015. +void MarkSweep::copy_rescued_objects_back() {
  1016. +
  1017. + if (_rescued_oops != NULL) {
  1018. +
  1019. + for (int i=0; i<_rescued_oops->length(); i++) {
  1020. + oop rescued_obj = _rescued_oops->at(i);
  1021. +
  1022. + int size = rescued_obj->size();
  1023. + oop new_obj = rescued_obj->forwardee();
  1024. +
  1025. + assert(rescued_obj->blueprint()->new_version() != NULL, "just checking");
  1026. +
  1027. + if (rescued_obj->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1028. + MarkSweep::update_fields(rescued_obj, new_obj);
  1029. + } else {
  1030. + rescued_obj->set_klass_no_check(rescued_obj->blueprint()->new_version());
  1031. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1032. + }
  1033. +
  1034. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1035. +
  1036. + new_obj->init_mark();
  1037. + assert(new_obj->is_oop(), "must be a valid oop");
  1038. + }
  1039. + _rescued_oops->clear();
  1040. + _rescued_oops = NULL;
  1041. + }
  1042. +}
  1043. +
  1044. +// (tw) Update instances of a class whose fields changed.
  1045. +void MarkSweep::update_fields(oop q, oop new_location) {
  1046. +
  1047. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1048. +
  1049. + klassOop old_klass_oop = q->klass();
  1050. + klassOop new_klass_oop = q->blueprint()->new_version();
  1051. +
  1052. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1053. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1054. +
  1055. + int size = q->size_given_klass(old_klass);
  1056. + int new_size = q->size_given_klass(new_klass);
  1057. +
  1058. + oop tmp_obj = q;
  1059. +
  1060. + // Save object somewhere, there is an overlap in fields
  1061. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1062. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1063. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1064. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1065. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1066. + }
  1067. + }
  1068. +
  1069. + tmp_obj->set_klass_no_check(new_klass_oop);
  1070. + int *cur = new_klass_oop->klass_part()->update_information();
  1071. + assert(cur != NULL, "just checking");
  1072. + MarkSweep::update_fields(new_location, tmp_obj, cur);
  1073. +
  1074. + if (tmp_obj != q) {
  1075. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1076. + }
  1077. +}
  1078. +
  1079. +void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
  1080. + assert(cur != NULL, "just checking");
  1081. + char* to = (char*)new_location;
  1082. + while (*cur != 0) {
  1083. + int size = *cur;
  1084. + if (size > 0) {
  1085. + cur++;
  1086. + int offset = *cur;
  1087. + HeapWord* from = (HeapWord*)(((char *)tmp_obj) + offset);
  1088. + if (size == HeapWordSize) {
  1089. + *((HeapWord*)to) = *from;
  1090. + } else if (size == HeapWordSize * 2) {
  1091. + *((HeapWord*)to) = *from;
  1092. + *(((HeapWord*)to) + 1) = *(from + 1);
  1093. + } else {
  1094. + Copy::conjoint_jbytes(from, to, size);
  1095. + }
  1096. + to += size;
  1097. + cur++;
  1098. + } else {
  1099. + assert(size < 0, "");
  1100. + int skip = -*cur;
  1101. + Copy::fill_to_bytes(to, skip, 0);
  1102. + to += skip;
  1103. + cur++;
  1104. + }
  1105. + }
  1106. +}
  1107. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1108. index eb8252c..40118db 100644
  1109. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1110. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1111. @@ -117,7 +117,11 @@
  1112. friend class AdjustPointerClosure;
  1113. friend class KeepAliveClosure;
  1114. friend class VM_MarkSweep;
  1115. + friend class GenMarkSweep;
  1116. friend void marksweep_init();
  1117. +
  1118. +public:
  1119. + static GrowableArray<oop>* _rescued_oops;
  1120. //
  1121. // Vars
  1122. @@ -208,6 +212,9 @@
  1123. template <class T> static inline void mark_and_push(T* p);
  1124. static inline void push_objarray(oop obj, size_t index);
  1125. + static void copy_rescued_objects_back();
  1126. + static void update_fields(oop q, oop new_location);
  1127. + static void update_fields(oop new_location, oop tmp_obj, int *cur);
  1128. static void follow_stack(); // Empty marking stack.
  1129. static void preserve_mark(oop p, markOop mark);
  1130. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1131. index 1a1af1b..e6b4166 100644
  1132. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1133. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1134. @@ -402,7 +402,7 @@
  1135. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1136. assert(h_exception->is_oop(), "just checking");
  1137. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1138. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1139. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1140. if (ExitVMOnVerifyError) vm_exit(-1);
  1141. ShouldNotReachHere();
  1142. }
  1143. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1144. index 1676add..ec32845 100644
  1145. --- a/src/share/vm/interpreter/linkResolver.cpp
  1146. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1147. @@ -153,8 +153,8 @@
  1148. // Klass resolution
  1149. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1150. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1151. - sel_klass->as_klassOop(),
  1152. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1153. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1154. true)) {
  1155. ResourceMark rm(THREAD);
  1156. Exceptions::fthrow(
  1157. @@ -346,7 +346,7 @@
  1158. // We'll check for the method name first, as that's most likely
  1159. // to be false (so we'll short-circuit out of these tests).
  1160. if (sel_method->name() == vmSymbols::clone_name() &&
  1161. - sel_klass() == SystemDictionary::Object_klass() &&
  1162. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1163. resolved_klass->oop_is_array()) {
  1164. // We need to change "protected" to "public".
  1165. assert(flags.is_protected(), "clone not protected?");
  1166. @@ -643,7 +643,7 @@
  1167. }
  1168. // Final fields can only be accessed from its own class.
  1169. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1170. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1171. THROW(vmSymbols::java_lang_IllegalAccessError());
  1172. }
  1173. @@ -848,7 +848,7 @@
  1174. bool check_access, bool check_null_and_abstract, TRAPS) {
  1175. methodHandle resolved_method;
  1176. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1177. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1178. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1179. }
  1180. // throws linktime exceptions
  1181. @@ -878,6 +878,7 @@
  1182. KlassHandle resolved_klass,
  1183. Handle recv,
  1184. KlassHandle recv_klass,
  1185. + KlassHandle current_klass,
  1186. bool check_null_and_abstract,
  1187. TRAPS) {
  1188. @@ -926,6 +927,9 @@
  1189. // recv_klass might be an arrayKlassOop but all vtables start at
  1190. // the same place. The cast is to avoid virtual call and assertion.
  1191. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1192. +
  1193. + // (tw) Check that the receiver is a subtype of the holder of the resolved method.
  1194. + assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
  1195. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  1196. }
  1197. }
  1198. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  1199. index dfd74f9..6ca1b54 100644
  1200. --- a/src/share/vm/interpreter/linkResolver.hpp
  1201. +++ b/src/share/vm/interpreter/linkResolver.hpp
  1202. @@ -110,7 +110,8 @@
  1203. // It does all necessary link-time checks & throws exceptions if necessary.
  1204. class LinkResolver: AllStatic {
  1205. - private:
  1206. +private:
  1207. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  1208. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1209. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1210. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1211. @@ -133,7 +134,7 @@
  1212. 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);
  1213. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  1214. - 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);
  1215. + 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);
  1216. 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);
  1217. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  1218. diff --git a/src/share/vm/interpreter/oopMapCache.cpp b/src/share/vm/interpreter/oopMapCache.cpp
  1219. index 01d5753..6816b3a 100644
  1220. --- a/src/share/vm/interpreter/oopMapCache.cpp
  1221. +++ b/src/share/vm/interpreter/oopMapCache.cpp
  1222. @@ -536,9 +536,9 @@
  1223. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  1224. // Cache entry is occupied by an old redefined method and we don't want
  1225. // to pin it down so flush the entry.
  1226. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  1227. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  1228. _array[i].method()->name()->as_C_string(),
  1229. - _array[i].method()->signature()->as_C_string(), i));
  1230. + _array[i].method()->signature()->as_C_string(), i);
  1231. _array[i].flush();
  1232. }
  1233. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  1234. index 76e18d8..6af7c14 100644
  1235. --- a/src/share/vm/memory/genMarkSweep.cpp
  1236. +++ b/src/share/vm/memory/genMarkSweep.cpp
  1237. @@ -421,6 +421,7 @@
  1238. // in the same order in phase2, phase3 and phase4. We don't quite do that
  1239. // here (perm_gen first rather than last), so we tell the validate code
  1240. // to use a higher index (saved from phase2) when verifying perm_gen.
  1241. + assert(_rescued_oops == NULL, "must be empty before processing");
  1242. GenCollectedHeap* gch = GenCollectedHeap::heap();
  1243. Generation* pg = gch->perm_gen();
  1244. @@ -433,10 +434,14 @@
  1245. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  1246. + MarkSweep::copy_rescued_objects_back();
  1247. +
  1248. GenCompactClosure blk;
  1249. gch->generation_iterate(&blk, true);
  1250. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  1251. + MarkSweep::copy_rescued_objects_back();
  1252. +
  1253. pg->post_compact(); // Shared spaces verification.
  1254. }
  1255. diff --git a/src/share/vm/memory/iterator.hpp b/src/share/vm/memory/iterator.hpp
  1256. index b5f8e0e..856cfce 100644
  1257. --- a/src/share/vm/memory/iterator.hpp
  1258. +++ b/src/share/vm/memory/iterator.hpp
  1259. @@ -101,6 +101,12 @@
  1260. #endif
  1261. };
  1262. +class OopClosureNoHeader : public OopClosure {
  1263. +public:
  1264. + // If "true", invoke on header klass field.
  1265. + bool do_header() { return false; } // Note that this is non-virtual.
  1266. +};
  1267. +
  1268. // ObjectClosure is used for iterating through an object space
  1269. class ObjectClosure : public Closure {
  1270. diff --git a/src/share/vm/memory/oopFactory.cpp b/src/share/vm/memory/oopFactory.cpp
  1271. index def88cc..016d7eb 100644
  1272. --- a/src/share/vm/memory/oopFactory.cpp
  1273. +++ b/src/share/vm/memory/oopFactory.cpp
  1274. @@ -129,11 +129,11 @@
  1275. unsigned int nonstatic_oop_map_count,
  1276. AccessFlags access_flags,
  1277. ReferenceType rt,
  1278. - KlassHandle host_klass, TRAPS) {
  1279. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  1280. instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
  1281. return ikk->allocate_instance_klass(name, vtable_len, itable_len,
  1282. static_field_size, nonstatic_oop_map_count,
  1283. - access_flags, rt, host_klass, CHECK_NULL);
  1284. + access_flags, rt, host_klass, old_klass, CHECK_NULL);
  1285. }
  1286. diff --git a/src/share/vm/memory/oopFactory.hpp b/src/share/vm/memory/oopFactory.hpp
  1287. index e7e22d4..ce39ada 100644
  1288. --- a/src/share/vm/memory/oopFactory.hpp
  1289. +++ b/src/share/vm/memory/oopFactory.hpp
  1290. @@ -80,7 +80,7 @@
  1291. unsigned int nonstatic_oop_map_count,
  1292. AccessFlags access_flags,
  1293. ReferenceType rt,
  1294. - KlassHandle host_klass, TRAPS);
  1295. + KlassHandle host_klass, KlassHandle old_klass, TRAPS);
  1296. // Methods
  1297. private:
  1298. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  1299. index f97bc34..c8563b2 100644
  1300. --- a/src/share/vm/memory/space.cpp
  1301. +++ b/src/share/vm/memory/space.cpp
  1302. @@ -378,9 +378,8 @@
  1303. _compaction_top = bottom();
  1304. }
  1305. -HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1306. - CompactPoint* cp, HeapWord* compact_top) {
  1307. - // q is alive
  1308. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  1309. +HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
  1310. // First check if we should switch compaction space
  1311. assert(this == cp->space, "'this' should be current compaction space.");
  1312. size_t compaction_max_size = pointer_delta(end(), compact_top);
  1313. @@ -400,8 +399,15 @@
  1314. compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  1315. }
  1316. + return compact_top;
  1317. +}
  1318. +
  1319. +HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1320. + CompactPoint* cp, HeapWord* compact_top) {
  1321. + compact_top = forward_compact_top(size, cp, compact_top);
  1322. +
  1323. // store the forwarding pointer into the mark word
  1324. - if ((HeapWord*)q != compact_top) {
  1325. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  1326. q->forward_to(oop(compact_top));
  1327. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  1328. } else {
  1329. @@ -423,6 +429,58 @@
  1330. return compact_top;
  1331. }
  1332. +// Compute the forward sizes and leave out objects whose position could
  1333. +// possibly overlap other objects.
  1334. +HeapWord* CompactibleSpace::forward_with_rescue(oop q, size_t size,
  1335. + CompactPoint* cp, HeapWord* compact_top) {
  1336. + size_t forward_size = size;
  1337. +
  1338. + // (DCEVM) There is a new version of the class of q => different size
  1339. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1340. +
  1341. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1342. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1343. + forward_size = new_size;
  1344. + }
  1345. +
  1346. + compact_top = forward_compact_top(forward_size, cp, compact_top);
  1347. +
  1348. + if (must_rescue(oop(q), oop(compact_top))) {
  1349. + if (MarkSweep::_rescued_oops == NULL) {
  1350. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1351. + }
  1352. + MarkSweep::_rescued_oops->append(oop(q));
  1353. + return compact_top;
  1354. + }
  1355. +
  1356. + return forward(q, forward_size, cp, compact_top);
  1357. +}
  1358. +
  1359. +// Compute the forwarding addresses for the objects that need to be rescued.
  1360. +HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
  1361. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  1362. + if (MarkSweep::_rescued_oops != NULL) {
  1363. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  1364. + oop q = MarkSweep::_rescued_oops->at(i);
  1365. +
  1366. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  1367. + size_t size = block_size((HeapWord*)q);
  1368. +
  1369. + // (tw) There is a new version of the class of q => different size
  1370. + if (oop(q)->blueprint()->new_version() != NULL) {
  1371. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1372. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1373. + size = new_size;
  1374. + }
  1375. +
  1376. + compact_top = cp->space->forward(oop(q), size, cp, compact_top);
  1377. + assert(compact_top <= end(), "must not write over end of space!");
  1378. + }
  1379. + MarkSweep::_rescued_oops->clear();
  1380. + MarkSweep::_rescued_oops = NULL;
  1381. + }
  1382. + return compact_top;
  1383. +}
  1384. bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1385. HeapWord* q, size_t deadlength) {
  1386. @@ -444,12 +502,17 @@
  1387. #define adjust_obj_size(s) s
  1388. void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  1389. - SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
  1390. + SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
  1391. }
  1392. // Faster object search.
  1393. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  1394. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  1395. + if (!Universe::is_redefining_gc_run()) {
  1396. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
  1397. + } else {
  1398. + // Redefinition run
  1399. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
  1400. + }
  1401. }
  1402. void Space::adjust_pointers() {
  1403. @@ -490,6 +553,111 @@
  1404. assert(q == t, "just checking");
  1405. }
  1406. +
  1407. +#ifdef ASSERT
  1408. +
  1409. +int CompactibleSpace::space_index(oop obj) {
  1410. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  1411. +
  1412. + if (heap->is_in_permanent(obj)) {
  1413. + return -1;
  1414. + }
  1415. +
  1416. + int index = 0;
  1417. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1418. + Generation* gen = heap->get_gen(i);
  1419. + CompactibleSpace* space = gen->first_compaction_space();
  1420. + while (space != NULL) {
  1421. + if (space->is_in_reserved(obj)) {
  1422. + return index;
  1423. + }
  1424. + space = space->next_compaction_space();
  1425. + index++;
  1426. + }
  1427. + }
  1428. +
  1429. + tty->print_cr("could not compute space_index for %08xh", obj);
  1430. + index = 0;
  1431. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1432. + Generation* gen = heap->get_gen(i);
  1433. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  1434. +
  1435. + CompactibleSpace* space = gen->first_compaction_space();
  1436. + while (space != NULL) {
  1437. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  1438. + space = space->next_compaction_space();
  1439. + index++;
  1440. + }
  1441. + }
  1442. +
  1443. + ShouldNotReachHere();
  1444. + return 0;
  1445. +}
  1446. +#endif
  1447. +
  1448. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  1449. + // Only redefined objects can have the need to be rescued.
  1450. + if (oop(old_obj)->blueprint()->new_version() == NULL) return false;
  1451. +
  1452. + if (old_obj->is_perm()) {
  1453. + // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
  1454. + return true;
  1455. + }
  1456. +
  1457. + int new_size = old_obj->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  1458. + int original_size = old_obj->size();
  1459. +
  1460. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  1461. + bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
  1462. + bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
  1463. + if (old_in_tenured == new_in_tenured) {
  1464. + // Rescue if object may overlap with a higher memory address.
  1465. + bool overlap = (old_obj + original_size < new_obj + new_size);
  1466. + if (old_in_tenured) {
  1467. + // Old and new address are in same space, so just compare the address.
  1468. + // Must rescue if object moves towards the top of the space.
  1469. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  1470. + } else {
  1471. + // In the new generation, eden is located before the from space, so a
  1472. + // simple pointer comparison is sufficient.
  1473. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1474. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1475. + assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  1476. + }
  1477. + return overlap;
  1478. +
  1479. + } else {
  1480. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  1481. + if (tenured_gen->is_in_reserved(new_obj)) {
  1482. + // Must never rescue when moving from the new into the old generation.
  1483. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1484. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  1485. + return false;
  1486. +
  1487. + } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
  1488. + // Must always rescue when moving from the old into the new generation.
  1489. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1490. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  1491. + return true;
  1492. + }
  1493. + }
  1494. +}
  1495. +
  1496. +oop CompactibleSpace::rescue(oop old_obj) {
  1497. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  1498. +
  1499. + int size = old_obj->size();
  1500. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1501. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  1502. +
  1503. + if (MarkSweep::_rescued_oops == NULL) {
  1504. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1505. + }
  1506. +
  1507. + MarkSweep::_rescued_oops->append(rescued_obj);
  1508. + return rescued_obj;
  1509. +}
  1510. +
  1511. void CompactibleSpace::adjust_pointers() {
  1512. // Check first is there is any work to do.
  1513. if (used() == 0) {
  1514. @@ -500,7 +668,13 @@
  1515. }
  1516. void CompactibleSpace::compact() {
  1517. - SCAN_AND_COMPACT(obj_size);
  1518. +
  1519. + if(!Universe::is_redefining_gc_run()) {
  1520. + SCAN_AND_COMPACT(obj_size, false);
  1521. + } else {
  1522. + // Redefinition run
  1523. + SCAN_AND_COMPACT(obj_size, true)
  1524. + }
  1525. }
  1526. void Space::print_short() const { print_short_on(tty); }
  1527. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  1528. index ef2f2c6..ff95a8b 100644
  1529. --- a/src/share/vm/memory/space.hpp
  1530. +++ b/src/share/vm/memory/space.hpp
  1531. @@ -445,6 +445,9 @@
  1532. // indicates when the next such action should be taken.
  1533. virtual void prepare_for_compaction(CompactPoint* cp);
  1534. // MarkSweep support phase3
  1535. + DEBUG_ONLY(int space_index(oop obj));
  1536. + bool must_rescue(oop old_obj, oop new_obj);
  1537. + oop rescue(oop old_obj);
  1538. virtual void adjust_pointers();
  1539. // MarkSweep support phase4
  1540. virtual void compact();
  1541. @@ -474,6 +477,15 @@
  1542. // accordingly".
  1543. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  1544. HeapWord* compact_top);
  1545. + // (DCEVM) same as forwad, but can rescue objects. Invoked only during
  1546. + // redefinition runs
  1547. + HeapWord* forward_with_rescue(oop q, size_t size, CompactPoint* cp,
  1548. + HeapWord* compact_top);
  1549. +
  1550. + HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
  1551. +
  1552. + // (tw) Compute new compact top without actually forwarding the object.
  1553. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1554. // Return a size with adjusments as required of the space.
  1555. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  1556. @@ -504,7 +516,7 @@
  1557. size_t word_len);
  1558. };
  1559. -#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
  1560. +#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
  1561. /* Compute the new addresses for the live objects and store it in the mark \
  1562. * Used by universe::mark_sweep_phase2() \
  1563. */ \
  1564. @@ -564,7 +576,17 @@
  1565. Prefetch::write(q, interval); \
  1566. /* size_t size = oop(q)->size(); changing this for cms for perm gen */\
  1567. size_t size = block_size(q); \
  1568. - compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1569. + if (redefinition_run) { \
  1570. + compact_top = cp->space->forward_with_rescue(oop(q), size, \
  1571. + cp, compact_top); \
  1572. + if (q < first_dead && oop(q)->is_gc_marked()) { \
  1573. + /* Was moved (otherwise, forward would reset mark), \
  1574. + set first_dead to here */ \
  1575. + first_dead = q; \
  1576. + } \
  1577. + } else { \
  1578. + compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1579. + } \
  1580. q += size; \
  1581. end_of_live = q; \
  1582. } else { \
  1583. @@ -612,6 +634,8 @@
  1584. q = end; \
  1585. } \
  1586. } \
  1587. + \
  1588. + if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
  1589. \
  1590. assert(q == t, "just checking"); \
  1591. if (liveRange != NULL) { \
  1592. @@ -665,13 +689,8 @@
  1593. q += size; \
  1594. } \
  1595. \
  1596. - if (_first_dead == t) { \
  1597. - q = t; \
  1598. - } else { \
  1599. - /* $$$ This is funky. Using this to read the previously written \
  1600. - * LiveRange. See also use below. */ \
  1601. - q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
  1602. - } \
  1603. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1604. + q = _first_dead; \
  1605. } \
  1606. \
  1607. const intx interval = PrefetchScanIntervalInBytes; \
  1608. @@ -702,7 +721,7 @@
  1609. assert(q == t, "just checking"); \
  1610. }
  1611. -#define SCAN_AND_COMPACT(obj_size) { \
  1612. +#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
  1613. /* Copy all live objects to their new location \
  1614. * Used by MarkSweep::mark_sweep_phase4() */ \
  1615. \
  1616. @@ -728,12 +747,8 @@
  1617. } \
  1618. ) /* debug_only */ \
  1619. \
  1620. - if (_first_dead == t) { \
  1621. - q = t; \
  1622. - } else { \
  1623. - /* $$$ Funky */ \
  1624. - q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
  1625. - } \
  1626. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1627. + q = _first_dead; \
  1628. } \
  1629. \
  1630. const intx scan_interval = PrefetchScanIntervalInBytes; \
  1631. @@ -752,13 +767,36 @@
  1632. size_t size = obj_size(q); \
  1633. HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
  1634. \
  1635. + if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
  1636. + oop dest_obj = rescue(oop(q)); \
  1637. + debug_only(Copy::fill_to_words(q, size, 0)); \
  1638. + q += size; \
  1639. + continue; \
  1640. + } \
  1641. + \
  1642. /* prefetch beyond compaction_top */ \
  1643. Prefetch::write(compaction_top, copy_interval); \
  1644. \
  1645. /* copy object and reinit its mark */ \
  1646. VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, \
  1647. compaction_top)); \
  1648. - assert(q != compaction_top, "everything in this pass should be moving"); \
  1649. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, \
  1650. + "everything in this pass should be moving"); \
  1651. + if (redefinition_run && oop(q)->blueprint()->new_version() != NULL) { \
  1652. + klassOop new_version = oop(q)->blueprint()->new_version(); \
  1653. + if (new_version->klass_part()->update_information() == NULL) { \
  1654. + Copy::aligned_conjoint_words(q, compaction_top, size); \
  1655. + oop(compaction_top)->set_klass_no_check(new_version); \
  1656. + } else { \
  1657. + MarkSweep::update_fields(oop(q), oop(compaction_top)); \
  1658. + } \
  1659. + oop(compaction_top)->init_mark(); \
  1660. + assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1661. + \
  1662. + debug_only(prev_q = q); \
  1663. + q += size; \
  1664. + continue; \
  1665. + } \
  1666. Copy::aligned_conjoint_words(q, compaction_top, size); \
  1667. oop(compaction_top)->init_mark(); \
  1668. assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1669. diff --git a/src/share/vm/memory/specialized_oop_closures.hpp b/src/share/vm/memory/specialized_oop_closures.hpp
  1670. index 4d7c50b..671787e 100644
  1671. --- a/src/share/vm/memory/specialized_oop_closures.hpp
  1672. +++ b/src/share/vm/memory/specialized_oop_closures.hpp
  1673. @@ -37,6 +37,7 @@
  1674. // Forward declarations.
  1675. class OopClosure;
  1676. +class OopClosureNoHeader;
  1677. class OopsInGenClosure;
  1678. // DefNew
  1679. class ScanClosure;
  1680. @@ -74,6 +75,7 @@
  1681. #endif
  1682. #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
  1683. + f(OopClosureNoHeader,_v) \
  1684. f(ScanClosure,_nv) \
  1685. f(FastScanClosure,_nv) \
  1686. f(FilteringClosure,_nv)
  1687. @@ -132,6 +134,7 @@
  1688. #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
  1689. f(OopClosure,_v) \
  1690. + f(OopClosureNoHeader,_v) \
  1691. SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
  1692. #endif // SERIALGC
  1693. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  1694. index 4030d9d..052fb27 100644
  1695. --- a/src/share/vm/memory/universe.cpp
  1696. +++ b/src/share/vm/memory/universe.cpp
  1697. @@ -100,6 +100,8 @@
  1698. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  1699. #endif
  1700. +bool Universe::_is_redefining_gc_run = false;
  1701. +
  1702. // Known objects
  1703. klassOop Universe::_boolArrayKlassObj = NULL;
  1704. klassOop Universe::_byteArrayKlassObj = NULL;
  1705. @@ -202,6 +204,42 @@
  1706. f(instanceKlassKlassObj());
  1707. f(constantPoolKlassObj());
  1708. f(systemObjArrayKlassObj());
  1709. +}
  1710. +
  1711. +// (tw) This method should iterate all pointers that are not within heap objects.
  1712. +void Universe::root_oops_do(OopClosure *oopClosure) {
  1713. +
  1714. + class AlwaysTrueClosure: public BoolObjectClosure {
  1715. + public:
  1716. + void do_object(oop p) { ShouldNotReachHere(); }
  1717. + bool do_object_b(oop p) { return true; }
  1718. + };
  1719. + AlwaysTrueClosure always_true;
  1720. +
  1721. + Universe::oops_do(oopClosure);
  1722. +// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
  1723. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  1724. + Threads::oops_do(oopClosure, NULL);
  1725. + ObjectSynchronizer::oops_do(oopClosure);
  1726. + FlatProfiler::oops_do(oopClosure);
  1727. + JvmtiExport::oops_do(oopClosure);
  1728. +
  1729. + // Now adjust pointers in remaining weak roots. (All of which should
  1730. + // have been cleared if they pointed to non-surviving objects.)
  1731. + // Global (weak) JNI handles
  1732. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  1733. +
  1734. + CodeCache::oops_do(oopClosure);
  1735. + StringTable::oops_do(oopClosure);
  1736. +
  1737. + // (tw) TODO: Check if this is correct?
  1738. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  1739. + //Management::oops_do(oopClosure);
  1740. + //ref_processor()->weak_oops_do(&oopClosure);
  1741. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  1742. +
  1743. + // SO_AllClasses
  1744. + SystemDictionary::oops_do(oopClosure);
  1745. }
  1746. void Universe::oops_do(OopClosure* f, bool do_all) {
  1747. @@ -1599,10 +1637,9 @@
  1748. }
  1749. // RC_TRACE macro has an embedded ResourceMark
  1750. - RC_TRACE(0x00000100,
  1751. - ("add: %s(%s): adding prev version ref for cached method @%d",
  1752. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  1753. method->name()->as_C_string(), method->signature()->as_C_string(),
  1754. - _prev_methods->length()));
  1755. + _prev_methods->length());
  1756. methodHandle method_h(method);
  1757. jweak method_ref = JNIHandles::make_weak_global(method_h);
  1758. @@ -1629,9 +1666,8 @@
  1759. JNIHandles::destroy_weak_global(method_ref);
  1760. _prev_methods->remove_at(i);
  1761. } else {
  1762. - // RC_TRACE macro has an embedded ResourceMark
  1763. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  1764. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  1765. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  1766. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  1767. }
  1768. }
  1769. } // end add_previous_version()
  1770. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  1771. index 50fcb62..afb6b33 100644
  1772. --- a/src/share/vm/memory/universe.hpp
  1773. +++ b/src/share/vm/memory/universe.hpp
  1774. @@ -127,6 +127,8 @@
  1775. friend class SystemDictionary;
  1776. friend class VMStructs;
  1777. friend class CompactingPermGenGen;
  1778. + friend class Space;
  1779. + friend class ContiguousSpace;
  1780. friend class VM_PopulateDumpSharedSpace;
  1781. friend jint universe_init();
  1782. @@ -258,7 +260,18 @@
  1783. static void compute_verify_oop_data();
  1784. + static bool _is_redefining_gc_run;
  1785. +
  1786. public:
  1787. +
  1788. + static bool is_redefining_gc_run() {
  1789. + return _is_redefining_gc_run;
  1790. + }
  1791. +
  1792. + static void set_redefining_gc_run(bool b) {
  1793. + _is_redefining_gc_run = b;
  1794. + }
  1795. +
  1796. // Known classes in the VM
  1797. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  1798. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  1799. @@ -403,6 +416,8 @@
  1800. // Iteration
  1801. + static void root_oops_do(OopClosure *f);
  1802. +
  1803. // Apply "f" to the addresses of all the direct heap pointers maintained
  1804. // as static fields of "Universe".
  1805. static void oops_do(OopClosure* f, bool do_all = false);
  1806. @@ -419,6 +434,7 @@
  1807. // Debugging
  1808. static bool verify_in_progress() { return _verify_in_progress; }
  1809. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  1810. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  1811. static void verify(const char* prefix, bool silent = VerifySilently) {
  1812. verify(VerifyOption_Default, prefix, silent);
  1813. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  1814. index ad62921..79f509c 100644
  1815. --- a/src/share/vm/oops/cpCacheOop.cpp
  1816. +++ b/src/share/vm/oops/cpCacheOop.cpp
  1817. @@ -40,6 +40,11 @@
  1818. void ConstantPoolCacheEntry::initialize_entry(int index) {
  1819. assert(0 < index && index < 0x10000, "sanity check");
  1820. _indices = index;
  1821. +// (DCEVM) Should put something else to force JVM to fail if these invalid entries are accessed!
  1822. +//#ifdef ASSERT
  1823. + _f1 = NULL;
  1824. + _f2 = 0;
  1825. +//#endif
  1826. assert(constant_pool_index() == index, "");
  1827. }
  1828. @@ -162,7 +167,8 @@
  1829. int vtable_index) {
  1830. assert(!is_secondary_entry(), "");
  1831. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  1832. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1833. + // (tw) No longer valid assert
  1834. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1835. int byte_no = -1;
  1836. bool change_to_virtual = false;
  1837. @@ -516,116 +522,6 @@
  1838. }
  1839. #endif // SERIALGC
  1840. -// RedefineClasses() API support:
  1841. -// If this constantPoolCacheEntry refers to old_method then update it
  1842. -// to refer to new_method.
  1843. -bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  1844. - methodOop new_method, bool * trace_name_printed) {
  1845. -
  1846. - if (is_vfinal()) {
  1847. - // virtual and final so _f2 contains method ptr instead of vtable index
  1848. - if (f2_as_vfinal_method() == old_method) {
  1849. - // match old_method so need an update
  1850. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  1851. - _f2 = (intptr_t)new_method;
  1852. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1853. - if (!(*trace_name_printed)) {
  1854. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1855. - RC_TRACE_MESG(("adjust: name=%s",
  1856. - Klass::cast(old_method->method_holder())->external_name()));
  1857. - *trace_name_printed = true;
  1858. - }
  1859. - // RC_TRACE macro has an embedded ResourceMark
  1860. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  1861. - new_method->name()->as_C_string(),
  1862. - new_method->signature()->as_C_string()));
  1863. - }
  1864. -
  1865. - return true;
  1866. - }
  1867. -
  1868. - // f1() is not used with virtual entries so bail out
  1869. - return false;
  1870. - }
  1871. -
  1872. - if ((oop)_f1 == NULL) {
  1873. - // NULL f1() means this is a virtual entry so bail out
  1874. - // We are assuming that the vtable index does not need change.
  1875. - return false;
  1876. - }
  1877. -
  1878. - if ((oop)_f1 == old_method) {
  1879. - _f1 = new_method;
  1880. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1881. - if (!(*trace_name_printed)) {
  1882. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1883. - RC_TRACE_MESG(("adjust: name=%s",
  1884. - Klass::cast(old_method->method_holder())->external_name()));
  1885. - *trace_name_printed = true;
  1886. - }
  1887. - // RC_TRACE macro has an embedded ResourceMark
  1888. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  1889. - new_method->name()->as_C_string(),
  1890. - new_method->signature()->as_C_string()));
  1891. - }
  1892. -
  1893. - return true;
  1894. - }
  1895. -
  1896. - return false;
  1897. -}
  1898. -
  1899. -// a constant pool cache entry should never contain old or obsolete methods
  1900. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  1901. - if (is_vfinal()) {
  1902. - // virtual and final so _f2 contains method ptr instead of vtable index
  1903. - methodOop m = (methodOop)_f2;
  1904. - // Return false if _f2 refers to an old or an obsolete method.
  1905. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  1906. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  1907. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  1908. - // _f1 == NULL || !_f1->is_method() are OK here
  1909. - return true;
  1910. - }
  1911. -
  1912. - methodOop m = (methodOop)_f1;
  1913. - // return false if _f1 refers to an old or an obsolete method
  1914. - return (!m->is_old() && !m->is_obsolete());
  1915. -}
  1916. -
  1917. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  1918. - if (!is_method_entry()) {
  1919. - // not a method entry so not interesting by default
  1920. - return false;
  1921. - }
  1922. -
  1923. - methodOop m = NULL;
  1924. - if (is_vfinal()) {
  1925. - // virtual and final so _f2 contains method ptr instead of vtable index
  1926. - m = f2_as_vfinal_method();
  1927. - } else if (is_f1_null()) {
  1928. - // NULL _f1 means this is a virtual entry so also not interesting
  1929. - return false;
  1930. - } else {
  1931. - oop f1 = _f1; // _f1 is volatile
  1932. - if (!f1->is_method()) {
  1933. - // _f1 can also contain a klassOop for an interface
  1934. - return false;
  1935. - }
  1936. - m = f1_as_method();
  1937. - }
  1938. -
  1939. - assert(m != NULL && m->is_method(), "sanity check");
  1940. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  1941. - // robustness for above sanity checks or method is not in
  1942. - // the interesting class
  1943. - return false;
  1944. - }
  1945. -
  1946. - // the method is in the interesting class so the entry is interesting
  1947. - return true;
  1948. -}
  1949. -
  1950. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  1951. // print separator
  1952. if (index == 0) st->print_cr(" -------------");
  1953. @@ -663,60 +559,12 @@
  1954. }
  1955. }
  1956. -// RedefineClasses() API support:
  1957. -// If any entry of this constantPoolCache points to any of
  1958. -// old_methods, replace it with the corresponding new_method.
  1959. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  1960. - int methods_length, bool * trace_name_printed) {
  1961. -
  1962. - if (methods_length == 0) {
  1963. - // nothing to do if there are no methods
  1964. - return;
  1965. - }
  1966. -
  1967. - // get shorthand for the interesting class
  1968. - klassOop old_holder = old_methods[0]->method_holder();
  1969. +void constantPoolCacheOopDesc::adjust_entries() {
  1970. for (int i = 0; i < length(); i++) {
  1971. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  1972. - // skip uninteresting methods
  1973. - continue;
  1974. - }
  1975. -
  1976. - // The constantPoolCache contains entries for several different
  1977. - // things, but we only care about methods. In fact, we only care
  1978. - // about methods in the same class as the one that contains the
  1979. - // old_methods. At this point, we have an interesting entry.
  1980. -
  1981. - for (int j = 0; j < methods_length; j++) {
  1982. - methodOop old_method = old_methods[j];
  1983. - methodOop new_method = new_methods[j];
  1984. -
  1985. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  1986. - trace_name_printed)) {
  1987. - // current old_method matched this entry and we updated it so
  1988. - // break out and get to the next interesting entry if there one
  1989. - break;
  1990. - }
  1991. - }
  1992. + if (!entry_at(i)->is_secondary_entry()) {
  1993. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  1994. + }
  1995. }
  1996. }
  1997. -// the constant pool cache should never contain old or obsolete methods
  1998. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  1999. - for (int i = 1; i < length(); i++) {
  2000. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  2001. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  2002. - return false;
  2003. - }
  2004. - }
  2005. - return true;
  2006. -}
  2007. -
  2008. -void constantPoolCacheOopDesc::dump_cache() {
  2009. - for (int i = 1; i < length(); i++) {
  2010. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  2011. - entry_at(i)->print(tty, i);
  2012. - }
  2013. - }
  2014. -}
  2015. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  2016. index b9107cd..79d3e5b 100644
  2017. --- a/src/share/vm/oops/cpCacheOop.hpp
  2018. +++ b/src/share/vm/oops/cpCacheOop.hpp
  2019. @@ -362,17 +362,6 @@
  2020. void update_pointers();
  2021. - // RedefineClasses() API support:
  2022. - // If this constantPoolCacheEntry refers to old_method then update it
  2023. - // to refer to new_method.
  2024. - // trace_name_printed is set to true if the current call has
  2025. - // printed the klass name so that other routines in the adjust_*
  2026. - // group don't print the klass name.
  2027. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  2028. - bool * trace_name_printed);
  2029. - bool check_no_old_or_obsolete_entries();
  2030. - bool is_interesting_method_entry(klassOop k);
  2031. -
  2032. // Debugging & Printing
  2033. void print (outputStream* st, int index) const;
  2034. void verify(outputStream* st) const;
  2035. @@ -492,16 +481,8 @@
  2036. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  2037. }
  2038. - // RedefineClasses() API support:
  2039. - // If any entry of this constantPoolCache points to any of
  2040. - // old_methods, replace it with the corresponding new_method.
  2041. - // trace_name_printed is set to true if the current call has
  2042. - // printed the klass name so that other routines in the adjust_*
  2043. - // group don't print the klass name.
  2044. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  2045. - int methods_length, bool * trace_name_printed);
  2046. - bool check_no_old_or_obsolete_entries();
  2047. - void dump_cache();
  2048. + // (tw) Clear references to methods and fields from this cache.
  2049. + void adjust_entries();
  2050. };
  2051. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  2052. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  2053. index a775b02..2667644 100644
  2054. --- a/src/share/vm/oops/instanceKlass.cpp
  2055. +++ b/src/share/vm/oops/instanceKlass.cpp
  2056. @@ -255,7 +255,7 @@
  2057. // 1) Verify the bytecodes
  2058. Verifier::Mode mode =
  2059. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  2060. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  2061. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  2062. }
  2063. @@ -362,7 +362,13 @@
  2064. jt->get_thread_stat()->perf_recursion_counts_addr(),
  2065. jt->get_thread_stat()->perf_timers_addr(),
  2066. PerfClassTraceTime::CLASS_VERIFY);
  2067. + if (this_oop->is_redefining()) {
  2068. + Thread::current()->set_pretend_new_universe(true);
  2069. + }
  2070. bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  2071. + if (this_oop->is_redefining()) {
  2072. + Thread::current()->set_pretend_new_universe(false);
  2073. + }
  2074. if (!verify_ok) {
  2075. return false;
  2076. }
  2077. @@ -400,7 +406,8 @@
  2078. }
  2079. #endif
  2080. this_oop->set_init_state(linked);
  2081. - if (JvmtiExport::should_post_class_prepare()) {
  2082. + // (tw) Must check for old version in order to prevent infinite loops.
  2083. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  2084. Thread *thread = THREAD;
  2085. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  2086. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  2087. @@ -454,7 +461,9 @@
  2088. // If we were to use wait() instead of waitInterruptibly() then
  2089. // we might end up throwing IE from link/symbol resolution sites
  2090. // that aren't expected to throw. This would wreak havoc. See 6320309.
  2091. - while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
  2092. + // (tw) Wait also for the old class version to be fully initialized.
  2093. + while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
  2094. + || (this_oop->old_version() != NULL && ((instanceKlass*)this_oop->old_version()->klass_part())->is_being_initialized())) {
  2095. wait = true;
  2096. ol.waitUninterruptibly(CHECK);
  2097. }
  2098. @@ -667,6 +676,18 @@
  2099. assert(Klass::cast(k)->is_interface(), "should be an interface class");
  2100. for (int i = 0; i < transitive_interfaces()->length(); i++) {
  2101. if (transitive_interfaces()->obj_at(i) == k) {
  2102. + return true;
  2103. + }
  2104. + }
  2105. + return false;
  2106. +}
  2107. +
  2108. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  2109. + k = k->klass_part()->newest_version();
  2110. + if (this->newest_version() == k) return true;
  2111. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  2112. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  2113. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  2114. return true;
  2115. }
  2116. }
  2117. @@ -949,6 +970,18 @@
  2118. }
  2119. }
  2120. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  2121. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  2122. + for (int i=0; i<values.length(); i++) {
  2123. + arr[i] = values.at(i);
  2124. + }
  2125. + set_update_information(arr);
  2126. +}
  2127. +
  2128. +void instanceKlass::clear_update_information() {
  2129. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  2130. + set_update_information(NULL);
  2131. +}
  2132. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  2133. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  2134. @@ -1368,6 +1401,20 @@
  2135. return id;
  2136. }
  2137. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  2138. + size_t idnum = (size_t)method->method_idnum();
  2139. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  2140. + size_t length; // length assigned as debugging crumb
  2141. + jmethodID id = NULL;
  2142. + if (jmeths != NULL && // If there is a cache
  2143. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  2144. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  2145. + return true;
  2146. + }
  2147. +
  2148. + return false;
  2149. +}
  2150. +
  2151. // Cache an itable index
  2152. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  2153. @@ -1527,6 +1574,13 @@
  2154. last = b;
  2155. b = b->next();
  2156. }
  2157. +
  2158. + // (tw) Hack as dependencies get wrong version of klassOop
  2159. + if(this->old_version() != NULL) {
  2160. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  2161. + return;
  2162. + }
  2163. +
  2164. #ifdef ASSERT
  2165. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  2166. nm->print();
  2167. @@ -1931,16 +1985,6 @@
  2168. if (breakpoints() != 0x0) {
  2169. methods_do(clear_all_breakpoints);
  2170. assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2171. - }
  2172. -
  2173. - // deallocate information about previous versions
  2174. - if (_previous_versions != NULL) {
  2175. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2176. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2177. - delete pv_node;
  2178. - }
  2179. - delete _previous_versions;
  2180. - _previous_versions = NULL;
  2181. }
  2182. // deallocate the cached class file
  2183. @@ -2580,275 +2624,10 @@
  2184. }
  2185. #endif
  2186. -
  2187. -// RedefineClasses() support for previous versions:
  2188. -
  2189. -// Add an information node that contains weak references to the
  2190. -// interesting parts of the previous version of the_class.
  2191. -// This is also where we clean out any unused weak references.
  2192. -// Note that while we delete nodes from the _previous_versions
  2193. -// array, we never delete the array itself until the klass is
  2194. -// unloaded. The has_been_redefined() query depends on that fact.
  2195. -//
  2196. -void instanceKlass::add_previous_version(instanceKlassHandle ikh,
  2197. - BitMap* emcp_methods, int emcp_method_count) {
  2198. - assert(Thread::current()->is_VM_thread(),
  2199. - "only VMThread can add previous versions");
  2200. -
  2201. - if (_previous_versions == NULL) {
  2202. - // This is the first previous version so make some space.
  2203. - // Start with 2 elements under the assumption that the class
  2204. - // won't be redefined much.
  2205. - _previous_versions = new (ResourceObj::C_HEAP, mtClass)
  2206. - GrowableArray<PreviousVersionNode *>(2, true);
  2207. - }
  2208. -
  2209. - // RC_TRACE macro has an embedded ResourceMark
  2210. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  2211. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  2212. - constantPoolHandle cp_h(ikh->constants());
  2213. - jobject cp_ref;
  2214. - if (cp_h->is_shared()) {
  2215. - // a shared ConstantPool requires a regular reference; a weak
  2216. - // reference would be collectible
  2217. - cp_ref = JNIHandles::make_global(cp_h);
  2218. - } else {
  2219. - cp_ref = JNIHandles::make_weak_global(cp_h);
  2220. - }
  2221. - PreviousVersionNode * pv_node = NULL;
  2222. - objArrayOop old_methods = ikh->methods();
  2223. -
  2224. - if (emcp_method_count == 0) {
  2225. - // non-shared ConstantPool gets a weak reference
  2226. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  2227. - RC_TRACE(0x00000400,
  2228. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  2229. - } else {
  2230. - int local_count = 0;
  2231. - GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass)
  2232. - GrowableArray<jweak>(emcp_method_count, true);
  2233. - for (int i = 0; i < old_methods->length(); i++) {
  2234. - if (emcp_methods->at(i)) {
  2235. - // this old method is EMCP so save a weak ref
  2236. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2237. - methodHandle old_method_h(old_method);
  2238. - jweak method_ref = JNIHandles::make_weak_global(old_method_h);
  2239. - method_refs->append(method_ref);
  2240. - if (++local_count >= emcp_method_count) {
  2241. - // no more EMCP methods so bail out now
  2242. - break;
  2243. - }
  2244. - }
  2245. - }
  2246. - // non-shared ConstantPool gets a weak reference
  2247. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs);
  2248. - }
  2249. -
  2250. - _previous_versions->append(pv_node);
  2251. -
  2252. - // Using weak references allows the interesting parts of previous
  2253. - // classes to be GC'ed when they are no longer needed. Since the
  2254. - // caller is the VMThread and we are at a safepoint, this is a good
  2255. - // time to clear out unused weak references.
  2256. -
  2257. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  2258. - _previous_versions->length()));
  2259. -
  2260. - // skip the last entry since we just added it
  2261. - for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  2262. - // check the previous versions array for a GC'ed weak refs
  2263. - pv_node = _previous_versions->at(i);
  2264. - cp_ref = pv_node->prev_constant_pool();
  2265. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2266. - if (cp_ref == NULL) {
  2267. - delete pv_node;
  2268. - _previous_versions->remove_at(i);
  2269. - // Since we are traversing the array backwards, we don't have to
  2270. - // do anything special with the index.
  2271. - continue; // robustness
  2272. - }
  2273. -
  2274. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2275. - if (cp == NULL) {
  2276. - // this entry has been GC'ed so remove it
  2277. - delete pv_node;
  2278. - _previous_versions->remove_at(i);
  2279. - // Since we are traversing the array backwards, we don't have to
  2280. - // do anything special with the index.
  2281. - continue;
  2282. - } else {
  2283. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  2284. - }
  2285. -
  2286. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2287. - if (method_refs != NULL) {
  2288. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  2289. - method_refs->length()));
  2290. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  2291. - jweak method_ref = method_refs->at(j);
  2292. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2293. - if (method_ref == NULL) {
  2294. - method_refs->remove_at(j);
  2295. - // Since we are traversing the array backwards, we don't have to
  2296. - // do anything special with the index.
  2297. - continue; // robustness
  2298. - }
  2299. -
  2300. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2301. - if (method == NULL || emcp_method_count == 0) {
  2302. - // This method entry has been GC'ed or the current
  2303. - // RedefineClasses() call has made all methods obsolete
  2304. - // so remove it.
  2305. - JNIHandles::destroy_weak_global(method_ref);
  2306. - method_refs->remove_at(j);
  2307. - } else {
  2308. - // RC_TRACE macro has an embedded ResourceMark
  2309. - RC_TRACE(0x00000400,
  2310. - ("add: %s(%s): previous method @%d in version @%d is alive",
  2311. - method->name()->as_C_string(), method->signature()->as_C_string(),
  2312. - j, i));
  2313. - }
  2314. - }
  2315. - }
  2316. - }
  2317. -
  2318. - int obsolete_method_count = old_methods->length() - emcp_method_count;
  2319. -
  2320. - if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  2321. - _previous_versions->length() > 1) {
  2322. - // We have a mix of obsolete and EMCP methods. If there is more
  2323. - // than the previous version that we just added, then we have to
  2324. - // clear out any matching EMCP method entries the hard way.
  2325. - int local_count = 0;
  2326. - for (int i = 0; i < old_methods->length(); i++) {
  2327. - if (!emcp_methods->at(i)) {
  2328. - // only obsolete methods are interesting
  2329. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2330. - Symbol* m_name = old_method->name();
  2331. - Symbol* m_signature = old_method->signature();
  2332. -
  2333. - // skip the last entry since we just added it
  2334. - for (int j = _previous_versions->length() - 2; j >= 0; j--) {
  2335. - // check the previous versions array for a GC'ed weak refs
  2336. - pv_node = _previous_versions->at(j);
  2337. - cp_ref = pv_node->prev_constant_pool();
  2338. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2339. - if (cp_ref == NULL) {
  2340. - delete pv_node;
  2341. - _previous_versions->remove_at(j);
  2342. - // Since we are traversing the array backwards, we don't have to
  2343. - // do anything special with the index.
  2344. - continue; // robustness
  2345. - }
  2346. -
  2347. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2348. - if (cp == NULL) {
  2349. - // this entry has been GC'ed so remove it
  2350. - delete pv_node;
  2351. - _previous_versions->remove_at(j);
  2352. - // Since we are traversing the array backwards, we don't have to
  2353. - // do anything special with the index.
  2354. - continue;
  2355. - }
  2356. -
  2357. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2358. - if (method_refs == NULL) {
  2359. - // We have run into a PreviousVersion generation where
  2360. - // all methods were made obsolete during that generation's
  2361. - // RedefineClasses() operation. At the time of that
  2362. - // operation, all EMCP methods were flushed so we don't
  2363. - // have to go back any further.
  2364. - //
  2365. - // A NULL method_refs is different than an empty method_refs.
  2366. - // We cannot infer any optimizations about older generations
  2367. - // from an empty method_refs for the current generation.
  2368. - break;
  2369. - }
  2370. -
  2371. - for (int k = method_refs->length() - 1; k >= 0; k--) {
  2372. - jweak method_ref = method_refs->at(k);
  2373. - assert(method_ref != NULL,
  2374. - "weak method ref was unexpectedly cleared");
  2375. - if (method_ref == NULL) {
  2376. - method_refs->remove_at(k);
  2377. - // Since we are traversing the array backwards, we don't
  2378. - // have to do anything special with the index.
  2379. - continue; // robustness
  2380. - }
  2381. -
  2382. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2383. - if (method == NULL) {
  2384. - // this method entry has been GC'ed so skip it
  2385. - JNIHandles::destroy_weak_global(method_ref);
  2386. - method_refs->remove_at(k);
  2387. - continue;
  2388. - }
  2389. -
  2390. - if (method->name() == m_name &&
  2391. - method->signature() == m_signature) {
  2392. - // The current RedefineClasses() call has made all EMCP
  2393. - // versions of this method obsolete so mark it as obsolete
  2394. - // and remove the weak ref.
  2395. - RC_TRACE(0x00000400,
  2396. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  2397. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  2398. -
  2399. - method->set_is_obsolete();
  2400. - JNIHandles::destroy_weak_global(method_ref);
  2401. - method_refs->remove_at(k);
  2402. - break;
  2403. - }
  2404. - }
  2405. -
  2406. - // The previous loop may not find a matching EMCP method, but
  2407. - // that doesn't mean that we can optimize and not go any
  2408. - // further back in the PreviousVersion generations. The EMCP
  2409. - // method for this generation could have already been GC'ed,
  2410. - // but there still may be an older EMCP method that has not
  2411. - // been GC'ed.
  2412. - }
  2413. -
  2414. - if (++local_count >= obsolete_method_count) {
  2415. - // no more obsolete methods so bail out now
  2416. - break;
  2417. - }
  2418. - }
  2419. - }
  2420. - }
  2421. -} // end add_previous_version()
  2422. -
  2423. -
  2424. // Determine if instanceKlass has a previous version.
  2425. bool instanceKlass::has_previous_version() const {
  2426. - if (_previous_versions == NULL) {
  2427. - // no previous versions array so answer is easy
  2428. - return false;
  2429. - }
  2430. -
  2431. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2432. - // Check the previous versions array for an info node that hasn't
  2433. - // been GC'ed
  2434. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2435. -
  2436. - jobject cp_ref = pv_node->prev_constant_pool();
  2437. - assert(cp_ref != NULL, "cp reference was unexpectedly cleared");
  2438. - if (cp_ref == NULL) {
  2439. - continue; // robustness
  2440. - }
  2441. -
  2442. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2443. - if (cp != NULL) {
  2444. - // we have at least one previous version
  2445. - return true;
  2446. - }
  2447. -
  2448. - // We don't have to check the method refs. If the constant pool has
  2449. - // been GC'ed then so have the methods.
  2450. - }
  2451. -
  2452. - // all of the underlying nodes' info has been GC'ed
  2453. - return false;
  2454. -} // end has_previous_version()
  2455. + return _old_version != NULL;
  2456. +}
  2457. methodOop instanceKlass::method_with_idnum(int idnum) {
  2458. methodOop m = NULL;
  2459. @@ -2889,153 +2668,3 @@
  2460. } // if no array and idnum isn't included there is nothing to do
  2461. }
  2462. -// Construct a PreviousVersionNode entry for the array hung off
  2463. -// the instanceKlass.
  2464. -PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool,
  2465. - bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) {
  2466. -
  2467. - _prev_constant_pool = prev_constant_pool;
  2468. - _prev_cp_is_weak = prev_cp_is_weak;
  2469. - _prev_EMCP_methods = prev_EMCP_methods;
  2470. -}
  2471. -
  2472. -
  2473. -// Destroy a PreviousVersionNode
  2474. -PreviousVersionNode::~PreviousVersionNode() {
  2475. - if (_prev_constant_pool != NULL) {
  2476. - if (_prev_cp_is_weak) {
  2477. - JNIHandles::destroy_weak_global(_prev_constant_pool);
  2478. - } else {
  2479. - JNIHandles::destroy_global(_prev_constant_pool);
  2480. - }
  2481. - }
  2482. -
  2483. - if (_prev_EMCP_methods != NULL) {
  2484. - for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) {
  2485. - jweak method_ref = _prev_EMCP_methods->at(i);
  2486. - if (method_ref != NULL) {
  2487. - JNIHandles::destroy_weak_global(method_ref);
  2488. - }
  2489. - }
  2490. - delete _prev_EMCP_methods;
  2491. - }
  2492. -}
  2493. -
  2494. -
  2495. -// Construct a PreviousVersionInfo entry
  2496. -PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) {
  2497. - _prev_constant_pool_handle = constantPoolHandle(); // NULL handle
  2498. - _prev_EMCP_method_handles = NULL;
  2499. -
  2500. - jobject cp_ref = pv_node->prev_constant_pool();
  2501. - assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared");
  2502. - if (cp_ref == NULL) {
  2503. - return; // robustness
  2504. - }
  2505. -
  2506. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2507. - if (cp == NULL) {
  2508. - // Weak reference has been GC'ed. Since the constant pool has been
  2509. - // GC'ed, the methods have also been GC'ed.
  2510. - return;
  2511. - }
  2512. -
  2513. - // make the constantPoolOop safe to return
  2514. - _prev_constant_pool_handle = constantPoolHandle(cp);
  2515. -
  2516. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2517. - if (method_refs == NULL) {
  2518. - // the instanceKlass did not have any EMCP methods
  2519. - return;
  2520. - }
  2521. -
  2522. - _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10);
  2523. -
  2524. - int n_methods = method_refs->length();
  2525. - for (int i = 0; i < n_methods; i++) {
  2526. - jweak method_ref = method_refs->at(i);
  2527. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2528. - if (method_ref == NULL) {
  2529. - continue; // robustness
  2530. - }
  2531. -
  2532. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2533. - if (method == NULL) {
  2534. - // this entry has been GC'ed so skip it
  2535. - continue;
  2536. - }
  2537. -
  2538. - // make the methodOop safe to return
  2539. - _prev_EMCP_method_handles->append(methodHandle(method));
  2540. - }
  2541. -}
  2542. -
  2543. -
  2544. -// Destroy a PreviousVersionInfo
  2545. -PreviousVersionInfo::~PreviousVersionInfo() {
  2546. - // Since _prev_EMCP_method_handles is not C-heap allocated, we
  2547. - // don't have to delete it.
  2548. -}
  2549. -
  2550. -
  2551. -// Construct a helper for walking the previous versions array
  2552. -PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) {
  2553. - _previous_versions = ik->previous_versions();
  2554. - _current_index = 0;
  2555. - // _hm needs no initialization
  2556. - _current_p = NULL;
  2557. -}
  2558. -
  2559. -
  2560. -// Destroy a PreviousVersionWalker
  2561. -PreviousVersionWalker::~PreviousVersionWalker() {
  2562. - // Delete the current info just in case the caller didn't walk to
  2563. - // the end of the previous versions list. No harm if _current_p is
  2564. - // already NULL.
  2565. - delete _current_p;
  2566. -
  2567. - // When _hm is destroyed, all the Handles returned in
  2568. - // PreviousVersionInfo objects will be destroyed.
  2569. - // Also, after this destructor is finished it will be
  2570. - // safe to delete the GrowableArray allocated in the
  2571. - // PreviousVersionInfo objects.
  2572. -}
  2573. -
  2574. -
  2575. -// Return the interesting information for the next previous version
  2576. -// of the klass. Returns NULL if there are no more previous versions.
  2577. -PreviousVersionInfo* PreviousVersionWalker::next_previous_version() {
  2578. - if (_previous_versions == NULL) {
  2579. - // no previous versions so nothing to return
  2580. - return NULL;
  2581. - }
  2582. -
  2583. - delete _current_p; // cleanup the previous info for the caller
  2584. - _current_p = NULL; // reset to NULL so we don't delete same object twice
  2585. -
  2586. - int length = _previous_versions->length();
  2587. -
  2588. - while (_current_index < length) {
  2589. - PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
  2590. - PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass)
  2591. - PreviousVersionInfo(pv_node);
  2592. -
  2593. - constantPoolHandle cp_h = pv_info->prev_constant_pool_handle();
  2594. - if (cp_h.is_null()) {
  2595. - delete pv_info;
  2596. -
  2597. - // The underlying node's info has been GC'ed so try the next one.
  2598. - // We don't have to check the methods. If the constant pool has
  2599. - // GC'ed then so have the methods.
  2600. - continue;
  2601. - }
  2602. -
  2603. - // Found a node with non GC'ed info so return it. The caller will
  2604. - // need to delete pv_info when they are done with it.
  2605. - _current_p = pv_info;
  2606. - return pv_info;
  2607. - }
  2608. -
  2609. - // all of the underlying nodes' info has been GC'ed
  2610. - return NULL;
  2611. -} // end next_previous_version()
  2612. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  2613. index bb613b0..00f762e 100644
  2614. --- a/src/share/vm/oops/instanceKlass.hpp
  2615. +++ b/src/share/vm/oops/instanceKlass.hpp
  2616. @@ -273,9 +273,6 @@
  2617. nmethodBucket* _dependencies; // list of dependent nmethods
  2618. nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
  2619. BreakpointInfo* _breakpoints; // bpt lists, managed by methodOop
  2620. - // Array of interesting part(s) of the previous version(s) of this
  2621. - // instanceKlass. See PreviousVersionWalker below.
  2622. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2623. // JVMTI fields can be moved to their own structure - see 6315920
  2624. unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH
  2625. jint _cached_class_file_len; // JVMTI: length of above
  2626. @@ -573,20 +570,11 @@
  2627. _nonstatic_oop_map_size = words;
  2628. }
  2629. - // RedefineClasses() support for previous versions:
  2630. - void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
  2631. - int emcp_method_count);
  2632. // If the _previous_versions array is non-NULL, then this klass
  2633. // has been redefined at least once even if we aren't currently
  2634. // tracking a previous version.
  2635. - bool has_been_redefined() const { return _previous_versions != NULL; }
  2636. + bool has_been_redefined() const { return _old_version != NULL; }
  2637. bool has_previous_version() const;
  2638. - void init_previous_versions() {
  2639. - _previous_versions = NULL;
  2640. - }
  2641. - GrowableArray<PreviousVersionNode *>* previous_versions() const {
  2642. - return _previous_versions;
  2643. - }
  2644. // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
  2645. void set_cached_class_file(unsigned char *class_file_bytes,
  2646. @@ -631,6 +619,7 @@
  2647. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  2648. size_t *length_p, jmethodID* id_p);
  2649. jmethodID jmethod_id_or_null(methodOop method);
  2650. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  2651. // cached itable index support
  2652. void set_cached_itable_index(size_t idnum, int index);
  2653. @@ -713,6 +702,7 @@
  2654. // subclass/subinterface checks
  2655. bool implements_interface(klassOop k) const;
  2656. + bool implements_interface_any_version(klassOop k) const;
  2657. // Access to the implementor of an interface.
  2658. klassOop implementor() const
  2659. @@ -762,6 +752,9 @@
  2660. void do_local_static_fields(FieldClosure* cl);
  2661. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  2662. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  2663. + void store_update_information(GrowableArray<int> &values);
  2664. + void clear_update_information();
  2665. +
  2666. void methods_do(void f(methodOop method));
  2667. void array_klasses_do(void f(klassOop k));
  2668. @@ -897,7 +890,6 @@
  2669. ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
  2670. #endif // !SERIALGC
  2671. -private:
  2672. // initialization state
  2673. #ifdef ASSERT
  2674. void set_init_state(ClassState state);
  2675. @@ -1064,106 +1056,6 @@
  2676. #endif
  2677. void verify(klassOop holder);
  2678. };
  2679. -
  2680. -
  2681. -// If breakpoints are more numerous than just JVMTI breakpoints,
  2682. -// consider compressing this data structure.
  2683. -// It is currently a simple linked list defined in methodOop.hpp.
  2684. -
  2685. -class BreakpointInfo;
  2686. -
  2687. -
  2688. -// A collection point for interesting information about the previous
  2689. -// version(s) of an instanceKlass. This class uses weak references to
  2690. -// the information so that the information may be collected as needed
  2691. -// by the system. If the information is shared, then a regular
  2692. -// reference must be used because a weak reference would be seen as
  2693. -// collectible. A GrowableArray of PreviousVersionNodes is attached
  2694. -// to the instanceKlass as needed. See PreviousVersionWalker below.
  2695. -class PreviousVersionNode : public CHeapObj<mtClass> {
  2696. - private:
  2697. - // A shared ConstantPool is never collected so we'll always have
  2698. - // a reference to it so we can update items in the cache. We'll
  2699. - // have a weak reference to a non-shared ConstantPool until all
  2700. - // of the methods (EMCP or obsolete) have been collected; the
  2701. - // non-shared ConstantPool becomes collectible at that point.
  2702. - jobject _prev_constant_pool; // regular or weak reference
  2703. - bool _prev_cp_is_weak; // true if not a shared ConstantPool
  2704. -
  2705. - // If the previous version of the instanceKlass doesn't have any
  2706. - // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
  2707. - // EMCP methods have been collected, then _prev_EMCP_methods can
  2708. - // have a length of zero.
  2709. - GrowableArray<jweak>* _prev_EMCP_methods;
  2710. -
  2711. -public:
  2712. - PreviousVersionNode(jobject prev_constant_pool, bool prev_cp_is_weak,
  2713. - GrowableArray<jweak>* prev_EMCP_methods);
  2714. - ~PreviousVersionNode();
  2715. - jobject prev_constant_pool() const {
  2716. - return _prev_constant_pool;
  2717. - }
  2718. - GrowableArray<jweak>* prev_EMCP_methods() const {
  2719. - return _prev_EMCP_methods;
  2720. - }
  2721. -};
  2722. -
  2723. -
  2724. -// A Handle-ized version of PreviousVersionNode.
  2725. -class PreviousVersionInfo : public ResourceObj {
  2726. - private:
  2727. - constantPoolHandle _prev_constant_pool_handle;
  2728. - // If the previous version of the instanceKlass doesn't have any
  2729. - // EMCP methods, then _prev_EMCP_methods will be NULL. Since the
  2730. - // methods cannot be collected while we hold a handle,
  2731. - // _prev_EMCP_methods should never have a length of zero.
  2732. - GrowableArray<methodHandle>* _prev_EMCP_method_handles;
  2733. -
  2734. -public:
  2735. - PreviousVersionInfo(PreviousVersionNode *pv_node);
  2736. - ~PreviousVersionInfo();
  2737. - constantPoolHandle prev_constant_pool_handle() const {
  2738. - return _prev_constant_pool_handle;
  2739. - }
  2740. - GrowableArray<methodHandle>* prev_EMCP_method_handles() const {
  2741. - return _prev_EMCP_method_handles;
  2742. - }
  2743. -};
  2744. -
  2745. -
  2746. -// Helper object for walking previous versions. This helper cleans up
  2747. -// the Handles that it allocates when the helper object is destroyed.
  2748. -// The PreviousVersionInfo object returned by next_previous_version()
  2749. -// is only valid until a subsequent call to next_previous_version() or
  2750. -// the helper object is destroyed.
  2751. -class PreviousVersionWalker : public StackObj {
  2752. - private:
  2753. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2754. - int _current_index;
  2755. - // Fields for cleaning up when we are done walking the previous versions:
  2756. - // A HandleMark for the PreviousVersionInfo handles:
  2757. - HandleMark _hm;
  2758. -
  2759. - // It would be nice to have a ResourceMark field in this helper also,
  2760. - // but the ResourceMark code says to be careful to delete handles held
  2761. - // in GrowableArrays _before_ deleting the GrowableArray. Since we
  2762. - // can't guarantee the order in which the fields are destroyed, we
  2763. - // have to let the creator of the PreviousVersionWalker object do
  2764. - // the right thing. Also, adding a ResourceMark here causes an
  2765. - // include loop.
  2766. -
  2767. - // A pointer to the current info object so we can handle the deletes.
  2768. - PreviousVersionInfo * _current_p;
  2769. -
  2770. - public:
  2771. - PreviousVersionWalker(instanceKlass *ik);
  2772. - ~PreviousVersionWalker();
  2773. -
  2774. - // Return the interesting information for the next previous version
  2775. - // of the klass. Returns NULL if there are no more previous versions.
  2776. - PreviousVersionInfo* next_previous_version();
  2777. -};
  2778. -
  2779. //
  2780. // nmethodBucket is used to record dependent nmethods for
  2781. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  2782. index 8e7dc12..5b9b266 100644
  2783. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  2784. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  2785. @@ -358,7 +358,7 @@
  2786. unsigned nonstatic_oop_map_count,
  2787. AccessFlags access_flags,
  2788. ReferenceType rt,
  2789. - KlassHandle host_klass, TRAPS) {
  2790. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  2791. const int nonstatic_oop_map_size =
  2792. instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count);
  2793. @@ -435,7 +435,6 @@
  2794. ik->set_jni_ids(NULL);
  2795. ik->set_osr_nmethods_head(NULL);
  2796. ik->set_breakpoints(NULL);
  2797. - ik->init_previous_versions();
  2798. ik->set_generic_signature(NULL);
  2799. ik->release_set_methods_jmethod_ids(NULL);
  2800. ik->release_set_methods_cached_itable_indices(NULL);
  2801. @@ -480,6 +479,28 @@
  2802. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  2803. klassKlass::oop_print_on(obj, st);
  2804. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  2805. +
  2806. + st->print(BULLET"revision: %d", ik->revision_number());
  2807. +
  2808. + if (ik->new_version() != NULL) {
  2809. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  2810. + }
  2811. +
  2812. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  2813. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  2814. + }
  2815. +
  2816. + if (ik->old_version() != NULL) {
  2817. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  2818. + }
  2819. +
  2820. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  2821. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  2822. + }
  2823. +
  2824. + st->cr();
  2825. +
  2826. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  2827. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  2828. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  2829. @@ -536,26 +557,6 @@
  2830. st->print_cr("%s", ik->source_debug_extension());
  2831. st->cr();
  2832. }
  2833. -
  2834. - {
  2835. - ResourceMark rm;
  2836. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  2837. - // contain a GrowableArray of handles. We have to clean up the
  2838. - // GrowableArray _after_ the PreviousVersionWalker destructor
  2839. - // has destroyed the handles.
  2840. - {
  2841. - bool have_pv = false;
  2842. - PreviousVersionWalker pvw(ik);
  2843. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  2844. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  2845. - if (!have_pv)
  2846. - st->print(BULLET"previous version: ");
  2847. - have_pv = true;
  2848. - pv_info->prev_constant_pool_handle()()->print_value_on(st);
  2849. - }
  2850. - if (have_pv) st->cr();
  2851. - } // pvw is cleaned up
  2852. - } // rm is cleaned up
  2853. if (ik->generic_signature() != NULL) {
  2854. st->print(BULLET"generic signature: ");
  2855. @@ -663,7 +664,7 @@
  2856. }
  2857. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  2858. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  2859. - guarantee(sib->super() == super, "siblings should have same superklass");
  2860. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  2861. sib = sib->next_sibling();
  2862. }
  2863. diff --git a/src/share/vm/oops/instanceKlassKlass.hpp b/src/share/vm/oops/instanceKlassKlass.hpp
  2864. index df674a9..45d0b66 100644
  2865. --- a/src/share/vm/oops/instanceKlassKlass.hpp
  2866. +++ b/src/share/vm/oops/instanceKlassKlass.hpp
  2867. @@ -50,6 +50,7 @@
  2868. AccessFlags access_flags,
  2869. ReferenceType rt,
  2870. KlassHandle host_klass,
  2871. + KlassHandle old_klass,
  2872. TRAPS);
  2873. // Casting from klassOop
  2874. diff --git a/src/share/vm/oops/instanceMirrorKlass.cpp b/src/share/vm/oops/instanceMirrorKlass.cpp
  2875. index e0dd7d7..a7eec08 100644
  2876. --- a/src/share/vm/oops/instanceMirrorKlass.cpp
  2877. +++ b/src/share/vm/oops/instanceMirrorKlass.cpp
  2878. @@ -156,6 +156,13 @@
  2879. assert_is_in_closed_subset)
  2880. }
  2881. +void instanceMirrorKlass::oop_fields_iterate(oop obj, OopClosure* blk) {
  2882. + InstanceMirrorKlass_OOP_ITERATE( \
  2883. + start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
  2884. + blk->do_oop(p), \
  2885. + assert_is_in_closed_subset)
  2886. +}
  2887. +
  2888. #ifndef SERIALGC
  2889. void instanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm,
  2890. oop obj) {
  2891. diff --git a/src/share/vm/oops/instanceMirrorKlass.hpp b/src/share/vm/oops/instanceMirrorKlass.hpp
  2892. index 2b8b2f4..31969c7 100644
  2893. --- a/src/share/vm/oops/instanceMirrorKlass.hpp
  2894. +++ b/src/share/vm/oops/instanceMirrorKlass.hpp
  2895. @@ -79,6 +79,9 @@
  2896. DEFINE_ALLOCATE_PERMANENT(instanceMirrorKlass);
  2897. instanceOop allocate_instance(KlassHandle k, TRAPS);
  2898. + // Class redefinition, iterate static fields
  2899. + static void oop_fields_iterate(oop obj, OopClosure* blk);
  2900. +
  2901. // Garbage collection
  2902. int oop_adjust_pointers(oop obj);
  2903. void oop_follow_contents(oop obj);
  2904. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  2905. index 7db4f03..1171487 100644
  2906. --- a/src/share/vm/oops/instanceRefKlass.cpp
  2907. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  2908. @@ -455,10 +455,13 @@
  2909. instanceKlass* ik = instanceKlass::cast(k);
  2910. // Check that we have the right class
  2911. - debug_only(static bool first_time = true);
  2912. - assert(k == SystemDictionary::Reference_klass() && first_time,
  2913. - "Invalid update of maps");
  2914. - debug_only(first_time = false);
  2915. +
  2916. + // (tw) Asserts no longer valid for class redefinition
  2917. + // debug_only(static bool first_time = true);
  2918. +
  2919. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  2920. + // "Invalid update of maps");
  2921. + //debug_only(first_time = false);
  2922. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  2923. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  2924. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  2925. index ff33181..94406fe 100644
  2926. --- a/src/share/vm/oops/klass.cpp
  2927. +++ b/src/share/vm/oops/klass.cpp
  2928. @@ -170,6 +170,13 @@
  2929. kl->set_alloc_size(0);
  2930. TRACE_INIT_ID(kl);
  2931. + kl->set_redefinition_flags(Klass::NoRedefinition);
  2932. + kl->set_redefining(false);
  2933. + kl->set_new_version(NULL);
  2934. + kl->set_old_version(NULL);
  2935. + kl->set_redefinition_index(-1);
  2936. + kl->set_revision_number(-1);
  2937. +
  2938. kl->set_prototype_header(markOopDesc::prototype());
  2939. kl->set_biased_lock_revocation_count(0);
  2940. kl->set_last_biased_lock_bulk_revocation_time(0);
  2941. @@ -241,7 +248,7 @@
  2942. set_super(NULL);
  2943. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  2944. assert(super_depth() == 0, "Object must already be initialized properly");
  2945. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  2946. + } else if (k != super() || k->klass_part()->super() == NULL) {
  2947. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  2948. "initialize this only once to a non-trivial value");
  2949. set_super(k);
  2950. @@ -394,7 +401,7 @@
  2951. void Klass::remove_from_sibling_list() {
  2952. // remove receiver from sibling list
  2953. instanceKlass* super = superklass();
  2954. - assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
  2955. + assert(super != NULL || as_klassOop()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version(), "should have super");
  2956. if (super == NULL) return; // special case: class Object
  2957. if (super->subklass() == this) {
  2958. // first subklass
  2959. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  2960. index a449e87..d2490b7 100644
  2961. --- a/src/share/vm/oops/klass.hpp
  2962. +++ b/src/share/vm/oops/klass.hpp
  2963. @@ -171,6 +171,7 @@
  2964. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  2965. };
  2966. +template<class L, class R> class Pair;
  2967. class Klass : public Klass_vtbl {
  2968. friend class VMStructs;
  2969. @@ -223,6 +224,31 @@
  2970. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  2971. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  2972. + // (tw) Different class redefinition flags of code evolution.
  2973. + enum RedefinitionFlags {
  2974. +
  2975. + // This class is not redefined at all!
  2976. + NoRedefinition,
  2977. +
  2978. + // There are changes to the class meta data.
  2979. + ModifyClass = 1,
  2980. +
  2981. + // The size of the class meta data changes.
  2982. + ModifyClassSize = ModifyClass << 1,
  2983. +
  2984. + // There are change to the instance format.
  2985. + ModifyInstances = ModifyClassSize << 1,
  2986. +
  2987. + // The size of instances changes.
  2988. + ModifyInstanceSize = ModifyInstances << 1,
  2989. +
  2990. + // A super type of this class is removed.
  2991. + RemoveSuperType = ModifyInstanceSize << 1,
  2992. +
  2993. + // This class has been marked as an affected class.
  2994. + MarkedAsAffected = RemoveSuperType << 1
  2995. + };
  2996. +
  2997. protected:
  2998. //
  2999. // The oop block. All oop fields must be declared here and only oop fields
  3000. @@ -242,6 +268,10 @@
  3001. oop _java_mirror;
  3002. // Superclass
  3003. klassOop _super;
  3004. + // Old class
  3005. + klassOop _old_version;
  3006. + // New class
  3007. + klassOop _new_version;
  3008. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3009. klassOop _subklass;
  3010. // Sibling link (or NULL); links all subklasses of a klass
  3011. @@ -253,6 +283,16 @@
  3012. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3013. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3014. +
  3015. + // (tw) Non-oop fields for enhanced class redefinition
  3016. + jint _revision_number; // The revision number for redefined classes
  3017. + jint _redefinition_index; // Index of this class when performing the redefinition
  3018. + bool _subtype_changed;
  3019. + int _redefinition_flags; // Level of class redefinition
  3020. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3021. + bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
  3022. + int * _update_information; // Update information
  3023. + bool _is_redefining;
  3024. #ifndef PRODUCT
  3025. int _verify_count; // to avoid redundant verifies
  3026. @@ -301,6 +341,75 @@
  3027. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3028. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3029. +
  3030. + // BEGIN class redefinition utilities
  3031. +
  3032. + // double links between new and old version of a class
  3033. + klassOop old_version() const { return _old_version; }
  3034. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3035. + klassOop new_version() const { return _new_version; }
  3036. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3037. +
  3038. + // A subtype of this class is no longer a subtype
  3039. + bool has_subtype_changed() const { return _subtype_changed; }
  3040. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3041. + _subtype_changed = b; }
  3042. + // state of being redefined
  3043. + int redefinition_index() const { return _redefinition_index; }
  3044. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3045. + void set_redefining(bool b) { _is_redefining = b; }
  3046. + bool is_redefining() const { return _is_redefining; }
  3047. + int redefinition_flags() const { return _redefinition_flags; }
  3048. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3049. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3050. + void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
  3051. + void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
  3052. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3053. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3054. +
  3055. + // update information
  3056. + int *update_information() const { return _update_information; }
  3057. + void set_update_information(int *info) { _update_information = info; }
  3058. +
  3059. + bool is_same_or_older_version(klassOop klass) const {
  3060. + if (Klass::cast(klass) == this) { return true; }
  3061. + else if (_old_version == NULL) { return false; }
  3062. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3063. + }
  3064. +
  3065. + // Revision number for redefined classes, -1 for originally loaded classes
  3066. + jint revision_number() const {
  3067. + return _revision_number;
  3068. + }
  3069. +
  3070. + bool was_redefined() const {
  3071. + return _revision_number != -1;
  3072. + }
  3073. +
  3074. + void set_revision_number(jint number) {
  3075. + _revision_number = number;
  3076. + }
  3077. +
  3078. + klassOop oldest_version() const {
  3079. + if (_old_version == NULL) { return this->as_klassOop(); }
  3080. + else { return _old_version->klass_part()->oldest_version(); };
  3081. + }
  3082. +
  3083. + klassOop newest_version() const {
  3084. + if (_new_version == NULL) { return this->as_klassOop(); }
  3085. + else { return _new_version->klass_part()->newest_version(); };
  3086. + }
  3087. +
  3088. + klassOop active_version() const {
  3089. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3090. + else { return _new_version->klass_part()->active_version(); };
  3091. + }
  3092. +
  3093. + bool is_newest_version() const {
  3094. + return _new_version == NULL;
  3095. + }
  3096. +
  3097. + // END class redefinition utilities
  3098. objArrayOop secondary_supers() const { return _secondary_supers; }
  3099. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3100. @@ -362,6 +471,8 @@
  3101. void set_next_sibling(klassOop s);
  3102. oop* adr_super() const { return (oop*)&_super; }
  3103. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3104. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3105. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3106. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3107. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3108. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3109. index 06809d5..1050eda 100644
  3110. --- a/src/share/vm/oops/klassKlass.cpp
  3111. +++ b/src/share/vm/oops/klassKlass.cpp
  3112. @@ -68,6 +68,8 @@
  3113. Klass* k = Klass::cast(klassOop(obj));
  3114. // If we are alive it is valid to keep our superclass and subtype caches alive
  3115. MarkSweep::mark_and_push(k->adr_super());
  3116. + MarkSweep::mark_and_push(k->adr_old_version());
  3117. + MarkSweep::mark_and_push(k->adr_new_version());
  3118. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3119. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3120. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3121. @@ -87,6 +89,8 @@
  3122. Klass* k = Klass::cast(klassOop(obj));
  3123. // If we are alive it is valid to keep our superclass and subtype caches alive
  3124. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3125. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3126. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3127. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3128. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3129. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3130. @@ -106,6 +110,8 @@
  3131. int size = oop_size(obj);
  3132. Klass* k = Klass::cast(klassOop(obj));
  3133. blk->do_oop(k->adr_super());
  3134. + blk->do_oop(k->adr_old_version());
  3135. + blk->do_oop(k->adr_new_version());
  3136. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3137. blk->do_oop(k->adr_primary_supers()+i);
  3138. blk->do_oop(k->adr_secondary_super_cache());
  3139. @@ -133,6 +139,10 @@
  3140. Klass* k = Klass::cast(klassOop(obj));
  3141. oop* adr;
  3142. adr = k->adr_super();
  3143. + if (mr.contains(adr)) blk->do_oop(adr);
  3144. + adr = k->adr_old_version();
  3145. + if (mr.contains(adr)) blk->do_oop(adr);
  3146. + adr = k->adr_new_version();
  3147. if (mr.contains(adr)) blk->do_oop(adr);
  3148. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3149. adr = k->adr_primary_supers()+i;
  3150. @@ -167,6 +177,8 @@
  3151. Klass* k = Klass::cast(klassOop(obj));
  3152. MarkSweep::adjust_pointer(k->adr_super());
  3153. + MarkSweep::adjust_pointer(k->adr_new_version());
  3154. + MarkSweep::adjust_pointer(k->adr_old_version());
  3155. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3156. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3157. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3158. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  3159. index ff22444..b366b73 100644
  3160. --- a/src/share/vm/oops/klassVtable.cpp
  3161. +++ b/src/share/vm/oops/klassVtable.cpp
  3162. @@ -649,17 +649,13 @@
  3163. if (unchecked_method_at(index) == old_method) {
  3164. put_method_at(new_method, index);
  3165. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3166. + IF_TRACE_RC4 {
  3167. if (!(*trace_name_printed)) {
  3168. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3169. - RC_TRACE_MESG(("adjust: name=%s",
  3170. - Klass::cast(old_method->method_holder())->external_name()));
  3171. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3172. *trace_name_printed = true;
  3173. }
  3174. - // RC_TRACE macro has an embedded ResourceMark
  3175. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  3176. - new_method->name()->as_C_string(),
  3177. - new_method->signature()->as_C_string()));
  3178. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  3179. + new_method->signature()->as_C_string());
  3180. }
  3181. // cannot 'break' here; see for-loop comment above.
  3182. }
  3183. @@ -1029,17 +1025,13 @@
  3184. if (ime->method() == old_method) {
  3185. ime->initialize(new_method);
  3186. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3187. + IF_TRACE_RC4 {
  3188. if (!(*trace_name_printed)) {
  3189. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3190. - RC_TRACE_MESG(("adjust: name=%s",
  3191. - Klass::cast(old_method->method_holder())->external_name()));
  3192. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3193. *trace_name_printed = true;
  3194. }
  3195. - // RC_TRACE macro has an embedded ResourceMark
  3196. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  3197. - new_method->name()->as_C_string(),
  3198. - new_method->signature()->as_C_string()));
  3199. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  3200. + new_method->signature()->as_C_string());
  3201. }
  3202. // cannot 'break' here; see for-loop comment above.
  3203. }
  3204. @@ -1262,6 +1254,7 @@
  3205. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  3206. vtableEntry* vte = &vt->table()[index];
  3207. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  3208. if (vte->method()->name() != table()[index].method()->name() ||
  3209. vte->method()->signature() != table()[index].method()->signature()) {
  3210. fatal("mismatched name/signature of vtable entries");
  3211. @@ -1281,6 +1274,8 @@
  3212. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3213. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  3214. + // (tw) TODO: Check: Does not hold?
  3215. + if (method() != NULL) {
  3216. assert(method() != NULL, "must have set method");
  3217. method()->verify();
  3218. // we sub_type, because it could be a miranda method
  3219. @@ -1288,7 +1283,13 @@
  3220. #ifndef PRODUCT
  3221. print();
  3222. #endif
  3223. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  3224. + klassOop first_klass = vt->klass()();
  3225. + klassOop second_klass = method()->method_holder();
  3226. + // (tw) the following fatal does not work for old versions of classes
  3227. + if (first_klass->klass_part()->is_newest_version()) {
  3228. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  3229. + }
  3230. + }
  3231. }
  3232. }
  3233. @@ -1296,8 +1297,8 @@
  3234. void vtableEntry::print() {
  3235. ResourceMark rm;
  3236. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  3237. if (Verbose) {
  3238. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  3239. tty->print("m %#lx ", (address)method());
  3240. }
  3241. }
  3242. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  3243. index 75d0b09..c4be146 100644
  3244. --- a/src/share/vm/oops/methodKlass.cpp
  3245. +++ b/src/share/vm/oops/methodKlass.cpp
  3246. @@ -93,6 +93,9 @@
  3247. m->set_adapter_entry(NULL);
  3248. m->clear_code(); // from_c/from_i get set to c2i/i2i
  3249. + m->set_new_version(NULL);
  3250. + m->set_old_version(NULL);
  3251. +
  3252. if (access_flags.is_native()) {
  3253. m->clear_native_function();
  3254. m->set_signature_handler(NULL);
  3255. @@ -122,6 +125,8 @@
  3256. // Performance tweak: We skip iterating over the klass pointer since we
  3257. // know that Universe::methodKlassObj never moves.
  3258. MarkSweep::mark_and_push(m->adr_constMethod());
  3259. + MarkSweep::mark_and_push(m->adr_new_version());
  3260. + MarkSweep::mark_and_push(m->adr_old_version());
  3261. if (m->method_data() != NULL) {
  3262. MarkSweep::mark_and_push(m->adr_method_data());
  3263. }
  3264. @@ -135,6 +140,8 @@
  3265. // Performance tweak: We skip iterating over the klass pointer since we
  3266. // know that Universe::methodKlassObj never moves.
  3267. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  3268. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  3269. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  3270. #ifdef COMPILER2
  3271. if (m->method_data() != NULL) {
  3272. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  3273. @@ -152,6 +159,8 @@
  3274. // Performance tweak: We skip iterating over the klass pointer since we
  3275. // know that Universe::methodKlassObj never moves
  3276. blk->do_oop(m->adr_constMethod());
  3277. + blk->do_oop(m->adr_new_version());
  3278. + blk->do_oop(m->adr_old_version());
  3279. if (m->method_data() != NULL) {
  3280. blk->do_oop(m->adr_method_data());
  3281. }
  3282. @@ -170,6 +179,10 @@
  3283. oop* adr;
  3284. adr = m->adr_constMethod();
  3285. if (mr.contains(adr)) blk->do_oop(adr);
  3286. + adr = m->adr_new_version();
  3287. + if (mr.contains(adr)) blk->do_oop(adr);
  3288. + adr = m->adr_old_version();
  3289. + if (mr.contains(adr)) blk->do_oop(adr);
  3290. if (m->method_data() != NULL) {
  3291. adr = m->adr_method_data();
  3292. if (mr.contains(adr)) blk->do_oop(adr);
  3293. @@ -187,6 +200,8 @@
  3294. // Performance tweak: We skip iterating over the klass pointer since we
  3295. // know that Universe::methodKlassObj never moves.
  3296. MarkSweep::adjust_pointer(m->adr_constMethod());
  3297. + MarkSweep::adjust_pointer(m->adr_new_version());
  3298. + MarkSweep::adjust_pointer(m->adr_old_version());
  3299. if (m->method_data() != NULL) {
  3300. MarkSweep::adjust_pointer(m->adr_method_data());
  3301. }
  3302. @@ -202,6 +217,8 @@
  3303. assert(obj->is_method(), "should be method");
  3304. methodOop m = methodOop(obj);
  3305. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  3306. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  3307. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  3308. #ifdef COMPILER2
  3309. if (m->method_data() != NULL) {
  3310. PSParallelCompact::adjust_pointer(m->adr_method_data());
  3311. @@ -222,7 +239,18 @@
  3312. methodOop m = methodOop(obj);
  3313. // get the effect of PrintOopAddress, always, for methods:
  3314. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  3315. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  3316. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  3317. +
  3318. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  3319. + st->print(" (old)");
  3320. + }
  3321. + st->cr();
  3322. +
  3323. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  3324. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  3325. + st->print_cr(" - new version: "INTPTR_FORMAT, (address)m->new_version());
  3326. + st->print_cr(" - old version: "INTPTR_FORMAT, (address)m->old_version());
  3327. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  3328. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  3329. m->constants()->print_value_on(st); st->cr();
  3330. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  3331. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  3332. index 4f59d3a..32cb4cf 100644
  3333. --- a/src/share/vm/oops/methodOop.cpp
  3334. +++ b/src/share/vm/oops/methodOop.cpp
  3335. @@ -1061,6 +1061,8 @@
  3336. // Reset correct method/const method, method size, and parameter info
  3337. newm->set_constMethod(newcm);
  3338. + newm->set_new_version(newm->new_version());
  3339. + newm->set_old_version(newm->old_version());
  3340. newm->constMethod()->set_code_size(new_code_length);
  3341. newm->constMethod()->set_constMethod_size(new_const_method_size);
  3342. newm->set_method_size(new_method_size);
  3343. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  3344. index 486e106..e35d5ed 100644
  3345. --- a/src/share/vm/oops/methodOop.hpp
  3346. +++ b/src/share/vm/oops/methodOop.hpp
  3347. @@ -114,6 +114,10 @@
  3348. AccessFlags _access_flags; // Access flags
  3349. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  3350. // note: can have vtables with >2**16 elements (because of inheritance)
  3351. + // (tw) Newer version of method available?
  3352. + methodOop _new_version;
  3353. + methodOop _old_version;
  3354. +
  3355. #ifdef CC_INTERP
  3356. int _result_index; // C++ interpreter needs for converting results to/from stack
  3357. #endif
  3358. @@ -174,6 +178,29 @@
  3359. Symbol* name() const { return constants()->symbol_at(name_index()); }
  3360. int name_index() const { return constMethod()->name_index(); }
  3361. void set_name_index(int index) { constMethod()->set_name_index(index); }
  3362. +
  3363. + methodOop new_version() const {return _new_version; }
  3364. + void set_new_version(methodOop m) { _new_version = m; }
  3365. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  3366. +
  3367. + methodOop old_version() const {return _old_version; };
  3368. + void set_old_version(methodOop m) {
  3369. + if (m == NULL) {
  3370. + _old_version = NULL;
  3371. + return;
  3372. + }
  3373. +
  3374. + assert(_old_version == NULL, "may only be set once");
  3375. + assert(this->code_size() == m->code_size(), "must have same code length");
  3376. + _old_version = m;
  3377. + }
  3378. +
  3379. + methodOop oldest_version() const {
  3380. + if(_old_version == NULL) return (methodOop)this;
  3381. + else {
  3382. + return old_version()->oldest_version();
  3383. + }
  3384. + }
  3385. // signature
  3386. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  3387. @@ -734,6 +761,8 @@
  3388. // Garbage collection support
  3389. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  3390. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3391. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3392. oop* adr_method_data() const { return (oop*)&_method_data; }
  3393. };
  3394. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  3395. index 5982c88..4873fca 100644
  3396. --- a/src/share/vm/oops/oop.hpp
  3397. +++ b/src/share/vm/oops/oop.hpp
  3398. @@ -95,6 +95,7 @@
  3399. narrowOop* compressed_klass_addr();
  3400. void set_klass(klassOop k);
  3401. + void set_klass_no_check(klassOop k);
  3402. // For klass field compression
  3403. int klass_gap() const;
  3404. @@ -135,6 +136,7 @@
  3405. bool is_array() const;
  3406. bool is_objArray() const;
  3407. bool is_klass() const;
  3408. + bool is_instanceKlass() const;
  3409. bool is_thread() const;
  3410. bool is_method() const;
  3411. bool is_constMethod() const;
  3412. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  3413. index f4eb2f7..0acb346 100644
  3414. --- a/src/share/vm/oops/oop.inline.hpp
  3415. +++ b/src/share/vm/oops/oop.inline.hpp
  3416. @@ -123,6 +123,14 @@
  3417. }
  3418. }
  3419. +inline void oopDesc::set_klass_no_check(klassOop k) {
  3420. + if (UseCompressedOops) {
  3421. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  3422. + } else {
  3423. + oop_store_without_check(klass_addr(), (oop) k);
  3424. + }
  3425. +}
  3426. +
  3427. inline int oopDesc::klass_gap() const {
  3428. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  3429. }
  3430. @@ -156,6 +164,7 @@
  3431. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  3432. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  3433. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  3434. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  3435. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  3436. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  3437. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  3438. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  3439. index 50e1263..701ed74 100644
  3440. --- a/src/share/vm/prims/jni.cpp
  3441. +++ b/src/share/vm/prims/jni.cpp
  3442. @@ -406,7 +406,7 @@
  3443. }
  3444. }
  3445. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3446. - Handle(), &st, true,
  3447. + Handle(), &st, true, KlassHandle(),
  3448. CHECK_NULL);
  3449. if (TraceClassResolution && k != NULL) {
  3450. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  3451. index ccd09f6..ef3f024 100644
  3452. --- a/src/share/vm/prims/jvm.cpp
  3453. +++ b/src/share/vm/prims/jvm.cpp
  3454. @@ -932,7 +932,7 @@
  3455. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  3456. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3457. protection_domain, &st,
  3458. - verify != 0,
  3459. + verify != 0, KlassHandle(),
  3460. CHECK_NULL);
  3461. if (TraceClassResolution && k != NULL) {
  3462. diff --git a/src/share/vm/prims/jvm_misc.hpp b/src/share/vm/prims/jvm_misc.hpp
  3463. index 2b46e36..549e949 100644
  3464. --- a/src/share/vm/prims/jvm_misc.hpp
  3465. +++ b/src/share/vm/prims/jvm_misc.hpp
  3466. @@ -84,6 +84,7 @@
  3467. (JNIEnv *env, jobject obj, jfieldID fieldID);
  3468. }
  3469. +// TODO(tw): Check if we need to "unquicken" because of class redefinition.
  3470. void quicken_jni_functions();
  3471. address jni_GetBooleanField_addr();
  3472. address jni_GetByteField_addr();
  3473. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  3474. index 4ac6b82..30b8e84 100644
  3475. --- a/src/share/vm/prims/jvmtiEnv.cpp
  3476. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  3477. @@ -290,7 +290,10 @@
  3478. class_definitions[index].klass = jcls;
  3479. }
  3480. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  3481. - VMThread::execute(&op);
  3482. + {
  3483. + MutexLocker sd_mutex(RedefineClasses_lock);
  3484. + VMThread::execute(&op);
  3485. + }
  3486. return (op.check_error());
  3487. } /* end RetransformClasses */
  3488. @@ -299,9 +302,12 @@
  3489. // class_definitions - pre-checked for NULL
  3490. jvmtiError
  3491. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  3492. -//TODO: add locking
  3493. +
  3494. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  3495. - VMThread::execute(&op);
  3496. + {
  3497. + MutexLocker sd_mutex(RedefineClasses_lock);
  3498. + VMThread::execute(&op);
  3499. + }
  3500. return (op.check_error());
  3501. } /* end RedefineClasses */
  3502. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  3503. index ec8ede3..2bd5983 100644
  3504. --- a/src/share/vm/prims/jvmtiExport.cpp
  3505. +++ b/src/share/vm/prims/jvmtiExport.cpp
  3506. @@ -2296,7 +2296,7 @@
  3507. // iterate over any code blob descriptors collected and post a
  3508. // DYNAMIC_CODE_GENERATED event to the profiler.
  3509. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  3510. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  3511. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  3512. // iterate over any code blob descriptors that we collected
  3513. if (_code_blobs != NULL) {
  3514. for (int i=0; i<_code_blobs->length(); i++) {
  3515. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  3516. index d3fa140..31a8a19 100644
  3517. --- a/src/share/vm/prims/jvmtiImpl.cpp
  3518. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  3519. @@ -284,60 +284,11 @@
  3520. }
  3521. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  3522. - ((methodOopDesc*)_method->*meth_act)(_bci);
  3523. -
  3524. - // add/remove breakpoint to/from versions of the method that
  3525. - // are EMCP. Directly or transitively obsolete methods are
  3526. - // not saved in the PreviousVersionInfo.
  3527. - Thread *thread = Thread::current();
  3528. - instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder());
  3529. - Symbol* m_name = _method->name();
  3530. - Symbol* m_signature = _method->signature();
  3531. -
  3532. - {
  3533. - ResourceMark rm(thread);
  3534. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  3535. - // contain a GrowableArray of handles. We have to clean up the
  3536. - // GrowableArray _after_ the PreviousVersionWalker destructor
  3537. - // has destroyed the handles.
  3538. - {
  3539. - // search previous versions if they exist
  3540. - PreviousVersionWalker pvw((instanceKlass *)ikh()->klass_part());
  3541. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  3542. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  3543. - GrowableArray<methodHandle>* methods =
  3544. - pv_info->prev_EMCP_method_handles();
  3545. -
  3546. - if (methods == NULL) {
  3547. - // We have run into a PreviousVersion generation where
  3548. - // all methods were made obsolete during that generation's
  3549. - // RedefineClasses() operation. At the time of that
  3550. - // operation, all EMCP methods were flushed so we don't
  3551. - // have to go back any further.
  3552. - //
  3553. - // A NULL methods array is different than an empty methods
  3554. - // array. We cannot infer any optimizations about older
  3555. - // generations from an empty methods array for the current
  3556. - // generation.
  3557. - break;
  3558. - }
  3559. -
  3560. - for (int i = methods->length() - 1; i >= 0; i--) {
  3561. - methodHandle method = methods->at(i);
  3562. - if (method->name() == m_name && method->signature() == m_signature) {
  3563. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  3564. - meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  3565. - method->name()->as_C_string(),
  3566. - method->signature()->as_C_string()));
  3567. - assert(!method->is_obsolete(), "only EMCP methods here");
  3568. -
  3569. - ((methodOopDesc*)method()->*meth_act)(_bci);
  3570. - break;
  3571. - }
  3572. - }
  3573. - }
  3574. - } // pvw is cleaned up
  3575. - } // rm is cleaned up
  3576. + methodOop method = _method;
  3577. + while (method != NULL) {
  3578. + ((methodOopDesc*)method->*meth_act)(_bci);
  3579. + method = method->old_version();
  3580. + }
  3581. }
  3582. void JvmtiBreakpoint::set() {
  3583. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3584. index 606be1c..cb90823 100644
  3585. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3586. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3587. @@ -1,5 +1,5 @@
  3588. /*
  3589. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  3590. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  3591. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3592. *
  3593. * This code is free software; you can redistribute it and/or modify it
  3594. @@ -35,545 +35,57 @@
  3595. #include "prims/jvmtiImpl.hpp"
  3596. #include "prims/jvmtiRedefineClasses.hpp"
  3597. #include "prims/methodComparator.hpp"
  3598. -#include "prims/methodHandles.hpp"
  3599. #include "runtime/deoptimization.hpp"
  3600. #include "runtime/relocator.hpp"
  3601. #include "utilities/bitMap.inline.hpp"
  3602. +#include "prims/jvmtiClassFileReconstituter.hpp"
  3603. +#include "compiler/compileBroker.hpp"
  3604. +#include "oops/instanceMirrorKlass.hpp"
  3605. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  3606. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  3607. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  3608. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  3609. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  3610. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  3611. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  3612. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  3613. +int* VM_RedefineClasses::_deleted_methods = NULL;
  3614. +int* VM_RedefineClasses::_added_methods = NULL;
  3615. int VM_RedefineClasses::_matching_methods_length = 0;
  3616. int VM_RedefineClasses::_deleted_methods_length = 0;
  3617. int VM_RedefineClasses::_added_methods_length = 0;
  3618. -klassOop VM_RedefineClasses::_the_class_oop = NULL;
  3619. +GrowableArray<instanceKlassHandle>* VM_RedefineClasses::_affected_klasses = NULL;
  3620. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  3621. - const jvmtiClassDefinition *class_defs,
  3622. - JvmtiClassLoadKind class_load_kind) {
  3623. +// Holds the revision number of the current class redefinition
  3624. +int VM_RedefineClasses::_revision_number = -1;
  3625. +
  3626. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  3627. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
  3628. + RC_TIMER_START(_timer_total);
  3629. _class_count = class_count;
  3630. _class_defs = class_defs;
  3631. _class_load_kind = class_load_kind;
  3632. - _res = JVMTI_ERROR_NONE;
  3633. + _result = JVMTI_ERROR_NONE;
  3634. }
  3635. -bool VM_RedefineClasses::doit_prologue() {
  3636. - if (_class_count == 0) {
  3637. - _res = JVMTI_ERROR_NONE;
  3638. - return false;
  3639. - }
  3640. - if (_class_defs == NULL) {
  3641. - _res = JVMTI_ERROR_NULL_POINTER;
  3642. - return false;
  3643. - }
  3644. - for (int i = 0; i < _class_count; i++) {
  3645. - if (_class_defs[i].klass == NULL) {
  3646. - _res = JVMTI_ERROR_INVALID_CLASS;
  3647. - return false;
  3648. - }
  3649. - if (_class_defs[i].class_byte_count == 0) {
  3650. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3651. - return false;
  3652. - }
  3653. - if (_class_defs[i].class_bytes == NULL) {
  3654. - _res = JVMTI_ERROR_NULL_POINTER;
  3655. - return false;
  3656. - }
  3657. - }
  3658. +VM_RedefineClasses::~VM_RedefineClasses() {
  3659. + unlock_threads();
  3660. + RC_TIMER_STOP(_timer_total);
  3661. - // Start timer after all the sanity checks; not quite accurate, but
  3662. - // better than adding a bunch of stop() calls.
  3663. - RC_TIMER_START(_timer_vm_op_prologue);
  3664. -
  3665. - // We first load new class versions in the prologue, because somewhere down the
  3666. - // call chain it is required that the current thread is a Java thread.
  3667. - _res = load_new_class_versions(Thread::current());
  3668. - if (_res != JVMTI_ERROR_NONE) {
  3669. - // Free os::malloc allocated memory in load_new_class_version.
  3670. - os::free(_scratch_classes);
  3671. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3672. - return false;
  3673. - }
  3674. -
  3675. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3676. - return true;
  3677. -}
  3678. -
  3679. -void VM_RedefineClasses::doit() {
  3680. - Thread *thread = Thread::current();
  3681. -
  3682. - if (UseSharedSpaces) {
  3683. - // Sharing is enabled so we remap the shared readonly space to
  3684. - // shared readwrite, private just in case we need to redefine
  3685. - // a shared class. We do the remap during the doit() phase of
  3686. - // the safepoint to be safer.
  3687. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  3688. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  3689. - ("failed to remap shared readonly space to readwrite, private"));
  3690. - _res = JVMTI_ERROR_INTERNAL;
  3691. - return;
  3692. - }
  3693. - }
  3694. -
  3695. - for (int i = 0; i < _class_count; i++) {
  3696. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  3697. - }
  3698. - // Disable any dependent concurrent compilations
  3699. - SystemDictionary::notice_modification();
  3700. -
  3701. - // Set flag indicating that some invariants are no longer true.
  3702. - // See jvmtiExport.hpp for detailed explanation.
  3703. - JvmtiExport::set_has_redefined_a_class();
  3704. -
  3705. -// check_class() is optionally called for product bits, but is
  3706. -// always called for non-product bits.
  3707. -#ifdef PRODUCT
  3708. - if (RC_TRACE_ENABLED(0x00004000)) {
  3709. -#endif
  3710. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  3711. - SystemDictionary::classes_do(check_class, thread);
  3712. -#ifdef PRODUCT
  3713. - }
  3714. -#endif
  3715. -}
  3716. -
  3717. -void VM_RedefineClasses::doit_epilogue() {
  3718. - // Free os::malloc allocated memory.
  3719. - // The memory allocated in redefine will be free'ed in next VM operation.
  3720. - os::free(_scratch_classes);
  3721. -
  3722. - if (RC_TRACE_ENABLED(0x00000004)) {
  3723. - // Used to have separate timers for "doit" and "all", but the timer
  3724. - // overhead skewed the measurements.
  3725. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  3726. - _timer_rsc_phase2.milliseconds();
  3727. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  3728. -
  3729. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  3730. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  3731. - _timer_vm_op_prologue.milliseconds(), doit_time));
  3732. - RC_TRACE(0x00000004,
  3733. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  3734. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  3735. + if (TimeRedefineClasses) {
  3736. + tty->print_cr("");
  3737. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  3738. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  3739. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  3740. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  3741. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  3742. + tty->print_cr("Timing Heap Iteration: %d", _timer_heap_iteration.milliseconds());
  3743. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  3744. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  3745. + tty->print_cr("------------------------------------------------------------------");
  3746. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  3747. + tty->print_cr("");
  3748. }
  3749. }
  3750. -
  3751. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  3752. - // classes for primitives cannot be redefined
  3753. - if (java_lang_Class::is_primitive(klass_mirror)) {
  3754. - return false;
  3755. - }
  3756. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  3757. - // classes for arrays cannot be redefined
  3758. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  3759. - return false;
  3760. - }
  3761. - return true;
  3762. -}
  3763. -
  3764. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  3765. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  3766. -// direct CP entries, there is just the current entry to append. For
  3767. -// indirect and double-indirect CP entries, there are zero or more
  3768. -// referenced CP entries along with the current entry to append.
  3769. -// Indirect and double-indirect CP entries are handled by recursive
  3770. -// calls to append_entry() as needed. The referenced CP entries are
  3771. -// always appended to *merge_cp_p before the referee CP entry. These
  3772. -// referenced CP entries may already exist in *merge_cp_p in which case
  3773. -// there is nothing extra to append and only the current entry is
  3774. -// appended.
  3775. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  3776. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  3777. - TRAPS) {
  3778. -
  3779. - // append is different depending on entry tag type
  3780. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3781. -
  3782. - // The old verifier is implemented outside the VM. It loads classes,
  3783. - // but does not resolve constant pool entries directly so we never
  3784. - // see Class entries here with the old verifier. Similarly the old
  3785. - // verifier does not like Class entries in the input constant pool.
  3786. - // The split-verifier is implemented in the VM so it can optionally
  3787. - // and directly resolve constant pool entries to load classes. The
  3788. - // split-verifier can accept either Class entries or UnresolvedClass
  3789. - // entries in the input constant pool. We revert the appended copy
  3790. - // back to UnresolvedClass so that either verifier will be happy
  3791. - // with the constant pool entry.
  3792. - case JVM_CONSTANT_Class:
  3793. - {
  3794. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  3795. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  3796. - scratch_cp->klass_name_at(scratch_i));
  3797. -
  3798. - if (scratch_i != *merge_cp_length_p) {
  3799. - // The new entry in *merge_cp_p is at a different index than
  3800. - // the new entry in scratch_cp so we need to map the index values.
  3801. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3802. - }
  3803. - (*merge_cp_length_p)++;
  3804. - } break;
  3805. -
  3806. - // these are direct CP entries so they can be directly appended,
  3807. - // but double and long take two constant pool entries
  3808. - case JVM_CONSTANT_Double: // fall through
  3809. - case JVM_CONSTANT_Long:
  3810. - {
  3811. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  3812. - THREAD);
  3813. -
  3814. - if (scratch_i != *merge_cp_length_p) {
  3815. - // The new entry in *merge_cp_p is at a different index than
  3816. - // the new entry in scratch_cp so we need to map the index values.
  3817. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3818. - }
  3819. - (*merge_cp_length_p) += 2;
  3820. - } break;
  3821. -
  3822. - // these are direct CP entries so they can be directly appended
  3823. - case JVM_CONSTANT_Float: // fall through
  3824. - case JVM_CONSTANT_Integer: // fall through
  3825. - case JVM_CONSTANT_Utf8: // fall through
  3826. -
  3827. - // This was an indirect CP entry, but it has been changed into
  3828. - // an interned string so this entry can be directly appended.
  3829. - case JVM_CONSTANT_String: // fall through
  3830. -
  3831. - // These were indirect CP entries, but they have been changed into
  3832. - // Symbol*s so these entries can be directly appended.
  3833. - case JVM_CONSTANT_UnresolvedClass: // fall through
  3834. - case JVM_CONSTANT_UnresolvedString:
  3835. - {
  3836. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  3837. - THREAD);
  3838. -
  3839. - if (scratch_i != *merge_cp_length_p) {
  3840. - // The new entry in *merge_cp_p is at a different index than
  3841. - // the new entry in scratch_cp so we need to map the index values.
  3842. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3843. - }
  3844. - (*merge_cp_length_p)++;
  3845. - } break;
  3846. -
  3847. - // this is an indirect CP entry so it needs special handling
  3848. - case JVM_CONSTANT_NameAndType:
  3849. - {
  3850. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  3851. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  3852. - merge_cp_length_p, THREAD);
  3853. -
  3854. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  3855. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  3856. - merge_cp_p, merge_cp_length_p,
  3857. - THREAD);
  3858. -
  3859. - // If the referenced entries already exist in *merge_cp_p, then
  3860. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  3861. - // In that case, all we are appending is the current entry.
  3862. - if (new_name_ref_i != name_ref_i) {
  3863. - RC_TRACE(0x00080000,
  3864. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  3865. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  3866. - }
  3867. - if (new_signature_ref_i != signature_ref_i) {
  3868. - RC_TRACE(0x00080000,
  3869. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  3870. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  3871. - }
  3872. -
  3873. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  3874. - new_name_ref_i, new_signature_ref_i);
  3875. - if (scratch_i != *merge_cp_length_p) {
  3876. - // The new entry in *merge_cp_p is at a different index than
  3877. - // the new entry in scratch_cp so we need to map the index values.
  3878. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3879. - }
  3880. - (*merge_cp_length_p)++;
  3881. - } break;
  3882. -
  3883. - // this is a double-indirect CP entry so it needs special handling
  3884. - case JVM_CONSTANT_Fieldref: // fall through
  3885. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  3886. - case JVM_CONSTANT_Methodref:
  3887. - {
  3888. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  3889. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  3890. - merge_cp_p, merge_cp_length_p, THREAD);
  3891. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  3892. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  3893. - merge_cp_p, merge_cp_length_p, THREAD);
  3894. -
  3895. - const char *entry_name;
  3896. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3897. - case JVM_CONSTANT_Fieldref:
  3898. - entry_name = "Fieldref";
  3899. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  3900. - new_name_and_type_ref_i);
  3901. - break;
  3902. - case JVM_CONSTANT_InterfaceMethodref:
  3903. - entry_name = "IFMethodref";
  3904. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  3905. - new_klass_ref_i, new_name_and_type_ref_i);
  3906. - break;
  3907. - case JVM_CONSTANT_Methodref:
  3908. - entry_name = "Methodref";
  3909. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  3910. - new_name_and_type_ref_i);
  3911. - break;
  3912. - default:
  3913. - guarantee(false, "bad switch");
  3914. - break;
  3915. - }
  3916. -
  3917. - if (klass_ref_i != new_klass_ref_i) {
  3918. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  3919. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  3920. - }
  3921. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  3922. - RC_TRACE(0x00080000,
  3923. - ("%s entry@%d name_and_type_index changed: %d to %d",
  3924. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  3925. - new_name_and_type_ref_i));
  3926. - }
  3927. -
  3928. - if (scratch_i != *merge_cp_length_p) {
  3929. - // The new entry in *merge_cp_p is at a different index than
  3930. - // the new entry in scratch_cp so we need to map the index values.
  3931. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3932. - }
  3933. - (*merge_cp_length_p)++;
  3934. - } break;
  3935. -
  3936. - // this is an indirect CP entry so it needs special handling
  3937. - case JVM_CONSTANT_MethodType:
  3938. - {
  3939. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  3940. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  3941. - merge_cp_length_p, THREAD);
  3942. - if (new_ref_i != ref_i) {
  3943. - RC_TRACE(0x00080000,
  3944. - ("MethodType entry@%d ref_index change: %d to %d",
  3945. - *merge_cp_length_p, ref_i, new_ref_i));
  3946. - }
  3947. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  3948. - if (scratch_i != *merge_cp_length_p) {
  3949. - // The new entry in *merge_cp_p is at a different index than
  3950. - // the new entry in scratch_cp so we need to map the index values.
  3951. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3952. - }
  3953. - (*merge_cp_length_p)++;
  3954. - } break;
  3955. -
  3956. - // this is an indirect CP entry so it needs special handling
  3957. - case JVM_CONSTANT_MethodHandle:
  3958. - {
  3959. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  3960. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  3961. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  3962. - merge_cp_length_p, THREAD);
  3963. - if (new_ref_i != ref_i) {
  3964. - RC_TRACE(0x00080000,
  3965. - ("MethodHandle entry@%d ref_index change: %d to %d",
  3966. - *merge_cp_length_p, ref_i, new_ref_i));
  3967. - }
  3968. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  3969. - if (scratch_i != *merge_cp_length_p) {
  3970. - // The new entry in *merge_cp_p is at a different index than
  3971. - // the new entry in scratch_cp so we need to map the index values.
  3972. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3973. - }
  3974. - (*merge_cp_length_p)++;
  3975. - } break;
  3976. -
  3977. - // this is an indirect CP entry so it needs special handling
  3978. - case JVM_CONSTANT_InvokeDynamic:
  3979. - {
  3980. - // Index of the bootstrap specifier in the operands array
  3981. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  3982. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  3983. - merge_cp_length_p, THREAD);
  3984. - // The bootstrap method NameAndType_info index
  3985. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  3986. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  3987. - merge_cp_length_p, THREAD);
  3988. - if (new_bs_i != old_bs_i) {
  3989. - RC_TRACE(0x00080000,
  3990. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  3991. - *merge_cp_length_p, old_bs_i, new_bs_i));
  3992. - }
  3993. - if (new_ref_i != old_ref_i) {
  3994. - RC_TRACE(0x00080000,
  3995. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  3996. - *merge_cp_length_p, old_ref_i, new_ref_i));
  3997. - }
  3998. -
  3999. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  4000. - if (scratch_i != *merge_cp_length_p) {
  4001. - // The new entry in *merge_cp_p is at a different index than
  4002. - // the new entry in scratch_cp so we need to map the index values.
  4003. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4004. - }
  4005. - (*merge_cp_length_p)++;
  4006. - } break;
  4007. -
  4008. - // At this stage, Class or UnresolvedClass could be here, but not
  4009. - // ClassIndex
  4010. - case JVM_CONSTANT_ClassIndex: // fall through
  4011. -
  4012. - // Invalid is used as the tag for the second constant pool entry
  4013. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  4014. - // not be seen by itself.
  4015. - case JVM_CONSTANT_Invalid: // fall through
  4016. -
  4017. - // At this stage, String or UnresolvedString could be here, but not
  4018. - // StringIndex
  4019. - case JVM_CONSTANT_StringIndex: // fall through
  4020. -
  4021. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  4022. - // here
  4023. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  4024. -
  4025. - default:
  4026. - {
  4027. - // leave a breadcrumb
  4028. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  4029. - ShouldNotReachHere();
  4030. - } break;
  4031. - } // end switch tag value
  4032. -} // end append_entry()
  4033. -
  4034. -
  4035. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  4036. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  4037. -
  4038. - int new_ref_i = ref_i;
  4039. - bool match = (ref_i < *merge_cp_length_p) &&
  4040. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  4041. -
  4042. - if (!match) {
  4043. - // forward reference in *merge_cp_p or not a direct match
  4044. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  4045. - if (found_i != 0) {
  4046. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  4047. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  4048. - new_ref_i = found_i;
  4049. - map_index(scratch_cp, ref_i, found_i);
  4050. - } else {
  4051. - // no match found so we have to append this entry to *merge_cp_p
  4052. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  4053. - // The above call to append_entry() can only append one entry
  4054. - // so the post call query of *merge_cp_length_p is only for
  4055. - // the sake of consistency.
  4056. - new_ref_i = *merge_cp_length_p - 1;
  4057. - }
  4058. - }
  4059. -
  4060. - return new_ref_i;
  4061. -} // end find_or_append_indirect_entry()
  4062. -
  4063. -
  4064. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  4065. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  4066. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  4067. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  4068. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  4069. -
  4070. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  4071. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  4072. - merge_cp_length_p, THREAD);
  4073. - if (new_ref_i != old_ref_i) {
  4074. - RC_TRACE(0x00080000,
  4075. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  4076. - _operands_cur_length, old_ref_i, new_ref_i));
  4077. - }
  4078. -
  4079. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  4080. - int new_bs_i = _operands_cur_length;
  4081. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  4082. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  4083. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  4084. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  4085. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  4086. -
  4087. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  4088. - merge_ops->short_at_put(new_base++, new_ref_i);
  4089. - merge_ops->short_at_put(new_base++, argc);
  4090. -
  4091. - for (int i = 0; i < argc; i++) {
  4092. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  4093. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  4094. - merge_cp_length_p, THREAD);
  4095. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  4096. - if (new_arg_ref_i != old_arg_ref_i) {
  4097. - RC_TRACE(0x00080000,
  4098. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  4099. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  4100. - }
  4101. - }
  4102. - if (old_bs_i != _operands_cur_length) {
  4103. - // The bootstrap specifier in *merge_cp_p is at a different index than
  4104. - // that in scratch_cp so we need to map the index values.
  4105. - map_operand_index(old_bs_i, new_bs_i);
  4106. - }
  4107. - _operands_cur_length++;
  4108. -} // end append_operand()
  4109. -
  4110. -
  4111. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  4112. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  4113. -
  4114. - int new_bs_i = old_bs_i; // bootstrap specifier index
  4115. - bool match = (old_bs_i < _operands_cur_length) &&
  4116. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  4117. -
  4118. - if (!match) {
  4119. - // forward reference in *merge_cp_p or not a direct match
  4120. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  4121. - _operands_cur_length, THREAD);
  4122. - if (found_i != -1) {
  4123. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  4124. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  4125. - new_bs_i = found_i;
  4126. - map_operand_index(old_bs_i, found_i);
  4127. - } else {
  4128. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  4129. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  4130. - new_bs_i = _operands_cur_length - 1;
  4131. - }
  4132. - }
  4133. - return new_bs_i;
  4134. -} // end find_or_append_operand()
  4135. -
  4136. -
  4137. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  4138. - if (merge_cp->operands() == NULL) {
  4139. - return;
  4140. - }
  4141. - // Shrink the merge_cp operands
  4142. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  4143. -
  4144. - if (RC_TRACE_ENABLED(0x00040000)) {
  4145. - // don't want to loop unless we are tracing
  4146. - int count = 0;
  4147. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  4148. - int value = _operands_index_map_p->at(i);
  4149. - if (value != -1) {
  4150. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  4151. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  4152. - count++;
  4153. - }
  4154. - }
  4155. - }
  4156. - // Clean-up
  4157. - _operands_index_map_p = NULL;
  4158. - _operands_cur_length = 0;
  4159. - _operands_index_map_count = 0;
  4160. -} // end finalize_operands_merge()
  4161. -
  4162. void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  4163. typeArrayOop save;
  4164. @@ -591,20 +103,604 @@
  4165. scratch_class->set_method_default_annotations_of(j, save);
  4166. }
  4167. +void VM_RedefineClasses::add_affected_klasses( klassOop klass )
  4168. +{
  4169. + assert(!_affected_klasses->contains(klass), "must not occur more than once!");
  4170. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  4171. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4172. - instanceKlassHandle the_class,
  4173. - instanceKlassHandle scratch_class) {
  4174. + Klass* k = klass->klass_part();
  4175. +
  4176. + if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4177. + _affected_klasses->append(klass);
  4178. + return;
  4179. + }
  4180. +
  4181. + for (juint i = 0; i < k->super_depth(); i++) {
  4182. + klassOop primary_oop = k->primary_super_of_depth(i);
  4183. + // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
  4184. + if (primary_oop == NULL) break;
  4185. + Klass* primary = Klass::cast(primary_oop);
  4186. + if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4187. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  4188. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  4189. + _affected_klasses->append(klass);
  4190. + return;
  4191. + }
  4192. + }
  4193. +
  4194. + // Check secondary supers
  4195. + int cnt = k->secondary_supers()->length();
  4196. + for (int i = 0; i < cnt; i++) {
  4197. + Klass* secondary = Klass::cast((klassOop) k->secondary_supers()->obj_at(i));
  4198. + if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  4199. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  4200. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  4201. + _affected_klasses->append(klass);
  4202. + return;
  4203. + }
  4204. + }
  4205. +}
  4206. +
  4207. +
  4208. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4209. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes() {
  4210. +
  4211. + assert(_affected_klasses, "");
  4212. + for (int i = 0; i < _class_count; i++) {
  4213. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4214. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4215. + klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
  4216. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4217. + }
  4218. +
  4219. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4220. + SystemDictionary::classes_do(VM_RedefineClasses::add_affected_klasses);
  4221. + TRACE_RC1("%d classes affected", _affected_klasses->length());
  4222. +
  4223. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4224. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
  4225. + IF_TRACE_RC2 {
  4226. + TRACE_RC2("Redefine order: ");
  4227. + for (int i = 0; i < _affected_klasses->length(); i++) {
  4228. + TRACE_RC2("%s", _affected_klasses->at(i)->name()->as_C_string());
  4229. + }
  4230. + }
  4231. +
  4232. + return result;
  4233. +}
  4234. +
  4235. +// Searches for the class bytes of the given class and returns them as a byte array.
  4236. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4237. +
  4238. + *not_changed = false;
  4239. +
  4240. + // Search for the index in the redefinition array that corresponds to the current class
  4241. + int j;
  4242. + for (j=0; j<_class_count; j++) {
  4243. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4244. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4245. + if (the_class_oop == the_class()) {
  4246. + break;
  4247. + }
  4248. + }
  4249. +
  4250. + if (j == _class_count) {
  4251. +
  4252. + *not_changed = true;
  4253. +
  4254. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4255. + // so the user did not specify a different bytecode for that class.
  4256. +
  4257. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4258. + // not cached, we need to reconstitute the class file from VM representation
  4259. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4260. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4261. +
  4262. + JvmtiClassFileReconstituter reconstituter(the_class);
  4263. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4264. + return reconstituter.get_error();
  4265. + }
  4266. +
  4267. + *class_byte_count = (jint)reconstituter.class_file_size();
  4268. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4269. +
  4270. + TRACE_RC3("Reconstituted class bytes");
  4271. +
  4272. + } else {
  4273. +
  4274. + // it is cached, get it from the cache
  4275. + *class_byte_count = the_class->get_cached_class_file_len();
  4276. + *class_bytes = the_class->get_cached_class_file_bytes();
  4277. +
  4278. +
  4279. + TRACE_RC3("Retrieved cached class bytes");
  4280. + }
  4281. +
  4282. + } else {
  4283. +
  4284. + // Redefine with bytecodes at index j
  4285. + *class_bytes = _class_defs[j].class_bytes;
  4286. + *class_byte_count = _class_defs[j].class_byte_count;
  4287. + }
  4288. +
  4289. + return JVMTI_ERROR_NONE;
  4290. +}
  4291. +
  4292. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4293. +bool VM_RedefineClasses::doit_prologue() {
  4294. +
  4295. + _revision_number++;
  4296. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  4297. + lock_threads();
  4298. +
  4299. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4300. + RC_TIMER_START(_timer_prologue);
  4301. +
  4302. + if (!check_arguments()) {
  4303. + RC_TIMER_STOP(_timer_prologue);
  4304. + return false;
  4305. + }
  4306. +
  4307. + // We first load new class versions in the prologue, because somewhere down the
  4308. + // call chain it is required that the current thread is a Java thread.
  4309. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4310. +
  4311. + assert(_affected_klasses == NULL, "");
  4312. + _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
  4313. +
  4314. +
  4315. + _result = load_new_class_versions(Thread::current());
  4316. +
  4317. + TRACE_RC1("Loaded new class versions!");
  4318. + if (_result != JVMTI_ERROR_NONE) {
  4319. + TRACE_RC1("error occured: %d!", _result);
  4320. + delete _new_classes;
  4321. + _new_classes = NULL;
  4322. + delete _affected_klasses;
  4323. + _affected_klasses = NULL;
  4324. + RC_TIMER_STOP(_timer_prologue);
  4325. + return false;
  4326. + }
  4327. +
  4328. + TRACE_RC2("nearly finished");
  4329. + VM_GC_Operation::doit_prologue();
  4330. + RC_TIMER_STOP(_timer_prologue);
  4331. + TRACE_RC2("doit_prologue finished!");
  4332. + return true;
  4333. +}
  4334. +
  4335. +// Checks basic properties of the arguments of the redefinition command.
  4336. +jvmtiError VM_RedefineClasses::check_arguments_error() {
  4337. + if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
  4338. + for (int i = 0; i < _class_count; i++) {
  4339. + if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
  4340. + if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4341. + if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
  4342. + }
  4343. + return JVMTI_ERROR_NONE;
  4344. +}
  4345. +
  4346. +// Returns false and sets an result error code if the redefinition should be aborted.
  4347. +bool VM_RedefineClasses::check_arguments() {
  4348. + jvmtiError error = check_arguments_error();
  4349. + if (error != JVMTI_ERROR_NONE || _class_count == 0) {
  4350. + _result = error;
  4351. + return false;
  4352. + }
  4353. + return true;
  4354. +}
  4355. +
  4356. +jvmtiError VM_RedefineClasses::check_exception() const {
  4357. + Thread* THREAD = Thread::current();
  4358. + if (HAS_PENDING_EXCEPTION) {
  4359. +
  4360. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4361. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  4362. + if (TraceRedefineClasses >= 1) {
  4363. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4364. + tty->print_cr("");
  4365. + }
  4366. + CLEAR_PENDING_EXCEPTION;
  4367. +
  4368. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4369. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4370. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4371. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4372. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4373. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4374. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4375. + // The message will be "XXX (wrong name: YYY)"
  4376. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4377. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4378. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4379. + } else {
  4380. + // Just in case more exceptions can be thrown..
  4381. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4382. + }
  4383. + }
  4384. +
  4385. + return JVMTI_ERROR_NONE;
  4386. +}
  4387. +
  4388. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4389. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4390. +
  4391. + ResourceMark rm(THREAD);
  4392. +
  4393. + TRACE_RC1("===================================================================");
  4394. + TRACE_RC1("redefinition started by thread \"%s\"", THREAD->name());
  4395. + TRACE_RC1("load new class versions (%d)", _class_count);
  4396. +
  4397. + // Retrieve an array of all classes that need to be redefined
  4398. + jvmtiError err = find_sorted_affected_classes();
  4399. + if (err != JVMTI_ERROR_NONE) {
  4400. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  4401. + return err;
  4402. + }
  4403. +
  4404. +
  4405. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4406. +
  4407. + _max_redefinition_flags = Klass::NoRedefinition;
  4408. + jvmtiError result = JVMTI_ERROR_NONE;
  4409. +
  4410. + for (int i=0; i<_affected_klasses->length(); i++) {
  4411. + TRACE_RC2("Processing affected class %d of %d", i+1, _affected_klasses->length());
  4412. +
  4413. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4414. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  4415. +
  4416. + the_class->link_class(THREAD);
  4417. + result = check_exception();
  4418. + if (result != JVMTI_ERROR_NONE) break;
  4419. +
  4420. + // Find new class bytes
  4421. + const unsigned char* class_bytes;
  4422. + jint class_byte_count;
  4423. + jvmtiError error;
  4424. + jboolean not_changed;
  4425. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4426. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  4427. + result = error;
  4428. + break;
  4429. + }
  4430. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4431. +
  4432. +
  4433. + // Set redefined class handle in JvmtiThreadState class.
  4434. + // This redefined class is sent to agent event handler for class file
  4435. + // load hook event.
  4436. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4437. +
  4438. + TRACE_RC2("Before resolving from stream");
  4439. +
  4440. + RC_TIMER_STOP(_timer_prologue);
  4441. + RC_TIMER_START(_timer_class_loading);
  4442. +
  4443. +
  4444. + // Parse the stream.
  4445. + Handle the_class_loader(THREAD, the_class->class_loader());
  4446. + Handle protection_domain(THREAD, the_class->protection_domain());
  4447. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4448. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class->name(),
  4449. + the_class_loader,
  4450. + protection_domain,
  4451. + &st,
  4452. + true,
  4453. + the_class,
  4454. + THREAD));
  4455. +
  4456. + RC_TIMER_STOP(_timer_class_loading);
  4457. + RC_TIMER_START(_timer_prologue);
  4458. +
  4459. + TRACE_RC2("After resolving class from stream!");
  4460. + // Clear class_being_redefined just to be sure.
  4461. + state->clear_class_being_redefined();
  4462. +
  4463. + result = check_exception();
  4464. + if (result != JVMTI_ERROR_NONE) break;
  4465. +
  4466. + not_changed = false;
  4467. +
  4468. +#ifdef ASSERT
  4469. +
  4470. + assert(new_class() != NULL, "Class could not be loaded!");
  4471. + assert(new_class() != the_class(), "must be different");
  4472. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4473. +
  4474. +
  4475. + objArrayOop k_interfaces = new_class->local_interfaces();
  4476. + for (int j=0; j<k_interfaces->length(); j++) {
  4477. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4478. + }
  4479. +
  4480. + if (!THREAD->is_Compiler_thread()) {
  4481. +
  4482. + 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());
  4483. + // If we are on the compiler thread, we must not try to resolve a class.
  4484. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4485. +
  4486. + if (systemLookup != NULL) {
  4487. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4488. +
  4489. +
  4490. + Klass *subklass = new_class()->klass_part()->subklass();
  4491. + while (subklass != NULL) {
  4492. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4493. + subklass = subklass->next_sibling();
  4494. + }
  4495. + } else {
  4496. + // This can happen for reflection generated classes.. ?
  4497. + CLEAR_PENDING_EXCEPTION;
  4498. + }
  4499. + }
  4500. +
  4501. +#endif
  4502. +
  4503. + IF_TRACE_RC1 {
  4504. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4505. + 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());
  4506. + }
  4507. + }
  4508. +
  4509. + // Set the new version of the class
  4510. + new_class->set_revision_number(_revision_number);
  4511. + new_class->set_redefinition_index(i);
  4512. + the_class->set_new_version(new_class());
  4513. + _new_classes->append(new_class);
  4514. +
  4515. + assert(new_class->new_version() == NULL, "");
  4516. +
  4517. + int redefinition_flags = Klass::NoRedefinition;
  4518. +
  4519. + if (not_changed) {
  4520. + redefinition_flags = Klass::NoRedefinition;
  4521. + } else if (AllowAdvancedClassRedefinition) {
  4522. + redefinition_flags = calculate_redefinition_flags(new_class);
  4523. + if (redefinition_flags >= Klass::RemoveSuperType) {
  4524. + TRACE_RC1("Remove super type is not allowed");
  4525. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4526. + break;
  4527. + }
  4528. + } else {
  4529. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4530. + if (allowed != JVMTI_ERROR_NONE) {
  4531. + TRACE_RC1("Error redefinition not allowed!");
  4532. + result = allowed;
  4533. + break;
  4534. + }
  4535. + redefinition_flags = Klass::ModifyClass;
  4536. + }
  4537. +
  4538. + if (new_class->super() != NULL) {
  4539. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4540. + }
  4541. +
  4542. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4543. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4544. + }
  4545. +
  4546. + new_class->set_redefinition_flags(redefinition_flags);
  4547. +
  4548. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4549. +
  4550. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4551. + // TODO: Check if watch access flags of static fields are updated correctly.
  4552. + calculate_instance_update_information(_new_classes->at(i)());
  4553. + } else {
  4554. + // Fields were not changed, transfer special flags only
  4555. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4556. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4557. +
  4558. + JavaFieldStream old_fs(the_class);
  4559. + JavaFieldStream new_fs(new_class);
  4560. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4561. + AccessFlags flags = new_fs.access_flags();
  4562. + flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
  4563. + flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
  4564. + new_fs.set_access_flags(flags);
  4565. + }
  4566. + }
  4567. +
  4568. + IF_TRACE_RC3 {
  4569. + if (new_class->super() != NULL) {
  4570. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  4571. + }
  4572. + }
  4573. +
  4574. +#ifdef ASSERT
  4575. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4576. +
  4577. + the_class->vtable()->verify(tty);
  4578. + new_class->vtable()->verify(tty);
  4579. +#endif
  4580. +
  4581. + TRACE_RC2("Verification done!");
  4582. +
  4583. + if (i == _affected_klasses->length() - 1) {
  4584. +
  4585. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4586. +
  4587. + for (int j=0; j<_affected_klasses->length(); j++) {
  4588. +
  4589. + klassOop initial_klass = _affected_klasses->at(j)();
  4590. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4591. + Klass *cur_klass = initial_subklass;
  4592. + while(cur_klass != NULL) {
  4593. +
  4594. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
  4595. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4596. + if (!_affected_klasses->contains(handle)) {
  4597. +
  4598. + int k = i + 1;
  4599. + for (; k<_affected_klasses->length(); k++) {
  4600. + if (_affected_klasses->at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4601. + break;
  4602. + }
  4603. + }
  4604. + _affected_klasses->insert_before(k, handle);
  4605. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  4606. + }
  4607. + }
  4608. +
  4609. + cur_klass = cur_klass->next_sibling();
  4610. + }
  4611. + }
  4612. +
  4613. + int new_count = _affected_klasses->length() - 1 - i;
  4614. + if (new_count != 0) {
  4615. +
  4616. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  4617. + }
  4618. + }
  4619. + }
  4620. +
  4621. + if (result != JVMTI_ERROR_NONE) {
  4622. + rollback();
  4623. + return result;
  4624. + }
  4625. +
  4626. + RC_TIMER_STOP(_timer_prologue);
  4627. + RC_TIMER_START(_timer_class_linking);
  4628. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4629. + for (int i=0; i<_affected_klasses->length(); i++) {
  4630. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4631. + instanceKlassHandle new_class(the_class->new_version());
  4632. +
  4633. + TRACE_RC2("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string());
  4634. + new_class->link_class(THREAD);
  4635. +
  4636. + result = check_exception();
  4637. + if (result != JVMTI_ERROR_NONE) break;
  4638. + }
  4639. + RC_TIMER_STOP(_timer_class_linking);
  4640. + RC_TIMER_START(_timer_prologue);
  4641. +
  4642. + if (result != JVMTI_ERROR_NONE) {
  4643. + rollback();
  4644. + return result;
  4645. + }
  4646. +
  4647. + TRACE_RC2("All classes loaded!");
  4648. +
  4649. +#ifdef ASSERT
  4650. + for (int i=0; i<_affected_klasses->length(); i++) {
  4651. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4652. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4653. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  4654. + assert(new_version->new_version() == NULL, "Must be newest version");
  4655. +
  4656. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  4657. + new_version()->print();
  4658. + new_version->super()->print();
  4659. + }
  4660. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  4661. + }
  4662. +
  4663. + SystemDictionary::classes_do(check_class, THREAD);
  4664. +
  4665. +#endif
  4666. +
  4667. + TRACE_RC1("Finished verification!");
  4668. + return JVMTI_ERROR_NONE;
  4669. +}
  4670. +
  4671. +void VM_RedefineClasses::lock_threads() {
  4672. +
  4673. + RC_TIMER_START(_timer_wait_for_locks);
  4674. +
  4675. +
  4676. + JavaThread *javaThread = Threads::first();
  4677. + while (javaThread != NULL) {
  4678. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4679. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4680. + compilerThread->set_should_bailout(true);
  4681. + }
  4682. + javaThread = javaThread->next();
  4683. + }
  4684. +
  4685. + int cnt = 0;
  4686. + javaThread = Threads::first();
  4687. + while (javaThread != NULL) {
  4688. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4689. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4690. + compilerThread->compilation_mutex()->lock();
  4691. + cnt++;
  4692. + }
  4693. + javaThread = javaThread->next();
  4694. + }
  4695. +
  4696. + TRACE_RC2("Locked %d compiler threads", cnt);
  4697. +
  4698. + cnt = 0;
  4699. + javaThread = Threads::first();
  4700. + while (javaThread != NULL) {
  4701. + if (javaThread != Thread::current()) {
  4702. + javaThread->redefine_classes_mutex()->lock();
  4703. + cnt++;
  4704. + }
  4705. + javaThread = javaThread->next();
  4706. + }
  4707. +
  4708. +
  4709. + TRACE_RC2("Locked %d threads", cnt);
  4710. +
  4711. + RC_TIMER_STOP(_timer_wait_for_locks);
  4712. +}
  4713. +
  4714. +void VM_RedefineClasses::unlock_threads() {
  4715. +
  4716. + int cnt = 0;
  4717. + JavaThread *javaThread = Threads::first();
  4718. + Thread *thread = Thread::current();
  4719. + while (javaThread != NULL) {
  4720. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4721. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4722. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  4723. + compilerThread->compilation_mutex()->unlock();
  4724. + cnt++;
  4725. + }
  4726. + }
  4727. + javaThread = javaThread->next();
  4728. + }
  4729. +
  4730. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  4731. +
  4732. + cnt = 0;
  4733. + javaThread = Threads::first();
  4734. + while (javaThread != NULL) {
  4735. + if (javaThread != Thread::current()) {
  4736. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  4737. + javaThread->redefine_classes_mutex()->unlock();
  4738. + cnt++;
  4739. + }
  4740. + }
  4741. + javaThread = javaThread->next();
  4742. + }
  4743. +
  4744. + TRACE_RC2("Unlocked %d threads", cnt);
  4745. +}
  4746. +
  4747. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  4748. +
  4749. +
  4750. +
  4751. + // Compatibility mode => check for unsupported modification
  4752. +
  4753. +
  4754. + assert(scratch_class->old_version() != NULL, "must have old version");
  4755. + instanceKlassHandle the_class(scratch_class->old_version());
  4756. +
  4757. int i;
  4758. // Check superclasses, or rather their names, since superclasses themselves can be
  4759. // requested to replace.
  4760. // Check for NULL superclass first since this might be java.lang.Object
  4761. if (the_class->super() != scratch_class->super() &&
  4762. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  4763. - Klass::cast(the_class->super())->name() !=
  4764. - Klass::cast(scratch_class->super())->name())) {
  4765. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4766. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  4767. + Klass::cast(the_class->super())->name() !=
  4768. + Klass::cast(scratch_class->super())->name())) {
  4769. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4770. }
  4771. // Check if the number, names and order of directly implemented interfaces are the same.
  4772. @@ -622,8 +718,8 @@
  4773. }
  4774. for (i = 0; i < n_intfs; i++) {
  4775. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  4776. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4777. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4778. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4779. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4780. }
  4781. }
  4782. @@ -772,12 +868,8 @@
  4783. idnum_owner->set_method_idnum(new_num);
  4784. }
  4785. k_new_method->set_method_idnum(old_num);
  4786. - swap_all_method_annotations(old_num, new_num, scratch_class);
  4787. }
  4788. }
  4789. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  4790. - k_new_method->name_and_sig_as_C_string(), ni,
  4791. - k_old_method->name_and_sig_as_C_string(), oi));
  4792. // advance to next pair of methods
  4793. ++oi;
  4794. ++ni;
  4795. @@ -786,11 +878,11 @@
  4796. // method added, see if it is OK
  4797. new_flags = (jushort) k_new_method->access_flags().get_flags();
  4798. if ((new_flags & JVM_ACC_PRIVATE) == 0
  4799. - // hack: private should be treated as final, but alas
  4800. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4801. - ) {
  4802. - // new methods must be private
  4803. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4804. + // hack: private should be treated as final, but alas
  4805. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4806. + ) {
  4807. + // new methods must be private
  4808. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4809. }
  4810. {
  4811. u2 num = the_class->next_method_idnum();
  4812. @@ -805,24 +897,19 @@
  4813. idnum_owner->set_method_idnum(new_num);
  4814. }
  4815. k_new_method->set_method_idnum(num);
  4816. - swap_all_method_annotations(new_num, num, scratch_class);
  4817. }
  4818. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  4819. - k_new_method->name_and_sig_as_C_string(), ni));
  4820. ++ni; // advance to next new method
  4821. break;
  4822. case deleted:
  4823. // method deleted, see if it is OK
  4824. old_flags = (jushort) k_old_method->access_flags().get_flags();
  4825. if ((old_flags & JVM_ACC_PRIVATE) == 0
  4826. - // hack: private should be treated as final, but alas
  4827. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4828. - ) {
  4829. - // deleted methods must be private
  4830. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4831. + // hack: private should be treated as final, but alas
  4832. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4833. + ) {
  4834. + // deleted methods must be private
  4835. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4836. }
  4837. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  4838. - k_old_method->name_and_sig_as_C_string(), oi));
  4839. ++oi; // advance to next old method
  4840. break;
  4841. default:
  4842. @@ -833,2119 +920,1332 @@
  4843. return JVMTI_ERROR_NONE;
  4844. }
  4845. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  4846. -// Find new constant pool index value for old constant pool index value
  4847. -// by seaching the index map. Returns zero (0) if there is no mapped
  4848. -// value for the old constant pool index.
  4849. -int VM_RedefineClasses::find_new_index(int old_index) {
  4850. - if (_index_map_count == 0) {
  4851. - // map is empty so nothing can be found
  4852. - return 0;
  4853. + int result = Klass::NoRedefinition;
  4854. +
  4855. +
  4856. +
  4857. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  4858. +
  4859. + assert(new_class->old_version() != NULL, "must have old version");
  4860. + instanceKlassHandle the_class(new_class->old_version());
  4861. +
  4862. + // Check whether class is in the error init state.
  4863. + if (the_class->is_in_error_state()) {
  4864. + // TBD #5057930: special error code is needed in 1.6
  4865. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  4866. }
  4867. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  4868. - // The old_index is out of range so it is not mapped. This should
  4869. - // not happen in regular constant pool merging use, but it can
  4870. - // happen if a corrupt annotation is processed.
  4871. - return 0;
  4872. - }
  4873. + int i;
  4874. - int value = _index_map_p->at(old_index);
  4875. - if (value == -1) {
  4876. - // the old_index is not mapped
  4877. - return 0;
  4878. - }
  4879. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4880. + // Check superclasses
  4881. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  4882. + if (the_class->super() != new_class->super()) {
  4883. + // Super class changed
  4884. - return value;
  4885. -} // end find_new_index()
  4886. + klassOop cur_klass = the_class->super();
  4887. + while (cur_klass != NULL) {
  4888. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  4889. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  4890. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  4891. -
  4892. -// Find new bootstrap specifier index value for old bootstrap specifier index
  4893. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  4894. -// value for the old bootstrap specifier index.
  4895. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  4896. - if (_operands_index_map_count == 0) {
  4897. - // map is empty so nothing can be found
  4898. - return -1;
  4899. - }
  4900. -
  4901. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  4902. - // The old_index is out of range so it is not mapped.
  4903. - // This should not happen in regular constant pool merging use.
  4904. - return -1;
  4905. - }
  4906. -
  4907. - int value = _operands_index_map_p->at(old_index);
  4908. -
  4909. - return value;
  4910. -} // end find_new_operand_index()
  4911. -
  4912. -
  4913. -// Returns true if the current mismatch is due to a resolved/unresolved
  4914. -// class pair. Otherwise, returns false.
  4915. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  4916. - int index1, constantPoolHandle cp2, int index2) {
  4917. -
  4918. - jbyte t1 = cp1->tag_at(index1).value();
  4919. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  4920. - return false; // wrong entry type; not our special case
  4921. - }
  4922. -
  4923. - jbyte t2 = cp2->tag_at(index2).value();
  4924. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  4925. - return false; // wrong entry type; not our special case
  4926. - }
  4927. -
  4928. - if (t1 == t2) {
  4929. - return false; // not a mismatch; not our special case
  4930. - }
  4931. -
  4932. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  4933. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  4934. - if (strcmp(s1, s2) != 0) {
  4935. - return false; // strings don't match; not our special case
  4936. - }
  4937. -
  4938. - return true; // made it through the gauntlet; this is our special case
  4939. -} // end is_unresolved_class_mismatch()
  4940. -
  4941. -
  4942. -// Returns true if the current mismatch is due to a resolved/unresolved
  4943. -// string pair. Otherwise, returns false.
  4944. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  4945. - int index1, constantPoolHandle cp2, int index2) {
  4946. -
  4947. - jbyte t1 = cp1->tag_at(index1).value();
  4948. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  4949. - return false; // wrong entry type; not our special case
  4950. - }
  4951. -
  4952. - jbyte t2 = cp2->tag_at(index2).value();
  4953. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  4954. - return false; // wrong entry type; not our special case
  4955. - }
  4956. -
  4957. - if (t1 == t2) {
  4958. - return false; // not a mismatch; not our special case
  4959. - }
  4960. -
  4961. - char *s1 = cp1->string_at_noresolve(index1);
  4962. - char *s2 = cp2->string_at_noresolve(index2);
  4963. - if (strcmp(s1, s2) != 0) {
  4964. - return false; // strings don't match; not our special case
  4965. - }
  4966. -
  4967. - return true; // made it through the gauntlet; this is our special case
  4968. -} // end is_unresolved_string_mismatch()
  4969. -
  4970. -
  4971. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4972. - // For consistency allocate memory using os::malloc wrapper.
  4973. - _scratch_classes = (instanceKlassHandle *)
  4974. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  4975. - if (_scratch_classes == NULL) {
  4976. - return JVMTI_ERROR_OUT_OF_MEMORY;
  4977. - }
  4978. -
  4979. - ResourceMark rm(THREAD);
  4980. -
  4981. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4982. - // state can only be NULL if the current thread is exiting which
  4983. - // should not happen since we're trying to do a RedefineClasses
  4984. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  4985. - for (int i = 0; i < _class_count; i++) {
  4986. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4987. - // classes for primitives cannot be redefined
  4988. - if (!is_modifiable_class(mirror)) {
  4989. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  4990. - }
  4991. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4992. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  4993. - Symbol* the_class_sym = the_class->name();
  4994. -
  4995. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  4996. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  4997. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  4998. - the_class->external_name(), _class_load_kind,
  4999. - os::available_memory() >> 10));
  5000. -
  5001. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5002. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5003. -
  5004. - // Parse the stream.
  5005. - Handle the_class_loader(THREAD, the_class->class_loader());
  5006. - Handle protection_domain(THREAD, the_class->protection_domain());
  5007. - // Set redefined class handle in JvmtiThreadState class.
  5008. - // This redefined class is sent to agent event handler for class file
  5009. - // load hook event.
  5010. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5011. -
  5012. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5013. - the_class_loader,
  5014. - protection_domain,
  5015. - &st,
  5016. - THREAD);
  5017. - // Clear class_being_redefined just to be sure.
  5018. - state->clear_class_being_redefined();
  5019. -
  5020. - // TODO: if this is retransform, and nothing changed we can skip it
  5021. -
  5022. - instanceKlassHandle scratch_class (THREAD, k);
  5023. -
  5024. - if (HAS_PENDING_EXCEPTION) {
  5025. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5026. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5027. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5028. - ex_name->as_C_string()));
  5029. - CLEAR_PENDING_EXCEPTION;
  5030. -
  5031. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5032. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5033. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5034. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5035. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5036. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5037. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5038. - // The message will be "XXX (wrong name: YYY)"
  5039. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5040. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5041. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5042. - } else { // Just in case more exceptions can be thrown..
  5043. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5044. - }
  5045. - }
  5046. -
  5047. - // Ensure class is linked before redefine
  5048. - if (!the_class->is_linked()) {
  5049. - the_class->link_class(THREAD);
  5050. - if (HAS_PENDING_EXCEPTION) {
  5051. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5052. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5053. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5054. - ex_name->as_C_string()));
  5055. - CLEAR_PENDING_EXCEPTION;
  5056. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5057. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5058. - } else {
  5059. - return JVMTI_ERROR_INTERNAL;
  5060. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5061. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  5062. + cur_klass->klass_part()->set_subtype_changed(true);
  5063. }
  5064. }
  5065. +
  5066. + cur_klass = cur_klass->klass_part()->super();
  5067. }
  5068. - // Do the validity checks in compare_and_normalize_class_versions()
  5069. - // before verifying the byte codes. By doing these checks first, we
  5070. - // limit the number of functions that require redirection from
  5071. - // the_class to scratch_class. In particular, we don't have to
  5072. - // modify JNI GetSuperclass() and thus won't change its performance.
  5073. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5074. - scratch_class);
  5075. - if (res != JVMTI_ERROR_NONE) {
  5076. - return res;
  5077. - }
  5078. -
  5079. - // verify what the caller passed us
  5080. - {
  5081. - // The bug 6214132 caused the verification to fail.
  5082. - // Information about the_class and scratch_class is temporarily
  5083. - // recorded into jvmtiThreadState. This data is used to redirect
  5084. - // the_class to scratch_class in the JVM_* functions called by the
  5085. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5086. - // description.
  5087. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5088. - Verifier::verify(
  5089. - scratch_class, Verifier::ThrowException, true, THREAD);
  5090. - }
  5091. -
  5092. - if (HAS_PENDING_EXCEPTION) {
  5093. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5094. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5095. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5096. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5097. - CLEAR_PENDING_EXCEPTION;
  5098. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5099. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5100. - } else {
  5101. - // tell the caller the bytecodes are bad
  5102. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5103. + cur_klass = new_class->super();
  5104. + while (cur_klass != NULL) {
  5105. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5106. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  5107. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5108. }
  5109. - }
  5110. -
  5111. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5112. - if (res != JVMTI_ERROR_NONE) {
  5113. - return res;
  5114. - }
  5115. -
  5116. - if (VerifyMergedCPBytecodes) {
  5117. - // verify what we have done during constant pool merging
  5118. - {
  5119. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5120. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  5121. - }
  5122. -
  5123. - if (HAS_PENDING_EXCEPTION) {
  5124. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5125. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5126. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5127. - ("verify_byte_codes post merge-CP exception: '%s'",
  5128. - ex_name->as_C_string()));
  5129. - CLEAR_PENDING_EXCEPTION;
  5130. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5131. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5132. - } else {
  5133. - // tell the caller that constant pool merging screwed up
  5134. - return JVMTI_ERROR_INTERNAL;
  5135. - }
  5136. - }
  5137. - }
  5138. -
  5139. - Rewriter::rewrite(scratch_class, THREAD);
  5140. - if (!HAS_PENDING_EXCEPTION) {
  5141. - Rewriter::relocate_and_link(scratch_class, THREAD);
  5142. - }
  5143. - if (HAS_PENDING_EXCEPTION) {
  5144. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5145. - CLEAR_PENDING_EXCEPTION;
  5146. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5147. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5148. - } else {
  5149. - return JVMTI_ERROR_INTERNAL;
  5150. - }
  5151. - }
  5152. -
  5153. - _scratch_classes[i] = scratch_class;
  5154. -
  5155. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5156. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5157. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  5158. - the_class->external_name(), os::available_memory() >> 10));
  5159. - }
  5160. -
  5161. - return JVMTI_ERROR_NONE;
  5162. -}
  5163. -
  5164. -
  5165. -// Map old_index to new_index as needed. scratch_cp is only needed
  5166. -// for RC_TRACE() calls.
  5167. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  5168. - int old_index, int new_index) {
  5169. - if (find_new_index(old_index) != 0) {
  5170. - // old_index is already mapped
  5171. - return;
  5172. - }
  5173. -
  5174. - if (old_index == new_index) {
  5175. - // no mapping is needed
  5176. - return;
  5177. - }
  5178. -
  5179. - _index_map_p->at_put(old_index, new_index);
  5180. - _index_map_count++;
  5181. -
  5182. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  5183. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  5184. -} // end map_index()
  5185. -
  5186. -
  5187. -// Map old_index to new_index as needed.
  5188. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  5189. - if (find_new_operand_index(old_index) != -1) {
  5190. - // old_index is already mapped
  5191. - return;
  5192. - }
  5193. -
  5194. - if (old_index == new_index) {
  5195. - // no mapping is needed
  5196. - return;
  5197. - }
  5198. -
  5199. - _operands_index_map_p->at_put(old_index, new_index);
  5200. - _operands_index_map_count++;
  5201. -
  5202. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  5203. -} // end map_index()
  5204. -
  5205. -
  5206. -// Merge old_cp and scratch_cp and return the results of the merge via
  5207. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  5208. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  5209. -// in *merge_cp_p. Also creates a map of indices from entries in
  5210. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  5211. -// entries are only created for entries in scratch_cp that occupy a
  5212. -// different location in *merged_cp_p.
  5213. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  5214. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  5215. - int *merge_cp_length_p, TRAPS) {
  5216. -
  5217. - if (merge_cp_p == NULL) {
  5218. - assert(false, "caller must provide scatch constantPool");
  5219. - return false; // robustness
  5220. - }
  5221. - if (merge_cp_length_p == NULL) {
  5222. - assert(false, "caller must provide scatch CP length");
  5223. - return false; // robustness
  5224. - }
  5225. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  5226. - // but the caller might be smart so make sure we have at least
  5227. - // the minimum.
  5228. - if ((*merge_cp_p)->length() < old_cp->length()) {
  5229. - assert(false, "merge area too small");
  5230. - return false; // robustness
  5231. - }
  5232. -
  5233. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5234. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  5235. - scratch_cp->length()));
  5236. -
  5237. - {
  5238. - // Pass 0:
  5239. - // The old_cp is copied to *merge_cp_p; this means that any code
  5240. - // using old_cp does not have to change. This work looks like a
  5241. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  5242. - // handle one special case:
  5243. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  5244. - // This will make verification happy.
  5245. -
  5246. - int old_i; // index into old_cp
  5247. -
  5248. - // index zero (0) is not used in constantPools
  5249. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  5250. - // leave debugging crumb
  5251. - jbyte old_tag = old_cp->tag_at(old_i).value();
  5252. - switch (old_tag) {
  5253. - case JVM_CONSTANT_Class:
  5254. - case JVM_CONSTANT_UnresolvedClass:
  5255. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5256. - // May be resolving while calling this so do the same for
  5257. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  5258. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  5259. - old_cp->klass_name_at(old_i));
  5260. - break;
  5261. -
  5262. - case JVM_CONSTANT_Double:
  5263. - case JVM_CONSTANT_Long:
  5264. - // just copy the entry to *merge_cp_p, but double and long take
  5265. - // two constant pool entries
  5266. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5267. - old_i++;
  5268. - break;
  5269. -
  5270. - default:
  5271. - // just copy the entry to *merge_cp_p
  5272. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5273. - break;
  5274. - }
  5275. - } // end for each old_cp entry
  5276. -
  5277. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  5278. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  5279. -
  5280. - // We don't need to sanity check that *merge_cp_length_p is within
  5281. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  5282. - (*merge_cp_length_p) = old_i;
  5283. - }
  5284. -
  5285. - // merge_cp_len should be the same as old_cp->length() at this point
  5286. - // so this trace message is really a "warm-and-breathing" message.
  5287. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5288. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  5289. -
  5290. - int scratch_i; // index into scratch_cp
  5291. - {
  5292. - // Pass 1a:
  5293. - // Compare scratch_cp entries to the old_cp entries that we have
  5294. - // already copied to *merge_cp_p. In this pass, we are eliminating
  5295. - // exact duplicates (matching entry at same index) so we only
  5296. - // compare entries in the common indice range.
  5297. - int increment = 1;
  5298. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  5299. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  5300. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5301. - case JVM_CONSTANT_Double:
  5302. - case JVM_CONSTANT_Long:
  5303. - // double and long take two constant pool entries
  5304. - increment = 2;
  5305. - break;
  5306. -
  5307. - default:
  5308. - increment = 1;
  5309. - break;
  5310. - }
  5311. -
  5312. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  5313. - scratch_i, CHECK_0);
  5314. - if (match) {
  5315. - // found a match at the same index so nothing more to do
  5316. - continue;
  5317. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  5318. - *merge_cp_p, scratch_i)) {
  5319. - // The mismatch in compare_entry_to() above is because of a
  5320. - // resolved versus unresolved class entry at the same index
  5321. - // with the same string value. Since Pass 0 reverted any
  5322. - // class entries to unresolved class entries in *merge_cp_p,
  5323. - // we go with the unresolved class entry.
  5324. - continue;
  5325. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  5326. - *merge_cp_p, scratch_i)) {
  5327. - // The mismatch in compare_entry_to() above is because of a
  5328. - // resolved versus unresolved string entry at the same index
  5329. - // with the same string value. We can live with whichever
  5330. - // happens to be at scratch_i in *merge_cp_p.
  5331. - continue;
  5332. - }
  5333. -
  5334. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  5335. - CHECK_0);
  5336. - if (found_i != 0) {
  5337. - guarantee(found_i != scratch_i,
  5338. - "compare_entry_to() and find_matching_entry() do not agree");
  5339. -
  5340. - // Found a matching entry somewhere else in *merge_cp_p so
  5341. - // just need a mapping entry.
  5342. - map_index(scratch_cp, scratch_i, found_i);
  5343. - continue;
  5344. - }
  5345. -
  5346. - // The find_matching_entry() call above could fail to find a match
  5347. - // due to a resolved versus unresolved class or string entry situation
  5348. - // like we solved above with the is_unresolved_*_mismatch() calls.
  5349. - // However, we would have to call is_unresolved_*_mismatch() over
  5350. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  5351. - // worth the time.
  5352. -
  5353. - // No match found so we have to append this entry and any unique
  5354. - // referenced entries to *merge_cp_p.
  5355. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5356. - CHECK_0);
  5357. + cur_klass = cur_klass->klass_part()->super();
  5358. }
  5359. }
  5360. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5361. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5362. - *merge_cp_length_p, scratch_i, _index_map_count));
  5363. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5364. + // Check interfaces
  5365. - if (scratch_i < scratch_cp->length()) {
  5366. - // Pass 1b:
  5367. - // old_cp is smaller than scratch_cp so there are entries in
  5368. - // scratch_cp that we have not yet processed. We take care of
  5369. - // those now.
  5370. - int increment = 1;
  5371. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  5372. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5373. - case JVM_CONSTANT_Double:
  5374. - case JVM_CONSTANT_Long:
  5375. - // double and long take two constant pool entries
  5376. - increment = 2;
  5377. - break;
  5378. -
  5379. - default:
  5380. - increment = 1;
  5381. - break;
  5382. + // Interfaces removed?
  5383. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5384. + for (i = 0; i<old_interfaces->length(); i++) {
  5385. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5386. + if (!new_class->implements_interface_any_version(old_interface())) {
  5387. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5388. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  5389. +
  5390. + if (!old_interface->has_subtype_changed()) {
  5391. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  5392. + old_interface->set_subtype_changed(true);
  5393. }
  5394. -
  5395. - int found_i =
  5396. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  5397. - if (found_i != 0) {
  5398. - // Found a matching entry somewhere else in *merge_cp_p so
  5399. - // just need a mapping entry.
  5400. - map_index(scratch_cp, scratch_i, found_i);
  5401. - continue;
  5402. - }
  5403. -
  5404. - // No match found so we have to append this entry and any unique
  5405. - // referenced entries to *merge_cp_p.
  5406. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5407. - CHECK_0);
  5408. }
  5409. -
  5410. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5411. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5412. - *merge_cp_length_p, scratch_i, _index_map_count));
  5413. - }
  5414. - finalize_operands_merge(*merge_cp_p, THREAD);
  5415. -
  5416. - return true;
  5417. -} // end merge_constant_pools()
  5418. -
  5419. -
  5420. -// Merge constant pools between the_class and scratch_class and
  5421. -// potentially rewrite bytecodes in scratch_class to use the merged
  5422. -// constant pool.
  5423. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  5424. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  5425. - TRAPS) {
  5426. - // worst case merged constant pool length is old and new combined
  5427. - int merge_cp_length = the_class->constants()->length()
  5428. - + scratch_class->constants()->length();
  5429. -
  5430. - constantPoolHandle old_cp(THREAD, the_class->constants());
  5431. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  5432. -
  5433. - // Constant pools are not easily reused so we allocate a new one
  5434. - // each time.
  5435. - // merge_cp is created unsafe for concurrent GC processing. It
  5436. - // should be marked safe before discarding it. Even though
  5437. - // garbage, if it crosses a card boundary, it may be scanned
  5438. - // in order to find the start of the first complete object on the card.
  5439. - constantPoolHandle merge_cp(THREAD,
  5440. - oopFactory::new_constantPool(merge_cp_length,
  5441. - oopDesc::IsUnsafeConc,
  5442. - THREAD));
  5443. - int orig_length = old_cp->orig_length();
  5444. - if (orig_length == 0) {
  5445. - // This old_cp is an actual original constant pool. We save
  5446. - // the original length in the merged constant pool so that
  5447. - // merge_constant_pools() can be more efficient. If a constant
  5448. - // pool has a non-zero orig_length() value, then that constant
  5449. - // pool was created by a merge operation in RedefineClasses.
  5450. - merge_cp->set_orig_length(old_cp->length());
  5451. - } else {
  5452. - // This old_cp is a merged constant pool from a previous
  5453. - // RedefineClasses() calls so just copy the orig_length()
  5454. - // value.
  5455. - merge_cp->set_orig_length(old_cp->orig_length());
  5456. }
  5457. - ResourceMark rm(THREAD);
  5458. - _index_map_count = 0;
  5459. - _index_map_p = new intArray(scratch_cp->length(), -1);
  5460. -
  5461. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  5462. - _operands_index_map_count = 0;
  5463. - _operands_index_map_p = new intArray(
  5464. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  5465. -
  5466. - // reference to the cp holder is needed for copy_operands()
  5467. - merge_cp->set_pool_holder(scratch_class());
  5468. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  5469. - &merge_cp_length, THREAD);
  5470. - merge_cp->set_pool_holder(NULL);
  5471. -
  5472. - if (!result) {
  5473. - // The merge can fail due to memory allocation failure or due
  5474. - // to robustness checks.
  5475. - return JVMTI_ERROR_INTERNAL;
  5476. + // Interfaces added?
  5477. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5478. + for (i = 0; i<new_interfaces->length(); i++) {
  5479. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5480. + result = result | Klass::ModifyClass;
  5481. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  5482. + }
  5483. }
  5484. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5485. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  5486. - if (_index_map_count == 0) {
  5487. - // there is nothing to map between the new and merged constant pools
  5488. + // Check whether class modifiers are the same.
  5489. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5490. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5491. + if (old_flags != new_flags) {
  5492. + // TODO (tw): Can this have any effects?
  5493. + }
  5494. +
  5495. + // Check if the number, names, types and order of fields declared in these classes
  5496. + // are the same.
  5497. + JavaFieldStream old_fs(the_class);
  5498. + JavaFieldStream new_fs(new_class);
  5499. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5500. + // access
  5501. + old_flags = old_fs.access_flags().as_short();
  5502. + new_flags = new_fs.access_flags().as_short();
  5503. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5504. + // TODO (tw) can this have any effect?
  5505. + }
  5506. + // offset
  5507. + if (old_fs.offset() != new_fs.offset()) {
  5508. + result = result | Klass::ModifyInstances;
  5509. + }
  5510. + // name and signature
  5511. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5512. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5513. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5514. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5515. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5516. + result = result | Klass::ModifyInstances;
  5517. + }
  5518. + }
  5519. - if (old_cp->length() == scratch_cp->length()) {
  5520. - // The old and new constant pools are the same length and the
  5521. - // index map is empty. This means that the three constant pools
  5522. - // are equivalent (but not the same). Unfortunately, the new
  5523. - // constant pool has not gone through link resolution nor have
  5524. - // the new class bytecodes gone through constant pool cache
  5525. - // rewriting so we can't use the old constant pool with the new
  5526. - // class.
  5527. + // If both streams aren't done then we have a differing number of
  5528. + // fields.
  5529. + if (!old_fs.done() || !new_fs.done()) {
  5530. + result = result | Klass::ModifyInstances;
  5531. + }
  5532. - merge_cp()->set_is_conc_safe(true);
  5533. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5534. - } else if (old_cp->length() < scratch_cp->length()) {
  5535. - // The old constant pool has fewer entries than the new constant
  5536. - // pool and the index map is empty. This means the new constant
  5537. - // pool is a superset of the old constant pool. However, the old
  5538. - // class bytecodes have already gone through constant pool cache
  5539. - // rewriting so we can't use the new constant pool with the old
  5540. - // class.
  5541. + // Do a parallel walk through the old and new methods. Detect
  5542. + // cases where they match (exist in both), have been added in
  5543. + // the new methods, or have been deleted (exist only in the
  5544. + // old methods). The class file parser places methods in order
  5545. + // by method name, but does not order overloaded methods by
  5546. + // signature. In order to determine what fate befell the methods,
  5547. + // this code places the overloaded new methods that have matching
  5548. + // old methods in the same order as the old methods and places
  5549. + // new overloaded methods at the end of overloaded methods of
  5550. + // that name. The code for this order normalization is adapted
  5551. + // from the algorithm used in instanceKlass::find_method().
  5552. + // Since we are swapping out of order entries as we find them,
  5553. + // we only have to search forward through the overloaded methods.
  5554. + // Methods which are added and have the same name as an existing
  5555. + // method (but different signature) will be put at the end of
  5556. + // the methods with that name, and the name mismatch code will
  5557. + // handle them.
  5558. + objArrayHandle k_old_methods(the_class->methods());
  5559. + objArrayHandle k_new_methods(new_class->methods());
  5560. + int n_old_methods = k_old_methods->length();
  5561. + int n_new_methods = k_new_methods->length();
  5562. - merge_cp()->set_is_conc_safe(true);
  5563. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5564. + int ni = 0;
  5565. + int oi = 0;
  5566. + while (true) {
  5567. + methodOop k_old_method;
  5568. + methodOop k_new_method;
  5569. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  5570. +
  5571. + if (oi >= n_old_methods) {
  5572. + if (ni >= n_new_methods) {
  5573. + break; // we've looked at everything, done
  5574. + }
  5575. + // New method at the end
  5576. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5577. + method_was = added;
  5578. + } else if (ni >= n_new_methods) {
  5579. + // Old method, at the end, is deleted
  5580. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5581. + method_was = deleted;
  5582. } else {
  5583. - // The old constant pool has more entries than the new constant
  5584. - // pool and the index map is empty. This means that both the old
  5585. - // and merged constant pools are supersets of the new constant
  5586. - // pool.
  5587. + // There are more methods in both the old and new lists
  5588. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5589. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5590. + if (k_old_method->name() != k_new_method->name()) {
  5591. + // Methods are sorted by method name, so a mismatch means added
  5592. + // or deleted
  5593. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  5594. + method_was = added;
  5595. + } else {
  5596. + method_was = deleted;
  5597. + }
  5598. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5599. + // Both the name and signature match
  5600. + method_was = matched;
  5601. + } else {
  5602. + // The name matches, but the signature doesn't, which means we have to
  5603. + // search forward through the new overloaded methods.
  5604. + int nj; // outside the loop for post-loop check
  5605. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5606. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5607. + if (k_old_method->name() != m->name()) {
  5608. + // reached another method name so no more overloaded methods
  5609. + method_was = deleted;
  5610. + break;
  5611. + }
  5612. + if (k_old_method->signature() == m->signature()) {
  5613. + // found a match so swap the methods
  5614. + k_new_methods->obj_at_put(ni, m);
  5615. + k_new_methods->obj_at_put(nj, k_new_method);
  5616. + k_new_method = m;
  5617. + method_was = matched;
  5618. + break;
  5619. + }
  5620. + }
  5621. - // Replace the new constant pool with a shrunken copy of the
  5622. - // merged constant pool; the previous new constant pool will
  5623. - // get GCed.
  5624. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  5625. - THREAD);
  5626. - // drop local ref to the merged constant pool
  5627. - merge_cp()->set_is_conc_safe(true);
  5628. - merge_cp = constantPoolHandle();
  5629. - }
  5630. - } else {
  5631. - if (RC_TRACE_ENABLED(0x00040000)) {
  5632. - // don't want to loop unless we are tracing
  5633. - int count = 0;
  5634. - for (int i = 1; i < _index_map_p->length(); i++) {
  5635. - int value = _index_map_p->at(i);
  5636. -
  5637. - if (value != -1) {
  5638. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5639. - ("index_map[%d]: old=%d new=%d", count, i, value));
  5640. - count++;
  5641. + if (nj >= n_new_methods) {
  5642. + // reached the end without a match; so method was deleted
  5643. + method_was = deleted;
  5644. }
  5645. }
  5646. }
  5647. - // We have entries mapped between the new and merged constant pools
  5648. - // so we have to rewrite some constant pool references.
  5649. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  5650. - return JVMTI_ERROR_INTERNAL;
  5651. + switch (method_was) {
  5652. + case matched:
  5653. + // methods match, be sure modifiers do too
  5654. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5655. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5656. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  5657. + // (tw) Can this have any effects? Probably yes on vtables?
  5658. + result = result | Klass::ModifyClass;
  5659. }
  5660. -
  5661. - // Replace the new constant pool with a shrunken copy of the
  5662. - // merged constant pool so now the rewritten bytecodes have
  5663. - // valid references; the previous new constant pool will get
  5664. - // GCed.
  5665. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  5666. - THREAD);
  5667. - merge_cp()->set_is_conc_safe(true);
  5668. - }
  5669. - assert(old_cp()->is_conc_safe(), "Just checking");
  5670. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  5671. -
  5672. - return JVMTI_ERROR_NONE;
  5673. -} // end merge_cp_and_rewrite()
  5674. -
  5675. -
  5676. -// Rewrite constant pool references in klass scratch_class.
  5677. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  5678. - TRAPS) {
  5679. -
  5680. - // rewrite constant pool references in the methods:
  5681. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  5682. - // propagate failure back to caller
  5683. - return false;
  5684. - }
  5685. -
  5686. - // rewrite constant pool references in the class_annotations:
  5687. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  5688. - // propagate failure back to caller
  5689. - return false;
  5690. - }
  5691. -
  5692. - // rewrite constant pool references in the fields_annotations:
  5693. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  5694. - // propagate failure back to caller
  5695. - return false;
  5696. - }
  5697. -
  5698. - // rewrite constant pool references in the methods_annotations:
  5699. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  5700. - // propagate failure back to caller
  5701. - return false;
  5702. - }
  5703. -
  5704. - // rewrite constant pool references in the methods_parameter_annotations:
  5705. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  5706. - THREAD)) {
  5707. - // propagate failure back to caller
  5708. - return false;
  5709. - }
  5710. -
  5711. - // rewrite constant pool references in the methods_default_annotations:
  5712. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  5713. - THREAD)) {
  5714. - // propagate failure back to caller
  5715. - return false;
  5716. - }
  5717. -
  5718. - return true;
  5719. -} // end rewrite_cp_refs()
  5720. -
  5721. -
  5722. -// Rewrite constant pool references in the methods.
  5723. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  5724. - instanceKlassHandle scratch_class, TRAPS) {
  5725. -
  5726. - objArrayHandle methods(THREAD, scratch_class->methods());
  5727. -
  5728. - if (methods.is_null() || methods->length() == 0) {
  5729. - // no methods so nothing to do
  5730. - return true;
  5731. - }
  5732. -
  5733. - // rewrite constant pool references in the methods:
  5734. - for (int i = methods->length() - 1; i >= 0; i--) {
  5735. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  5736. - methodHandle new_method;
  5737. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  5738. - if (!new_method.is_null()) {
  5739. - // the method has been replaced so save the new method version
  5740. - methods->obj_at_put(i, new_method());
  5741. + {
  5742. + u2 new_num = k_new_method->method_idnum();
  5743. + u2 old_num = k_old_method->method_idnum();
  5744. + if (new_num != old_num) {
  5745. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  5746. + if (idnum_owner != NULL) {
  5747. + // There is already a method assigned this idnum -- switch them
  5748. + idnum_owner->set_method_idnum(new_num);
  5749. + }
  5750. + k_new_method->set_method_idnum(old_num);
  5751. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  5752. + swap_all_method_annotations(old_num, new_num, new_class);
  5753. + }
  5754. + }
  5755. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  5756. + k_new_method->name_and_sig_as_C_string(), ni,
  5757. + k_old_method->name_and_sig_as_C_string(), oi);
  5758. + // advance to next pair of methods
  5759. + ++oi;
  5760. + ++ni;
  5761. + break;
  5762. + case added:
  5763. + // method added, see if it is OK
  5764. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5765. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5766. + // hack: private should be treated as final, but alas
  5767. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5768. + ) {
  5769. + // new methods must be private
  5770. + result = result | Klass::ModifyClass;
  5771. + }
  5772. + {
  5773. + u2 num = the_class->next_method_idnum();
  5774. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5775. + // cannot add any more methods
  5776. + result = result | Klass::ModifyClass;
  5777. + }
  5778. + u2 new_num = k_new_method->method_idnum();
  5779. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5780. + if (idnum_owner != NULL) {
  5781. + // There is already a method assigned this idnum -- switch them
  5782. + idnum_owner->set_method_idnum(new_num);
  5783. + }
  5784. + k_new_method->set_method_idnum(num);
  5785. + swap_all_method_annotations(new_num, num, new_class);
  5786. + }
  5787. + TRACE_RC1("Method added: new: %s [%d]",
  5788. + k_new_method->name_and_sig_as_C_string(), ni);
  5789. + ++ni; // advance to next new method
  5790. + break;
  5791. + case deleted:
  5792. + // method deleted, see if it is OK
  5793. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5794. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5795. + // hack: private should be treated as final, but alas
  5796. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5797. + ) {
  5798. + // deleted methods must be private
  5799. + result = result | Klass::ModifyClass;
  5800. + }
  5801. + TRACE_RC1("Method deleted: old: %s [%d]",
  5802. + k_old_method->name_and_sig_as_C_string(), oi);
  5803. + ++oi; // advance to next old method
  5804. + break;
  5805. + default:
  5806. + ShouldNotReachHere();
  5807. }
  5808. }
  5809. - return true;
  5810. + if (new_class()->size() != new_class->old_version()->size()) {
  5811. + result |= Klass::ModifyClassSize;
  5812. + }
  5813. +
  5814. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  5815. + result |= Klass::ModifyInstanceSize;
  5816. + }
  5817. +
  5818. + // (tw) Check method bodies to be able to return NoChange?
  5819. + return result;
  5820. +}
  5821. +
  5822. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  5823. +
  5824. + class CalculateFieldUpdates : public FieldClosure {
  5825. +
  5826. + private:
  5827. + instanceKlass* _old_ik;
  5828. + GrowableArray<int> _update_info;
  5829. + int _position;
  5830. + bool _copy_backwards;
  5831. +
  5832. + public:
  5833. +
  5834. + bool does_copy_backwards() {
  5835. + return _copy_backwards;
  5836. + }
  5837. +
  5838. + CalculateFieldUpdates(instanceKlass* old_ik) :
  5839. + _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
  5840. + _update_info.append(_position);
  5841. + _update_info.append(0);
  5842. + }
  5843. +
  5844. + GrowableArray<int> &finish() {
  5845. + _update_info.append(0);
  5846. + return _update_info;
  5847. + }
  5848. +
  5849. + void do_field(fieldDescriptor* fd) {
  5850. + int alignment = fd->offset() - _position;
  5851. + if (alignment > 0) {
  5852. + // This field was aligned, so we need to make sure that we fill the gap
  5853. + fill(alignment);
  5854. + }
  5855. +
  5856. + assert(_position == fd->offset(), "must be correct offset!");
  5857. +
  5858. + fieldDescriptor old_fd;
  5859. + if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
  5860. + // Found field in the old class, copy
  5861. + copy(old_fd.offset(), type2aelembytes(fd->field_type()));
  5862. +
  5863. + if (old_fd.offset() < fd->offset()) {
  5864. + _copy_backwards = true;
  5865. + }
  5866. +
  5867. + // Transfer special flags
  5868. + fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
  5869. + fd->set_is_field_access_watched(old_fd.is_field_access_watched());
  5870. + } else {
  5871. + // New field, fill
  5872. + fill(type2aelembytes(fd->field_type()));
  5873. + }
  5874. + }
  5875. +
  5876. + private:
  5877. +
  5878. + void fill(int size) {
  5879. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
  5880. + (*_update_info.adr_at(_update_info.length() - 1)) -= size;
  5881. + } else {
  5882. + _update_info.append(-size);
  5883. + }
  5884. + _position += size;
  5885. + }
  5886. +
  5887. + void copy(int offset, int size) {
  5888. + int prev_end = -1;
  5889. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
  5890. + prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
  5891. + }
  5892. +
  5893. + if (prev_end == offset) {
  5894. + (*_update_info.adr_at(_update_info.length() - 2)) += size;
  5895. + } else {
  5896. + _update_info.append(size);
  5897. + _update_info.append(offset);
  5898. + }
  5899. +
  5900. + _position += size;
  5901. + }
  5902. + };
  5903. +
  5904. + instanceKlass* ik = instanceKlass::cast(new_version);
  5905. + instanceKlass* old_ik = instanceKlass::cast(new_version->klass_part()->old_version());
  5906. + CalculateFieldUpdates cl(old_ik);
  5907. + ik->do_nonstatic_fields(&cl);
  5908. +
  5909. + GrowableArray<int> result = cl.finish();
  5910. + ik->store_update_information(result);
  5911. + ik->set_copying_backwards(cl.does_copy_backwards());
  5912. +
  5913. + IF_TRACE_RC2 {
  5914. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  5915. + if (cl.does_copy_backwards()) {
  5916. + TRACE_RC2("\tDoes copy backwards!");
  5917. + }
  5918. + for (int i=0; i<result.length(); i++) {
  5919. + int curNum = result.at(i);
  5920. + if (curNum < 0) {
  5921. + TRACE_RC2("\t%d CLEAN", curNum);
  5922. + } else if (curNum > 0) {
  5923. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  5924. + i++;
  5925. + } else {
  5926. + TRACE_RC2("\tEND");
  5927. + }
  5928. + }
  5929. + }
  5930. +}
  5931. +
  5932. +void VM_RedefineClasses::rollback() {
  5933. + TRACE_RC1("Rolling back redefinition!");
  5934. + SystemDictionary::rollback_redefinition();
  5935. +
  5936. + TRACE_RC1("After rolling back system dictionary!");
  5937. + for (int i=0; i<_new_classes->length(); i++) {
  5938. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  5939. + }
  5940. +
  5941. + for (int i=0; i<_new_classes->length(); i++) {
  5942. + instanceKlassHandle new_class = _new_classes->at(i);
  5943. + new_class->set_redefining(false);
  5944. + new_class->old_version()->klass_part()->set_new_version(NULL);
  5945. + new_class->set_old_version(NULL);
  5946. + }
  5947. +
  5948. +}
  5949. +
  5950. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  5951. + markOop first_mark = first->mark();
  5952. + markOop second_mark = second->mark();
  5953. + first->set_mark(second_mark);
  5954. + second->set_mark(first_mark);
  5955. }
  5956. -// Rewrite constant pool references in the specific method. This code
  5957. -// was adapted from Rewriter::rewrite_method().
  5958. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  5959. - methodHandle *new_method_p, TRAPS) {
  5960. +class FieldCopier : public FieldClosure {
  5961. + public:
  5962. + void do_field(fieldDescriptor* fd) {
  5963. + instanceKlass* cur = instanceKlass::cast(fd->field_holder());
  5964. + oop cur_oop = cur->java_mirror();
  5965. - *new_method_p = methodHandle(); // default is no new method
  5966. + instanceKlass* old = instanceKlass::cast(cur->old_version());
  5967. + oop old_oop = old->java_mirror();
  5968. - // We cache a pointer to the bytecodes here in code_base. If GC
  5969. - // moves the methodOop, then the bytecodes will also move which
  5970. - // will likely cause a crash. We create a No_Safepoint_Verifier
  5971. - // object to detect whether we pass a possible safepoint in this
  5972. - // code block.
  5973. - No_Safepoint_Verifier nsv;
  5974. + fieldDescriptor result;
  5975. + bool found = old->find_local_field(fd->name(), fd->signature(), &result);
  5976. + if (found && result.is_static()) {
  5977. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d",
  5978. + fd->name()->as_C_string(), result.offset(), fd->offset());
  5979. + memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
  5980. + old_oop->obj_field_addr<HeapWord>(result.offset()),
  5981. + type2aelembytes(fd->field_type()));
  5982. - // Bytecodes and their length
  5983. - address code_base = method->code_base();
  5984. - int code_length = method->code_size();
  5985. + // Static fields may have references to java.lang.Class
  5986. + if (fd->field_type() == T_OBJECT) {
  5987. + oop oop = cur_oop->obj_field(fd->offset());
  5988. + if (oop != NULL && oop->is_instanceMirror()) {
  5989. + klassOop klass = java_lang_Class::as_klassOop(oop);
  5990. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  5991. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  5992. + if (klass->klass_part()->new_version() != NULL) {
  5993. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  5994. - int bc_length;
  5995. - for (int bci = 0; bci < code_length; bci += bc_length) {
  5996. - address bcp = code_base + bci;
  5997. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  5998. -
  5999. - bc_length = Bytecodes::length_for(c);
  6000. - if (bc_length == 0) {
  6001. - // More complicated bytecodes report a length of zero so
  6002. - // we have to try again a slightly different way.
  6003. - bc_length = Bytecodes::length_at(method(), bcp);
  6004. - }
  6005. -
  6006. - assert(bc_length != 0, "impossible bytecode length");
  6007. -
  6008. - switch (c) {
  6009. - case Bytecodes::_ldc:
  6010. - {
  6011. - int cp_index = *(bcp + 1);
  6012. - int new_index = find_new_index(cp_index);
  6013. -
  6014. - if (StressLdcRewrite && new_index == 0) {
  6015. - // If we are stressing ldc -> ldc_w rewriting, then we
  6016. - // always need a new_index value.
  6017. - new_index = cp_index;
  6018. + cur_oop->obj_field_put(fd->offset(), oop);
  6019. + }
  6020. + }
  6021. }
  6022. - if (new_index != 0) {
  6023. - // the original index is mapped so we have more work to do
  6024. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  6025. - // The new value can still use ldc instead of ldc_w
  6026. - // unless we are trying to stress ldc -> ldc_w rewriting
  6027. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6028. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6029. - bcp, cp_index, new_index));
  6030. - *(bcp + 1) = new_index;
  6031. - } else {
  6032. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6033. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  6034. - Bytecodes::name(c), bcp, cp_index, new_index));
  6035. - // the new value needs ldc_w instead of ldc
  6036. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  6037. - bcp = (address)inst_buffer;
  6038. - // construct new instruction sequence
  6039. - *bcp = Bytecodes::_ldc_w;
  6040. - bcp++;
  6041. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  6042. - // See comment below for difference between put_Java_u2()
  6043. - // and put_native_u2().
  6044. - Bytes::put_Java_u2(bcp, new_index);
  6045. + }
  6046. + }
  6047. + }
  6048. +};
  6049. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  6050. - methodHandle m;
  6051. - {
  6052. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  6053. +void VM_RedefineClasses::mark_as_scavengable(nmethod* nm) {
  6054. + if (!nm->on_scavenge_root_list()) {
  6055. + CodeCache::add_scavenge_root_nmethod(nm);
  6056. + }
  6057. +}
  6058. - // ldc is 2 bytes and ldc_w is 3 bytes
  6059. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  6060. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  6061. - guarantee(false, "insert_space_at() failed");
  6062. +struct StoreBarrier {
  6063. + template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
  6064. +};
  6065. +
  6066. +struct StoreNoBarrier {
  6067. + template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
  6068. +};
  6069. +
  6070. +template <class S>
  6071. +class ChangePointersOopClosure : public OopClosureNoHeader {
  6072. + // Forward pointers to instanceKlass and mirror class to new versions
  6073. + template <class T>
  6074. + inline void do_oop_work(T* p) {
  6075. + oop oop = oopDesc::load_decode_heap_oop(p);
  6076. + if (oop == NULL) {
  6077. + return;
  6078. + }
  6079. + if (oop->is_instanceKlass()) {
  6080. + klassOop klass = (klassOop) oop;
  6081. + if (klass->klass_part()->new_version() != NULL) {
  6082. + oop = klass->klass_part()->new_version();
  6083. + S::oop_store(p, oop);
  6084. + }
  6085. + } else if (oop->is_instanceMirror()) {
  6086. + klassOop klass = java_lang_Class::as_klassOop(oop);
  6087. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  6088. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  6089. + if (klass->klass_part()->new_version() != NULL) {
  6090. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  6091. + S::oop_store(p, oop);
  6092. + }
  6093. + }
  6094. + }
  6095. + }
  6096. +
  6097. + virtual void do_oop(oop* o) {
  6098. + do_oop_work(o);
  6099. + }
  6100. +
  6101. + virtual void do_oop(narrowOop* o) {
  6102. + do_oop_work(o);
  6103. + }
  6104. +};
  6105. +
  6106. +void VM_RedefineClasses::doit() {
  6107. + Thread *thread = Thread::current();
  6108. +
  6109. + TRACE_RC1("Entering doit!");
  6110. +
  6111. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  6112. +
  6113. + if (UseSharedSpaces) {
  6114. + // Sharing is enabled so we remap the shared readonly space to
  6115. + // shared readwrite, private just in case we need to redefine
  6116. + // a shared class. We do the remap during the doit() phase of
  6117. + // the safepoint to be safer.
  6118. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  6119. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  6120. + _result = JVMTI_ERROR_INTERNAL;
  6121. + return;
  6122. + }
  6123. + }
  6124. +
  6125. + RC_TIMER_START(_timer_prepare_redefinition);
  6126. + for (int i = 0; i < _new_classes->length(); i++) {
  6127. + redefine_single_class(_new_classes->at(i), thread);
  6128. + }
  6129. +
  6130. + // Deoptimize all compiled code that depends on this class
  6131. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  6132. +
  6133. + // Adjust constantpool caches and vtables for all classes
  6134. + // that reference methods of the evolved class.
  6135. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  6136. +
  6137. + RC_TIMER_STOP(_timer_prepare_redefinition);
  6138. + RC_TIMER_START(_timer_heap_iteration);
  6139. +
  6140. + class ChangePointersObjectClosure : public ObjectClosure {
  6141. +
  6142. + private:
  6143. +
  6144. + OopClosureNoHeader *_closure;
  6145. + bool _needs_instance_update;
  6146. + oop _tmp_obj;
  6147. + int _tmp_obj_size;
  6148. +
  6149. + public:
  6150. + ChangePointersObjectClosure(OopClosureNoHeader *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
  6151. +
  6152. + bool needs_instance_update() {
  6153. + return _needs_instance_update;
  6154. + }
  6155. +
  6156. + void copy_to_tmp(oop o) {
  6157. + int size = o->size();
  6158. + if (_tmp_obj_size < size) {
  6159. + _tmp_obj_size = size;
  6160. + _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  6161. + }
  6162. + Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
  6163. + }
  6164. +
  6165. + virtual void do_object(oop obj) {
  6166. + if (obj->is_instanceKlass()) return;
  6167. + if (obj->is_instanceMirror()) {
  6168. + // static fields may have references to old java.lang.Class instances, update them
  6169. + // at the same time, we don't want to update other oops in the java.lang.Class
  6170. + // Causes SIGSEGV?
  6171. + //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
  6172. + } else {
  6173. + obj->oop_iterate(_closure);
  6174. + }
  6175. +
  6176. + // Update method handles
  6177. + // FIXME: should we also update fields?
  6178. + if (java_lang_invoke_MemberName::is_instance(obj)) {
  6179. + oop target = java_lang_invoke_MemberName::vmtarget(obj);
  6180. + if (target != NULL && target->is_method()) {
  6181. + methodOop m = (methodOop) target;
  6182. + klassOop holder = m->method_holder();
  6183. + if (!holder->klass_part()->is_newest_version()) {
  6184. + // Let's try to re-resolve method
  6185. + klassOop newest = holder->klass_part()->newest_version();
  6186. + methodOop new_method = instanceKlass::cast(newest)->find_method(m->name(), m->signature());
  6187. + java_lang_invoke_MemberName::set_vmtarget(obj, new_method);
  6188. + }
  6189. + }
  6190. + }
  6191. +
  6192. + if (obj->blueprint()->new_version() != NULL) {
  6193. + Klass* new_klass = obj->blueprint()->new_version()->klass_part();
  6194. + if (obj->is_perm()) {
  6195. + _needs_instance_update = true;
  6196. + } else if(new_klass->update_information() != NULL) {
  6197. + int size_diff = obj->size() - obj->size_given_klass(new_klass);
  6198. +
  6199. + // Either new size is bigger or gap is to small to be filled
  6200. + if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
  6201. + // We need an instance update => set back to old klass
  6202. + _needs_instance_update = true;
  6203. + } else {
  6204. + oop src = obj;
  6205. + if (new_klass->is_copying_backwards()) {
  6206. + copy_to_tmp(obj);
  6207. + src = _tmp_obj;
  6208. + }
  6209. + src->set_klass_no_check(obj->blueprint()->new_version());
  6210. + MarkSweep::update_fields(obj, src, new_klass->update_information());
  6211. +
  6212. + if (size_diff > 0) {
  6213. + HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
  6214. + CollectedHeap::fill_with_object(dead_space, size_diff);
  6215. }
  6216. }
  6217. -
  6218. - // return the new method so that the caller can update
  6219. - // the containing class
  6220. - *new_method_p = method = m;
  6221. - // switch our bytecode processing loop from the old method
  6222. - // to the new method
  6223. - code_base = method->code_base();
  6224. - code_length = method->code_size();
  6225. - bcp = code_base + bci;
  6226. - c = (Bytecodes::Code)(*bcp);
  6227. - bc_length = Bytecodes::length_for(c);
  6228. - assert(bc_length != 0, "sanity check");
  6229. - } // end we need ldc_w instead of ldc
  6230. - } // end if there is a mapped index
  6231. - } break;
  6232. -
  6233. - // these bytecodes have a two-byte constant pool index
  6234. - case Bytecodes::_anewarray : // fall through
  6235. - case Bytecodes::_checkcast : // fall through
  6236. - case Bytecodes::_getfield : // fall through
  6237. - case Bytecodes::_getstatic : // fall through
  6238. - case Bytecodes::_instanceof : // fall through
  6239. - case Bytecodes::_invokedynamic : // fall through
  6240. - case Bytecodes::_invokeinterface: // fall through
  6241. - case Bytecodes::_invokespecial : // fall through
  6242. - case Bytecodes::_invokestatic : // fall through
  6243. - case Bytecodes::_invokevirtual : // fall through
  6244. - case Bytecodes::_ldc_w : // fall through
  6245. - case Bytecodes::_ldc2_w : // fall through
  6246. - case Bytecodes::_multianewarray : // fall through
  6247. - case Bytecodes::_new : // fall through
  6248. - case Bytecodes::_putfield : // fall through
  6249. - case Bytecodes::_putstatic :
  6250. - {
  6251. - address p = bcp + 1;
  6252. - int cp_index = Bytes::get_Java_u2(p);
  6253. - int new_index = find_new_index(cp_index);
  6254. - if (new_index != 0) {
  6255. - // the original index is mapped so update w/ new value
  6256. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6257. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6258. - bcp, cp_index, new_index));
  6259. - // Rewriter::rewrite_method() uses put_native_u2() in this
  6260. - // situation because it is reusing the constant pool index
  6261. - // location for a native index into the constantPoolCache.
  6262. - // Since we are updating the constant pool index prior to
  6263. - // verification and constantPoolCache initialization, we
  6264. - // need to keep the new index in Java byte order.
  6265. - Bytes::put_Java_u2(p, new_index);
  6266. + } else {
  6267. + obj->set_klass_no_check(obj->blueprint()->new_version());
  6268. + }
  6269. }
  6270. - } break;
  6271. + }
  6272. + };
  6273. +
  6274. + ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
  6275. + ChangePointersOopClosure<StoreBarrier> oopClosure;
  6276. + ChangePointersObjectClosure objectClosure(&oopClosure);
  6277. +
  6278. + {
  6279. + // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
  6280. + // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
  6281. + // mark such nmethod's as "scavengable".
  6282. + // For now, mark all nmethod's as scavengable that are not scavengable already
  6283. + if (ScavengeRootsInCode) {
  6284. + CodeCache::nmethods_do(mark_as_scavengable);
  6285. + }
  6286. +
  6287. + SharedHeap::heap()->gc_prologue(true);
  6288. + Universe::heap()->object_iterate(&objectClosure);
  6289. + Universe::root_oops_do(&oopClosureNoBarrier);
  6290. + SharedHeap::heap()->gc_epilogue(false);
  6291. }
  6292. - } // end for each bytecode
  6293. -} // end rewrite_cp_refs_in_method()
  6294. -// Rewrite constant pool references in the class_annotations field.
  6295. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  6296. - instanceKlassHandle scratch_class, TRAPS) {
  6297. + for (int i=0; i<_new_classes->length(); i++) {
  6298. + klassOop cur_oop = _new_classes->at(i)();
  6299. + instanceKlass* cur = instanceKlass::cast(cur_oop);
  6300. + klassOop old_oop = cur->old_version();
  6301. + instanceKlass* old = instanceKlass::cast(old_oop);
  6302. - typeArrayHandle class_annotations(THREAD,
  6303. - scratch_class->class_annotations());
  6304. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  6305. - // no class_annotations so nothing to do
  6306. - return true;
  6307. + // Swap marks to have same hashcodes
  6308. + swap_marks(cur_oop, old_oop);
  6309. + swap_marks(cur->java_mirror(), old->java_mirror());
  6310. +
  6311. + // Revert pool holder for old version of klass (it was updated by one of ours closure!)
  6312. + old->constants()->set_pool_holder(old_oop);
  6313. +
  6314. +
  6315. + if (old->array_klasses() != NULL) {
  6316. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  6317. + assert(cur->array_klasses() == NULL, "just checking");
  6318. + cur->set_array_klasses(old->array_klasses());
  6319. + }
  6320. +
  6321. + // Initialize the new class! Special static initialization that does not execute the
  6322. + // static constructor but copies static field values from the old class if name
  6323. + // and signature of a static field match.
  6324. + FieldCopier copier;
  6325. + cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
  6326. + old->set_java_mirror(cur->java_mirror());
  6327. +
  6328. + // Transfer init state
  6329. + instanceKlass::ClassState state = old->init_state();
  6330. + if (state > instanceKlass::linked) {
  6331. + cur->set_init_state(state);
  6332. + }
  6333. + }
  6334. +
  6335. + RC_TIMER_STOP(_timer_heap_iteration);
  6336. + RC_TIMER_START(_timer_redefinition);
  6337. + if (objectClosure.needs_instance_update()){
  6338. +
  6339. + // Do a full garbage collection to update the instance sizes accordingly
  6340. + TRACE_RC1("Before performing full GC!");
  6341. + Universe::set_redefining_gc_run(true);
  6342. + notify_gc_begin(true);
  6343. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  6344. + notify_gc_end();
  6345. + Universe::set_redefining_gc_run(false);
  6346. + TRACE_RC1("GC done!");
  6347. }
  6348. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6349. - ("class_annotations length=%d", class_annotations->length()));
  6350. + // Unmark klassOops as "redefining"
  6351. + for (int i=0; i<_new_classes->length(); i++) {
  6352. + klassOop cur_klass = _new_classes->at(i)();
  6353. + instanceKlass* cur = (instanceKlass*)cur_klass->klass_part();
  6354. + cur->set_redefining(false);
  6355. + cur->clear_update_information();
  6356. + }
  6357. - int byte_i = 0; // byte index into class_annotations
  6358. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  6359. - THREAD);
  6360. + // Disable any dependent concurrent compilations
  6361. + SystemDictionary::notice_modification();
  6362. +
  6363. + // Set flag indicating that some invariants are no longer true.
  6364. + // See jvmtiExport.hpp for detailed explanation.
  6365. + JvmtiExport::set_has_redefined_a_class();
  6366. +
  6367. + // Clean up caches in the compiler interface and compiler threads
  6368. + ciObjectFactory::resort_shared_ci_objects();
  6369. +
  6370. +#ifdef ASSERT
  6371. +
  6372. + // Universe::verify();
  6373. + // JNIHandles::verify();
  6374. +
  6375. + SystemDictionary::classes_do(check_class, thread);
  6376. +#endif
  6377. +
  6378. + RC_TIMER_STOP(_timer_redefinition);
  6379. +
  6380. + if (TraceRedefineClasses > 0) {
  6381. + tty->flush();
  6382. + }
  6383. }
  6384. +void VM_RedefineClasses::doit_epilogue() {
  6385. -// Rewrite constant pool references in an annotations typeArray. This
  6386. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  6387. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  6388. -//
  6389. -// annotations_typeArray {
  6390. -// u2 num_annotations;
  6391. -// annotation annotations[num_annotations];
  6392. -// }
  6393. -//
  6394. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  6395. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6396. + RC_TIMER_START(_timer_vm_op_epilogue);
  6397. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6398. - // not enough room for num_annotations field
  6399. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6400. - ("length() is too small for num_annotations field"));
  6401. - return false;
  6402. - }
  6403. + //unlock_threads();
  6404. - u2 num_annotations = Bytes::get_Java_u2((address)
  6405. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6406. - byte_i_ref += 2;
  6407. + ResourceMark mark;
  6408. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6409. - ("num_annotations=%d", num_annotations));
  6410. + VM_GC_Operation::doit_epilogue();
  6411. + TRACE_RC1("GC Operation epilogue finished! ");
  6412. - int calc_num_annotations = 0;
  6413. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  6414. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6415. - byte_i_ref, THREAD)) {
  6416. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6417. - ("bad annotation_struct at %d", calc_num_annotations));
  6418. - // propagate failure back to caller
  6419. - return false;
  6420. - }
  6421. - }
  6422. - assert(num_annotations == calc_num_annotations, "sanity check");
  6423. + // Free the array of scratch classes
  6424. + delete _new_classes;
  6425. + _new_classes = NULL;
  6426. - return true;
  6427. -} // end rewrite_cp_refs_in_annotations_typeArray()
  6428. + // Free the array of affected classes
  6429. + delete _affected_klasses;
  6430. + _affected_klasses = NULL;
  6431. + TRACE_RC1("Redefinition finished!");
  6432. -// Rewrite constant pool references in the annotation struct portion of
  6433. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  6434. -// the 2nd-edition of the VM spec:
  6435. -//
  6436. -// struct annotation {
  6437. -// u2 type_index;
  6438. -// u2 num_element_value_pairs;
  6439. -// {
  6440. -// u2 element_name_index;
  6441. -// element_value value;
  6442. -// } element_value_pairs[num_element_value_pairs];
  6443. -// }
  6444. -//
  6445. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  6446. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6447. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  6448. - // not enough room for smallest annotation_struct
  6449. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6450. - ("length() is too small for annotation_struct"));
  6451. - return false;
  6452. - }
  6453. -
  6454. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  6455. - byte_i_ref, "mapped old type_index=%d", THREAD);
  6456. -
  6457. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  6458. - annotations_typeArray->byte_at_addr(
  6459. - byte_i_ref));
  6460. - byte_i_ref += 2;
  6461. -
  6462. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6463. - ("type_index=%d num_element_value_pairs=%d", type_index,
  6464. - num_element_value_pairs));
  6465. -
  6466. - int calc_num_element_value_pairs = 0;
  6467. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  6468. - calc_num_element_value_pairs++) {
  6469. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6470. - // not enough room for another element_name_index, let alone
  6471. - // the rest of another component
  6472. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6473. - ("length() is too small for element_name_index"));
  6474. - return false;
  6475. - }
  6476. -
  6477. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  6478. - annotations_typeArray, byte_i_ref,
  6479. - "mapped old element_name_index=%d", THREAD);
  6480. -
  6481. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6482. - ("element_name_index=%d", element_name_index));
  6483. -
  6484. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  6485. - byte_i_ref, THREAD)) {
  6486. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6487. - ("bad element_value at %d", calc_num_element_value_pairs));
  6488. - // propagate failure back to caller
  6489. - return false;
  6490. - }
  6491. - } // end for each component
  6492. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  6493. - "sanity check");
  6494. -
  6495. - return true;
  6496. -} // end rewrite_cp_refs_in_annotation_struct()
  6497. -
  6498. -
  6499. -// Rewrite a constant pool reference at the current position in
  6500. -// annotations_typeArray if needed. Returns the original constant
  6501. -// pool reference if a rewrite was not needed or the new constant
  6502. -// pool reference if a rewrite was needed.
  6503. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  6504. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  6505. - const char * trace_mesg, TRAPS) {
  6506. -
  6507. - address cp_index_addr = (address)
  6508. - annotations_typeArray->byte_at_addr(byte_i_ref);
  6509. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  6510. - u2 new_cp_index = find_new_index(old_cp_index);
  6511. - if (new_cp_index != 0) {
  6512. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  6513. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  6514. - old_cp_index = new_cp_index;
  6515. - }
  6516. - byte_i_ref += 2;
  6517. - return old_cp_index;
  6518. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  6519. }
  6520. -
  6521. -// Rewrite constant pool references in the element_value portion of an
  6522. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  6523. -// the 2nd-edition of the VM spec:
  6524. -//
  6525. -// struct element_value {
  6526. -// u1 tag;
  6527. -// union {
  6528. -// u2 const_value_index;
  6529. -// {
  6530. -// u2 type_name_index;
  6531. -// u2 const_name_index;
  6532. -// } enum_const_value;
  6533. -// u2 class_info_index;
  6534. -// annotation annotation_value;
  6535. -// struct {
  6536. -// u2 num_values;
  6537. -// element_value values[num_values];
  6538. -// } array_value;
  6539. -// } value;
  6540. -// }
  6541. -//
  6542. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  6543. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6544. -
  6545. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  6546. - // not enough room for a tag let alone the rest of an element_value
  6547. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6548. - ("length() is too small for a tag"));
  6549. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  6550. + // classes for primitives cannot be redefined
  6551. + if (java_lang_Class::is_primitive(klass_mirror)) {
  6552. return false;
  6553. }
  6554. -
  6555. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  6556. - byte_i_ref++;
  6557. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  6558. -
  6559. - switch (tag) {
  6560. - // These BaseType tag values are from Table 4.2 in VM spec:
  6561. - case 'B': // byte
  6562. - case 'C': // char
  6563. - case 'D': // double
  6564. - case 'F': // float
  6565. - case 'I': // int
  6566. - case 'J': // long
  6567. - case 'S': // short
  6568. - case 'Z': // boolean
  6569. -
  6570. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  6571. - // the VM spec:
  6572. - case 's':
  6573. - {
  6574. - // For the above tag values (including the BaseType values),
  6575. - // value.const_value_index is right union field.
  6576. -
  6577. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6578. - // not enough room for a const_value_index
  6579. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6580. - ("length() is too small for a const_value_index"));
  6581. - return false;
  6582. - }
  6583. -
  6584. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  6585. - annotations_typeArray, byte_i_ref,
  6586. - "mapped old const_value_index=%d", THREAD);
  6587. -
  6588. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6589. - ("const_value_index=%d", const_value_index));
  6590. - } break;
  6591. -
  6592. - case 'e':
  6593. - {
  6594. - // for the above tag value, value.enum_const_value is right union field
  6595. -
  6596. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  6597. - // not enough room for a enum_const_value
  6598. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6599. - ("length() is too small for a enum_const_value"));
  6600. - return false;
  6601. - }
  6602. -
  6603. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  6604. - annotations_typeArray, byte_i_ref,
  6605. - "mapped old type_name_index=%d", THREAD);
  6606. -
  6607. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  6608. - annotations_typeArray, byte_i_ref,
  6609. - "mapped old const_name_index=%d", THREAD);
  6610. -
  6611. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6612. - ("type_name_index=%d const_name_index=%d", type_name_index,
  6613. - const_name_index));
  6614. - } break;
  6615. -
  6616. - case 'c':
  6617. - {
  6618. - // for the above tag value, value.class_info_index is right union field
  6619. -
  6620. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6621. - // not enough room for a class_info_index
  6622. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6623. - ("length() is too small for a class_info_index"));
  6624. - return false;
  6625. - }
  6626. -
  6627. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  6628. - annotations_typeArray, byte_i_ref,
  6629. - "mapped old class_info_index=%d", THREAD);
  6630. -
  6631. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6632. - ("class_info_index=%d", class_info_index));
  6633. - } break;
  6634. -
  6635. - case '@':
  6636. - // For the above tag value, value.attr_value is the right union
  6637. - // field. This is a nested annotation.
  6638. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6639. - byte_i_ref, THREAD)) {
  6640. - // propagate failure back to caller
  6641. - return false;
  6642. - }
  6643. - break;
  6644. -
  6645. - case '[':
  6646. - {
  6647. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6648. - // not enough room for a num_values field
  6649. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6650. - ("length() is too small for a num_values field"));
  6651. - return false;
  6652. - }
  6653. -
  6654. - // For the above tag value, value.array_value is the right union
  6655. - // field. This is an array of nested element_value.
  6656. - u2 num_values = Bytes::get_Java_u2((address)
  6657. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6658. - byte_i_ref += 2;
  6659. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  6660. -
  6661. - int calc_num_values = 0;
  6662. - for (; calc_num_values < num_values; calc_num_values++) {
  6663. - if (!rewrite_cp_refs_in_element_value(
  6664. - annotations_typeArray, byte_i_ref, THREAD)) {
  6665. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6666. - ("bad nested element_value at %d", calc_num_values));
  6667. - // propagate failure back to caller
  6668. - return false;
  6669. - }
  6670. - }
  6671. - assert(num_values == calc_num_values, "sanity check");
  6672. - } break;
  6673. -
  6674. - default:
  6675. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  6676. - return false;
  6677. - } // end decode tag field
  6678. -
  6679. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  6680. + // classes for arrays cannot be redefined
  6681. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  6682. + return false;
  6683. + }
  6684. return true;
  6685. -} // end rewrite_cp_refs_in_element_value()
  6686. +}
  6687. +#ifdef ASSERT
  6688. -// Rewrite constant pool references in a fields_annotations field.
  6689. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  6690. - instanceKlassHandle scratch_class, TRAPS) {
  6691. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  6692. + klassOop k_oop = k_oop_latest;
  6693. + while (k_oop != NULL) {
  6694. - objArrayHandle fields_annotations(THREAD,
  6695. - scratch_class->fields_annotations());
  6696. -
  6697. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  6698. - // no fields_annotations so nothing to do
  6699. - return true;
  6700. + instanceKlassHandle k_handle(THREAD, k_oop);
  6701. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  6702. + k_oop = k_oop->klass_part()->old_version();
  6703. }
  6704. +}
  6705. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6706. - ("fields_annotations length=%d", fields_annotations->length()));
  6707. +#endif
  6708. - for (int i = 0; i < fields_annotations->length(); i++) {
  6709. - typeArrayHandle field_annotations(THREAD,
  6710. - (typeArrayOop)fields_annotations->obj_at(i));
  6711. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  6712. - // this field does not have any annotations so skip it
  6713. - continue;
  6714. - }
  6715. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  6716. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  6717. +// do that, they assume that cache entry is resolved already.
  6718. +void VM_RedefineClasses::unpatch_bytecode(methodOop method) {
  6719. + RawBytecodeStream bcs(method);
  6720. + Bytecodes::Code code;
  6721. + Bytecodes::Code java_code;
  6722. + while (!bcs.is_last_bytecode()) {
  6723. + code = bcs.raw_next();
  6724. + address bcp = bcs.bcp();
  6725. - int byte_i = 0; // byte index into field_annotations
  6726. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  6727. - THREAD)) {
  6728. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6729. - ("bad field_annotations at %d", i));
  6730. - // propagate failure back to caller
  6731. - return false;
  6732. - }
  6733. - }
  6734. -
  6735. - return true;
  6736. -} // end rewrite_cp_refs_in_fields_annotations()
  6737. -
  6738. -
  6739. -// Rewrite constant pool references in a methods_annotations field.
  6740. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  6741. - instanceKlassHandle scratch_class, TRAPS) {
  6742. -
  6743. - objArrayHandle methods_annotations(THREAD,
  6744. - scratch_class->methods_annotations());
  6745. -
  6746. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  6747. - // no methods_annotations so nothing to do
  6748. - return true;
  6749. - }
  6750. -
  6751. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6752. - ("methods_annotations length=%d", methods_annotations->length()));
  6753. -
  6754. - for (int i = 0; i < methods_annotations->length(); i++) {
  6755. - typeArrayHandle method_annotations(THREAD,
  6756. - (typeArrayOop)methods_annotations->obj_at(i));
  6757. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  6758. - // this method does not have any annotations so skip it
  6759. - continue;
  6760. - }
  6761. -
  6762. - int byte_i = 0; // byte index into method_annotations
  6763. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  6764. - THREAD)) {
  6765. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6766. - ("bad method_annotations at %d", i));
  6767. - // propagate failure back to caller
  6768. - return false;
  6769. - }
  6770. - }
  6771. -
  6772. - return true;
  6773. -} // end rewrite_cp_refs_in_methods_annotations()
  6774. -
  6775. -
  6776. -// Rewrite constant pool references in a methods_parameter_annotations
  6777. -// field. This "structure" is adapted from the
  6778. -// RuntimeVisibleParameterAnnotations_attribute described in section
  6779. -// 4.8.17 of the 2nd-edition of the VM spec:
  6780. -//
  6781. -// methods_parameter_annotations_typeArray {
  6782. -// u1 num_parameters;
  6783. -// {
  6784. -// u2 num_annotations;
  6785. -// annotation annotations[num_annotations];
  6786. -// } parameter_annotations[num_parameters];
  6787. -// }
  6788. -//
  6789. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  6790. - instanceKlassHandle scratch_class, TRAPS) {
  6791. -
  6792. - objArrayHandle methods_parameter_annotations(THREAD,
  6793. - scratch_class->methods_parameter_annotations());
  6794. -
  6795. - if (methods_parameter_annotations.is_null()
  6796. - || methods_parameter_annotations->length() == 0) {
  6797. - // no methods_parameter_annotations so nothing to do
  6798. - return true;
  6799. - }
  6800. -
  6801. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6802. - ("methods_parameter_annotations length=%d",
  6803. - methods_parameter_annotations->length()));
  6804. -
  6805. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  6806. - typeArrayHandle method_parameter_annotations(THREAD,
  6807. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  6808. - if (method_parameter_annotations.is_null()
  6809. - || method_parameter_annotations->length() == 0) {
  6810. - // this method does not have any parameter annotations so skip it
  6811. - continue;
  6812. - }
  6813. -
  6814. - if (method_parameter_annotations->length() < 1) {
  6815. - // not enough room for a num_parameters field
  6816. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6817. - ("length() is too small for a num_parameters field at %d", i));
  6818. - return false;
  6819. - }
  6820. -
  6821. - int byte_i = 0; // byte index into method_parameter_annotations
  6822. -
  6823. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  6824. - byte_i++;
  6825. -
  6826. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6827. - ("num_parameters=%d", num_parameters));
  6828. -
  6829. - int calc_num_parameters = 0;
  6830. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  6831. - if (!rewrite_cp_refs_in_annotations_typeArray(
  6832. - method_parameter_annotations, byte_i, THREAD)) {
  6833. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6834. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  6835. - // propagate failure back to caller
  6836. - return false;
  6837. + if (code == Bytecodes::_breakpoint) {
  6838. + int bci = method->bci_from(bcp);
  6839. + code = method->orig_bytecode_at(bci);
  6840. + java_code = Bytecodes::java_code(code);
  6841. + if (code != java_code &&
  6842. + (java_code == Bytecodes::_getfield ||
  6843. + java_code == Bytecodes::_putfield ||
  6844. + java_code == Bytecodes::_aload_0)) {
  6845. + // Let breakpoint table handling unpatch bytecode
  6846. + method->set_orig_bytecode_at(bci, java_code);
  6847. }
  6848. - }
  6849. - assert(num_parameters == calc_num_parameters, "sanity check");
  6850. - }
  6851. -
  6852. - return true;
  6853. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  6854. -
  6855. -
  6856. -// Rewrite constant pool references in a methods_default_annotations
  6857. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  6858. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  6859. -//
  6860. -// methods_default_annotations_typeArray {
  6861. -// element_value default_value;
  6862. -// }
  6863. -//
  6864. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  6865. - instanceKlassHandle scratch_class, TRAPS) {
  6866. -
  6867. - objArrayHandle methods_default_annotations(THREAD,
  6868. - scratch_class->methods_default_annotations());
  6869. -
  6870. - if (methods_default_annotations.is_null()
  6871. - || methods_default_annotations->length() == 0) {
  6872. - // no methods_default_annotations so nothing to do
  6873. - return true;
  6874. - }
  6875. -
  6876. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6877. - ("methods_default_annotations length=%d",
  6878. - methods_default_annotations->length()));
  6879. -
  6880. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  6881. - typeArrayHandle method_default_annotations(THREAD,
  6882. - (typeArrayOop)methods_default_annotations->obj_at(i));
  6883. - if (method_default_annotations.is_null()
  6884. - || method_default_annotations->length() == 0) {
  6885. - // this method does not have any default annotations so skip it
  6886. - continue;
  6887. - }
  6888. -
  6889. - int byte_i = 0; // byte index into method_default_annotations
  6890. -
  6891. - if (!rewrite_cp_refs_in_element_value(
  6892. - method_default_annotations, byte_i, THREAD)) {
  6893. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6894. - ("bad default element_value at %d", i));
  6895. - // propagate failure back to caller
  6896. - return false;
  6897. - }
  6898. - }
  6899. -
  6900. - return true;
  6901. -} // end rewrite_cp_refs_in_methods_default_annotations()
  6902. -
  6903. -
  6904. -// Rewrite constant pool references in the method's stackmap table.
  6905. -// These "structures" are adapted from the StackMapTable_attribute that
  6906. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  6907. -// (dated 2005.10.26):
  6908. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6909. -//
  6910. -// stack_map {
  6911. -// u2 number_of_entries;
  6912. -// stack_map_frame entries[number_of_entries];
  6913. -// }
  6914. -//
  6915. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  6916. - methodHandle method, TRAPS) {
  6917. -
  6918. - if (!method->has_stackmap_table()) {
  6919. - return;
  6920. - }
  6921. -
  6922. - typeArrayOop stackmap_data = method->stackmap_data();
  6923. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  6924. - address stackmap_end = stackmap_p + stackmap_data->length();
  6925. -
  6926. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  6927. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  6928. - stackmap_p += 2;
  6929. -
  6930. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6931. - ("number_of_entries=%u", number_of_entries));
  6932. -
  6933. - // walk through each stack_map_frame
  6934. - u2 calc_number_of_entries = 0;
  6935. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  6936. - // The stack_map_frame structure is a u1 frame_type followed by
  6937. - // 0 or more bytes of data:
  6938. - //
  6939. - // union stack_map_frame {
  6940. - // same_frame;
  6941. - // same_locals_1_stack_item_frame;
  6942. - // same_locals_1_stack_item_frame_extended;
  6943. - // chop_frame;
  6944. - // same_frame_extended;
  6945. - // append_frame;
  6946. - // full_frame;
  6947. - // }
  6948. -
  6949. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  6950. - // The Linux compiler does not like frame_type to be u1 or u2. It
  6951. - // issues the following warning for the first if-statement below:
  6952. - //
  6953. - // "warning: comparison is always true due to limited range of data type"
  6954. - //
  6955. - u4 frame_type = *stackmap_p;
  6956. - stackmap_p++;
  6957. -
  6958. - // same_frame {
  6959. - // u1 frame_type = SAME; /* 0-63 */
  6960. - // }
  6961. - if (frame_type >= 0 && frame_type <= 63) {
  6962. - // nothing more to do for same_frame
  6963. - }
  6964. -
  6965. - // same_locals_1_stack_item_frame {
  6966. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  6967. - // verification_type_info stack[1];
  6968. - // }
  6969. - else if (frame_type >= 64 && frame_type <= 127) {
  6970. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6971. - calc_number_of_entries, frame_type, THREAD);
  6972. - }
  6973. -
  6974. - // reserved for future use
  6975. - else if (frame_type >= 128 && frame_type <= 246) {
  6976. - // nothing more to do for reserved frame_types
  6977. - }
  6978. -
  6979. - // same_locals_1_stack_item_frame_extended {
  6980. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  6981. - // u2 offset_delta;
  6982. - // verification_type_info stack[1];
  6983. - // }
  6984. - else if (frame_type == 247) {
  6985. - stackmap_p += 2;
  6986. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6987. - calc_number_of_entries, frame_type, THREAD);
  6988. - }
  6989. -
  6990. - // chop_frame {
  6991. - // u1 frame_type = CHOP; /* 248-250 */
  6992. - // u2 offset_delta;
  6993. - // }
  6994. - else if (frame_type >= 248 && frame_type <= 250) {
  6995. - stackmap_p += 2;
  6996. - }
  6997. -
  6998. - // same_frame_extended {
  6999. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  7000. - // u2 offset_delta;
  7001. - // }
  7002. - else if (frame_type == 251) {
  7003. - stackmap_p += 2;
  7004. - }
  7005. -
  7006. - // append_frame {
  7007. - // u1 frame_type = APPEND; /* 252-254 */
  7008. - // u2 offset_delta;
  7009. - // verification_type_info locals[frame_type - 251];
  7010. - // }
  7011. - else if (frame_type >= 252 && frame_type <= 254) {
  7012. - assert(stackmap_p + 2 <= stackmap_end,
  7013. - "no room for offset_delta");
  7014. - stackmap_p += 2;
  7015. - u1 len = frame_type - 251;
  7016. - for (u1 i = 0; i < len; i++) {
  7017. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7018. - calc_number_of_entries, frame_type, THREAD);
  7019. + } else {
  7020. + java_code = Bytecodes::java_code(code);
  7021. + if (code != java_code &&
  7022. + (java_code == Bytecodes::_getfield ||
  7023. + java_code == Bytecodes::_putfield ||
  7024. + java_code == Bytecodes::_aload_0)) {
  7025. + *bcp = java_code;
  7026. }
  7027. }
  7028. - // full_frame {
  7029. - // u1 frame_type = FULL_FRAME; /* 255 */
  7030. - // u2 offset_delta;
  7031. - // u2 number_of_locals;
  7032. - // verification_type_info locals[number_of_locals];
  7033. - // u2 number_of_stack_items;
  7034. - // verification_type_info stack[number_of_stack_items];
  7035. - // }
  7036. - else if (frame_type == 255) {
  7037. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  7038. - "no room for smallest full_frame");
  7039. - stackmap_p += 2;
  7040. -
  7041. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  7042. - stackmap_p += 2;
  7043. -
  7044. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  7045. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7046. - calc_number_of_entries, frame_type, THREAD);
  7047. - }
  7048. -
  7049. - // Use the largest size for the number_of_stack_items, but only get
  7050. - // the right number of bytes.
  7051. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  7052. - stackmap_p += 2;
  7053. -
  7054. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  7055. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7056. - calc_number_of_entries, frame_type, THREAD);
  7057. - }
  7058. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  7059. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  7060. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  7061. + assert(code2 == Bytecodes::_fast_igetfield ||
  7062. + code2 == Bytecodes::_fast_agetfield ||
  7063. + code2 == Bytecodes::_fast_fgetfield, "");
  7064. + *(bcp + 1) = Bytecodes::java_code(code2);
  7065. }
  7066. - } // end while there is a stack_map_frame
  7067. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  7068. -} // end rewrite_cp_refs_in_stack_map_table()
  7069. + }
  7070. +}
  7071. -
  7072. -// Rewrite constant pool references in the verification type info
  7073. -// portion of the method's stackmap table. These "structures" are
  7074. -// adapted from the StackMapTable_attribute that is described in
  7075. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  7076. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  7077. -//
  7078. -// The verification_type_info structure is a u1 tag followed by 0 or
  7079. -// more bytes of data:
  7080. -//
  7081. -// union verification_type_info {
  7082. -// Top_variable_info;
  7083. -// Integer_variable_info;
  7084. -// Float_variable_info;
  7085. -// Long_variable_info;
  7086. -// Double_variable_info;
  7087. -// Null_variable_info;
  7088. -// UninitializedThis_variable_info;
  7089. -// Object_variable_info;
  7090. -// Uninitialized_variable_info;
  7091. -// }
  7092. -//
  7093. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  7094. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  7095. - u1 frame_type, TRAPS) {
  7096. -
  7097. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  7098. - u1 tag = *stackmap_p_ref;
  7099. - stackmap_p_ref++;
  7100. -
  7101. - switch (tag) {
  7102. - // Top_variable_info {
  7103. - // u1 tag = ITEM_Top; /* 0 */
  7104. - // }
  7105. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  7106. - case 0: // fall through
  7107. -
  7108. - // Integer_variable_info {
  7109. - // u1 tag = ITEM_Integer; /* 1 */
  7110. - // }
  7111. - case ITEM_Integer: // fall through
  7112. -
  7113. - // Float_variable_info {
  7114. - // u1 tag = ITEM_Float; /* 2 */
  7115. - // }
  7116. - case ITEM_Float: // fall through
  7117. -
  7118. - // Double_variable_info {
  7119. - // u1 tag = ITEM_Double; /* 3 */
  7120. - // }
  7121. - case ITEM_Double: // fall through
  7122. -
  7123. - // Long_variable_info {
  7124. - // u1 tag = ITEM_Long; /* 4 */
  7125. - // }
  7126. - case ITEM_Long: // fall through
  7127. -
  7128. - // Null_variable_info {
  7129. - // u1 tag = ITEM_Null; /* 5 */
  7130. - // }
  7131. - case ITEM_Null: // fall through
  7132. -
  7133. - // UninitializedThis_variable_info {
  7134. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  7135. - // }
  7136. - case ITEM_UninitializedThis:
  7137. - // nothing more to do for the above tag types
  7138. - break;
  7139. -
  7140. - // Object_variable_info {
  7141. - // u1 tag = ITEM_Object; /* 7 */
  7142. - // u2 cpool_index;
  7143. - // }
  7144. - case ITEM_Object:
  7145. - {
  7146. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  7147. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  7148. - u2 new_cp_index = find_new_index(cpool_index);
  7149. - if (new_cp_index != 0) {
  7150. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7151. - ("mapped old cpool_index=%d", cpool_index));
  7152. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  7153. - cpool_index = new_cp_index;
  7154. - }
  7155. - stackmap_p_ref += 2;
  7156. -
  7157. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7158. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  7159. - frame_type, cpool_index));
  7160. - } break;
  7161. -
  7162. - // Uninitialized_variable_info {
  7163. - // u1 tag = ITEM_Uninitialized; /* 8 */
  7164. - // u2 offset;
  7165. - // }
  7166. - case ITEM_Uninitialized:
  7167. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  7168. - stackmap_p_ref += 2;
  7169. - break;
  7170. -
  7171. - default:
  7172. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7173. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  7174. - ShouldNotReachHere();
  7175. - break;
  7176. - } // end switch (tag)
  7177. -} // end rewrite_cp_refs_in_verification_type_info()
  7178. -
  7179. -
  7180. -// Change the constant pool associated with klass scratch_class to
  7181. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  7182. -// are copied from scratch_cp to a smaller constant pool and the
  7183. -// smaller constant pool is associated with scratch_class.
  7184. -void VM_RedefineClasses::set_new_constant_pool(
  7185. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  7186. - int scratch_cp_length, TRAPS) {
  7187. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  7188. -
  7189. - // scratch_cp is a merged constant pool and has enough space for a
  7190. - // worst case merge situation. We want to associate the minimum
  7191. - // sized constant pool with the klass to save space.
  7192. - constantPoolHandle smaller_cp(THREAD,
  7193. - oopFactory::new_constantPool(scratch_cp_length,
  7194. - oopDesc::IsUnsafeConc,
  7195. - THREAD));
  7196. - // preserve orig_length() value in the smaller copy
  7197. - int orig_length = scratch_cp->orig_length();
  7198. - assert(orig_length != 0, "sanity check");
  7199. - smaller_cp->set_orig_length(orig_length);
  7200. -
  7201. - // attach klass to new constant pool
  7202. - // reference to the cp holder is needed for copy_operands()
  7203. - smaller_cp->set_pool_holder(scratch_class());
  7204. -
  7205. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  7206. - scratch_cp = smaller_cp;
  7207. - smaller_cp()->set_is_conc_safe(true);
  7208. -
  7209. - // attach new constant pool to klass
  7210. - scratch_class->set_constants(scratch_cp());
  7211. -
  7212. - int i; // for portability
  7213. -
  7214. - // update each field in klass to use new constant pool indices as needed
  7215. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  7216. - jshort cur_index = fs.name_index();
  7217. - jshort new_index = find_new_index(cur_index);
  7218. - if (new_index != 0) {
  7219. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7220. - ("field-name_index change: %d to %d", cur_index, new_index));
  7221. - fs.set_name_index(new_index);
  7222. - }
  7223. - cur_index = fs.signature_index();
  7224. - new_index = find_new_index(cur_index);
  7225. - if (new_index != 0) {
  7226. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7227. - ("field-signature_index change: %d to %d", cur_index, new_index));
  7228. - fs.set_signature_index(new_index);
  7229. - }
  7230. - cur_index = fs.initval_index();
  7231. - new_index = find_new_index(cur_index);
  7232. - if (new_index != 0) {
  7233. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7234. - ("field-initval_index change: %d to %d", cur_index, new_index));
  7235. - fs.set_initval_index(new_index);
  7236. - }
  7237. - cur_index = fs.generic_signature_index();
  7238. - new_index = find_new_index(cur_index);
  7239. - if (new_index != 0) {
  7240. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7241. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  7242. - fs.set_generic_signature_index(new_index);
  7243. - }
  7244. - } // end for each field
  7245. -
  7246. - // Update constant pool indices in the inner classes info to use
  7247. - // new constant indices as needed. The inner classes info is a
  7248. - // quadruple:
  7249. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  7250. - InnerClassesIterator iter(scratch_class);
  7251. - for (; !iter.done(); iter.next()) {
  7252. - int cur_index = iter.inner_class_info_index();
  7253. - if (cur_index == 0) {
  7254. - continue; // JVM spec. allows null inner class refs so skip it
  7255. - }
  7256. - int new_index = find_new_index(cur_index);
  7257. - if (new_index != 0) {
  7258. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7259. - ("inner_class_info change: %d to %d", cur_index, new_index));
  7260. - iter.set_inner_class_info_index(new_index);
  7261. - }
  7262. - cur_index = iter.outer_class_info_index();
  7263. - new_index = find_new_index(cur_index);
  7264. - if (new_index != 0) {
  7265. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7266. - ("outer_class_info change: %d to %d", cur_index, new_index));
  7267. - iter.set_outer_class_info_index(new_index);
  7268. - }
  7269. - cur_index = iter.inner_name_index();
  7270. - new_index = find_new_index(cur_index);
  7271. - if (new_index != 0) {
  7272. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7273. - ("inner_name change: %d to %d", cur_index, new_index));
  7274. - iter.set_inner_name_index(new_index);
  7275. - }
  7276. - } // end for each inner class
  7277. -
  7278. - // Attach each method in klass to the new constant pool and update
  7279. - // to use new constant pool indices as needed:
  7280. - objArrayHandle methods(THREAD, scratch_class->methods());
  7281. - for (i = methods->length() - 1; i >= 0; i--) {
  7282. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7283. - method->set_constants(scratch_cp());
  7284. -
  7285. - int new_index = find_new_index(method->name_index());
  7286. - if (new_index != 0) {
  7287. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7288. - ("method-name_index change: %d to %d", method->name_index(),
  7289. - new_index));
  7290. - method->set_name_index(new_index);
  7291. - }
  7292. - new_index = find_new_index(method->signature_index());
  7293. - if (new_index != 0) {
  7294. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7295. - ("method-signature_index change: %d to %d",
  7296. - method->signature_index(), new_index));
  7297. - method->set_signature_index(new_index);
  7298. - }
  7299. - new_index = find_new_index(method->generic_signature_index());
  7300. - if (new_index != 0) {
  7301. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7302. - ("method-generic_signature_index change: %d to %d",
  7303. - method->generic_signature_index(), new_index));
  7304. - method->set_generic_signature_index(new_index);
  7305. - }
  7306. -
  7307. - // Update constant pool indices in the method's checked exception
  7308. - // table to use new constant indices as needed.
  7309. - int cext_length = method->checked_exceptions_length();
  7310. - if (cext_length > 0) {
  7311. - CheckedExceptionElement * cext_table =
  7312. - method->checked_exceptions_start();
  7313. - for (int j = 0; j < cext_length; j++) {
  7314. - int cur_index = cext_table[j].class_cp_index;
  7315. - int new_index = find_new_index(cur_index);
  7316. - if (new_index != 0) {
  7317. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7318. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  7319. - cext_table[j].class_cp_index = (u2)new_index;
  7320. - }
  7321. - } // end for each checked exception table entry
  7322. - } // end if there are checked exception table entries
  7323. -
  7324. - // Update each catch type index in the method's exception table
  7325. - // to use new constant pool indices as needed. The exception table
  7326. - // holds quadruple entries of the form:
  7327. - // (beg_bci, end_bci, handler_bci, klass_index)
  7328. -
  7329. - ExceptionTable ex_table(method());
  7330. - int ext_length = ex_table.length();
  7331. -
  7332. - for (int j = 0; j < ext_length; j ++) {
  7333. - int cur_index = ex_table.catch_type_index(j);
  7334. - int new_index = find_new_index(cur_index);
  7335. - if (new_index != 0) {
  7336. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7337. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  7338. - ex_table.set_catch_type_index(j, new_index);
  7339. - }
  7340. - } // end for each exception table entry
  7341. -
  7342. - // Update constant pool indices in the method's local variable
  7343. - // table to use new constant indices as needed. The local variable
  7344. - // table hold sextuple entries of the form:
  7345. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  7346. - int lvt_length = method->localvariable_table_length();
  7347. - if (lvt_length > 0) {
  7348. - LocalVariableTableElement * lv_table =
  7349. - method->localvariable_table_start();
  7350. - for (int j = 0; j < lvt_length; j++) {
  7351. - int cur_index = lv_table[j].name_cp_index;
  7352. - int new_index = find_new_index(cur_index);
  7353. - if (new_index != 0) {
  7354. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7355. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  7356. - lv_table[j].name_cp_index = (u2)new_index;
  7357. - }
  7358. - cur_index = lv_table[j].descriptor_cp_index;
  7359. - new_index = find_new_index(cur_index);
  7360. - if (new_index != 0) {
  7361. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7362. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  7363. - new_index));
  7364. - lv_table[j].descriptor_cp_index = (u2)new_index;
  7365. - }
  7366. - cur_index = lv_table[j].signature_cp_index;
  7367. - new_index = find_new_index(cur_index);
  7368. - if (new_index != 0) {
  7369. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7370. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  7371. - lv_table[j].signature_cp_index = (u2)new_index;
  7372. - }
  7373. - } // end for each local variable table entry
  7374. - } // end if there are local variable table entries
  7375. -
  7376. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  7377. - } // end for each method
  7378. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7379. -} // end set_new_constant_pool()
  7380. -
  7381. -
  7382. -// Unevolving classes may point to methods of the_class directly
  7383. +// Unevolving classes may point to old methods directly
  7384. // from their constant pool caches, itables, and/or vtables. We
  7385. // use the SystemDictionary::classes_do() facility and this helper
  7386. -// to fix up these pointers.
  7387. +// to fix up these pointers. Additional field offsets and vtable indices
  7388. +// in the constant pool cache entries are fixed.
  7389. //
  7390. // Note: We currently don't support updating the vtable in
  7391. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7392. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  7393. - oop initiating_loader, TRAPS) {
  7394. - Klass *k = k_oop->klass_part();
  7395. - if (k->oop_is_instance()) {
  7396. - HandleMark hm(THREAD);
  7397. - instanceKlass *ik = (instanceKlass *) k;
  7398. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7399. + klassOop k_oop = k_oop_latest;
  7400. + while (k_oop != NULL) {
  7401. + Klass *k = k_oop->klass_part();
  7402. + if (k->oop_is_instance()) {
  7403. + HandleMark hm(THREAD);
  7404. + instanceKlass *ik = (instanceKlass *) k;
  7405. - // HotSpot specific optimization! HotSpot does not currently
  7406. - // support delegation from the bootstrap class loader to a
  7407. - // user-defined class loader. This means that if the bootstrap
  7408. - // class loader is the initiating class loader, then it will also
  7409. - // be the defining class loader. This also means that classes
  7410. - // loaded by the bootstrap class loader cannot refer to classes
  7411. - // loaded by a user-defined class loader. Note: a user-defined
  7412. - // class loader can delegate to the bootstrap class loader.
  7413. - //
  7414. - // If the current class being redefined has a user-defined class
  7415. - // loader as its defining class loader, then we can skip all
  7416. - // classes loaded by the bootstrap class loader.
  7417. - bool is_user_defined =
  7418. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  7419. - if (is_user_defined && ik->class_loader() == NULL) {
  7420. - return;
  7421. - }
  7422. + constantPoolHandle other_cp;
  7423. + constantPoolCacheOop cp_cache;
  7424. - // This is a very busy routine. We don't want too much tracing
  7425. - // printed out.
  7426. - bool trace_name_printed = false;
  7427. -
  7428. - // Very noisy: only enable this call if you are trying to determine
  7429. - // that a specific class gets found by this routine.
  7430. - // RC_TRACE macro has an embedded ResourceMark
  7431. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  7432. - // ("adjust check: name=%s", ik->external_name()));
  7433. - // trace_name_printed = true;
  7434. -
  7435. - // Fix the vtable embedded in the_class and subclasses of the_class,
  7436. - // if one exists. We discard scratch_class and we don't keep an
  7437. - // instanceKlass around to hold obsolete methods so we don't have
  7438. - // any other instanceKlass embedded vtables to update. The vtable
  7439. - // holds the methodOops for virtual (but not final) methods.
  7440. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  7441. - // ik->vtable() creates a wrapper object; rm cleans it up
  7442. - ResourceMark rm(THREAD);
  7443. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  7444. - _matching_new_methods,
  7445. - _matching_methods_length,
  7446. - &trace_name_printed);
  7447. - }
  7448. -
  7449. - // If the current class has an itable and we are either redefining an
  7450. - // interface or if the current class is a subclass of the_class, then
  7451. - // we potentially have to fix the itable. If we are redefining an
  7452. - // interface, then we have to call adjust_method_entries() for
  7453. - // every instanceKlass that has an itable since there isn't a
  7454. - // subclass relationship between an interface and an instanceKlass.
  7455. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  7456. - || ik->is_subclass_of(_the_class_oop))) {
  7457. - // ik->itable() creates a wrapper object; rm cleans it up
  7458. - ResourceMark rm(THREAD);
  7459. - ik->itable()->adjust_method_entries(_matching_old_methods,
  7460. - _matching_new_methods,
  7461. - _matching_methods_length,
  7462. - &trace_name_printed);
  7463. - }
  7464. -
  7465. - // The constant pools in other classes (other_cp) can refer to
  7466. - // methods in the_class. We have to update method information in
  7467. - // other_cp's cache. If other_cp has a previous version, then we
  7468. - // have to repeat the process for each previous version. The
  7469. - // constant pool cache holds the methodOops for non-virtual
  7470. - // methods and for virtual, final methods.
  7471. - //
  7472. - // Special case: if the current class is the_class, then new_cp
  7473. - // has already been attached to the_class and old_cp has already
  7474. - // been added as a previous version. The new_cp doesn't have any
  7475. - // cached references to old methods so it doesn't need to be
  7476. - // updated. We can simply start with the previous version(s) in
  7477. - // that case.
  7478. - constantPoolHandle other_cp;
  7479. - constantPoolCacheOop cp_cache;
  7480. -
  7481. - if (k_oop != _the_class_oop) {
  7482. - // this klass' constant pool cache may need adjustment
  7483. other_cp = constantPoolHandle(ik->constants());
  7484. +
  7485. + for (int i=0; i<other_cp->length(); i++) {
  7486. + if (other_cp->tag_at(i).is_klass()) {
  7487. + klassOop klass = other_cp->klass_at(i, THREAD);
  7488. + if (klass->klass_part()->new_version() != NULL) {
  7489. +
  7490. + // (tw) TODO: check why/if this is necessary
  7491. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  7492. + }
  7493. + klass = other_cp->klass_at(i, THREAD);
  7494. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  7495. + }
  7496. + }
  7497. +
  7498. cp_cache = other_cp->cache();
  7499. +
  7500. if (cp_cache != NULL) {
  7501. - cp_cache->adjust_method_entries(_matching_old_methods,
  7502. - _matching_new_methods,
  7503. - _matching_methods_length,
  7504. - &trace_name_printed);
  7505. + cp_cache->adjust_entries();
  7506. + }
  7507. +
  7508. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
  7509. + if (RewriteBytecodes) {
  7510. + ik->methods_do(unpatch_bytecode);
  7511. }
  7512. }
  7513. - {
  7514. - ResourceMark rm(THREAD);
  7515. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  7516. - // contain a GrowableArray of handles. We have to clean up the
  7517. - // GrowableArray _after_ the PreviousVersionWalker destructor
  7518. - // has destroyed the handles.
  7519. - {
  7520. - // the previous versions' constant pool caches may need adjustment
  7521. - PreviousVersionWalker pvw(ik);
  7522. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  7523. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  7524. - other_cp = pv_info->prev_constant_pool_handle();
  7525. - cp_cache = other_cp->cache();
  7526. - if (cp_cache != NULL) {
  7527. - cp_cache->adjust_method_entries(_matching_old_methods,
  7528. - _matching_new_methods,
  7529. - _matching_methods_length,
  7530. - &trace_name_printed);
  7531. - }
  7532. - }
  7533. - } // pvw is cleaned up
  7534. - } // rm is cleaned up
  7535. + k_oop = k_oop->klass_part()->old_version();
  7536. }
  7537. }
  7538. void VM_RedefineClasses::update_jmethod_ids() {
  7539. for (int j = 0; j < _matching_methods_length; ++j) {
  7540. - methodOop old_method = _matching_old_methods[j];
  7541. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7542. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  7543. +
  7544. jmethodID jmid = old_method->find_jmethod_id_or_null();
  7545. + if (old_method->new_version() != NULL && jmid == NULL) {
  7546. + // (tw) Have to create jmethodID in this case
  7547. + jmid = old_method->jmethod_id();
  7548. + }
  7549. +
  7550. if (jmid != NULL) {
  7551. // There is a jmethodID, change it to point to the new method
  7552. - methodHandle new_method_h(_matching_new_methods[j]);
  7553. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  7554. + if (old_method->new_version() == NULL) {
  7555. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  7556. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  7557. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  7558. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  7559. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7560. + } else {
  7561. + jmethodID mid = new_method_h->jmethod_id();
  7562. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  7563. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  7564. + }
  7565. JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7566. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  7567. - "should be replaced");
  7568. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  7569. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  7570. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  7571. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  7572. +
  7573. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7574. }
  7575. }
  7576. }
  7577. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  7578. - BitMap *emcp_methods, int * emcp_method_count_p) {
  7579. - *emcp_method_count_p = 0;
  7580. - int obsolete_count = 0;
  7581. - int old_index = 0;
  7582. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7583. - methodOop old_method = _matching_old_methods[j];
  7584. - methodOop new_method = _matching_new_methods[j];
  7585. - methodOop old_array_method;
  7586. - // Maintain an old_index into the _old_methods array by skipping
  7587. - // deleted methods
  7588. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7589. - != old_method) {
  7590. - ++old_index;
  7591. - }
  7592. +// Deoptimize all compiled code that depends on this class.
  7593. +//
  7594. +// If the can_redefine_classes capability is obtained in the onload
  7595. +// phase then the compiler has recorded all dependencies from startup.
  7596. +// In that case we need only deoptimize and throw away all compiled code
  7597. +// that depends on the class.
  7598. +//
  7599. +// If can_redefine_classes is obtained sometime after the onload
  7600. +// phase then the dependency information may be incomplete. In that case
  7601. +// the first call to RedefineClasses causes all compiled code to be
  7602. +// thrown away. As can_redefine_classes has been obtained then
  7603. +// all future compilations will record dependencies so second and
  7604. +// subsequent calls to RedefineClasses need only throw away code
  7605. +// that depends on the class.
  7606. +//
  7607. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  7608. + assert_locked_or_safepoint(Compile_lock);
  7609. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7610. - // The EMCP definition from JSR-163 requires the bytecodes to be
  7611. - // the same with the exception of constant pool indices which may
  7612. - // differ. However, the constants referred to by those indices
  7613. - // must be the same.
  7614. - //
  7615. - // We use methods_EMCP() for comparison since constant pool
  7616. - // merging can remove duplicate constant pool entries that were
  7617. - // present in the old method and removed from the rewritten new
  7618. - // method. A faster binary comparison function would consider the
  7619. - // old and new methods to be different when they are actually
  7620. - // EMCP.
  7621. - //
  7622. - // The old and new methods are EMCP and you would think that we
  7623. - // could get rid of one of them here and now and save some space.
  7624. - // However, the concept of EMCP only considers the bytecodes and
  7625. - // the constant pool entries in the comparison. Other things,
  7626. - // e.g., the line number table (LNT) or the local variable table
  7627. - // (LVT) don't count in the comparison. So the new (and EMCP)
  7628. - // method can have a new LNT that we need so we can't just
  7629. - // overwrite the new method with the old method.
  7630. - //
  7631. - // When this routine is called, we have already attached the new
  7632. - // methods to the_class so the old methods are effectively
  7633. - // overwritten. However, if an old method is still executing,
  7634. - // then the old method cannot be collected until sometime after
  7635. - // the old method call has returned. So the overwriting of old
  7636. - // methods by new methods will save us space except for those
  7637. - // (hopefully few) old methods that are still executing.
  7638. - //
  7639. - // A method refers to a constMethodOop and this presents another
  7640. - // possible avenue to space savings. The constMethodOop in the
  7641. - // new method contains possibly new attributes (LNT, LVT, etc).
  7642. - // At first glance, it seems possible to save space by replacing
  7643. - // the constMethodOop in the old method with the constMethodOop
  7644. - // from the new method. The old and new methods would share the
  7645. - // same constMethodOop and we would save the space occupied by
  7646. - // the old constMethodOop. However, the constMethodOop contains
  7647. - // a back reference to the containing method. Sharing the
  7648. - // constMethodOop between two methods could lead to confusion in
  7649. - // the code that uses the back reference. This would lead to
  7650. - // brittle code that could be broken in non-obvious ways now or
  7651. - // in the future.
  7652. - //
  7653. - // Another possibility is to copy the constMethodOop from the new
  7654. - // method to the old method and then overwrite the new method with
  7655. - // the old method. Since the constMethodOop contains the bytecodes
  7656. - // for the method embedded in the oop, this option would change
  7657. - // the bytecodes out from under any threads executing the old
  7658. - // method and make the thread's bcp invalid. Since EMCP requires
  7659. - // that the bytecodes be the same modulo constant pool indices, it
  7660. - // is straight forward to compute the correct new bcp in the new
  7661. - // constMethodOop from the old bcp in the old constMethodOop. The
  7662. - // time consuming part would be searching all the frames in all
  7663. - // of the threads to find all of the calls to the old method.
  7664. - //
  7665. - // It looks like we will have to live with the limited savings
  7666. - // that we get from effectively overwriting the old methods
  7667. - // when the new methods are attached to the_class.
  7668. + // All dependencies have been recorded from startup or this is a second or
  7669. + // subsequent use of RedefineClasses
  7670. - // track which methods are EMCP for add_previous_version() call
  7671. - emcp_methods->set_bit(old_index);
  7672. - (*emcp_method_count_p)++;
  7673. + // For now deopt all
  7674. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  7675. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  7676. + Universe::flush_evol_dependents_on(k_h);
  7677. + } else {
  7678. + CodeCache::mark_all_nmethods_for_deoptimization();
  7679. - // An EMCP method is _not_ obsolete. An obsolete method has a
  7680. - // different jmethodID than the current method. An EMCP method
  7681. - // has the same jmethodID as the current method. Having the
  7682. - // same jmethodID for all EMCP versions of a method allows for
  7683. - // a consistent view of the EMCP methods regardless of which
  7684. - // EMCP method you happen to have in hand. For example, a
  7685. - // breakpoint set in one EMCP method will work for all EMCP
  7686. - // versions of the method including the current one.
  7687. - } else {
  7688. - // mark obsolete methods as such
  7689. - old_method->set_is_obsolete();
  7690. - obsolete_count++;
  7691. + ResourceMark rm(THREAD);
  7692. + DeoptimizationMarker dm;
  7693. - // obsolete methods need a unique idnum
  7694. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  7695. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  7696. -// u2 old_num = old_method->method_idnum();
  7697. - old_method->set_method_idnum(num);
  7698. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  7699. + // Deoptimize all activations depending on marked nmethods
  7700. + Deoptimization::deoptimize_dependents();
  7701. +
  7702. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  7703. + CodeCache::make_marked_nmethods_not_entrant();
  7704. +
  7705. + // From now on we know that the dependency information is complete
  7706. + JvmtiExport::set_all_dependencies_are_recorded(true);
  7707. + }
  7708. +}
  7709. +
  7710. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7711. + methodOop old_method;
  7712. + methodOop new_method;
  7713. +
  7714. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7715. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7716. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  7717. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7718. +
  7719. + _matching_methods_length = 0;
  7720. + _deleted_methods_length = 0;
  7721. + _added_methods_length = 0;
  7722. +
  7723. + int nj = 0;
  7724. + int oj = 0;
  7725. + while (true) {
  7726. + if (oj >= _old_methods->length()) {
  7727. + if (nj >= _new_methods->length()) {
  7728. + break; // we've looked at everything, done
  7729. }
  7730. + // New method at the end
  7731. + new_method = (methodOop) _new_methods->obj_at(nj);
  7732. + _added_methods[_added_methods_length++] = nj;
  7733. + ++nj;
  7734. + } else if (nj >= _new_methods->length()) {
  7735. + // Old method, at the end, is deleted
  7736. + old_method = (methodOop) _old_methods->obj_at(oj);
  7737. + _deleted_methods[_deleted_methods_length++] = oj;
  7738. + ++oj;
  7739. + } else {
  7740. + old_method = (methodOop) _old_methods->obj_at(oj);
  7741. + new_method = (methodOop) _new_methods->obj_at(nj);
  7742. + if (old_method->name() == new_method->name()) {
  7743. + if (old_method->signature() == new_method->signature()) {
  7744. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  7745. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  7746. + ++nj;
  7747. + ++oj;
  7748. + } else {
  7749. + // added overloaded have already been moved to the end,
  7750. + // so this is a deleted overloaded method
  7751. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7752. + ++oj;
  7753. + }
  7754. + } else { // names don't match
  7755. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  7756. + // new method
  7757. + _added_methods[_added_methods_length++] = nj;//new_method;
  7758. + ++nj;
  7759. + } else {
  7760. + // deleted method
  7761. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7762. + ++oj;
  7763. + }
  7764. + }
  7765. + }
  7766. + }
  7767. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  7768. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  7769. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  7770. +}
  7771. +
  7772. +
  7773. +
  7774. +// Install the redefinition of a class:
  7775. +// - house keeping (flushing breakpoints and caches, deoptimizing
  7776. +// dependent compiled code)
  7777. +// - adjusting constant pool caches and vtables in other classes
  7778. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  7779. +
  7780. + ResourceMark rm(THREAD);
  7781. +
  7782. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7783. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7784. +
  7785. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  7786. +
  7787. +#ifndef JVMTI_KERNEL
  7788. + // Remove all breakpoints in methods of this class
  7789. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  7790. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  7791. +#endif // !JVMTI_KERNEL
  7792. +
  7793. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  7794. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  7795. + // cached and users of the cache care about each active version of
  7796. + // the method so we have to track this previous version.
  7797. + // Do this before methods get switched
  7798. + Universe::reflect_invoke_cache()->add_previous_version(
  7799. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7800. + }
  7801. +
  7802. + _old_methods = the_old_class->methods();
  7803. + _new_methods = the_new_class->methods();
  7804. + compute_added_deleted_matching_methods();
  7805. +
  7806. + // track which methods are EMCP for add_previous_version() call below
  7807. +
  7808. + // (tw) TODO: Check if we need the concept of EMCP?
  7809. + BitMap emcp_methods(_old_methods->length());
  7810. + int emcp_method_count = 0;
  7811. + emcp_methods.clear(); // clears 0..(length() - 1)
  7812. +
  7813. + // We need to mark methods as old!!
  7814. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  7815. + update_jmethod_ids();
  7816. +
  7817. + // TODO:
  7818. + transfer_old_native_function_registrations(the_old_class);
  7819. +
  7820. +
  7821. +
  7822. +#ifdef ASSERT
  7823. +
  7824. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  7825. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  7826. +
  7827. + //JNIHandles::verify();
  7828. +
  7829. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  7830. +
  7831. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  7832. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7833. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7834. +
  7835. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  7836. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  7837. + }
  7838. +
  7839. + _old_methods->verify();
  7840. + _new_methods->verify();
  7841. +
  7842. + the_new_class->vtable()->verify(tty);
  7843. + the_old_class->vtable()->verify(tty);
  7844. +
  7845. +#endif
  7846. +
  7847. + // increment the classRedefinedCount field in the_class and in any
  7848. + // direct and indirect subclasses of the_class
  7849. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  7850. +
  7851. +}
  7852. +
  7853. +
  7854. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  7855. + TRACE_RC3("Checking matching methods for EMCP");
  7856. + *emcp_method_count_p = 0;
  7857. + int obsolete_count = 0;
  7858. + int old_index = 0;
  7859. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7860. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7861. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  7862. + methodOop old_array_method;
  7863. +
  7864. + // Maintain an old_index into the _old_methods array by skipping
  7865. + // deleted methods
  7866. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7867. + != old_method) {
  7868. + ++old_index;
  7869. + }
  7870. +
  7871. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7872. + // The EMCP definition from JSR-163 requires the bytecodes to be
  7873. + // the same with the exception of constant pool indices which may
  7874. + // differ. However, the constants referred to by those indices
  7875. + // must be the same.
  7876. + //
  7877. + // We use methods_EMCP() for comparison since constant pool
  7878. + // merging can remove duplicate constant pool entries that were
  7879. + // present in the old method and removed from the rewritten new
  7880. + // method. A faster binary comparison function would consider the
  7881. + // old and new methods to be different when they are actually
  7882. + // EMCP.
  7883. +
  7884. + // track which methods are EMCP for add_previous_version() call
  7885. + emcp_methods->set_bit(old_index);
  7886. + (*emcp_method_count_p)++;
  7887. +
  7888. + // An EMCP method is _not_ obsolete. An obsolete method has a
  7889. + // different jmethodID than the current method. An EMCP method
  7890. + // has the same jmethodID as the current method. Having the
  7891. + // same jmethodID for all EMCP versions of a method allows for
  7892. + // a consistent view of the EMCP methods regardless of which
  7893. + // EMCP method you happen to have in hand. For example, a
  7894. + // breakpoint set in one EMCP method will work for all EMCP
  7895. + // versions of the method including the current one.
  7896. +
  7897. + old_method->set_new_version(new_method);
  7898. + new_method->set_old_version(old_method);
  7899. +
  7900. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  7901. +
  7902. + // Transfer breakpoints
  7903. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  7904. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  7905. + TRACE_RC2("Checking breakpoint");
  7906. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  7907. + if (bp->match(old_method)) {
  7908. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  7909. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  7910. + new_method->set_breakpoint(bp->bci());
  7911. + }
  7912. + }
  7913. + } else {
  7914. + // mark obsolete methods as such
  7915. + old_method->set_is_obsolete();
  7916. + obsolete_count++;
  7917. +
  7918. + // With tracing we try not to "yack" too much. The position of
  7919. + // this trace assumes there are fewer obsolete methods than
  7920. + // EMCP methods.
  7921. + TRACE_RC3("mark %s(%s) as obsolete",
  7922. + old_method->name()->as_C_string(),
  7923. + old_method->signature()->as_C_string());
  7924. + }
  7925. + old_method->set_is_old();
  7926. + }
  7927. + for (int i = 0; i < _deleted_methods_length; ++i) {
  7928. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  7929. +
  7930. + //assert(old_method->vtable_index() < 0,
  7931. + // "cannot delete methods with vtable entries");;
  7932. +
  7933. + // Mark all deleted methods as old and obsolete
  7934. + old_method->set_is_old();
  7935. + old_method->set_is_obsolete();
  7936. + ++obsolete_count;
  7937. // With tracing we try not to "yack" too much. The position of
  7938. // this trace assumes there are fewer obsolete methods than
  7939. // EMCP methods.
  7940. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  7941. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  7942. old_method->name()->as_C_string(),
  7943. - old_method->signature()->as_C_string()));
  7944. + old_method->signature()->as_C_string());
  7945. }
  7946. - old_method->set_is_old();
  7947. - }
  7948. - for (int i = 0; i < _deleted_methods_length; ++i) {
  7949. - methodOop old_method = _deleted_methods[i];
  7950. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  7951. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  7952. +}
  7953. - assert(old_method->vtable_index() < 0,
  7954. - "cannot delete methods with vtable entries");;
  7955. +// Increment the classRedefinedCount field in the specific instanceKlass
  7956. +// and in all direct and indirect subclasses.
  7957. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  7958. + oop class_mirror = ik->java_mirror();
  7959. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  7960. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  7961. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  7962. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  7963. +}
  7964. - // Mark all deleted methods as old and obsolete
  7965. - old_method->set_is_old();
  7966. - old_method->set_is_obsolete();
  7967. - ++obsolete_count;
  7968. - // With tracing we try not to "yack" too much. The position of
  7969. - // this trace assumes there are fewer obsolete methods than
  7970. - // EMCP methods.
  7971. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  7972. - old_method->name()->as_C_string(),
  7973. - old_method->signature()->as_C_string()));
  7974. +#ifndef PRODUCT
  7975. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  7976. + Klass *k = k_oop->klass_part();
  7977. + if (k->oop_is_instance()) {
  7978. + HandleMark hm(THREAD);
  7979. + instanceKlass *ik = (instanceKlass *) k;
  7980. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  7981. +
  7982. + if (ik->vtable_length() > 0) {
  7983. + ResourceMark rm(THREAD);
  7984. + if (!ik->vtable()->check_no_old_or_obsolete_entries()) {
  7985. + TRACE_RC1("size of class: %d\n", k_oop->size());
  7986. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  7987. + assert(false, "OLD method found");
  7988. + }
  7989. +
  7990. + ik->vtable()->verify(tty, true);
  7991. + }
  7992. }
  7993. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  7994. - "sanity check");
  7995. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  7996. - obsolete_count));
  7997. +}
  7998. +
  7999. +#endif
  8000. +
  8001. +static bool match_right(void* value, Pair<klassOop, klassOop> elem) {
  8002. + return elem.right() == value;
  8003. +}
  8004. +
  8005. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS)
  8006. +{
  8007. + GrowableArray< Pair<klassOop, klassOop> > links;
  8008. +
  8009. + for (int i=0; i<class_count; i++) {
  8010. +
  8011. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  8012. + instanceKlassHandle the_class(THREAD, java_lang_Class::as_klassOop(mirror));
  8013. + Handle the_class_loader(THREAD, the_class->class_loader());
  8014. + Handle protection_domain(THREAD, the_class->protection_domain());
  8015. +
  8016. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  8017. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  8018. + ClassFileParser cfp(&st);
  8019. +
  8020. + GrowableArray<Symbol*> symbolArr;
  8021. + TempNewSymbol parsed_name;
  8022. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  8023. + cfp.parseClassFile(the_class->name(), the_class_loader, protection_domain, the_class, KlassHandle(), NULL, &symbolArr, parsed_name, false, THREAD);
  8024. +
  8025. + for (int j=0; j<symbolArr.length(); j++) {
  8026. + Symbol* sym = symbolArr.at(j);
  8027. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  8028. + klassOop super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
  8029. + if (super_klass != NULL) {
  8030. + instanceKlassHandle the_super_class(THREAD, super_klass);
  8031. + if (_affected_klasses->contains(the_super_class)) {
  8032. + TRACE_RC2("Found class to link");
  8033. + links.append(Pair<klassOop, klassOop>(super_klass, the_class()));
  8034. + }
  8035. + }
  8036. + }
  8037. +
  8038. + assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
  8039. + the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
  8040. + }
  8041. +
  8042. +
  8043. + TRACE_RC1("Identified links between classes! ");
  8044. +
  8045. + for (int i=0; i < _affected_klasses->length(); i++) {
  8046. + instanceKlassHandle klass = _affected_klasses->at(i);
  8047. +
  8048. + if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
  8049. + klass->clear_redefinition_flag(Klass::MarkedAsAffected);
  8050. + klassOop superKlass = klass->super();
  8051. + if (_affected_klasses->contains(superKlass)) {
  8052. + links.append(Pair<klassOop, klassOop>(superKlass, klass()));
  8053. + }
  8054. +
  8055. + objArrayOop superInterfaces = klass->local_interfaces();
  8056. + for (int j=0; j<superInterfaces->length(); j++) {
  8057. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  8058. + if (_affected_klasses->contains(interfaceKlass)) {
  8059. + links.append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  8060. + }
  8061. + }
  8062. + }
  8063. + }
  8064. +
  8065. + IF_TRACE_RC2 {
  8066. + TRACE_RC2("Identified links: ");
  8067. + for (int i=0; i<links.length(); i++) {
  8068. + TRACE_RC2("%s to %s", links.at(i).left()->klass_part()->name()->as_C_string(),
  8069. + links.at(i).right()->klass_part()->name()->as_C_string());
  8070. + }
  8071. + }
  8072. +
  8073. + for (int i = 0; i < _affected_klasses->length(); i++) {
  8074. + int j;
  8075. + for (j = i; j < _affected_klasses->length(); j++) {
  8076. + // Search for node with no incoming edges
  8077. + klassOop oop = _affected_klasses->at(j)();
  8078. + int k = links.find(oop, match_right);
  8079. + if (k == -1) break;
  8080. + }
  8081. + if (j == _affected_klasses->length()) {
  8082. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  8083. + }
  8084. +
  8085. + // Remove all links from this node
  8086. + klassOop oop = _affected_klasses->at(j)();
  8087. + int k = 0;
  8088. + while (k < links.length()) {
  8089. + if (links.adr_at(k)->left() == oop) {
  8090. + links.delete_at(k);
  8091. + } else {
  8092. + k++;
  8093. + }
  8094. + }
  8095. +
  8096. + // Swap node
  8097. + instanceKlassHandle tmp = _affected_klasses->at(j);
  8098. + _affected_klasses->at_put(j, _affected_klasses->at(i));
  8099. + _affected_klasses->at_put(i, tmp);
  8100. + }
  8101. +
  8102. + return JVMTI_ERROR_NONE;
  8103. }
  8104. // This internal class transfers the native function registration from old methods
  8105. @@ -2969,7 +2269,7 @@
  8106. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8107. //
  8108. class TransferNativeFunctionRegistration {
  8109. - private:
  8110. +private:
  8111. instanceKlassHandle the_class;
  8112. int prefix_count;
  8113. char** prefixes;
  8114. @@ -2982,42 +2282,42 @@
  8115. // (2) with the prefix.
  8116. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  8117. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  8118. - Symbol* signature) {
  8119. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8120. - if (name_symbol != NULL) {
  8121. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  8122. - if (method != NULL) {
  8123. - // Even if prefixed, intermediate methods must exist.
  8124. - if (method->is_native()) {
  8125. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8126. - return method;
  8127. - }
  8128. - if (depth < prefix_count) {
  8129. - // Try applying further prefixes (other than this one).
  8130. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8131. - if (method != NULL) {
  8132. - return method; // found
  8133. + Symbol* signature) {
  8134. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8135. + if (name_symbol != NULL) {
  8136. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  8137. + if (method != NULL) {
  8138. + // Even if prefixed, intermediate methods must exist.
  8139. + if (method->is_native()) {
  8140. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8141. + return method;
  8142. }
  8143. + if (depth < prefix_count) {
  8144. + // Try applying further prefixes (other than this one).
  8145. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8146. + if (method != NULL) {
  8147. + return method; // found
  8148. + }
  8149. - // Try adding this prefix to the method name and see if it matches
  8150. - // another method name.
  8151. - char* prefix = prefixes[depth];
  8152. - size_t prefix_len = strlen(prefix);
  8153. - size_t trial_len = name_len + prefix_len;
  8154. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8155. - strcpy(trial_name_str, prefix);
  8156. - strcat(trial_name_str, name_str);
  8157. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8158. - signature);
  8159. - if (method != NULL) {
  8160. - // If found along this branch, it was prefixed, mark as such
  8161. - method->set_is_prefixed_native();
  8162. - return method; // found
  8163. + // Try adding this prefix to the method name and see if it matches
  8164. + // another method name.
  8165. + char* prefix = prefixes[depth];
  8166. + size_t prefix_len = strlen(prefix);
  8167. + size_t trial_len = name_len + prefix_len;
  8168. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8169. + strcpy(trial_name_str, prefix);
  8170. + strcat(trial_name_str, name_str);
  8171. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8172. + signature);
  8173. + if (method != NULL) {
  8174. + // If found along this branch, it was prefixed, mark as such
  8175. + method->set_is_prefixed_native();
  8176. + return method; // found
  8177. + }
  8178. }
  8179. }
  8180. }
  8181. - }
  8182. - return NULL; // This whole branch bore nothing
  8183. + return NULL; // This whole branch bore nothing
  8184. }
  8185. // Return the method name with old prefixes stripped away.
  8186. @@ -3042,10 +2342,10 @@
  8187. ResourceMark rm;
  8188. char* name_str = method_name_without_prefixes(method);
  8189. return search_prefix_name_space(0, name_str, strlen(name_str),
  8190. - method->signature());
  8191. + method->signature());
  8192. }
  8193. - public:
  8194. +public:
  8195. // Construct a native method transfer processor for this class.
  8196. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  8197. @@ -3056,9 +2356,9 @@
  8198. }
  8199. // Attempt to transfer any of the old or deleted methods that are native
  8200. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  8201. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  8202. for (int j = 0; j < methods_length; j++) {
  8203. - methodOop old_method = old_methods[j];
  8204. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  8205. if (old_method->is_native() && old_method->has_native_function()) {
  8206. methodOop new_method = strip_and_search_for_new_native(old_method);
  8207. @@ -3067,7 +2367,9 @@
  8208. // Redefine does not send events (except CFLH), certainly not this
  8209. // behind the scenes re-registration.
  8210. new_method->set_native_function(old_method->native_function(),
  8211. - !methodOopDesc::native_bind_event_is_interesting);
  8212. + !methodOopDesc::native_bind_event_is_interesting);
  8213. +
  8214. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  8215. }
  8216. }
  8217. }
  8218. @@ -3075,544 +2377,8 @@
  8219. };
  8220. // Don't lose the association between a native method and its JNI function.
  8221. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  8222. - TransferNativeFunctionRegistration transfer(the_class);
  8223. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  8224. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  8225. -}
  8226. -
  8227. -// Deoptimize all compiled code that depends on this class.
  8228. -//
  8229. -// If the can_redefine_classes capability is obtained in the onload
  8230. -// phase then the compiler has recorded all dependencies from startup.
  8231. -// In that case we need only deoptimize and throw away all compiled code
  8232. -// that depends on the class.
  8233. -//
  8234. -// If can_redefine_classes is obtained sometime after the onload
  8235. -// phase then the dependency information may be incomplete. In that case
  8236. -// the first call to RedefineClasses causes all compiled code to be
  8237. -// thrown away. As can_redefine_classes has been obtained then
  8238. -// all future compilations will record dependencies so second and
  8239. -// subsequent calls to RedefineClasses need only throw away code
  8240. -// that depends on the class.
  8241. -//
  8242. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  8243. - assert_locked_or_safepoint(Compile_lock);
  8244. -
  8245. - // All dependencies have been recorded from startup or this is a second or
  8246. - // subsequent use of RedefineClasses
  8247. - if (JvmtiExport::all_dependencies_are_recorded()) {
  8248. - Universe::flush_evol_dependents_on(k_h);
  8249. - } else {
  8250. - CodeCache::mark_all_nmethods_for_deoptimization();
  8251. -
  8252. - ResourceMark rm(THREAD);
  8253. - DeoptimizationMarker dm;
  8254. -
  8255. - // Deoptimize all activations depending on marked nmethods
  8256. - Deoptimization::deoptimize_dependents();
  8257. -
  8258. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  8259. - CodeCache::make_marked_nmethods_not_entrant();
  8260. -
  8261. - // From now on we know that the dependency information is complete
  8262. - JvmtiExport::set_all_dependencies_are_recorded(true);
  8263. - }
  8264. -}
  8265. -
  8266. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  8267. - methodOop old_method;
  8268. - methodOop new_method;
  8269. -
  8270. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8271. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8272. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  8273. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8274. -
  8275. - _matching_methods_length = 0;
  8276. - _deleted_methods_length = 0;
  8277. - _added_methods_length = 0;
  8278. -
  8279. - int nj = 0;
  8280. - int oj = 0;
  8281. - while (true) {
  8282. - if (oj >= _old_methods->length()) {
  8283. - if (nj >= _new_methods->length()) {
  8284. - break; // we've looked at everything, done
  8285. - }
  8286. - // New method at the end
  8287. - new_method = (methodOop) _new_methods->obj_at(nj);
  8288. - _added_methods[_added_methods_length++] = new_method;
  8289. - ++nj;
  8290. - } else if (nj >= _new_methods->length()) {
  8291. - // Old method, at the end, is deleted
  8292. - old_method = (methodOop) _old_methods->obj_at(oj);
  8293. - _deleted_methods[_deleted_methods_length++] = old_method;
  8294. - ++oj;
  8295. - } else {
  8296. - old_method = (methodOop) _old_methods->obj_at(oj);
  8297. - new_method = (methodOop) _new_methods->obj_at(nj);
  8298. - if (old_method->name() == new_method->name()) {
  8299. - if (old_method->signature() == new_method->signature()) {
  8300. - _matching_old_methods[_matching_methods_length ] = old_method;
  8301. - _matching_new_methods[_matching_methods_length++] = new_method;
  8302. - ++nj;
  8303. - ++oj;
  8304. - } else {
  8305. - // added overloaded have already been moved to the end,
  8306. - // so this is a deleted overloaded method
  8307. - _deleted_methods[_deleted_methods_length++] = old_method;
  8308. - ++oj;
  8309. - }
  8310. - } else { // names don't match
  8311. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  8312. - // new method
  8313. - _added_methods[_added_methods_length++] = new_method;
  8314. - ++nj;
  8315. - } else {
  8316. - // deleted method
  8317. - _deleted_methods[_deleted_methods_length++] = old_method;
  8318. - ++oj;
  8319. - }
  8320. - }
  8321. - }
  8322. - }
  8323. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  8324. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  8325. -}
  8326. -
  8327. -
  8328. -
  8329. -// Install the redefinition of a class:
  8330. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8331. -// dependent compiled code)
  8332. -// - replacing parts in the_class with parts from scratch_class
  8333. -// - adding a weak reference to track the obsolete but interesting
  8334. -// parts of the_class
  8335. -// - adjusting constant pool caches and vtables in other classes
  8336. -// that refer to methods in the_class. These adjustments use the
  8337. -// SystemDictionary::classes_do() facility which only allows
  8338. -// a helper method to be specified. The interesting parameters
  8339. -// that we would like to pass to the helper method are saved in
  8340. -// static global fields in the VM operation.
  8341. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  8342. - instanceKlassHandle scratch_class, TRAPS) {
  8343. -
  8344. - RC_TIMER_START(_timer_rsc_phase1);
  8345. -
  8346. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  8347. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  8348. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  8349. -
  8350. - // Remove all breakpoints in methods of this class
  8351. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  8352. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  8353. -
  8354. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  8355. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  8356. - // cached and users of the cache care about each active version of
  8357. - // the method so we have to track this previous version.
  8358. - // Do this before methods get switched
  8359. - Universe::reflect_invoke_cache()->add_previous_version(
  8360. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  8361. - }
  8362. -
  8363. - // Deoptimize all compiled code that depends on this class
  8364. - flush_dependent_code(the_class, THREAD);
  8365. -
  8366. - _old_methods = the_class->methods();
  8367. - _new_methods = scratch_class->methods();
  8368. - _the_class_oop = the_class_oop;
  8369. - compute_added_deleted_matching_methods();
  8370. - update_jmethod_ids();
  8371. -
  8372. - // Attach new constant pool to the original klass. The original
  8373. - // klass still refers to the old constant pool (for now).
  8374. - scratch_class->constants()->set_pool_holder(the_class());
  8375. -
  8376. -#if 0
  8377. - // In theory, with constant pool merging in place we should be able
  8378. - // to save space by using the new, merged constant pool in place of
  8379. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  8380. - // the klass version we are replacing now and any constant pool(s) in
  8381. - // previous versions of klass. Nice theory, doesn't work in practice.
  8382. - // When this code is enabled, even simple programs throw NullPointer
  8383. - // exceptions. I'm guessing that this is caused by some constant pool
  8384. - // cache difference between the new, merged constant pool and the
  8385. - // constant pool that was just being used by the klass. I'm keeping
  8386. - // this code around to archive the idea, but the code has to remain
  8387. - // disabled for now.
  8388. -
  8389. - // Attach each old method to the new constant pool. This can be
  8390. - // done here since we are past the bytecode verification and
  8391. - // constant pool optimization phases.
  8392. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  8393. - methodOop method = (methodOop)_old_methods->obj_at(i);
  8394. - method->set_constants(scratch_class->constants());
  8395. - }
  8396. -
  8397. - {
  8398. - // walk all previous versions of the klass
  8399. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  8400. - PreviousVersionWalker pvw(ik);
  8401. - instanceKlassHandle ikh;
  8402. - do {
  8403. - ikh = pvw.next_previous_version();
  8404. - if (!ikh.is_null()) {
  8405. - ik = ikh();
  8406. -
  8407. - // attach previous version of klass to the new constant pool
  8408. - ik->set_constants(scratch_class->constants());
  8409. -
  8410. - // Attach each method in the previous version of klass to the
  8411. - // new constant pool
  8412. - objArrayOop prev_methods = ik->methods();
  8413. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  8414. - methodOop method = (methodOop)prev_methods->obj_at(i);
  8415. - method->set_constants(scratch_class->constants());
  8416. - }
  8417. - }
  8418. - } while (!ikh.is_null());
  8419. - }
  8420. -#endif
  8421. -
  8422. - // Replace methods and constantpool
  8423. - the_class->set_methods(_new_methods);
  8424. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  8425. - // and to be able to undo operation easily.
  8426. -
  8427. - constantPoolOop old_constants = the_class->constants();
  8428. - the_class->set_constants(scratch_class->constants());
  8429. - scratch_class->set_constants(old_constants); // See the previous comment.
  8430. -#if 0
  8431. - // We are swapping the guts of "the new class" with the guts of "the
  8432. - // class". Since the old constant pool has just been attached to "the
  8433. - // new class", it seems logical to set the pool holder in the old
  8434. - // constant pool also. However, doing this will change the observable
  8435. - // class hierarchy for any old methods that are still executing. A
  8436. - // method can query the identity of its "holder" and this query uses
  8437. - // the method's constant pool link to find the holder. The change in
  8438. - // holding class from "the class" to "the new class" can confuse
  8439. - // things.
  8440. - //
  8441. - // Setting the old constant pool's holder will also cause
  8442. - // verification done during vtable initialization below to fail.
  8443. - // During vtable initialization, the vtable's class is verified to be
  8444. - // a subtype of the method's holder. The vtable's class is "the
  8445. - // class" and the method's holder is gotten from the constant pool
  8446. - // link in the method itself. For "the class"'s directly implemented
  8447. - // methods, the method holder is "the class" itself (as gotten from
  8448. - // the new constant pool). The check works fine in this case. The
  8449. - // check also works fine for methods inherited from super classes.
  8450. - //
  8451. - // Miranda methods are a little more complicated. A miranda method is
  8452. - // provided by an interface when the class implementing the interface
  8453. - // does not provide its own method. These interfaces are implemented
  8454. - // internally as an instanceKlass. These special instanceKlasses
  8455. - // share the constant pool of the class that "implements" the
  8456. - // interface. By sharing the constant pool, the method holder of a
  8457. - // miranda method is the class that "implements" the interface. In a
  8458. - // non-redefine situation, the subtype check works fine. However, if
  8459. - // the old constant pool's pool holder is modified, then the check
  8460. - // fails because there is no class hierarchy relationship between the
  8461. - // vtable's class and "the new class".
  8462. -
  8463. - old_constants->set_pool_holder(scratch_class());
  8464. -#endif
  8465. -
  8466. - // track which methods are EMCP for add_previous_version() call below
  8467. - BitMap emcp_methods(_old_methods->length());
  8468. - int emcp_method_count = 0;
  8469. - emcp_methods.clear(); // clears 0..(length() - 1)
  8470. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  8471. - transfer_old_native_function_registrations(the_class);
  8472. -
  8473. - // The class file bytes from before any retransformable agents mucked
  8474. - // with them was cached on the scratch class, move to the_class.
  8475. - // Note: we still want to do this if nothing needed caching since it
  8476. - // should get cleared in the_class too.
  8477. - if (the_class->get_cached_class_file_bytes() == 0) {
  8478. - // the_class doesn't have a cache yet so copy it
  8479. - the_class->set_cached_class_file(
  8480. - scratch_class->get_cached_class_file_bytes(),
  8481. - scratch_class->get_cached_class_file_len());
  8482. - }
  8483. -#ifndef PRODUCT
  8484. - else {
  8485. - assert(the_class->get_cached_class_file_bytes() ==
  8486. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  8487. - assert(the_class->get_cached_class_file_len() ==
  8488. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  8489. - }
  8490. -#endif
  8491. -
  8492. - // Replace inner_classes
  8493. - typeArrayOop old_inner_classes = the_class->inner_classes();
  8494. - the_class->set_inner_classes(scratch_class->inner_classes());
  8495. - scratch_class->set_inner_classes(old_inner_classes);
  8496. -
  8497. - // Initialize the vtable and interface table after
  8498. - // methods have been rewritten
  8499. - {
  8500. - ResourceMark rm(THREAD);
  8501. - // no exception should happen here since we explicitly
  8502. - // do not check loader constraints.
  8503. - // compare_and_normalize_class_versions has already checked:
  8504. - // - classloaders unchanged, signatures unchanged
  8505. - // - all instanceKlasses for redefined classes reused & contents updated
  8506. - the_class->vtable()->initialize_vtable(false, THREAD);
  8507. - the_class->itable()->initialize_itable(false, THREAD);
  8508. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  8509. - }
  8510. -
  8511. - // Leave arrays of jmethodIDs and itable index cache unchanged
  8512. -
  8513. - // Copy the "source file name" attribute from new class version
  8514. - the_class->set_source_file_name(scratch_class->source_file_name());
  8515. -
  8516. - // Copy the "source debug extension" attribute from new class version
  8517. - the_class->set_source_debug_extension(
  8518. - scratch_class->source_debug_extension(),
  8519. - scratch_class->source_debug_extension() == NULL ? 0 :
  8520. - (int)strlen(scratch_class->source_debug_extension()));
  8521. -
  8522. - // Use of javac -g could be different in the old and the new
  8523. - if (scratch_class->access_flags().has_localvariable_table() !=
  8524. - the_class->access_flags().has_localvariable_table()) {
  8525. -
  8526. - AccessFlags flags = the_class->access_flags();
  8527. - if (scratch_class->access_flags().has_localvariable_table()) {
  8528. - flags.set_has_localvariable_table();
  8529. - } else {
  8530. - flags.clear_has_localvariable_table();
  8531. - }
  8532. - the_class->set_access_flags(flags);
  8533. - }
  8534. -
  8535. - // Replace class annotation fields values
  8536. - typeArrayOop old_class_annotations = the_class->class_annotations();
  8537. - the_class->set_class_annotations(scratch_class->class_annotations());
  8538. - scratch_class->set_class_annotations(old_class_annotations);
  8539. -
  8540. - // Replace fields annotation fields values
  8541. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  8542. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  8543. - scratch_class->set_fields_annotations(old_fields_annotations);
  8544. -
  8545. - // Replace methods annotation fields values
  8546. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  8547. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  8548. - scratch_class->set_methods_annotations(old_methods_annotations);
  8549. -
  8550. - // Replace methods parameter annotation fields values
  8551. - objArrayOop old_methods_parameter_annotations =
  8552. - the_class->methods_parameter_annotations();
  8553. - the_class->set_methods_parameter_annotations(
  8554. - scratch_class->methods_parameter_annotations());
  8555. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  8556. -
  8557. - // Replace methods default annotation fields values
  8558. - objArrayOop old_methods_default_annotations =
  8559. - the_class->methods_default_annotations();
  8560. - the_class->set_methods_default_annotations(
  8561. - scratch_class->methods_default_annotations());
  8562. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  8563. -
  8564. - // Replace minor version number of class file
  8565. - u2 old_minor_version = the_class->minor_version();
  8566. - the_class->set_minor_version(scratch_class->minor_version());
  8567. - scratch_class->set_minor_version(old_minor_version);
  8568. -
  8569. - // Replace major version number of class file
  8570. - u2 old_major_version = the_class->major_version();
  8571. - the_class->set_major_version(scratch_class->major_version());
  8572. - scratch_class->set_major_version(old_major_version);
  8573. -
  8574. - // Replace CP indexes for class and name+type of enclosing method
  8575. - u2 old_class_idx = the_class->enclosing_method_class_index();
  8576. - u2 old_method_idx = the_class->enclosing_method_method_index();
  8577. - the_class->set_enclosing_method_indices(
  8578. - scratch_class->enclosing_method_class_index(),
  8579. - scratch_class->enclosing_method_method_index());
  8580. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  8581. -
  8582. - // keep track of previous versions of this class
  8583. - the_class->add_previous_version(scratch_class, &emcp_methods,
  8584. - emcp_method_count);
  8585. -
  8586. - RC_TIMER_STOP(_timer_rsc_phase1);
  8587. - RC_TIMER_START(_timer_rsc_phase2);
  8588. -
  8589. - // Adjust constantpool caches and vtables for all classes
  8590. - // that reference methods of the evolved class.
  8591. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  8592. -
  8593. - // JSR-292 support
  8594. - MemberNameTable* mnt = the_class->member_names();
  8595. - if (mnt != NULL) {
  8596. - bool trace_name_printed = false;
  8597. - mnt->adjust_method_entries(_matching_old_methods,
  8598. - _matching_new_methods,
  8599. - _matching_methods_length,
  8600. - &trace_name_printed);
  8601. - }
  8602. -
  8603. - if (the_class->oop_map_cache() != NULL) {
  8604. - // Flush references to any obsolete methods from the oop map cache
  8605. - // so that obsolete methods are not pinned.
  8606. - the_class->oop_map_cache()->flush_obsolete_entries();
  8607. - }
  8608. -
  8609. - // increment the classRedefinedCount field in the_class and in any
  8610. - // direct and indirect subclasses of the_class
  8611. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  8612. -
  8613. - // RC_TRACE macro has an embedded ResourceMark
  8614. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  8615. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  8616. - the_class->external_name(),
  8617. - java_lang_Class::classRedefinedCount(the_class_mirror),
  8618. - os::available_memory() >> 10));
  8619. -
  8620. - RC_TIMER_STOP(_timer_rsc_phase2);
  8621. -} // end redefine_single_class()
  8622. -
  8623. -
  8624. -// Increment the classRedefinedCount field in the specific instanceKlass
  8625. -// and in all direct and indirect subclasses.
  8626. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  8627. - oop class_mirror = ik->java_mirror();
  8628. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  8629. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  8630. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  8631. -
  8632. - if (class_oop != _the_class_oop) {
  8633. - // _the_class_oop count is printed at end of redefine_single_class()
  8634. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  8635. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  8636. - }
  8637. -
  8638. - for (Klass *subk = ik->subklass(); subk != NULL;
  8639. - subk = subk->next_sibling()) {
  8640. - if (subk->oop_is_instance()) {
  8641. - // Only update instanceKlasses
  8642. - instanceKlass *subik = (instanceKlass*)subk;
  8643. - // recursively do subclasses of the current subclass
  8644. - increment_class_counter(subik, THREAD);
  8645. - }
  8646. - }
  8647. -}
  8648. -
  8649. -void VM_RedefineClasses::check_class(klassOop k_oop,
  8650. - oop initiating_loader, TRAPS) {
  8651. - Klass *k = k_oop->klass_part();
  8652. - if (k->oop_is_instance()) {
  8653. - HandleMark hm(THREAD);
  8654. - instanceKlass *ik = (instanceKlass *) k;
  8655. - bool no_old_methods = true; // be optimistic
  8656. - ResourceMark rm(THREAD);
  8657. -
  8658. - // a vtable should never contain old or obsolete methods
  8659. - if (ik->vtable_length() > 0 &&
  8660. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  8661. - if (RC_TRACE_ENABLED(0x00004000)) {
  8662. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8663. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  8664. - " -- OLD or OBSOLETE method found -- class: %s",
  8665. - ik->signature_name()));
  8666. - ik->vtable()->dump_vtable();
  8667. - }
  8668. - no_old_methods = false;
  8669. - }
  8670. -
  8671. - // an itable should never contain old or obsolete methods
  8672. - if (ik->itable_length() > 0 &&
  8673. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  8674. - if (RC_TRACE_ENABLED(0x00004000)) {
  8675. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8676. - ("klassItable::check_no_old_or_obsolete_entries failure"
  8677. - " -- OLD or OBSOLETE method found -- class: %s",
  8678. - ik->signature_name()));
  8679. - ik->itable()->dump_itable();
  8680. - }
  8681. - no_old_methods = false;
  8682. - }
  8683. -
  8684. - // the constant pool cache should never contain old or obsolete methods
  8685. - if (ik->constants() != NULL &&
  8686. - ik->constants()->cache() != NULL &&
  8687. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  8688. - if (RC_TRACE_ENABLED(0x00004000)) {
  8689. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8690. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  8691. - " -- OLD or OBSOLETE method found -- class: %s",
  8692. - ik->signature_name()));
  8693. - ik->constants()->cache()->dump_cache();
  8694. - }
  8695. - no_old_methods = false;
  8696. - }
  8697. -
  8698. - if (!no_old_methods) {
  8699. - if (RC_TRACE_ENABLED(0x00004000)) {
  8700. - dump_methods();
  8701. - } else {
  8702. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  8703. - "to see more info about the following guarantee() failure.");
  8704. - }
  8705. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  8706. - }
  8707. - }
  8708. -}
  8709. -
  8710. -void VM_RedefineClasses::dump_methods() {
  8711. - int j;
  8712. - RC_TRACE(0x00004000, ("_old_methods --"));
  8713. - for (j = 0; j < _old_methods->length(); ++j) {
  8714. - methodOop m = (methodOop) _old_methods->obj_at(j);
  8715. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8716. - m->access_flags().print_on(tty);
  8717. - tty->print(" -- ");
  8718. - m->print_name(tty);
  8719. - tty->cr();
  8720. - }
  8721. - RC_TRACE(0x00004000, ("_new_methods --"));
  8722. - for (j = 0; j < _new_methods->length(); ++j) {
  8723. - methodOop m = (methodOop) _new_methods->obj_at(j);
  8724. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8725. - m->access_flags().print_on(tty);
  8726. - tty->print(" -- ");
  8727. - m->print_name(tty);
  8728. - tty->cr();
  8729. - }
  8730. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  8731. - for (j = 0; j < _matching_methods_length; ++j) {
  8732. - methodOop m = _matching_old_methods[j];
  8733. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8734. - m->access_flags().print_on(tty);
  8735. - tty->print(" -- ");
  8736. - m->print_name(tty);
  8737. - tty->cr();
  8738. - m = _matching_new_methods[j];
  8739. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  8740. - m->access_flags().print_on(tty);
  8741. - tty->cr();
  8742. - }
  8743. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  8744. - for (j = 0; j < _deleted_methods_length; ++j) {
  8745. - methodOop m = _deleted_methods[j];
  8746. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8747. - m->access_flags().print_on(tty);
  8748. - tty->print(" -- ");
  8749. - m->print_name(tty);
  8750. - tty->cr();
  8751. - }
  8752. - RC_TRACE(0x00004000, ("_added_methods --"));
  8753. - for (j = 0; j < _added_methods_length; ++j) {
  8754. - methodOop m = _added_methods[j];
  8755. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8756. - m->access_flags().print_on(tty);
  8757. - tty->print(" -- ");
  8758. - m->print_name(tty);
  8759. - tty->cr();
  8760. - }
  8761. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  8762. + TransferNativeFunctionRegistration transfer(old_klass);
  8763. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  8764. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  8765. }
  8766. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8767. index bfac62c..8333cee 100644
  8768. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8769. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8770. @@ -1,5 +1,5 @@
  8771. /*
  8772. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  8773. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  8774. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8775. *
  8776. * This code is free software; you can redistribute it and/or modify it
  8777. @@ -30,332 +30,29 @@
  8778. #include "memory/resourceArea.hpp"
  8779. #include "oops/objArrayKlass.hpp"
  8780. #include "oops/objArrayOop.hpp"
  8781. +#include "oops/fieldStreams.hpp"
  8782. #include "prims/jvmtiRedefineClassesTrace.hpp"
  8783. -#include "runtime/vm_operations.hpp"
  8784. +#include "gc_implementation/shared/vmGCOperations.hpp"
  8785. -// Introduction:
  8786. -//
  8787. -// The RedefineClasses() API is used to change the definition of one or
  8788. -// more classes. While the API supports redefining more than one class
  8789. -// in a single call, in general, the API is discussed in the context of
  8790. -// changing the definition of a single current class to a single new
  8791. -// class. For clarity, the current class is will always be called
  8792. -// "the_class" and the new class will always be called "scratch_class".
  8793. -//
  8794. -// The name "the_class" is used because there is only one structure
  8795. -// that represents a specific class; redefinition does not replace the
  8796. -// structure, but instead replaces parts of the structure. The name
  8797. -// "scratch_class" is used because the structure that represents the
  8798. -// new definition of a specific class is simply used to carry around
  8799. -// the parts of the new definition until they are used to replace the
  8800. -// appropriate parts in the_class. Once redefinition of a class is
  8801. -// complete, scratch_class is thrown away.
  8802. -//
  8803. -//
  8804. -// Implementation Overview:
  8805. -//
  8806. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  8807. -// does the real work. The work is split in varying degrees between
  8808. -// doit_prologue(), doit() and doit_epilogue().
  8809. -//
  8810. -// 1) doit_prologue() is called by the JavaThread on the way to a
  8811. -// safepoint. It does parameter verification and loads scratch_class
  8812. -// which involves:
  8813. -// - parsing the incoming class definition using the_class' class
  8814. -// loader and security context
  8815. -// - linking scratch_class
  8816. -// - merging constant pools and rewriting bytecodes as needed
  8817. -// for the merged constant pool
  8818. -// - verifying the bytecodes in scratch_class
  8819. -// - setting up the constant pool cache and rewriting bytecodes
  8820. -// as needed to use the cache
  8821. -// - finally, scratch_class is compared to the_class to verify
  8822. -// that it is a valid replacement class
  8823. -// - if everything is good, then scratch_class is saved in an
  8824. -// instance field in the VM operation for the doit() call
  8825. -//
  8826. -// Note: A JavaThread must do the above work.
  8827. -//
  8828. -// 2) doit() is called by the VMThread during a safepoint. It installs
  8829. -// the new class definition(s) which involves:
  8830. -// - retrieving the scratch_class from the instance field in the
  8831. -// VM operation
  8832. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8833. -// dependent compiled code)
  8834. -// - replacing parts in the_class with parts from scratch_class
  8835. -// - adding weak reference(s) to track the obsolete but interesting
  8836. -// parts of the_class
  8837. -// - adjusting constant pool caches and vtables in other classes
  8838. -// that refer to methods in the_class. These adjustments use the
  8839. -// SystemDictionary::classes_do() facility which only allows
  8840. -// a helper method to be specified. The interesting parameters
  8841. -// that we would like to pass to the helper method are saved in
  8842. -// static global fields in the VM operation.
  8843. -// - telling the SystemDictionary to notice our changes
  8844. -//
  8845. -// Note: the above work must be done by the VMThread to be safe.
  8846. -//
  8847. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  8848. -// is finished and the safepoint is done. It simply cleans up
  8849. -// memory allocated in doit_prologue() and used in doit().
  8850. -//
  8851. -//
  8852. -// Constant Pool Details:
  8853. -//
  8854. -// When the_class is redefined, we cannot just replace the constant
  8855. -// pool in the_class with the constant pool from scratch_class because
  8856. -// that could confuse obsolete methods that may still be running.
  8857. -// Instead, the constant pool from the_class, old_cp, is merged with
  8858. -// the constant pool from scratch_class, scratch_cp. The resulting
  8859. -// constant pool, merge_cp, replaces old_cp in the_class.
  8860. -//
  8861. -// The key part of any merging algorithm is the entry comparison
  8862. -// function so we have to know the types of entries in a constant pool
  8863. -// in order to merge two of them together. Constant pools can contain
  8864. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  8865. -// is not presently used so we only have to worry about the other 11
  8866. -// entry types. For the purposes of constant pool merging, it is
  8867. -// helpful to know that the 11 entry types fall into 3 different
  8868. -// subtypes: "direct", "indirect" and "double-indirect".
  8869. -//
  8870. -// Direct CP entries contain data and do not contain references to
  8871. -// other CP entries. The following are direct CP entries:
  8872. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  8873. -//
  8874. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  8875. -// and no other data. The following are indirect CP entries:
  8876. -// JVM_CONSTANT_{Class,NameAndType,String}
  8877. -//
  8878. -// Double-indirect CP entries contain two references to indirect CP
  8879. -// entries and no other data. The following are double-indirect CP
  8880. -// entries:
  8881. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  8882. -//
  8883. -// When comparing entries between two constant pools, the entry types
  8884. -// are compared first and if they match, then further comparisons are
  8885. -// made depending on the entry subtype. Comparing direct CP entries is
  8886. -// simply a matter of comparing the data associated with each entry.
  8887. -// Comparing both indirect and double-indirect CP entries requires
  8888. -// recursion.
  8889. -//
  8890. -// Fortunately, the recursive combinations are limited because indirect
  8891. -// CP entries can only refer to direct CP entries and double-indirect
  8892. -// CP entries can only refer to indirect CP entries. The following is
  8893. -// an example illustration of the deepest set of indirections needed to
  8894. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  8895. -//
  8896. -// JVM_CONSTANT_Fieldref {
  8897. -// class_index => JVM_CONSTANT_Class {
  8898. -// name_index => JVM_CONSTANT_Utf8 {
  8899. -// <data-1>
  8900. -// }
  8901. -// }
  8902. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  8903. -// name_index => JVM_CONSTANT_Utf8 {
  8904. -// <data-2>
  8905. -// }
  8906. -// descriptor_index => JVM_CONSTANT_Utf8 {
  8907. -// <data-3>
  8908. -// }
  8909. -// }
  8910. -// }
  8911. -//
  8912. -// The above illustration is not a data structure definition for any
  8913. -// computer language. The curly braces ('{' and '}') are meant to
  8914. -// delimit the context of the "fields" in the CP entry types shown.
  8915. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  8916. -// "=>", e.g., the class_index is used to indirectly reference a
  8917. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  8918. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  8919. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  8920. -// have to do a total of 5 indirections just to get to the CP entries
  8921. -// that contain the interesting pieces of data and then we have to
  8922. -// fetch the three pieces of data. This means we have to do a total of
  8923. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  8924. -// entries.
  8925. -//
  8926. -// Here is the indirection, data and dereference count for each entry
  8927. -// type:
  8928. -//
  8929. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  8930. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  8931. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  8932. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  8933. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  8934. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  8935. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  8936. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  8937. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  8938. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  8939. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  8940. -//
  8941. -// So different subtypes of CP entries require different amounts of
  8942. -// work for a proper comparison.
  8943. -//
  8944. -// Now that we've talked about the different entry types and how to
  8945. -// compare them we need to get back to merging. This is not a merge in
  8946. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  8947. -// constant pools, we copy all the entries from old_cp to merge_cp,
  8948. -// preserving entry order. Next we append all the unique entries from
  8949. -// scratch_cp to merge_cp and we track the index changes from the
  8950. -// location in scratch_cp to the possibly new location in merge_cp.
  8951. -// When we are done, any obsolete code that is still running that
  8952. -// uses old_cp should not be able to observe any difference if it
  8953. -// were to use merge_cp. As for the new code in scratch_class, it is
  8954. -// modified to use the appropriate index values in merge_cp before it
  8955. -// is used to replace the code in the_class.
  8956. -//
  8957. -// There is one small complication in copying the entries from old_cp
  8958. -// to merge_cp. Two of the CP entry types are special in that they are
  8959. -// lazily resolved. Before explaining the copying complication, we need
  8960. -// to digress into CP entry resolution.
  8961. -//
  8962. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  8963. -// the class file, but are not stored in memory as such until they are
  8964. -// resolved. The entries are not resolved unless they are used because
  8965. -// resolution is expensive. During class file parsing the entries are
  8966. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  8967. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  8968. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  8969. -// have been parsed, but the index values in the entries have not been
  8970. -// validated. After the entire constant pool has been parsed, the index
  8971. -// values can be validated and then the entries are converted into
  8972. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  8973. -// entries. During this conversion process, the UTF8 values that are
  8974. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  8975. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  8976. -// entries are modified to refer to the Symbol*s. This optimization
  8977. -// eliminates one level of indirection for those two CP entry types and
  8978. -// gets the entries ready for verification. During class file parsing
  8979. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  8980. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  8981. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  8982. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  8983. -// entries.
  8984. -//
  8985. -// Now we can get back to the copying complication. When we copy
  8986. -// entries from old_cp to merge_cp, we have to revert any
  8987. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  8988. -// or verification will fail.
  8989. -//
  8990. -// It is important to explicitly state that the merging algorithm
  8991. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  8992. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  8993. -// entries in the merge_cp. This is done both to make verification
  8994. -// happy and to avoid adding more brittleness between RedefineClasses
  8995. -// and the constant pool cache. By allowing the constant pool cache
  8996. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  8997. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  8998. -// about those algorithms in RedefineClasses.
  8999. -//
  9000. -// Appending unique entries from scratch_cp to merge_cp is straight
  9001. -// forward for direct CP entries and most indirect CP entries. For the
  9002. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  9003. -// indirect CP entry types, the presence of more than one piece of
  9004. -// interesting data makes appending the entries more complicated.
  9005. -//
  9006. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  9007. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  9008. -// If the index in scratch_cp is different than the destination index
  9009. -// in merge_cp, then the change in index value is tracked.
  9010. -//
  9011. -// Note: the above discussion for the direct CP entries also applies
  9012. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  9013. -//
  9014. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  9015. -// one data element at the end of the recursion, we know that we have
  9016. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  9017. -// unique then it is appended to merge_cp before the current entry.
  9018. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  9019. -// is updated to refer to the duplicate entry in merge_cp before it is
  9020. -// appended to merge_cp. Again, any changes in index values are tracked
  9021. -// as needed.
  9022. -//
  9023. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  9024. -// types is theoretical. Since those entry types have already been
  9025. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  9026. -// they are handled as direct CP entries.
  9027. -//
  9028. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  9029. -// data elements at the end of the recursions, we know that we have
  9030. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  9031. -// entries are appended to merge_cp before the current entry. For any
  9032. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  9033. -// updated to refer to the duplicate entry in merge_cp before it is
  9034. -// appended to merge_cp. Again, any changes in index values are tracked
  9035. -// as needed.
  9036. -//
  9037. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  9038. -// types, since there are two indirect CP entries and three data
  9039. -// elements at the end of the recursions, we know that we have between
  9040. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  9041. -// above for an example of all six entries. The uniqueness algorithm
  9042. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  9043. -// covered above. Any unique entries are appended to merge_cp before
  9044. -// the current entry. For any entries that are not unique, the current
  9045. -// entry is updated to refer to the duplicate entry in merge_cp before
  9046. -// it is appended to merge_cp. Again, any changes in index values are
  9047. -// tracked as needed.
  9048. -//
  9049. -//
  9050. -// Other Details:
  9051. -//
  9052. -// Details for other parts of RedefineClasses need to be written.
  9053. -// This is a placeholder section.
  9054. -//
  9055. -//
  9056. -// Open Issues (in no particular order):
  9057. -//
  9058. -// - How do we serialize the RedefineClasses() API without deadlocking?
  9059. -//
  9060. -// - SystemDictionary::parse_stream() was called with a NULL protection
  9061. -// domain since the initial version. This has been changed to pass
  9062. -// the_class->protection_domain(). This change has been tested with
  9063. -// all NSK tests and nothing broke, but what will adding it now break
  9064. -// in ways that we don't test?
  9065. -//
  9066. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  9067. -// (indirect) use of the Relocator class that the max instruction
  9068. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  9069. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  9070. -// what it does to the bytecodes. More investigation is needed.
  9071. -//
  9072. -// - java.lang.Object methods can be called on arrays. This is
  9073. -// implemented via the arrayKlassOop vtable which we don't
  9074. -// update. For example, if we redefine java.lang.Object.toString(),
  9075. -// then the new version of the method will not be called for array
  9076. -// objects.
  9077. -//
  9078. -// - How do we know if redefine_single_class() and the guts of
  9079. -// instanceKlass are out of sync? I don't think this can be
  9080. -// automated, but we should probably order the work in
  9081. -// redefine_single_class() to match the order of field
  9082. -// definitions in instanceKlass. We also need to add some
  9083. -// comments about keeping things in sync.
  9084. -//
  9085. -// - set_new_constant_pool() is huge and we should consider refactoring
  9086. -// it into smaller chunks of work.
  9087. -//
  9088. -// - The exception table update code in set_new_constant_pool() defines
  9089. -// const values that are also defined in a local context elsewhere.
  9090. -// The same literal values are also used in elsewhere. We need to
  9091. -// coordinate a cleanup of these constants with Runtime.
  9092. -//
  9093. -
  9094. -class VM_RedefineClasses: public VM_Operation {
  9095. +// New version that allows arbitrary changes to already loaded classes.
  9096. +class VM_RedefineClasses: public VM_GC_Operation {
  9097. private:
  9098. +
  9099. // These static fields are needed by SystemDictionary::classes_do()
  9100. // facility and the adjust_cpool_cache_and_vtable() helper:
  9101. static objArrayOop _old_methods;
  9102. static objArrayOop _new_methods;
  9103. - static methodOop* _matching_old_methods;
  9104. - static methodOop* _matching_new_methods;
  9105. - static methodOop* _deleted_methods;
  9106. - static methodOop* _added_methods;
  9107. + static int* _matching_old_methods;
  9108. + static int* _matching_new_methods;
  9109. + static int* _deleted_methods;
  9110. + static int* _added_methods;
  9111. static int _matching_methods_length;
  9112. static int _deleted_methods_length;
  9113. static int _added_methods_length;
  9114. - static klassOop _the_class_oop;
  9115. +
  9116. + static int _revision_number;
  9117. +
  9118. + static GrowableArray<instanceKlassHandle>* _affected_klasses;
  9119. // The instance fields are used to pass information from
  9120. // doit_prologue() to doit() and doit_epilogue().
  9121. @@ -366,46 +63,27 @@
  9122. // RetransformClasses. Indicate which.
  9123. JvmtiClassLoadKind _class_load_kind;
  9124. - // _index_map_count is just an optimization for knowing if
  9125. - // _index_map_p contains any entries.
  9126. - int _index_map_count;
  9127. - intArray * _index_map_p;
  9128. -
  9129. - // _operands_index_map_count is just an optimization for knowing if
  9130. - // _operands_index_map_p contains any entries.
  9131. - int _operands_cur_length;
  9132. - int _operands_index_map_count;
  9133. - intArray * _operands_index_map_p;
  9134. -
  9135. - // ptr to _class_count scratch_classes
  9136. - instanceKlassHandle * _scratch_classes;
  9137. - jvmtiError _res;
  9138. + GrowableArray<instanceKlassHandle>* _new_classes;
  9139. + jvmtiError _result;
  9140. + int _max_redefinition_flags;
  9141. // Performance measurement support. These timers do not cover all
  9142. // the work done for JVM/TI RedefineClasses() but they do cover
  9143. // the heavy lifting.
  9144. - elapsedTimer _timer_rsc_phase1;
  9145. - elapsedTimer _timer_rsc_phase2;
  9146. - elapsedTimer _timer_vm_op_prologue;
  9147. + elapsedTimer _timer_total;
  9148. + elapsedTimer _timer_prologue;
  9149. + elapsedTimer _timer_class_linking;
  9150. + elapsedTimer _timer_class_loading;
  9151. + elapsedTimer _timer_prepare_redefinition;
  9152. + elapsedTimer _timer_wait_for_locks;
  9153. + elapsedTimer _timer_heap_iteration;
  9154. + elapsedTimer _timer_redefinition;
  9155. + elapsedTimer _timer_vm_op_epilogue;
  9156. - // These routines are roughly in call order unless otherwise noted.
  9157. -
  9158. - // Load the caller's new class definition(s) into _scratch_classes.
  9159. - // Constant pool merging work is done here as needed. Also calls
  9160. - // compare_and_normalize_class_versions() to verify the class
  9161. - // definition(s).
  9162. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  9163. + jvmtiError find_sorted_affected_classes( );
  9164. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  9165. jvmtiError load_new_class_versions(TRAPS);
  9166. -
  9167. - // Verify that the caller provided class definition(s) that meet
  9168. - // the restrictions of RedefineClasses. Normalize the order of
  9169. - // overloaded methods as needed.
  9170. - jvmtiError compare_and_normalize_class_versions(
  9171. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  9172. -
  9173. - // Swap annotations[i] with annotations[j]
  9174. - // Used by compare_and_normalize_class_versions() when normalizing
  9175. - // overloaded methods or changing idnum as when adding or deleting methods.
  9176. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  9177. // Figure out which new methods match old methods in name and signature,
  9178. // which methods have been added, and which are no longer present
  9179. @@ -414,103 +92,71 @@
  9180. // Change jmethodIDs to point to the new methods
  9181. void update_jmethod_ids();
  9182. - // In addition to marking methods as obsolete, this routine
  9183. - // records which methods are EMCP (Equivalent Module Constant
  9184. - // Pool) in the emcp_methods BitMap and returns the number of
  9185. - // EMCP methods via emcp_method_count_p. This information is
  9186. - // used when information about the previous version of the_class
  9187. - // is squirreled away.
  9188. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  9189. - int * emcp_method_count_p);
  9190. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9191. + void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  9192. - // Unevolving classes may point to methods of the_class directly
  9193. - // from their constant pool caches, itables, and/or vtables. We
  9194. - // use the SystemDictionary::classes_do() facility and this helper
  9195. - // to fix up these pointers.
  9196. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  9197. + static void add_affected_klasses( klassOop obj );
  9198. +
  9199. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
  9200. // Install the redefinition of a class
  9201. - void redefine_single_class(jclass the_jclass,
  9202. - instanceKlassHandle scratch_class, TRAPS);
  9203. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  9204. // Increment the classRedefinedCount field in the specific instanceKlass
  9205. // and in all direct and indirect subclasses.
  9206. void increment_class_counter(instanceKlass *ik, TRAPS);
  9207. - // Support for constant pool merging (these routines are in alpha order):
  9208. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  9209. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9210. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  9211. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9212. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  9213. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  9214. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9215. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  9216. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  9217. - int find_new_index(int old_index);
  9218. - int find_new_operand_index(int old_bootstrap_spec_index);
  9219. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  9220. - constantPoolHandle cp2, int index2);
  9221. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  9222. - constantPoolHandle cp2, int index2);
  9223. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  9224. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  9225. - bool merge_constant_pools(constantPoolHandle old_cp,
  9226. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  9227. - int *merge_cp_length_p, TRAPS);
  9228. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  9229. - instanceKlassHandle scratch_class, TRAPS);
  9230. - u2 rewrite_cp_ref_in_annotation_data(
  9231. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  9232. - const char * trace_mesg, TRAPS);
  9233. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  9234. - bool rewrite_cp_refs_in_annotation_struct(
  9235. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9236. - bool rewrite_cp_refs_in_annotations_typeArray(
  9237. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  9238. - bool rewrite_cp_refs_in_class_annotations(
  9239. - instanceKlassHandle scratch_class, TRAPS);
  9240. - bool rewrite_cp_refs_in_element_value(
  9241. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9242. - bool rewrite_cp_refs_in_fields_annotations(
  9243. - instanceKlassHandle scratch_class, TRAPS);
  9244. - void rewrite_cp_refs_in_method(methodHandle method,
  9245. - methodHandle * new_method_p, TRAPS);
  9246. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  9247. - bool rewrite_cp_refs_in_methods_annotations(
  9248. - instanceKlassHandle scratch_class, TRAPS);
  9249. - bool rewrite_cp_refs_in_methods_default_annotations(
  9250. - instanceKlassHandle scratch_class, TRAPS);
  9251. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  9252. - instanceKlassHandle scratch_class, TRAPS);
  9253. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  9254. - void rewrite_cp_refs_in_verification_type_info(
  9255. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  9256. - u1 frame_size, TRAPS);
  9257. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  9258. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  9259. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  9260. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  9261. - static void dump_methods();
  9262. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  9263. +
  9264. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  9265. +
  9266. + static void unpatch_bytecode(methodOop method);
  9267. +
  9268. +#ifdef ASSERT
  9269. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  9270. +#endif
  9271. +
  9272. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  9273. + void calculate_instance_update_information(klassOop new_version);
  9274. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  9275. + static void mark_as_scavengable(nmethod* nm);
  9276. +
  9277. + bool check_arguments();
  9278. + jvmtiError check_arguments_error();
  9279. public:
  9280. - VM_RedefineClasses(jint class_count,
  9281. - const jvmtiClassDefinition *class_defs,
  9282. - JvmtiClassLoadKind class_load_kind);
  9283. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  9284. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  9285. + virtual ~VM_RedefineClasses();
  9286. +
  9287. bool doit_prologue();
  9288. void doit();
  9289. void doit_epilogue();
  9290. + void rollback();
  9291. - bool allow_nested_vm_operations() const { return true; }
  9292. - jvmtiError check_error() { return _res; }
  9293. + jvmtiError check_exception() const;
  9294. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  9295. + bool skip_operation() const { return false; }
  9296. + bool allow_nested_vm_operations() const { return true; }
  9297. + jvmtiError check_error() { return _result; }
  9298. // Modifiable test must be shared between IsModifiableClass query
  9299. // and redefine implementation
  9300. static bool is_modifiable_class(oop klass_mirror);
  9301. +
  9302. + // Utility methods for transfering field access flags
  9303. +
  9304. + static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
  9305. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  9306. +
  9307. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9308. +
  9309. + void lock_threads();
  9310. + void unlock_threads();
  9311. +
  9312. + static void swap_marks(oop first, oop second);
  9313. +
  9314. };
  9315. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  9316. diff --git a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9317. index 878d300..9dbe748 100644
  9318. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9319. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9320. @@ -1,5 +1,5 @@
  9321. /*
  9322. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  9323. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  9324. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9325. *
  9326. * This code is free software; you can redistribute it and/or modify it
  9327. @@ -22,114 +22,26 @@
  9328. *
  9329. */
  9330. -#ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9331. -#define SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9332. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  9333. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  9334. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  9335. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  9336. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  9337. -// RedefineClasses tracing support via the TraceRedefineClasses
  9338. -// option. A bit is assigned to each group of trace messages.
  9339. -// Groups of messages are individually selectable. We have to use
  9340. -// decimal values on the command line since the command option
  9341. -// parsing logic doesn't like non-decimal numerics. The HEX values
  9342. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  9343. -// the old cumulative behavior, pick the level after the one in
  9344. -// which you are interested and subtract one, e.g., 33554431 will
  9345. -// print every tracing message.
  9346. -//
  9347. -// 0x00000000 | 0 - default; no tracing messages
  9348. -// 0x00000001 | 1 - name each target class before loading, after
  9349. -// loading and after redefinition is completed
  9350. -// 0x00000002 | 2 - print info if parsing, linking or
  9351. -// verification throws an exception
  9352. -// 0x00000004 | 4 - print timer info for the VM operation
  9353. -// 0x00000008 | 8 - print subclass counter updates
  9354. -// 0x00000010 | 16 - unused
  9355. -// 0x00000020 | 32 - unused
  9356. -// 0x00000040 | 64 - unused
  9357. -// 0x00000080 | 128 - unused
  9358. -// 0x00000100 | 256 - previous class weak reference addition
  9359. -// 0x00000200 | 512 - previous class weak reference mgmt during
  9360. -// class unloading checks (GC)
  9361. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  9362. -// add previous ops (GC)
  9363. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  9364. -// 0x00001000 | 4096 - detect calls to obsolete methods
  9365. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  9366. -// 0x00004000 | 16384 - detect old/obsolete methods in metadata
  9367. -// 0x00008000 | 32768 - old/new method matching/add/delete
  9368. -// 0x00010000 | 65536 - impl details: CP size info
  9369. -// 0x00020000 | 131072 - impl details: CP merge pass info
  9370. -// 0x00040000 | 262144 - impl details: CP index maps
  9371. -// 0x00080000 | 524288 - impl details: modified CP index values
  9372. -// 0x00100000 | 1048576 - impl details: vtable updates
  9373. -// 0x00200000 | 2097152 - impl details: itable updates
  9374. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  9375. -// 0x00800000 | 8388608 - impl details: methodComparator info
  9376. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  9377. -// 0x02000000 | 33554432 - impl details: annotation updates
  9378. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  9379. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  9380. -// 0x10000000 | 268435456 - unused
  9381. -// 0x20000000 | 536870912 - unused
  9382. -// 0x40000000 | 1073741824 - unused
  9383. -// 0x80000000 | 2147483648 - unused
  9384. -//
  9385. -// Note: The ResourceMark is to cleanup resource allocated args.
  9386. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  9387. -#define RC_TRACE(level, args) \
  9388. - if ((TraceRedefineClasses & level) != 0) { \
  9389. - ResourceMark rm; \
  9390. - tty->print("RedefineClasses-0x%x: ", level); \
  9391. - tty->print_cr args; \
  9392. - } while (0)
  9393. -
  9394. -#define RC_TRACE_NO_CR(level, args) \
  9395. - if ((TraceRedefineClasses & level) != 0) { \
  9396. - ResourceMark rm; \
  9397. - tty->print("RedefineClasses-0x%x: ", level); \
  9398. - tty->print args; \
  9399. - } while (0)
  9400. -
  9401. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  9402. - if ((TraceRedefineClasses & level) != 0) { \
  9403. - ResourceMark rm(thread); \
  9404. - tty->print("RedefineClasses-0x%x: ", level); \
  9405. - tty->print_cr args; \
  9406. - } while (0)
  9407. -
  9408. -#define RC_TRACE_MESG(args) \
  9409. - { \
  9410. - ResourceMark rm; \
  9411. - tty->print("RedefineClasses: "); \
  9412. - tty->print_cr args; \
  9413. - } while (0)
  9414. -
  9415. -// Macro for checking if TraceRedefineClasses has a specific bit
  9416. -// enabled. Returns true if the bit specified by level is set.
  9417. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  9418. -
  9419. -// Macro for checking if TraceRedefineClasses has one or more bits
  9420. -// set in a range of bit values. Returns true if one or more bits
  9421. -// is set in the range from low..high inclusive. Assumes that low
  9422. -// and high are single bit values.
  9423. -//
  9424. -// ((high << 1) - 1)
  9425. -// Yields a mask that removes bits greater than the high bit value.
  9426. -// This algorithm doesn't work with highest bit.
  9427. -// ~(low - 1)
  9428. -// Yields a mask that removes bits lower than the low bit value.
  9429. -#define RC_TRACE_IN_RANGE(low, high) \
  9430. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  9431. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  9432. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  9433. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  9434. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  9435. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  9436. // Timer support macros. Only do timer operations if timer tracing
  9437. // is enabled. The "while (0)" is so we can use semi-colon at end of
  9438. // the macro.
  9439. #define RC_TIMER_START(t) \
  9440. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9441. + if (TimeRedefineClasses) { \
  9442. t.start(); \
  9443. } while (0)
  9444. #define RC_TIMER_STOP(t) \
  9445. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9446. + if (TimeRedefineClasses) { \
  9447. t.stop(); \
  9448. } while (0)
  9449. -
  9450. -#endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9451. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  9452. index 60eaf97..785dc24 100644
  9453. --- a/src/share/vm/prims/methodComparator.cpp
  9454. +++ b/src/share/vm/prims/methodComparator.cpp
  9455. @@ -42,10 +42,9 @@
  9456. if (old_method->code_size() != new_method->code_size())
  9457. return false;
  9458. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  9459. - // RC_TRACE macro has an embedded ResourceMark
  9460. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  9461. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  9462. old_method->name()->as_C_string(),
  9463. - check_stack_and_locals_size(old_method, new_method)));
  9464. + check_stack_and_locals_size(old_method, new_method));
  9465. return false;
  9466. }
  9467. @@ -114,10 +113,9 @@
  9468. // Now we can test all forward jumps
  9469. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  9470. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  9471. - RC_TRACE(0x00800000,
  9472. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9473. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9474. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  9475. - fwd_jmps.at(i*2+1)));
  9476. + fwd_jmps.at(i*2+1));
  9477. return false;
  9478. }
  9479. }
  9480. diff --git a/src/share/vm/prims/methodHandles.cpp b/src/share/vm/prims/methodHandles.cpp
  9481. index e077c06..8dbd9ce 100644
  9482. --- a/src/share/vm/prims/methodHandles.cpp
  9483. +++ b/src/share/vm/prims/methodHandles.cpp
  9484. @@ -1025,34 +1025,6 @@
  9485. return found;
  9486. }
  9487. -// It is called at safepoint only
  9488. -void MemberNameTable::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  9489. - int methods_length, bool *trace_name_printed) {
  9490. - assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
  9491. - // search the MemberNameTable for uses of either obsolete or EMCP methods
  9492. - for (int j = 0; j < methods_length; j++) {
  9493. - methodOop old_method = old_methods[j];
  9494. - methodOop new_method = new_methods[j];
  9495. - oop mem_name = find_member_name_by_method(old_method);
  9496. - if (mem_name != NULL) {
  9497. - java_lang_invoke_MemberName::adjust_vmtarget(mem_name, new_method);
  9498. -
  9499. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  9500. - if (!(*trace_name_printed)) {
  9501. - // RC_TRACE_MESG macro has an embedded ResourceMark
  9502. - RC_TRACE_MESG(("adjust: name=%s",
  9503. - Klass::cast(old_method->method_holder())->external_name()));
  9504. - *trace_name_printed = true;
  9505. - }
  9506. - // RC_TRACE macro has an embedded ResourceMark
  9507. - RC_TRACE(0x00400000, ("MemberName method update: %s(%s)",
  9508. - new_method->name()->as_C_string(),
  9509. - new_method->signature()->as_C_string()));
  9510. - }
  9511. - }
  9512. - }
  9513. -}
  9514. -
  9515. //
  9516. // Here are the native methods in java.lang.invoke.MethodHandleNatives
  9517. // They are the private interface between this JVM and the HotSpot-specific
  9518. diff --git a/src/share/vm/prims/methodHandles.hpp b/src/share/vm/prims/methodHandles.hpp
  9519. index 62d774a..09f5e3f 100644
  9520. --- a/src/share/vm/prims/methodHandles.hpp
  9521. +++ b/src/share/vm/prims/methodHandles.hpp
  9522. @@ -241,12 +241,6 @@
  9523. void add_member_name(int index, jweak mem_name_ref);
  9524. oop get_member_name(int index);
  9525. - public:
  9526. - // RedefineClasses() API support:
  9527. - // If a MemberName refers to old_method then update it
  9528. - // to refer to new_method.
  9529. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  9530. - int methods_length, bool *trace_name_printed);
  9531. private:
  9532. oop find_member_name_by_method(methodOop old_method);
  9533. };
  9534. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  9535. index 0496367..b324e90 100644
  9536. --- a/src/share/vm/runtime/arguments.cpp
  9537. +++ b/src/share/vm/runtime/arguments.cpp
  9538. @@ -54,8 +54,8 @@
  9539. #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  9540. #endif
  9541. -// Note: This is a special bug reporting site for the JVM
  9542. -#define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
  9543. +// (tw) The DCE VM has its own JIRA bug tracking system.
  9544. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  9545. #define DEFAULT_JAVA_LAUNCHER "generic"
  9546. char** Arguments::_jvm_flags_array = NULL;
  9547. @@ -1874,6 +1874,16 @@
  9548. status = false;
  9549. }
  9550. + // (tw) Must use serial GC. This limitation applies because the instance size changing GC modifications
  9551. + // are only built into the mark and compact algorithm.
  9552. + if (!UseSerialGC && i >= 1) {
  9553. + //jio_fprintf(defaultStream::error_stream(),
  9554. + // "Must use the serial GC in the Dynamic Code Evolution VM\n");
  9555. + //status = false;
  9556. + } else {
  9557. + UseSerialGC = true;
  9558. + }
  9559. +
  9560. return status;
  9561. }
  9562. @@ -3312,7 +3322,7 @@
  9563. // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  9564. set_aggressive_opts_flags();
  9565. -
  9566. +#ifndef COMPILER2
  9567. // Turn off biased locking for locking debug mode flags,
  9568. // which are subtlely different from each other but neither works with
  9569. // biased locking.
  9570. @@ -3329,6 +3339,7 @@
  9571. }
  9572. UseBiasedLocking = false;
  9573. }
  9574. +#endif
  9575. #ifdef CC_INTERP
  9576. // Clear flags not supported by the C++ interpreter
  9577. diff --git a/src/share/vm/runtime/fieldDescriptor.cpp b/src/share/vm/runtime/fieldDescriptor.cpp
  9578. index 3d5213f..9cc701b 100644
  9579. --- a/src/share/vm/runtime/fieldDescriptor.cpp
  9580. +++ b/src/share/vm/runtime/fieldDescriptor.cpp
  9581. @@ -92,7 +92,8 @@
  9582. instanceKlass* ik = instanceKlass::cast(k);
  9583. _cp = ik->constants();
  9584. FieldInfo* f = ik->field(index);
  9585. - assert(!f->is_internal(), "regular Java fields only");
  9586. + // (tw) do we need this?
  9587. +// assert(!f->is_internal(), "regular Java fields only");
  9588. _access_flags = accessFlags_from(f->access_flags());
  9589. guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
  9590. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  9591. index 0731ca0..1b5eb79 100644
  9592. --- a/src/share/vm/runtime/globals.hpp
  9593. +++ b/src/share/vm/runtime/globals.hpp
  9594. @@ -1232,6 +1232,11 @@
  9595. product(intx, TraceRedefineClasses, 0, \
  9596. "Trace level for JVMTI RedefineClasses") \
  9597. \
  9598. + product(bool, TimeRedefineClasses, false, \
  9599. + "Measure timing for JVMTI RedefineClasses") \
  9600. + \
  9601. + product(bool, AllowAdvancedClassRedefinition, true, \
  9602. + "Allow advanced class redefinition beyond swapping method bodies")\
  9603. develop(bool, StressMethodComparator, false, \
  9604. "run the MethodComparator on all loaded methods") \
  9605. \
  9606. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  9607. index 2875ee0..61fd8fe 100644
  9608. --- a/src/share/vm/runtime/interfaceSupport.hpp
  9609. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  9610. @@ -296,7 +296,7 @@
  9611. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  9612. // We are leaving the VM at this point and going directly to native code.
  9613. // Block, if we are in the middle of a safepoint synchronization.
  9614. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9615. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9616. thread->frame_anchor()->make_walkable(thread);
  9617. trans_and_fence(_thread_in_vm, _thread_in_native);
  9618. // Check for pending. async. exceptions or suspends.
  9619. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  9620. index edbba98..4a27925 100644
  9621. --- a/src/share/vm/runtime/javaCalls.cpp
  9622. +++ b/src/share/vm/runtime/javaCalls.cpp
  9623. @@ -60,7 +60,7 @@
  9624. bool clear_pending_exception = true;
  9625. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  9626. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9627. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9628. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  9629. _result = result;
  9630. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  9631. index 3cbcaca..30839d7 100644
  9632. --- a/src/share/vm/runtime/jniHandles.cpp
  9633. +++ b/src/share/vm/runtime/jniHandles.cpp
  9634. @@ -112,6 +112,10 @@
  9635. }
  9636. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  9637. + if (mh->newest_version() != mh()) {
  9638. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  9639. + return (jmethodID) make_weak_global(mh_new);
  9640. + }
  9641. return (jmethodID) make_weak_global(mh);
  9642. }
  9643. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  9644. index 2095237..c541434 100644
  9645. --- a/src/share/vm/runtime/mutex.cpp
  9646. +++ b/src/share/vm/runtime/mutex.cpp
  9647. @@ -1227,7 +1227,7 @@
  9648. // in increasing rank order (modulo any native ranks)
  9649. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9650. if (tmp->next() != NULL) {
  9651. - assert(tmp->rank() == Mutex::native ||
  9652. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9653. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9654. }
  9655. }
  9656. @@ -1247,7 +1247,7 @@
  9657. // in increasing rank order (modulo any native ranks)
  9658. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9659. if (tmp->next() != NULL) {
  9660. - assert(tmp->rank() == Mutex::native ||
  9661. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9662. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9663. }
  9664. }
  9665. @@ -1310,6 +1310,7 @@
  9666. // already hold Terminator_lock - may happen because of periodic safepoints
  9667. if (this->rank() != Mutex::native &&
  9668. this->rank() != Mutex::suspend_resume &&
  9669. + this->rank() != Mutex::redefine_classes &&
  9670. locks != NULL && locks->rank() <= this->rank() &&
  9671. !SafepointSynchronize::is_at_safepoint() &&
  9672. this != Interrupt_lock &&
  9673. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  9674. index 7d2cd82..11eb32e 100644
  9675. --- a/src/share/vm/runtime/mutex.hpp
  9676. +++ b/src/share/vm/runtime/mutex.hpp
  9677. @@ -109,7 +109,8 @@
  9678. barrier = safepoint + 1,
  9679. nonleaf = barrier + 1,
  9680. max_nonleaf = nonleaf + 900,
  9681. - native = max_nonleaf + 1
  9682. + native = max_nonleaf + 1,
  9683. + redefine_classes = native + 1
  9684. };
  9685. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  9686. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  9687. index 77fddef..1b583ff 100644
  9688. --- a/src/share/vm/runtime/mutexLocker.cpp
  9689. +++ b/src/share/vm/runtime/mutexLocker.cpp
  9690. @@ -49,6 +49,7 @@
  9691. // Consider using GCC's __read_mostly.
  9692. Mutex* Patching_lock = NULL;
  9693. +Mutex* RedefineClasses_lock = NULL;
  9694. Monitor* SystemDictionary_lock = NULL;
  9695. Mutex* PackageTable_lock = NULL;
  9696. Mutex* CompiledIC_lock = NULL;
  9697. @@ -283,6 +284,7 @@
  9698. def(Debug3_lock , Mutex , nonleaf+4, true );
  9699. def(CompileThread_lock , Monitor, nonleaf+5, false);
  9700. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  9701. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  9702. #ifdef INCLUDE_TRACE
  9703. def(JfrMsg_lock , Monitor, leaf, true);
  9704. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  9705. index a6549b1..f839f46 100644
  9706. --- a/src/share/vm/runtime/mutexLocker.hpp
  9707. +++ b/src/share/vm/runtime/mutexLocker.hpp
  9708. @@ -43,6 +43,7 @@
  9709. // Mutexes used in the VM.
  9710. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  9711. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  9712. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  9713. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  9714. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  9715. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  9716. index 1665d93..6baabba 100644
  9717. --- a/src/share/vm/runtime/reflection.cpp
  9718. +++ b/src/share/vm/runtime/reflection.cpp
  9719. @@ -468,7 +468,8 @@
  9720. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9721. if ( JDK_Version::is_gte_jdk14x_version()
  9722. && UseNewReflection
  9723. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9724. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9725. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9726. return true;
  9727. }
  9728. @@ -519,6 +520,12 @@
  9729. AccessFlags access,
  9730. bool classloader_only,
  9731. bool protected_restriction) {
  9732. +
  9733. + // (tw) Decide accessibility based on active version
  9734. + if (current_class != NULL) {
  9735. + current_class = current_class->klass_part()->active_version();
  9736. + }
  9737. +
  9738. // Verify that current_class can access a field of field_class, where that
  9739. // field's access bits are "access". We assume that we've already verified
  9740. // that current_class can access field_class.
  9741. @@ -560,7 +567,8 @@
  9742. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9743. if ( JDK_Version::is_gte_jdk14x_version()
  9744. && UseNewReflection
  9745. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9746. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9747. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9748. return true;
  9749. }
  9750. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  9751. index 709d783..689b9a2 100644
  9752. --- a/src/share/vm/runtime/sharedRuntime.cpp
  9753. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  9754. @@ -603,21 +603,13 @@
  9755. //
  9756. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  9757. JavaThread* thread, methodOopDesc* method))
  9758. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  9759. + assert(TraceRedefineClasses >= 4, "wrong call");
  9760. if (method->is_obsolete()) {
  9761. // We are calling an obsolete method, but this is not necessarily
  9762. // an error. Our method could have been redefined just after we
  9763. // fetched the methodOop from the constant pool.
  9764. -
  9765. - // RC_TRACE macro has an embedded ResourceMark
  9766. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  9767. - ("calling obsolete method '%s'",
  9768. - method->name_and_sig_as_C_string()));
  9769. - if (RC_TRACE_ENABLED(0x00002000)) {
  9770. - // this option is provided to debug calls to obsolete methods
  9771. - guarantee(false, "faulting at call to an obsolete method.");
  9772. - }
  9773. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  9774. }
  9775. return 0;
  9776. JRT_END
  9777. @@ -1137,7 +1129,20 @@
  9778. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  9779. int retry_count = 0;
  9780. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  9781. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  9782. + callee_method->method_holder()->klass_part()->super() != NULL) {
  9783. +
  9784. + // (tw) If we are executing an old method, this is OK!
  9785. + {
  9786. + ResourceMark rm(thread);
  9787. + RegisterMap cbl_map(thread, false);
  9788. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  9789. +
  9790. + CodeBlob* caller_cb = caller_frame.cb();
  9791. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  9792. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  9793. + if (caller_nm->method()->is_old()) break;
  9794. + }
  9795. +
  9796. // If has a pending exception then there is no need to re-try to
  9797. // resolve this method.
  9798. // If the method has been redefined, we need to try again.
  9799. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  9800. index f3acf4d..61cc152 100644
  9801. --- a/src/share/vm/runtime/thread.cpp
  9802. +++ b/src/share/vm/runtime/thread.cpp
  9803. @@ -216,6 +216,8 @@
  9804. set_self_raw_id(0);
  9805. set_lgrp_id(-1);
  9806. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  9807. +
  9808. // allocated data structures
  9809. set_osthread(NULL);
  9810. set_resource_area(new (mtThread)ResourceArea());
  9811. @@ -249,6 +251,7 @@
  9812. omFreeProvision = 32 ;
  9813. omInUseList = NULL ;
  9814. omInUseCount = 0 ;
  9815. + _pretend_new_universe = false;
  9816. #ifdef ASSERT
  9817. _visited_for_critical_count = false;
  9818. @@ -880,6 +883,15 @@
  9819. bool Thread::owns_locks_but_compiled_lock() const {
  9820. for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  9821. if (cur != Compile_lock) return true;
  9822. + }
  9823. + return false;
  9824. +}
  9825. +
  9826. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  9827. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  9828. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  9829. + return true;
  9830. + }
  9831. }
  9832. return false;
  9833. }
  9834. @@ -1637,7 +1649,7 @@
  9835. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  9836. assert(JavaThread::current() == this, "sanity check");
  9837. - assert(!Thread::current()->owns_locks(), "sanity check");
  9838. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  9839. DTRACE_THREAD_PROBE(start, this);
  9840. @@ -3193,7 +3205,7 @@
  9841. // Create a CompilerThread
  9842. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9843. -: JavaThread(&compiler_thread_entry) {
  9844. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  9845. _env = NULL;
  9846. _log = NULL;
  9847. _task = NULL;
  9848. @@ -3201,6 +3213,7 @@
  9849. _counters = counters;
  9850. _buffer_blob = NULL;
  9851. _scanned_nmethod = NULL;
  9852. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  9853. #ifndef PRODUCT
  9854. _ideal_graph_printer = NULL;
  9855. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  9856. index 774bd27..4620820 100644
  9857. --- a/src/share/vm/runtime/thread.hpp
  9858. +++ b/src/share/vm/runtime/thread.hpp
  9859. @@ -202,11 +202,14 @@
  9860. public:
  9861. void enter_signal_handler() { _num_nested_signal++; }
  9862. void leave_signal_handler() { _num_nested_signal--; }
  9863. - bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9864. + bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9865. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  9866. private:
  9867. // Debug tracing
  9868. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  9869. +
  9870. + Mutex* _redefine_classes_mutex;
  9871. // Active_handles points to a block of handles
  9872. JNIHandleBlock* _active_handles;
  9873. @@ -530,10 +533,15 @@
  9874. uintptr_t _self_raw_id; // used by get_thread (mutable)
  9875. int _lgrp_id;
  9876. +
  9877. + bool _pretend_new_universe;
  9878. +
  9879. public:
  9880. // Stack overflow support
  9881. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  9882. + 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; } }
  9883. + bool pretend_new_universe() { return _pretend_new_universe; }
  9884. void set_stack_base(address base) { _stack_base = base; }
  9885. size_t stack_size() const { return _stack_size; }
  9886. void set_stack_size(size_t size) { _stack_size = size; }
  9887. @@ -570,6 +578,7 @@
  9888. void print_owned_locks() const { print_owned_locks_on(tty); }
  9889. Monitor* owned_locks() const { return _owned_locks; }
  9890. bool owns_locks() const { return owned_locks() != NULL; }
  9891. + bool owns_locks_but_redefine_classes_lock() const;
  9892. bool owns_locks_but_compiled_lock() const;
  9893. // Deadlock detection
  9894. @@ -1793,6 +1802,8 @@
  9895. CompileTask* _task;
  9896. CompileQueue* _queue;
  9897. BufferBlob* _buffer_blob;
  9898. + bool _should_bailout;
  9899. + Mutex* _compilation_mutex;
  9900. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  9901. @@ -1802,12 +1813,16 @@
  9902. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  9903. + bool should_bailout() const { return _should_bailout; }
  9904. + void set_should_bailout(bool b) { _should_bailout = false; }
  9905. +
  9906. bool is_Compiler_thread() const { return true; }
  9907. // Hide this compiler thread from external view.
  9908. bool is_hidden_from_external_view() const { return true; }
  9909. CompileQueue* queue() { return _queue; }
  9910. CompilerCounters* counters() { return _counters; }
  9911. + Mutex *compilation_mutex() { return _compilation_mutex; }
  9912. // Get/set the thread's compilation environment.
  9913. ciEnv* env() { return _env; }
  9914. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  9915. index 0a3e0da..3c0b0e0 100644
  9916. --- a/src/share/vm/runtime/vmThread.cpp
  9917. +++ b/src/share/vm/runtime/vmThread.cpp
  9918. @@ -694,6 +694,9 @@
  9919. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  9920. Thread::oops_do(f, cf);
  9921. _vm_queue->oops_do(f);
  9922. + if (_cur_vm_operation != NULL) {
  9923. + _cur_vm_operation->oops_do(f);
  9924. + }
  9925. }
  9926. //------------------------------------------------------------------------------------------------------------------
  9927. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  9928. index 03f254d..18e324b 100644
  9929. --- a/src/share/vm/utilities/exceptions.cpp
  9930. +++ b/src/share/vm/utilities/exceptions.cpp
  9931. @@ -254,6 +254,8 @@
  9932. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  9933. assert(!thread->has_pending_exception(), "already has exception");
  9934. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  9935. + Thread::current()->set_pretend_new_universe(false);
  9936. Handle h_exception;
  9937. // Resolve exception klass
  9938. @@ -285,6 +287,7 @@
  9939. h_exception = Handle(thread, thread->pending_exception());
  9940. thread->clear_pending_exception();
  9941. }
  9942. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  9943. return h_exception;
  9944. }
  9945. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  9946. index ea92a80..05e940e 100644
  9947. --- a/src/share/vm/utilities/growableArray.hpp
  9948. +++ b/src/share/vm/utilities/growableArray.hpp
  9949. @@ -145,6 +145,33 @@
  9950. assert(on_stack(), "fast ResourceObj path only");
  9951. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  9952. }
  9953. +
  9954. +};
  9955. +
  9956. +template<class E, class F> class Pair : public StackObj
  9957. +{
  9958. +private:
  9959. + E _left;
  9960. + F _right;
  9961. +
  9962. +public:
  9963. +
  9964. + Pair() {
  9965. +
  9966. + }
  9967. +
  9968. + Pair(E left, F right) {
  9969. + this->_left = left;
  9970. + this->_right = right;
  9971. + }
  9972. +
  9973. + E left() {
  9974. + return _left;
  9975. + }
  9976. +
  9977. + F right() {
  9978. + return _right;
  9979. + }
  9980. };
  9981. template<class E> class GrowableArray : public GenericGrowableArray {