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-jdk7u40-b43.patch 431KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126
  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 @@ void InterpreterMacroAssembler::notify_method_entry() {
  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 @@ void InterpreterMacroAssembler::notify_method_entry() {
  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 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
  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 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
  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 @@ class Compilation: public StackObj {
  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 @@ void ciObjectFactory::print() {
  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 @@ private:
  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 @@ public:
  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 8d57bb1..8b7d5eb 100644
  111. --- a/src/share/vm/classfile/classFileParser.cpp
  112. +++ b/src/share/vm/classfile/classFileParser.cpp
  113. @@ -795,6 +795,7 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  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 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  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 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  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. @@ -2921,8 +2928,10 @@ typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annota
  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. @@ -2948,7 +2957,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -2971,10 +2980,13 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3090,6 +3102,30 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3130,7 +3166,11 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3148,7 +3188,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3202,7 +3242,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3591,6 +3633,19 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3599,6 +3654,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3691,7 +3747,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  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. @@ -3711,6 +3767,10 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  264. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  265. }
  266. + if (rt == REF_OTHER) {
  267. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  268. + }
  269. +
  270. // Allocate mirror and initialize static fields
  271. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  272. @@ -3856,7 +3916,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  273. }
  274. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  275. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  276. klassOop super = k->super();
  277. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  278. @@ -3864,7 +3924,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  279. if (!_has_empty_finalizer) {
  280. if (_has_finalizer ||
  281. (super != NULL && super->klass_part()->has_finalizer())) {
  282. - k->set_has_finalizer();
  283. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  284. + k->set_has_finalizer();
  285. + }
  286. }
  287. }
  288. @@ -3880,7 +3942,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  289. // Check if this klass supports the java.lang.Cloneable interface
  290. if (SystemDictionary::Cloneable_klass_loaded()) {
  291. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  292. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  293. k->set_is_cloneable();
  294. }
  295. }
  296. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  297. index 314ec5e..5fca1da 100644
  298. --- a/src/share/vm/classfile/classFileParser.hpp
  299. +++ b/src/share/vm/classfile/classFileParser.hpp
  300. @@ -151,6 +151,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  301. Handle class_loader,
  302. Handle protection_domain,
  303. Symbol* class_name,
  304. + KlassHandle old_klass,
  305. TRAPS);
  306. // Field parsing
  307. @@ -237,7 +238,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  308. unsigned int nonstatic_oop_map_count,
  309. int* nonstatic_oop_offsets,
  310. unsigned int* nonstatic_oop_counts);
  311. - void set_precomputed_flags(instanceKlassHandle k);
  312. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  313. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  314. objArrayHandle local_ifs, TRAPS);
  315. @@ -349,17 +350,20 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  316. instanceKlassHandle parseClassFile(Symbol* name,
  317. Handle class_loader,
  318. Handle protection_domain,
  319. + KlassHandle old_klass,
  320. TempNewSymbol& parsed_name,
  321. bool verify,
  322. TRAPS) {
  323. KlassHandle no_host_klass;
  324. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  325. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
  326. }
  327. instanceKlassHandle parseClassFile(Symbol* name,
  328. Handle class_loader,
  329. Handle protection_domain,
  330. + KlassHandle old_klass,
  331. KlassHandle host_klass,
  332. GrowableArray<Handle>* cp_patches,
  333. + GrowableArray<Symbol*>* parsed_super_symbols,
  334. TempNewSymbol& parsed_name,
  335. bool verify,
  336. TRAPS);
  337. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  338. index a2e61a4..450e19f 100644
  339. --- a/src/share/vm/classfile/classLoader.cpp
  340. +++ b/src/share/vm/classfile/classLoader.cpp
  341. @@ -915,6 +915,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
  342. instanceKlassHandle result = parser.parseClassFile(h_name,
  343. class_loader,
  344. protection_domain,
  345. + KlassHandle(),
  346. parsed_name,
  347. false,
  348. CHECK_(h));
  349. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  350. index 78e76cc..d167c98 100644
  351. --- a/src/share/vm/classfile/dictionary.cpp
  352. +++ b/src/share/vm/classfile/dictionary.cpp
  353. @@ -144,87 +144,10 @@ bool Dictionary::do_unloading(BoolObjectClosure* is_alive) {
  354. probe = *p;
  355. klassOop e = probe->klass();
  356. oop class_loader = probe->loader();
  357. -
  358. instanceKlass* ik = instanceKlass::cast(e);
  359. - if (ik->previous_versions() != NULL) {
  360. - // This klass has previous versions so see what we can cleanup
  361. - // while it is safe to do so.
  362. -
  363. - int gc_count = 0; // leave debugging breadcrumbs
  364. - int live_count = 0;
  365. -
  366. - // RC_TRACE macro has an embedded ResourceMark
  367. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  368. - ik->external_name(), ik->previous_versions()->length()));
  369. -
  370. - for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  371. - // check the previous versions array for GC'ed weak refs
  372. - PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
  373. - jobject cp_ref = pv_node->prev_constant_pool();
  374. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  375. - if (cp_ref == NULL) {
  376. - delete pv_node;
  377. - ik->previous_versions()->remove_at(i);
  378. - // Since we are traversing the array backwards, we don't have to
  379. - // do anything special with the index.
  380. - continue; // robustness
  381. - }
  382. -
  383. - constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  384. - if (pvcp == NULL) {
  385. - // this entry has been GC'ed so remove it
  386. - delete pv_node;
  387. - ik->previous_versions()->remove_at(i);
  388. - // Since we are traversing the array backwards, we don't have to
  389. - // do anything special with the index.
  390. - gc_count++;
  391. - continue;
  392. - } else {
  393. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  394. - if (is_alive->do_object_b(pvcp)) {
  395. - live_count++;
  396. - } else {
  397. - guarantee(false, "sanity check");
  398. - }
  399. - }
  400. -
  401. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  402. - if (method_refs != NULL) {
  403. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  404. - method_refs->length()));
  405. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  406. - jweak method_ref = method_refs->at(j);
  407. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  408. - if (method_ref == NULL) {
  409. - method_refs->remove_at(j);
  410. - // Since we are traversing the array backwards, we don't have to
  411. - // do anything special with the index.
  412. - continue; // robustness
  413. - }
  414. -
  415. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  416. - if (method == NULL) {
  417. - // this method entry has been GC'ed so remove it
  418. - JNIHandles::destroy_weak_global(method_ref);
  419. - method_refs->remove_at(j);
  420. - } else {
  421. - // RC_TRACE macro has an embedded ResourceMark
  422. - RC_TRACE(0x00000200,
  423. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  424. - method->name()->as_C_string(),
  425. - method->signature()->as_C_string(), j, i));
  426. - }
  427. - }
  428. - }
  429. - }
  430. - assert(ik->previous_versions()->length() == live_count, "sanity check");
  431. - RC_TRACE(0x00000200,
  432. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  433. - gc_count));
  434. - }
  435. -
  436. +
  437. // Non-unloadable classes were handled in always_strong_oops_do
  438. - if (!is_strongly_reachable(class_loader, e)) {
  439. + if (!ik->is_redefining() && !is_strongly_reachable(class_loader, e)) {
  440. // Entry was not visited in phase1 (negated test from phase1)
  441. assert(class_loader != NULL, "unloading entry with null class loader");
  442. oop k_def_class_loader = ik->class_loader();
  443. @@ -326,6 +249,7 @@ void Dictionary::classes_do(void f(klassOop)) {
  444. }
  445. }
  446. +
  447. // Added for initialize_itable_for_klass to handle exceptions
  448. // Just the classes from defining class loaders
  449. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  450. @@ -433,6 +357,33 @@ void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
  451. add_entry(index, entry);
  452. }
  453. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  454. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  455. +
  456. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  457. + bool found = false;
  458. + for (int index = 0; index < table_size(); index++) {
  459. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  460. + if (entry->klass() == old_class()) {
  461. + entry->set_literal(k());
  462. + found = true;
  463. + }
  464. + }
  465. + }
  466. +
  467. + return found;
  468. +}
  469. +
  470. +// (tw) Undo previous updates to the system dictionary
  471. +void Dictionary::rollback_redefinition() {
  472. + for (int index = 0; index < table_size(); index++) {
  473. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  474. + if (entry->klass()->klass_part()->is_redefining()) {
  475. + entry->set_literal(entry->klass()->klass_part()->old_version());
  476. + }
  477. + }
  478. + }
  479. +}
  480. // This routine does not lock the system dictionary.
  481. //
  482. @@ -459,12 +410,21 @@ DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
  483. return NULL;
  484. }
  485. +klassOop Dictionary::intercept_for_version(klassOop k) {
  486. + if (k == NULL) return k;
  487. +
  488. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  489. + return k->klass_part()->old_version();
  490. + }
  491. +
  492. + return k;
  493. +}
  494. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  495. Handle loader, Handle protection_domain, TRAPS) {
  496. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  497. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  498. - return entry->klass();
  499. + return intercept_for_version(entry->klass());
  500. } else {
  501. return NULL;
  502. }
  503. @@ -477,7 +437,7 @@ klassOop Dictionary::find_class(int index, unsigned int hash,
  504. assert (index == index_for(name, loader), "incorrect index?");
  505. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  506. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  507. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  508. }
  509. @@ -489,7 +449,7 @@ klassOop Dictionary::find_shared_class(int index, unsigned int hash,
  510. assert (index == index_for(name, Handle()), "incorrect index?");
  511. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  512. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  513. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  514. }
  515. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  516. index bd33760..ea1fe3c 100644
  517. --- a/src/share/vm/classfile/dictionary.hpp
  518. +++ b/src/share/vm/classfile/dictionary.hpp
  519. @@ -73,6 +73,10 @@ public:
  520. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  521. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  522. +
  523. + void rollback_redefinition();
  524. +
  525. klassOop find_class(int index, unsigned int hash,
  526. Symbol* name, Handle loader);
  527. @@ -105,6 +109,7 @@ public:
  528. bool do_unloading(BoolObjectClosure* is_alive);
  529. // Protection domains
  530. + static klassOop intercept_for_version(klassOop k);
  531. klassOop find(int index, unsigned int hash, Symbol* name,
  532. Handle loader, Handle protection_domain, TRAPS);
  533. bool is_valid_protection_domain(int index, unsigned int hash,
  534. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  535. index f8b10b3..c417a29 100644
  536. --- a/src/share/vm/classfile/javaClasses.cpp
  537. +++ b/src/share/vm/classfile/javaClasses.cpp
  538. @@ -621,6 +621,10 @@ klassOop java_lang_Class::as_klassOop(oop java_class) {
  539. assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  540. klassOop k = klassOop(java_class->obj_field(_klass_offset));
  541. assert(k == NULL || k->is_klass(), "type check");
  542. + // Necessary to make old verifier work.
  543. + if (Thread::current()->pretend_new_universe()) {
  544. + k = k->klass_part()->newest_version();
  545. + }
  546. return k;
  547. }
  548. @@ -1541,6 +1545,7 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, methodHandle met
  549. skip_throwableInit_check = true;
  550. }
  551. }
  552. + method = method->newest_version();
  553. if (method->is_hidden()) {
  554. if (skip_hidden) continue;
  555. }
  556. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  557. index b741cfa..5412831 100644
  558. --- a/src/share/vm/classfile/javaClasses.hpp
  559. +++ b/src/share/vm/classfile/javaClasses.hpp
  560. @@ -213,6 +213,7 @@ class java_lang_String : AllStatic {
  561. class java_lang_Class : AllStatic {
  562. friend class VMStructs;
  563. + friend class VM_RedefineClasses;
  564. private:
  565. // The fake offsets are added by the class loader when java.lang.Class is loaded
  566. @@ -248,7 +249,7 @@ class java_lang_Class : AllStatic {
  567. static void print_signature(oop java_class, outputStream *st);
  568. // Testing
  569. static bool is_instance(oop obj) {
  570. - return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
  571. + return obj != NULL && (obj->klass()->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version());
  572. }
  573. static bool is_primitive(oop java_class);
  574. static BasicType primitive_type(oop java_class);
  575. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  576. index 8650cd9..965cce2 100644
  577. --- a/src/share/vm/classfile/loaderConstraints.cpp
  578. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  579. @@ -449,7 +449,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
  580. if (k != NULL) {
  581. // We found the class in the system dictionary, so we should
  582. // make sure that the klassOop matches what we already have.
  583. - guarantee(k == probe->klass(), "klass should be in dictionary");
  584. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  585. } else {
  586. // If we don't find the class in the system dictionary, it
  587. // has to be in the placeholders table.
  588. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  589. index 899153a..3f64268 100644
  590. --- a/src/share/vm/classfile/systemDictionary.cpp
  591. +++ b/src/share/vm/classfile/systemDictionary.cpp
  592. @@ -157,6 +157,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_load
  593. // can return a null klass
  594. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  595. }
  596. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  597. return klass;
  598. }
  599. @@ -199,7 +200,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
  600. // Forwards to resolve_instance_class_or_null
  601. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  602. - assert(!THREAD->is_Compiler_thread(),
  603. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  604. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  605. class_name->as_C_string(),
  606. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  607. @@ -961,8 +962,10 @@ klassOop SystemDictionary::parse_stream(Symbol* class_name,
  608. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  609. class_loader,
  610. protection_domain,
  611. + KlassHandle(),
  612. host_klass,
  613. cp_patches,
  614. + NULL,
  615. parsed_name,
  616. true,
  617. THREAD);
  618. @@ -1022,7 +1025,15 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  619. Handle protection_domain,
  620. ClassFileStream* st,
  621. bool verify,
  622. + KlassHandle old_class,
  623. TRAPS) {
  624. +
  625. + bool redefine_classes_locked = false;
  626. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  627. + Thread::current()->redefine_classes_mutex()->lock();
  628. + redefine_classes_locked = true;
  629. + }
  630. +
  631. // Classloaders that support parallelism, e.g. bootstrap classloader,
  632. // or all classloaders with UnsyncloadClass do not acquire lock here
  633. bool DoObjectLock = true;
  634. @@ -1050,9 +1061,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  635. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  636. class_loader,
  637. protection_domain,
  638. + old_class,
  639. parsed_name,
  640. verify,
  641. THREAD);
  642. + if (!old_class.is_null() && !k.is_null()) {
  643. + k->set_redefining(true);
  644. + k->set_old_version(old_class());
  645. + }
  646. const char* pkg = "java/";
  647. if (!HAS_PENDING_EXCEPTION &&
  648. @@ -1087,13 +1103,18 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  649. // Add class just loaded
  650. // If a class loader supports parallel classloading handle parallel define requests
  651. // find_or_define_instance_class may return a different instanceKlass
  652. - if (is_parallelCapable(class_loader)) {
  653. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  654. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  655. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  656. } else {
  657. - define_instance_class(k, THREAD);
  658. + define_instance_class(k, old_class, THREAD);
  659. }
  660. }
  661. + if (redefine_classes_locked) {
  662. + Thread::current()->redefine_classes_mutex()->unlock();
  663. + }
  664. +
  665. // If parsing the class file or define_instance_class failed, we
  666. // need to remove the placeholder added on our behalf. But we
  667. // must make sure parsed_name is valid first (it won't be if we had
  668. @@ -1122,7 +1143,7 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  669. MutexLocker mu(SystemDictionary_lock, THREAD);
  670. klassOop check = find_class(parsed_name, class_loader);
  671. - assert(check == k(), "should be present in the dictionary");
  672. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  673. klassOop check2 = find_class(h_name, h_loader);
  674. assert(check == check2, "name inconsistancy in SystemDictionary");
  675. @@ -1349,7 +1370,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
  676. }
  677. }
  678. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  679. +void SystemDictionary::rollback_redefinition() {
  680. + dictionary()->rollback_redefinition();
  681. +}
  682. +
  683. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  684. Handle class_loader_h(THREAD, k->class_loader());
  685. @@ -1376,13 +1401,23 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  686. Symbol* name_h = k->name();
  687. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  688. int d_index = dictionary()->hash_to_index(d_hash);
  689. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  690. +
  691. + // (tw) Update version of the klassOop in the system dictionary
  692. + // TODO: Check for thread safety!
  693. + if (!old_class.is_null()) {
  694. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  695. + assert (ok, "must have found old class and updated!");
  696. + }
  697. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  698. +
  699. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  700. // Register class just loaded with class loader (placed in Vector)
  701. // Note we do this before updating the dictionary, as this can
  702. // fail with an OutOfMemoryError (if it does, we will *not* put this
  703. // class in the dictionary and will not update the class hierarchy).
  704. - if (k->class_loader() != NULL) {
  705. + // (tw) Only register if not redefining a class.
  706. + if (k->class_loader() != NULL && old_class.is_null()) {
  707. methodHandle m(THREAD, Universe::loader_addClass_method());
  708. JavaValue result(T_VOID);
  709. JavaCallArguments args(class_loader_h);
  710. @@ -1408,8 +1443,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  711. }
  712. k->eager_initialize(THREAD);
  713. + // (tw) Only notify jvmti if not redefining a class.
  714. // notify jvmti
  715. - if (JvmtiExport::should_post_class_load()) {
  716. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  717. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  718. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  719. @@ -1482,7 +1518,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
  720. }
  721. }
  722. - define_instance_class(k, THREAD);
  723. + define_instance_class(k, KlassHandle(), THREAD);
  724. Handle linkage_exception = Handle(); // null handle
  725. @@ -1612,6 +1648,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
  726. Universe::flush_dependents_on(k);
  727. }
  728. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  729. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  730. + assert(k.not_null(), "just checking");
  731. +
  732. + k->remove_from_sibling_list();
  733. +
  734. + // TODO (tw): Remove from interfaces.
  735. +}
  736. // ----------------------------------------------------------------------------
  737. // GC support
  738. @@ -1869,9 +1913,12 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) {
  739. // Preload ref klasses and set reference types
  740. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  741. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  742. +
  743. + // (tw) This is now done in parseClassFile in order to support class redefinition
  744. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  745. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  746. + // TODO(tw): Check that the following is also not necessary?
  747. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  748. instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
  749. instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
  750. @@ -1955,7 +2002,7 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
  751. // also holds array classes
  752. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  753. - if ((defining == true) || (k() != check)) {
  754. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  755. linkage_error = "loader (instance of %s): attempted duplicate class "
  756. "definition for name: \"%s\"";
  757. } else {
  758. @@ -2602,8 +2649,10 @@ void SystemDictionary::verify_obj_klass_present(Handle obj,
  759. name = find_placeholder(class_name, class_loader);
  760. }
  761. }
  762. - guarantee(probe != NULL || name != NULL,
  763. - "Loaded klasses should be in SystemDictionary");
  764. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  765. + guarantee(probe != NULL &&
  766. + (!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(),
  767. + "Loaded klasses should be in SystemDictionary");
  768. }
  769. // utility function for posting class load event
  770. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  771. index adf82e5..00cf392 100644
  772. --- a/src/share/vm/classfile/systemDictionary.hpp
  773. +++ b/src/share/vm/classfile/systemDictionary.hpp
  774. @@ -268,7 +268,7 @@ public:
  775. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  776. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  777. Handle protection_domain,
  778. - ClassFileStream* st, bool verify, TRAPS);
  779. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  780. // Lookup an already loaded class. If not found NULL is returned.
  781. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  782. @@ -343,6 +343,8 @@ public:
  783. // System loader lock
  784. static oop system_loader_lock() { return _system_loader_lock_obj; }
  785. + // Remove link to hierarchy
  786. + static void remove_from_hierarchy(instanceKlassHandle k);
  787. private:
  788. // Traverses preloaded oops: various system classes. These are
  789. // guaranteed to be in the perm gen.
  790. @@ -415,6 +417,8 @@ public:
  791. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  792. }
  793. + static void rollback_redefinition();
  794. +
  795. public:
  796. #define WK_KLASS_DECLARE(name, symbol, option) \
  797. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  798. @@ -596,7 +600,7 @@ private:
  799. // after waiting, but before reentering SystemDictionary_lock
  800. // to preserve lock order semantics.
  801. static void double_lock_wait(Handle lockObject, TRAPS);
  802. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  803. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  804. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  805. Handle class_loader,
  806. instanceKlassHandle k, TRAPS);
  807. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  808. index da188bb..097c50c 100644
  809. --- a/src/share/vm/classfile/verifier.cpp
  810. +++ b/src/share/vm/classfile/verifier.cpp
  811. @@ -106,7 +106,7 @@ bool Verifier::relax_verify_for(oop loader) {
  812. return !need_verify;
  813. }
  814. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  815. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  816. HandleMark hm;
  817. ResourceMark rm(THREAD);
  818. @@ -117,6 +117,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  819. const char* klassName = klass->external_name();
  820. bool can_failover = FailOverToOldVerifier &&
  821. + may_use_old_verifier &&
  822. klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  823. // If the class should be verified, first see if we can use the split
  824. @@ -138,6 +139,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  825. tty->print_cr(
  826. "Fail over class verification to old verifier for: %s", klassName);
  827. }
  828. + assert(may_use_old_verifier, "");
  829. exception_name = inference_verify(
  830. klass, message_buffer, message_buffer_len, THREAD);
  831. }
  832. @@ -145,6 +147,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  833. exception_message = split_verifier.exception_message();
  834. }
  835. } else {
  836. + assert(may_use_old_verifier, "");
  837. exception_name = inference_verify(
  838. klass, message_buffer, message_buffer_len, THREAD);
  839. }
  840. @@ -210,7 +213,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
  841. // NOTE: this is called too early in the bootstrapping process to be
  842. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  843. (refl_magic_klass == NULL ||
  844. - !klass->is_subtype_of(refl_magic_klass) ||
  845. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  846. VerifyReflectionBytecodes)
  847. );
  848. }
  849. @@ -517,7 +520,7 @@ void ErrorContext::stackmap_details(outputStream* ss, methodOop method) const {
  850. ClassVerifier::ClassVerifier(
  851. instanceKlassHandle klass, TRAPS)
  852. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  853. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  854. _this_type = VerificationType::reference_type(klass->name());
  855. // Create list to hold symbols in reference area.
  856. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  857. @@ -547,7 +550,7 @@ void ClassVerifier::verify_class(TRAPS) {
  858. _klass->external_name());
  859. }
  860. - objArrayHandle methods(THREAD, _klass->methods());
  861. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  862. int num_methods = methods->length();
  863. for (int index = 0; index < num_methods; index++) {
  864. @@ -2444,7 +2447,8 @@ void ClassVerifier::verify_invoke_instructions(
  865. VerificationType stack_object_type =
  866. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  867. if (current_type() != stack_object_type) {
  868. - assert(cp->cache() == NULL, "not rewritten yet");
  869. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  870. + //assert(cp->cache() == NULL, "not rewritten yet");
  871. Symbol* ref_class_name =
  872. cp->klass_name_at(cp->klass_ref_index_at(index));
  873. // See the comments in verify_field_instructions() for
  874. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  875. index 4457f4a..b1b96f2 100644
  876. --- a/src/share/vm/classfile/verifier.hpp
  877. +++ b/src/share/vm/classfile/verifier.hpp
  878. @@ -47,7 +47,7 @@ class Verifier : AllStatic {
  879. * Otherwise, no exception is thrown and the return indicates the
  880. * error.
  881. */
  882. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  883. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  884. // Return false if the class is loaded by the bootstrap loader,
  885. // or if defineClass was called requesting skipping verification
  886. @@ -256,7 +256,10 @@ class ClassVerifier : public StackObj {
  887. ErrorContext _error_context; // contains information about an error
  888. +public:
  889. void verify_method(methodHandle method, TRAPS);
  890. +
  891. +private:
  892. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  893. void verify_exception_handler_table(u4 code_length, char* code_data,
  894. int& min, int& max, TRAPS);
  895. @@ -329,6 +332,7 @@ class ClassVerifier : public StackObj {
  896. VerificationType object_type() const;
  897. + instanceKlassHandle _klass_to_verify;
  898. instanceKlassHandle _klass; // the class being verified
  899. methodHandle _method; // current method being verified
  900. VerificationType _this_type; // the verification type of the current class
  901. diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
  902. index 21c9413..59f5f7e 100644
  903. --- a/src/share/vm/code/nmethod.cpp
  904. +++ b/src/share/vm/code/nmethod.cpp
  905. @@ -2074,15 +2074,14 @@ bool nmethod::is_evol_dependent_on(klassOop dependee) {
  906. methodOop method = deps.method_argument(0);
  907. for (int j = 0; j < dependee_methods->length(); j++) {
  908. if ((methodOop) dependee_methods->obj_at(j) == method) {
  909. - // RC_TRACE macro has an embedded ResourceMark
  910. - RC_TRACE(0x01000000,
  911. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  912. + ResourceMark rm(Thread::current());
  913. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  914. _method->method_holder()->klass_part()->external_name(),
  915. _method->name()->as_C_string(),
  916. _method->signature()->as_C_string(), compile_id(),
  917. method->method_holder()->klass_part()->external_name(),
  918. method->name()->as_C_string(),
  919. - method->signature()->as_C_string()));
  920. + method->signature()->as_C_string());
  921. if (TraceDependencies || LogCompilation)
  922. deps.log_dependency(dependee);
  923. return true;
  924. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  925. index 0feca89..1c4b014 100644
  926. --- a/src/share/vm/compiler/compileBroker.cpp
  927. +++ b/src/share/vm/compiler/compileBroker.cpp
  928. @@ -1592,6 +1592,9 @@ void CompileBroker::compiler_thread_loop() {
  929. // Never compile a method if breakpoints are present in it
  930. if (method()->number_of_breakpoints() == 0) {
  931. + // (tw) Obtain a compilation lock. Class redefinition requires that there is no compilation in parallel.
  932. + thread->compilation_mutex()->lock();
  933. + thread->set_should_bailout(false);
  934. // Compile the method.
  935. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  936. #ifdef COMPILER1
  937. @@ -1615,6 +1618,7 @@ void CompileBroker::compiler_thread_loop() {
  938. // After compilation is disabled, remove remaining methods from queue
  939. method->clear_queued_for_compilation();
  940. }
  941. + thread->compilation_mutex()->unlock();
  942. }
  943. }
  944. }
  945. @@ -1780,7 +1784,11 @@ void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
  946. //assert(false, "compiler should always document failure");
  947. // The compiler elected, without comment, not to register a result.
  948. // Do not attempt further compilations of this method.
  949. - ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
  950. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  951. + ci_env.record_failure("compile externally aborted");
  952. + } else {
  953. + ci_env.record_method_not_compilable("compile failed");
  954. + }
  955. }
  956. // Copy this bit to the enclosing block:
  957. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  958. index b0c9ec8..7feadf9 100644
  959. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  960. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  961. @@ -162,6 +162,13 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
  962. }
  963. }
  964. +
  965. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  966. + CompactPoint* cp, HeapWord* compact_top) {
  967. + ShouldNotReachHere();
  968. + return NULL;
  969. +}
  970. +
  971. // Like CompactibleSpace forward() but always calls cross_threshold() to
  972. // update the block offset table. Removed initialize_threshold call because
  973. // CFLS does not use a block offset array for contiguous spaces.
  974. @@ -2118,7 +2125,7 @@ bool CompactibleFreeListSpace::should_concurrent_collect() const {
  975. // Support for compaction
  976. void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
  977. - SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
  978. + SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
  979. // prepare_for_compaction() uses the space between live objects
  980. // so that later phase can skip dead space quickly. So verification
  981. // of the free lists doesn't work after.
  982. @@ -2139,7 +2146,7 @@ void CompactibleFreeListSpace::adjust_pointers() {
  983. }
  984. void CompactibleFreeListSpace::compact() {
  985. - SCAN_AND_COMPACT(obj_size);
  986. + SCAN_AND_COMPACT(obj_size, false);
  987. }
  988. // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
  989. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  990. index 3b7bb9a..de7e54b 100644
  991. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  992. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  993. @@ -149,6 +149,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
  994. // Support for compacting cms
  995. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  996. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  997. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  998. // Initialization helpers.
  999. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1000. index 29841d8..d1386c7 100644
  1001. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1002. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1003. @@ -32,6 +32,8 @@
  1004. #include "oops/objArrayKlass.inline.hpp"
  1005. #include "oops/oop.inline.hpp"
  1006. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1007. +
  1008. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1009. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1010. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1011. @@ -357,3 +359,97 @@ void MarkSweep::trace(const char* msg) {
  1012. }
  1013. #endif
  1014. +
  1015. +// (tw) Copy the rescued objects to their destination address after compaction.
  1016. +void MarkSweep::copy_rescued_objects_back() {
  1017. +
  1018. + if (_rescued_oops != NULL) {
  1019. +
  1020. + for (int i=0; i<_rescued_oops->length(); i++) {
  1021. + oop rescued_obj = _rescued_oops->at(i);
  1022. +
  1023. + int size = rescued_obj->size();
  1024. + oop new_obj = rescued_obj->forwardee();
  1025. +
  1026. + assert(rescued_obj->blueprint()->new_version() != NULL, "just checking");
  1027. +
  1028. + if (rescued_obj->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1029. + MarkSweep::update_fields(rescued_obj, new_obj);
  1030. + } else {
  1031. + rescued_obj->set_klass_no_check(rescued_obj->blueprint()->new_version());
  1032. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1033. + }
  1034. +
  1035. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1036. +
  1037. + new_obj->init_mark();
  1038. + assert(new_obj->is_oop(), "must be a valid oop");
  1039. + }
  1040. + _rescued_oops->clear();
  1041. + _rescued_oops = NULL;
  1042. + }
  1043. +}
  1044. +
  1045. +// (tw) Update instances of a class whose fields changed.
  1046. +void MarkSweep::update_fields(oop q, oop new_location) {
  1047. +
  1048. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1049. +
  1050. + klassOop old_klass_oop = q->klass();
  1051. + klassOop new_klass_oop = q->blueprint()->new_version();
  1052. +
  1053. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1054. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1055. +
  1056. + int size = q->size_given_klass(old_klass);
  1057. + int new_size = q->size_given_klass(new_klass);
  1058. +
  1059. + oop tmp_obj = q;
  1060. +
  1061. + // Save object somewhere, there is an overlap in fields
  1062. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1063. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1064. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1065. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1066. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1067. + }
  1068. + }
  1069. +
  1070. + tmp_obj->set_klass_no_check(new_klass_oop);
  1071. + int *cur = new_klass_oop->klass_part()->update_information();
  1072. + assert(cur != NULL, "just checking");
  1073. + MarkSweep::update_fields(new_location, tmp_obj, cur);
  1074. +
  1075. + if (tmp_obj != q) {
  1076. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1077. + }
  1078. +}
  1079. +
  1080. +void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
  1081. + assert(cur != NULL, "just checking");
  1082. + char* to = (char*)new_location;
  1083. + while (*cur != 0) {
  1084. + int size = *cur;
  1085. + if (size > 0) {
  1086. + cur++;
  1087. + int offset = *cur;
  1088. + HeapWord* from = (HeapWord*)(((char *)tmp_obj) + offset);
  1089. + if (size == HeapWordSize) {
  1090. + *((HeapWord*)to) = *from;
  1091. + } else if (size == HeapWordSize * 2) {
  1092. + *((HeapWord*)to) = *from;
  1093. + *(((HeapWord*)to) + 1) = *(from + 1);
  1094. + } else {
  1095. + Copy::conjoint_jbytes(from, to, size);
  1096. + }
  1097. + to += size;
  1098. + cur++;
  1099. + } else {
  1100. + assert(size < 0, "");
  1101. + int skip = -*cur;
  1102. + Copy::fill_to_bytes(to, skip, 0);
  1103. + to += skip;
  1104. + cur++;
  1105. + }
  1106. + }
  1107. +}
  1108. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1109. index eb8252c..40118db 100644
  1110. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1111. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1112. @@ -117,8 +117,12 @@ class MarkSweep : AllStatic {
  1113. friend class AdjustPointerClosure;
  1114. friend class KeepAliveClosure;
  1115. friend class VM_MarkSweep;
  1116. + friend class GenMarkSweep;
  1117. friend void marksweep_init();
  1118. +public:
  1119. + static GrowableArray<oop>* _rescued_oops;
  1120. +
  1121. //
  1122. // Vars
  1123. //
  1124. @@ -208,6 +212,9 @@ class MarkSweep : AllStatic {
  1125. template <class T> static inline void mark_and_push(T* p);
  1126. static inline void push_objarray(oop obj, size_t index);
  1127. + static void copy_rescued_objects_back();
  1128. + static void update_fields(oop q, oop new_location);
  1129. + static void update_fields(oop new_location, oop tmp_obj, int *cur);
  1130. static void follow_stack(); // Empty marking stack.
  1131. static void preserve_mark(oop p, markOop mark);
  1132. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1133. index 32c0bdb..448d673 100644
  1134. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1135. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1136. @@ -402,7 +402,7 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
  1137. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1138. assert(h_exception->is_oop(), "just checking");
  1139. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1140. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1141. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1142. if (ExitVMOnVerifyError) vm_exit(-1);
  1143. ShouldNotReachHere();
  1144. }
  1145. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1146. index b17f405..1c96783 100644
  1147. --- a/src/share/vm/interpreter/linkResolver.cpp
  1148. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1149. @@ -153,8 +153,8 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass
  1150. // Klass resolution
  1151. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1152. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1153. - sel_klass->as_klassOop(),
  1154. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1155. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1156. true)) {
  1157. ResourceMark rm(THREAD);
  1158. Exceptions::fthrow(
  1159. @@ -338,7 +338,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
  1160. // We'll check for the method name first, as that's most likely
  1161. // to be false (so we'll short-circuit out of these tests).
  1162. if (sel_method->name() == vmSymbols::clone_name() &&
  1163. - sel_klass() == SystemDictionary::Object_klass() &&
  1164. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1165. resolved_klass->oop_is_array()) {
  1166. // We need to change "protected" to "public".
  1167. assert(flags.is_protected(), "clone not protected?");
  1168. @@ -634,7 +634,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  1169. }
  1170. // Final fields can only be accessed from its own class.
  1171. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1172. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1173. THROW(vmSymbols::java_lang_IllegalAccessError());
  1174. }
  1175. @@ -839,7 +839,7 @@ void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHand
  1176. bool check_access, bool check_null_and_abstract, TRAPS) {
  1177. methodHandle resolved_method;
  1178. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1179. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1180. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1181. }
  1182. // throws linktime exceptions
  1183. @@ -869,6 +869,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  1184. KlassHandle resolved_klass,
  1185. Handle recv,
  1186. KlassHandle recv_klass,
  1187. + KlassHandle current_klass,
  1188. bool check_null_and_abstract,
  1189. TRAPS) {
  1190. @@ -917,6 +918,9 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  1191. // recv_klass might be an arrayKlassOop but all vtables start at
  1192. // the same place. The cast is to avoid virtual call and assertion.
  1193. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1194. +
  1195. + // (tw) Check that the receiver is a subtype of the holder of the resolved method.
  1196. + assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
  1197. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  1198. }
  1199. }
  1200. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  1201. index dfd74f9..6ca1b54 100644
  1202. --- a/src/share/vm/interpreter/linkResolver.hpp
  1203. +++ b/src/share/vm/interpreter/linkResolver.hpp
  1204. @@ -110,7 +110,8 @@ class CallInfo: public LinkInfo {
  1205. // It does all necessary link-time checks & throws exceptions if necessary.
  1206. class LinkResolver: AllStatic {
  1207. - private:
  1208. +private:
  1209. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  1210. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1211. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1212. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1213. @@ -133,7 +134,7 @@ class LinkResolver: AllStatic {
  1214. 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);
  1215. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  1216. - 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);
  1217. + 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);
  1218. 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);
  1219. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  1220. diff --git a/src/share/vm/interpreter/oopMapCache.cpp b/src/share/vm/interpreter/oopMapCache.cpp
  1221. index 01d5753..6816b3a 100644
  1222. --- a/src/share/vm/interpreter/oopMapCache.cpp
  1223. +++ b/src/share/vm/interpreter/oopMapCache.cpp
  1224. @@ -536,9 +536,9 @@ void OopMapCache::flush_obsolete_entries() {
  1225. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  1226. // Cache entry is occupied by an old redefined method and we don't want
  1227. // to pin it down so flush the entry.
  1228. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  1229. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  1230. _array[i].method()->name()->as_C_string(),
  1231. - _array[i].method()->signature()->as_C_string(), i));
  1232. + _array[i].method()->signature()->as_C_string(), i);
  1233. _array[i].flush();
  1234. }
  1235. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  1236. index 76e18d8..6af7c14 100644
  1237. --- a/src/share/vm/memory/genMarkSweep.cpp
  1238. +++ b/src/share/vm/memory/genMarkSweep.cpp
  1239. @@ -421,6 +421,7 @@ void GenMarkSweep::mark_sweep_phase4() {
  1240. // in the same order in phase2, phase3 and phase4. We don't quite do that
  1241. // here (perm_gen first rather than last), so we tell the validate code
  1242. // to use a higher index (saved from phase2) when verifying perm_gen.
  1243. + assert(_rescued_oops == NULL, "must be empty before processing");
  1244. GenCollectedHeap* gch = GenCollectedHeap::heap();
  1245. Generation* pg = gch->perm_gen();
  1246. @@ -433,10 +434,14 @@ void GenMarkSweep::mark_sweep_phase4() {
  1247. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  1248. + MarkSweep::copy_rescued_objects_back();
  1249. +
  1250. GenCompactClosure blk;
  1251. gch->generation_iterate(&blk, true);
  1252. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  1253. + MarkSweep::copy_rescued_objects_back();
  1254. +
  1255. pg->post_compact(); // Shared spaces verification.
  1256. }
  1257. diff --git a/src/share/vm/memory/iterator.hpp b/src/share/vm/memory/iterator.hpp
  1258. index b5f8e0e..856cfce 100644
  1259. --- a/src/share/vm/memory/iterator.hpp
  1260. +++ b/src/share/vm/memory/iterator.hpp
  1261. @@ -101,6 +101,12 @@ class OopClosure : public Closure {
  1262. #endif
  1263. };
  1264. +class OopClosureNoHeader : public OopClosure {
  1265. +public:
  1266. + // If "true", invoke on header klass field.
  1267. + bool do_header() { return false; } // Note that this is non-virtual.
  1268. +};
  1269. +
  1270. // ObjectClosure is used for iterating through an object space
  1271. class ObjectClosure : public Closure {
  1272. diff --git a/src/share/vm/memory/oopFactory.cpp b/src/share/vm/memory/oopFactory.cpp
  1273. index def88cc..016d7eb 100644
  1274. --- a/src/share/vm/memory/oopFactory.cpp
  1275. +++ b/src/share/vm/memory/oopFactory.cpp
  1276. @@ -129,11 +129,11 @@ klassOop oopFactory::new_instanceKlass(Symbol* name, int vtable_len, int itable_
  1277. unsigned int nonstatic_oop_map_count,
  1278. AccessFlags access_flags,
  1279. ReferenceType rt,
  1280. - KlassHandle host_klass, TRAPS) {
  1281. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  1282. instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
  1283. return ikk->allocate_instance_klass(name, vtable_len, itable_len,
  1284. static_field_size, nonstatic_oop_map_count,
  1285. - access_flags, rt, host_klass, CHECK_NULL);
  1286. + access_flags, rt, host_klass, old_klass, CHECK_NULL);
  1287. }
  1288. diff --git a/src/share/vm/memory/oopFactory.hpp b/src/share/vm/memory/oopFactory.hpp
  1289. index e7e22d4..ce39ada 100644
  1290. --- a/src/share/vm/memory/oopFactory.hpp
  1291. +++ b/src/share/vm/memory/oopFactory.hpp
  1292. @@ -80,7 +80,7 @@ class oopFactory: AllStatic {
  1293. unsigned int nonstatic_oop_map_count,
  1294. AccessFlags access_flags,
  1295. ReferenceType rt,
  1296. - KlassHandle host_klass, TRAPS);
  1297. + KlassHandle host_klass, KlassHandle old_klass, TRAPS);
  1298. // Methods
  1299. private:
  1300. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  1301. index f97bc34..c8563b2 100644
  1302. --- a/src/share/vm/memory/space.cpp
  1303. +++ b/src/share/vm/memory/space.cpp
  1304. @@ -378,9 +378,8 @@ void CompactibleSpace::clear(bool mangle_space) {
  1305. _compaction_top = bottom();
  1306. }
  1307. -HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1308. - CompactPoint* cp, HeapWord* compact_top) {
  1309. - // q is alive
  1310. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  1311. +HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
  1312. // First check if we should switch compaction space
  1313. assert(this == cp->space, "'this' should be current compaction space.");
  1314. size_t compaction_max_size = pointer_delta(end(), compact_top);
  1315. @@ -400,8 +399,15 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1316. compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  1317. }
  1318. + return compact_top;
  1319. +}
  1320. +
  1321. +HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1322. + CompactPoint* cp, HeapWord* compact_top) {
  1323. + compact_top = forward_compact_top(size, cp, compact_top);
  1324. +
  1325. // store the forwarding pointer into the mark word
  1326. - if ((HeapWord*)q != compact_top) {
  1327. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  1328. q->forward_to(oop(compact_top));
  1329. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  1330. } else {
  1331. @@ -423,6 +429,58 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1332. return compact_top;
  1333. }
  1334. +// Compute the forward sizes and leave out objects whose position could
  1335. +// possibly overlap other objects.
  1336. +HeapWord* CompactibleSpace::forward_with_rescue(oop q, size_t size,
  1337. + CompactPoint* cp, HeapWord* compact_top) {
  1338. + size_t forward_size = size;
  1339. +
  1340. + // (DCEVM) There is a new version of the class of q => different size
  1341. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1342. +
  1343. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1344. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1345. + forward_size = new_size;
  1346. + }
  1347. +
  1348. + compact_top = forward_compact_top(forward_size, cp, compact_top);
  1349. +
  1350. + if (must_rescue(oop(q), oop(compact_top))) {
  1351. + if (MarkSweep::_rescued_oops == NULL) {
  1352. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1353. + }
  1354. + MarkSweep::_rescued_oops->append(oop(q));
  1355. + return compact_top;
  1356. + }
  1357. +
  1358. + return forward(q, forward_size, cp, compact_top);
  1359. +}
  1360. +
  1361. +// Compute the forwarding addresses for the objects that need to be rescued.
  1362. +HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
  1363. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  1364. + if (MarkSweep::_rescued_oops != NULL) {
  1365. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  1366. + oop q = MarkSweep::_rescued_oops->at(i);
  1367. +
  1368. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  1369. + size_t size = block_size((HeapWord*)q);
  1370. +
  1371. + // (tw) There is a new version of the class of q => different size
  1372. + if (oop(q)->blueprint()->new_version() != NULL) {
  1373. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1374. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1375. + size = new_size;
  1376. + }
  1377. +
  1378. + compact_top = cp->space->forward(oop(q), size, cp, compact_top);
  1379. + assert(compact_top <= end(), "must not write over end of space!");
  1380. + }
  1381. + MarkSweep::_rescued_oops->clear();
  1382. + MarkSweep::_rescued_oops = NULL;
  1383. + }
  1384. + return compact_top;
  1385. +}
  1386. bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1387. HeapWord* q, size_t deadlength) {
  1388. @@ -444,12 +502,17 @@ bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1389. #define adjust_obj_size(s) s
  1390. void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  1391. - SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
  1392. + SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
  1393. }
  1394. // Faster object search.
  1395. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  1396. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  1397. + if (!Universe::is_redefining_gc_run()) {
  1398. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
  1399. + } else {
  1400. + // Redefinition run
  1401. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
  1402. + }
  1403. }
  1404. void Space::adjust_pointers() {
  1405. @@ -490,6 +553,111 @@ void Space::adjust_pointers() {
  1406. assert(q == t, "just checking");
  1407. }
  1408. +
  1409. +#ifdef ASSERT
  1410. +
  1411. +int CompactibleSpace::space_index(oop obj) {
  1412. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  1413. +
  1414. + if (heap->is_in_permanent(obj)) {
  1415. + return -1;
  1416. + }
  1417. +
  1418. + int index = 0;
  1419. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1420. + Generation* gen = heap->get_gen(i);
  1421. + CompactibleSpace* space = gen->first_compaction_space();
  1422. + while (space != NULL) {
  1423. + if (space->is_in_reserved(obj)) {
  1424. + return index;
  1425. + }
  1426. + space = space->next_compaction_space();
  1427. + index++;
  1428. + }
  1429. + }
  1430. +
  1431. + tty->print_cr("could not compute space_index for %08xh", obj);
  1432. + index = 0;
  1433. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1434. + Generation* gen = heap->get_gen(i);
  1435. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  1436. +
  1437. + CompactibleSpace* space = gen->first_compaction_space();
  1438. + while (space != NULL) {
  1439. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  1440. + space = space->next_compaction_space();
  1441. + index++;
  1442. + }
  1443. + }
  1444. +
  1445. + ShouldNotReachHere();
  1446. + return 0;
  1447. +}
  1448. +#endif
  1449. +
  1450. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  1451. + // Only redefined objects can have the need to be rescued.
  1452. + if (oop(old_obj)->blueprint()->new_version() == NULL) return false;
  1453. +
  1454. + if (old_obj->is_perm()) {
  1455. + // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
  1456. + return true;
  1457. + }
  1458. +
  1459. + int new_size = old_obj->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  1460. + int original_size = old_obj->size();
  1461. +
  1462. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  1463. + bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
  1464. + bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
  1465. + if (old_in_tenured == new_in_tenured) {
  1466. + // Rescue if object may overlap with a higher memory address.
  1467. + bool overlap = (old_obj + original_size < new_obj + new_size);
  1468. + if (old_in_tenured) {
  1469. + // Old and new address are in same space, so just compare the address.
  1470. + // Must rescue if object moves towards the top of the space.
  1471. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  1472. + } else {
  1473. + // In the new generation, eden is located before the from space, so a
  1474. + // simple pointer comparison is sufficient.
  1475. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1476. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1477. + assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  1478. + }
  1479. + return overlap;
  1480. +
  1481. + } else {
  1482. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  1483. + if (tenured_gen->is_in_reserved(new_obj)) {
  1484. + // Must never rescue when moving from the new into the old generation.
  1485. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1486. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  1487. + return false;
  1488. +
  1489. + } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
  1490. + // Must always rescue when moving from the old into the new generation.
  1491. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1492. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  1493. + return true;
  1494. + }
  1495. + }
  1496. +}
  1497. +
  1498. +oop CompactibleSpace::rescue(oop old_obj) {
  1499. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  1500. +
  1501. + int size = old_obj->size();
  1502. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1503. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  1504. +
  1505. + if (MarkSweep::_rescued_oops == NULL) {
  1506. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1507. + }
  1508. +
  1509. + MarkSweep::_rescued_oops->append(rescued_obj);
  1510. + return rescued_obj;
  1511. +}
  1512. +
  1513. void CompactibleSpace::adjust_pointers() {
  1514. // Check first is there is any work to do.
  1515. if (used() == 0) {
  1516. @@ -500,7 +668,13 @@ void CompactibleSpace::adjust_pointers() {
  1517. }
  1518. void CompactibleSpace::compact() {
  1519. - SCAN_AND_COMPACT(obj_size);
  1520. +
  1521. + if(!Universe::is_redefining_gc_run()) {
  1522. + SCAN_AND_COMPACT(obj_size, false);
  1523. + } else {
  1524. + // Redefinition run
  1525. + SCAN_AND_COMPACT(obj_size, true)
  1526. + }
  1527. }
  1528. void Space::print_short() const { print_short_on(tty); }
  1529. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  1530. index ef2f2c6..ff95a8b 100644
  1531. --- a/src/share/vm/memory/space.hpp
  1532. +++ b/src/share/vm/memory/space.hpp
  1533. @@ -445,6 +445,9 @@ public:
  1534. // indicates when the next such action should be taken.
  1535. virtual void prepare_for_compaction(CompactPoint* cp);
  1536. // MarkSweep support phase3
  1537. + DEBUG_ONLY(int space_index(oop obj));
  1538. + bool must_rescue(oop old_obj, oop new_obj);
  1539. + oop rescue(oop old_obj);
  1540. virtual void adjust_pointers();
  1541. // MarkSweep support phase4
  1542. virtual void compact();
  1543. @@ -474,6 +477,15 @@ public:
  1544. // accordingly".
  1545. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  1546. HeapWord* compact_top);
  1547. + // (DCEVM) same as forwad, but can rescue objects. Invoked only during
  1548. + // redefinition runs
  1549. + HeapWord* forward_with_rescue(oop q, size_t size, CompactPoint* cp,
  1550. + HeapWord* compact_top);
  1551. +
  1552. + HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
  1553. +
  1554. + // (tw) Compute new compact top without actually forwarding the object.
  1555. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1556. // Return a size with adjusments as required of the space.
  1557. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  1558. @@ -504,7 +516,7 @@ protected:
  1559. size_t word_len);
  1560. };
  1561. -#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
  1562. +#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
  1563. /* Compute the new addresses for the live objects and store it in the mark \
  1564. * Used by universe::mark_sweep_phase2() \
  1565. */ \
  1566. @@ -564,7 +576,17 @@ protected:
  1567. Prefetch::write(q, interval); \
  1568. /* size_t size = oop(q)->size(); changing this for cms for perm gen */\
  1569. size_t size = block_size(q); \
  1570. - compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1571. + if (redefinition_run) { \
  1572. + compact_top = cp->space->forward_with_rescue(oop(q), size, \
  1573. + cp, compact_top); \
  1574. + if (q < first_dead && oop(q)->is_gc_marked()) { \
  1575. + /* Was moved (otherwise, forward would reset mark), \
  1576. + set first_dead to here */ \
  1577. + first_dead = q; \
  1578. + } \
  1579. + } else { \
  1580. + compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1581. + } \
  1582. q += size; \
  1583. end_of_live = q; \
  1584. } else { \
  1585. @@ -613,6 +635,8 @@ protected:
  1586. } \
  1587. } \
  1588. \
  1589. + if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
  1590. + \
  1591. assert(q == t, "just checking"); \
  1592. if (liveRange != NULL) { \
  1593. liveRange->set_end(q); \
  1594. @@ -665,13 +689,8 @@ protected:
  1595. q += size; \
  1596. } \
  1597. \
  1598. - if (_first_dead == t) { \
  1599. - q = t; \
  1600. - } else { \
  1601. - /* $$$ This is funky. Using this to read the previously written \
  1602. - * LiveRange. See also use below. */ \
  1603. - q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
  1604. - } \
  1605. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1606. + q = _first_dead; \
  1607. } \
  1608. \
  1609. const intx interval = PrefetchScanIntervalInBytes; \
  1610. @@ -702,7 +721,7 @@ protected:
  1611. assert(q == t, "just checking"); \
  1612. }
  1613. -#define SCAN_AND_COMPACT(obj_size) { \
  1614. +#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
  1615. /* Copy all live objects to their new location \
  1616. * Used by MarkSweep::mark_sweep_phase4() */ \
  1617. \
  1618. @@ -728,12 +747,8 @@ protected:
  1619. } \
  1620. ) /* debug_only */ \
  1621. \
  1622. - if (_first_dead == t) { \
  1623. - q = t; \
  1624. - } else { \
  1625. - /* $$$ Funky */ \
  1626. - q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
  1627. - } \
  1628. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1629. + q = _first_dead; \
  1630. } \
  1631. \
  1632. const intx scan_interval = PrefetchScanIntervalInBytes; \
  1633. @@ -752,13 +767,36 @@ protected:
  1634. size_t size = obj_size(q); \
  1635. HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
  1636. \
  1637. + if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
  1638. + oop dest_obj = rescue(oop(q)); \
  1639. + debug_only(Copy::fill_to_words(q, size, 0)); \
  1640. + q += size; \
  1641. + continue; \
  1642. + } \
  1643. + \
  1644. /* prefetch beyond compaction_top */ \
  1645. Prefetch::write(compaction_top, copy_interval); \
  1646. \
  1647. /* copy object and reinit its mark */ \
  1648. VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, \
  1649. compaction_top)); \
  1650. - assert(q != compaction_top, "everything in this pass should be moving"); \
  1651. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, \
  1652. + "everything in this pass should be moving"); \
  1653. + if (redefinition_run && oop(q)->blueprint()->new_version() != NULL) { \
  1654. + klassOop new_version = oop(q)->blueprint()->new_version(); \
  1655. + if (new_version->klass_part()->update_information() == NULL) { \
  1656. + Copy::aligned_conjoint_words(q, compaction_top, size); \
  1657. + oop(compaction_top)->set_klass_no_check(new_version); \
  1658. + } else { \
  1659. + MarkSweep::update_fields(oop(q), oop(compaction_top)); \
  1660. + } \
  1661. + oop(compaction_top)->init_mark(); \
  1662. + assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1663. + \
  1664. + debug_only(prev_q = q); \
  1665. + q += size; \
  1666. + continue; \
  1667. + } \
  1668. Copy::aligned_conjoint_words(q, compaction_top, size); \
  1669. oop(compaction_top)->init_mark(); \
  1670. assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1671. diff --git a/src/share/vm/memory/specialized_oop_closures.hpp b/src/share/vm/memory/specialized_oop_closures.hpp
  1672. index 4d7c50b..671787e 100644
  1673. --- a/src/share/vm/memory/specialized_oop_closures.hpp
  1674. +++ b/src/share/vm/memory/specialized_oop_closures.hpp
  1675. @@ -37,6 +37,7 @@
  1676. // Forward declarations.
  1677. class OopClosure;
  1678. +class OopClosureNoHeader;
  1679. class OopsInGenClosure;
  1680. // DefNew
  1681. class ScanClosure;
  1682. @@ -74,6 +75,7 @@ class CMSInnerParMarkAndPushClosure;
  1683. #endif
  1684. #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
  1685. + f(OopClosureNoHeader,_v) \
  1686. f(ScanClosure,_nv) \
  1687. f(FastScanClosure,_nv) \
  1688. f(FilteringClosure,_nv)
  1689. @@ -132,6 +134,7 @@ class CMSInnerParMarkAndPushClosure;
  1690. #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
  1691. f(OopClosure,_v) \
  1692. + f(OopClosureNoHeader,_v) \
  1693. SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
  1694. #endif // SERIALGC
  1695. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  1696. index 8ce17d9..fe37993 100644
  1697. --- a/src/share/vm/memory/universe.cpp
  1698. +++ b/src/share/vm/memory/universe.cpp
  1699. @@ -100,6 +100,8 @@
  1700. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  1701. #endif
  1702. +bool Universe::_is_redefining_gc_run = false;
  1703. +
  1704. // Known objects
  1705. klassOop Universe::_boolArrayKlassObj = NULL;
  1706. klassOop Universe::_byteArrayKlassObj = NULL;
  1707. @@ -204,6 +206,42 @@ void Universe::system_classes_do(void f(klassOop)) {
  1708. f(systemObjArrayKlassObj());
  1709. }
  1710. +// (tw) This method should iterate all pointers that are not within heap objects.
  1711. +void Universe::root_oops_do(OopClosure *oopClosure) {
  1712. +
  1713. + class AlwaysTrueClosure: public BoolObjectClosure {
  1714. + public:
  1715. + void do_object(oop p) { ShouldNotReachHere(); }
  1716. + bool do_object_b(oop p) { return true; }
  1717. + };
  1718. + AlwaysTrueClosure always_true;
  1719. +
  1720. + Universe::oops_do(oopClosure);
  1721. +// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
  1722. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  1723. + Threads::oops_do(oopClosure, NULL);
  1724. + ObjectSynchronizer::oops_do(oopClosure);
  1725. + FlatProfiler::oops_do(oopClosure);
  1726. + JvmtiExport::oops_do(oopClosure);
  1727. +
  1728. + // Now adjust pointers in remaining weak roots. (All of which should
  1729. + // have been cleared if they pointed to non-surviving objects.)
  1730. + // Global (weak) JNI handles
  1731. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  1732. +
  1733. + CodeCache::oops_do(oopClosure);
  1734. + StringTable::oops_do(oopClosure);
  1735. +
  1736. + // (tw) TODO: Check if this is correct?
  1737. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  1738. + //Management::oops_do(oopClosure);
  1739. + //ref_processor()->weak_oops_do(&oopClosure);
  1740. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  1741. +
  1742. + // SO_AllClasses
  1743. + SystemDictionary::oops_do(oopClosure);
  1744. +}
  1745. +
  1746. void Universe::oops_do(OopClosure* f, bool do_all) {
  1747. f->do_oop((oop*) &_int_mirror);
  1748. @@ -1590,10 +1628,9 @@ void ActiveMethodOopsCache::add_previous_version(const methodOop method) {
  1749. }
  1750. // RC_TRACE macro has an embedded ResourceMark
  1751. - RC_TRACE(0x00000100,
  1752. - ("add: %s(%s): adding prev version ref for cached method @%d",
  1753. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  1754. method->name()->as_C_string(), method->signature()->as_C_string(),
  1755. - _prev_methods->length()));
  1756. + _prev_methods->length());
  1757. methodHandle method_h(method);
  1758. jweak method_ref = JNIHandles::make_weak_global(method_h);
  1759. @@ -1620,9 +1657,8 @@ void ActiveMethodOopsCache::add_previous_version(const methodOop method) {
  1760. JNIHandles::destroy_weak_global(method_ref);
  1761. _prev_methods->remove_at(i);
  1762. } else {
  1763. - // RC_TRACE macro has an embedded ResourceMark
  1764. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  1765. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  1766. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  1767. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  1768. }
  1769. }
  1770. } // end add_previous_version()
  1771. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  1772. index da21a8b..676675e 100644
  1773. --- a/src/share/vm/memory/universe.hpp
  1774. +++ b/src/share/vm/memory/universe.hpp
  1775. @@ -127,6 +127,8 @@ class Universe: AllStatic {
  1776. friend class SystemDictionary;
  1777. friend class VMStructs;
  1778. friend class CompactingPermGenGen;
  1779. + friend class Space;
  1780. + friend class ContiguousSpace;
  1781. friend class VM_PopulateDumpSharedSpace;
  1782. friend jint universe_init();
  1783. @@ -258,7 +260,18 @@ class Universe: AllStatic {
  1784. static void compute_verify_oop_data();
  1785. + static bool _is_redefining_gc_run;
  1786. +
  1787. public:
  1788. +
  1789. + static bool is_redefining_gc_run() {
  1790. + return _is_redefining_gc_run;
  1791. + }
  1792. +
  1793. + static void set_redefining_gc_run(bool b) {
  1794. + _is_redefining_gc_run = b;
  1795. + }
  1796. +
  1797. // Known classes in the VM
  1798. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  1799. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  1800. @@ -403,6 +416,8 @@ class Universe: AllStatic {
  1801. // Iteration
  1802. + static void root_oops_do(OopClosure *f);
  1803. +
  1804. // Apply "f" to the addresses of all the direct heap pointers maintained
  1805. // as static fields of "Universe".
  1806. static void oops_do(OopClosure* f, bool do_all = false);
  1807. @@ -419,6 +434,7 @@ class Universe: AllStatic {
  1808. // Debugging
  1809. static bool verify_in_progress() { return _verify_in_progress; }
  1810. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  1811. static void verify(bool silent, VerifyOption option);
  1812. static void verify(bool silent) {
  1813. verify(silent, VerifyOption_Default /* option */);
  1814. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  1815. index ad62921..1cd422c 100644
  1816. --- a/src/share/vm/oops/cpCacheOop.cpp
  1817. +++ b/src/share/vm/oops/cpCacheOop.cpp
  1818. @@ -40,6 +40,11 @@
  1819. void ConstantPoolCacheEntry::initialize_entry(int index) {
  1820. assert(0 < index && index < 0x10000, "sanity check");
  1821. _indices = index;
  1822. +// (DCEVM) Should put something else to force JVM to fail if these invalid entries are accessed!
  1823. +//#ifdef ASSERT
  1824. + _f1 = NULL;
  1825. + _f2 = 0;
  1826. +//#endif
  1827. assert(constant_pool_index() == index, "");
  1828. }
  1829. @@ -162,7 +167,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  1830. int vtable_index) {
  1831. assert(!is_secondary_entry(), "");
  1832. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  1833. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1834. + // (tw) No longer valid assert
  1835. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1836. int byte_no = -1;
  1837. bool change_to_virtual = false;
  1838. @@ -516,116 +522,6 @@ void ConstantPoolCacheEntry::update_pointers() {
  1839. }
  1840. #endif // SERIALGC
  1841. -// RedefineClasses() API support:
  1842. -// If this constantPoolCacheEntry refers to old_method then update it
  1843. -// to refer to new_method.
  1844. -bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  1845. - methodOop new_method, bool * trace_name_printed) {
  1846. -
  1847. - if (is_vfinal()) {
  1848. - // virtual and final so _f2 contains method ptr instead of vtable index
  1849. - if (f2_as_vfinal_method() == old_method) {
  1850. - // match old_method so need an update
  1851. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  1852. - _f2 = (intptr_t)new_method;
  1853. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1854. - if (!(*trace_name_printed)) {
  1855. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1856. - RC_TRACE_MESG(("adjust: name=%s",
  1857. - Klass::cast(old_method->method_holder())->external_name()));
  1858. - *trace_name_printed = true;
  1859. - }
  1860. - // RC_TRACE macro has an embedded ResourceMark
  1861. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  1862. - new_method->name()->as_C_string(),
  1863. - new_method->signature()->as_C_string()));
  1864. - }
  1865. -
  1866. - return true;
  1867. - }
  1868. -
  1869. - // f1() is not used with virtual entries so bail out
  1870. - return false;
  1871. - }
  1872. -
  1873. - if ((oop)_f1 == NULL) {
  1874. - // NULL f1() means this is a virtual entry so bail out
  1875. - // We are assuming that the vtable index does not need change.
  1876. - return false;
  1877. - }
  1878. -
  1879. - if ((oop)_f1 == old_method) {
  1880. - _f1 = new_method;
  1881. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1882. - if (!(*trace_name_printed)) {
  1883. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1884. - RC_TRACE_MESG(("adjust: name=%s",
  1885. - Klass::cast(old_method->method_holder())->external_name()));
  1886. - *trace_name_printed = true;
  1887. - }
  1888. - // RC_TRACE macro has an embedded ResourceMark
  1889. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  1890. - new_method->name()->as_C_string(),
  1891. - new_method->signature()->as_C_string()));
  1892. - }
  1893. -
  1894. - return true;
  1895. - }
  1896. -
  1897. - return false;
  1898. -}
  1899. -
  1900. -// a constant pool cache entry should never contain old or obsolete methods
  1901. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  1902. - if (is_vfinal()) {
  1903. - // virtual and final so _f2 contains method ptr instead of vtable index
  1904. - methodOop m = (methodOop)_f2;
  1905. - // Return false if _f2 refers to an old or an obsolete method.
  1906. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  1907. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  1908. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  1909. - // _f1 == NULL || !_f1->is_method() are OK here
  1910. - return true;
  1911. - }
  1912. -
  1913. - methodOop m = (methodOop)_f1;
  1914. - // return false if _f1 refers to an old or an obsolete method
  1915. - return (!m->is_old() && !m->is_obsolete());
  1916. -}
  1917. -
  1918. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  1919. - if (!is_method_entry()) {
  1920. - // not a method entry so not interesting by default
  1921. - return false;
  1922. - }
  1923. -
  1924. - methodOop m = NULL;
  1925. - if (is_vfinal()) {
  1926. - // virtual and final so _f2 contains method ptr instead of vtable index
  1927. - m = f2_as_vfinal_method();
  1928. - } else if (is_f1_null()) {
  1929. - // NULL _f1 means this is a virtual entry so also not interesting
  1930. - return false;
  1931. - } else {
  1932. - oop f1 = _f1; // _f1 is volatile
  1933. - if (!f1->is_method()) {
  1934. - // _f1 can also contain a klassOop for an interface
  1935. - return false;
  1936. - }
  1937. - m = f1_as_method();
  1938. - }
  1939. -
  1940. - assert(m != NULL && m->is_method(), "sanity check");
  1941. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  1942. - // robustness for above sanity checks or method is not in
  1943. - // the interesting class
  1944. - return false;
  1945. - }
  1946. -
  1947. - // the method is in the interesting class so the entry is interesting
  1948. - return true;
  1949. -}
  1950. -
  1951. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  1952. // print separator
  1953. if (index == 0) st->print_cr(" -------------");
  1954. @@ -663,60 +559,10 @@ void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
  1955. }
  1956. }
  1957. -// RedefineClasses() API support:
  1958. -// If any entry of this constantPoolCache points to any of
  1959. -// old_methods, replace it with the corresponding new_method.
  1960. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  1961. - int methods_length, bool * trace_name_printed) {
  1962. -
  1963. - if (methods_length == 0) {
  1964. - // nothing to do if there are no methods
  1965. - return;
  1966. - }
  1967. -
  1968. - // get shorthand for the interesting class
  1969. - klassOop old_holder = old_methods[0]->method_holder();
  1970. +void constantPoolCacheOopDesc::adjust_entries() {
  1971. for (int i = 0; i < length(); i++) {
  1972. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  1973. - // skip uninteresting methods
  1974. - continue;
  1975. - }
  1976. -
  1977. - // The constantPoolCache contains entries for several different
  1978. - // things, but we only care about methods. In fact, we only care
  1979. - // about methods in the same class as the one that contains the
  1980. - // old_methods. At this point, we have an interesting entry.
  1981. -
  1982. - for (int j = 0; j < methods_length; j++) {
  1983. - methodOop old_method = old_methods[j];
  1984. - methodOop new_method = new_methods[j];
  1985. -
  1986. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  1987. - trace_name_printed)) {
  1988. - // current old_method matched this entry and we updated it so
  1989. - // break out and get to the next interesting entry if there one
  1990. - break;
  1991. - }
  1992. - }
  1993. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  1994. }
  1995. }
  1996. -// the constant pool cache should never contain old or obsolete methods
  1997. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  1998. - for (int i = 1; i < length(); i++) {
  1999. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  2000. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  2001. - return false;
  2002. - }
  2003. - }
  2004. - return true;
  2005. -}
  2006. -
  2007. -void constantPoolCacheOopDesc::dump_cache() {
  2008. - for (int i = 1; i < length(); i++) {
  2009. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  2010. - entry_at(i)->print(tty, i);
  2011. - }
  2012. - }
  2013. -}
  2014. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  2015. index ef26775..a270d0d 100644
  2016. --- a/src/share/vm/oops/cpCacheOop.hpp
  2017. +++ b/src/share/vm/oops/cpCacheOop.hpp
  2018. @@ -355,17 +355,6 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  2019. void update_pointers();
  2020. - // RedefineClasses() API support:
  2021. - // If this constantPoolCacheEntry refers to old_method then update it
  2022. - // to refer to new_method.
  2023. - // trace_name_printed is set to true if the current call has
  2024. - // printed the klass name so that other routines in the adjust_*
  2025. - // group don't print the klass name.
  2026. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  2027. - bool * trace_name_printed);
  2028. - bool check_no_old_or_obsolete_entries();
  2029. - bool is_interesting_method_entry(klassOop k);
  2030. -
  2031. // Debugging & Printing
  2032. void print (outputStream* st, int index) const;
  2033. void verify(outputStream* st) const;
  2034. @@ -485,16 +474,8 @@ class constantPoolCacheOopDesc: public oopDesc {
  2035. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  2036. }
  2037. - // RedefineClasses() API support:
  2038. - // If any entry of this constantPoolCache points to any of
  2039. - // old_methods, replace it with the corresponding new_method.
  2040. - // trace_name_printed is set to true if the current call has
  2041. - // printed the klass name so that other routines in the adjust_*
  2042. - // group don't print the klass name.
  2043. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  2044. - int methods_length, bool * trace_name_printed);
  2045. - bool check_no_old_or_obsolete_entries();
  2046. - void dump_cache();
  2047. + // (tw) Clear references to methods and fields from this cache.
  2048. + void adjust_entries();
  2049. };
  2050. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  2051. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  2052. index cd3dce0..666ffdf 100644
  2053. --- a/src/share/vm/oops/instanceKlass.cpp
  2054. +++ b/src/share/vm/oops/instanceKlass.cpp
  2055. @@ -255,7 +255,7 @@ bool instanceKlass::verify_code(
  2056. // 1) Verify the bytecodes
  2057. Verifier::Mode mode =
  2058. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  2059. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  2060. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  2061. }
  2062. @@ -362,7 +362,13 @@ bool instanceKlass::link_class_impl(
  2063. jt->get_thread_stat()->perf_recursion_counts_addr(),
  2064. jt->get_thread_stat()->perf_timers_addr(),
  2065. PerfClassTraceTime::CLASS_VERIFY);
  2066. + if (this_oop->is_redefining()) {
  2067. + Thread::current()->set_pretend_new_universe(true);
  2068. + }
  2069. bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  2070. + if (this_oop->is_redefining()) {
  2071. + Thread::current()->set_pretend_new_universe(false);
  2072. + }
  2073. if (!verify_ok) {
  2074. return false;
  2075. }
  2076. @@ -400,7 +406,8 @@ bool instanceKlass::link_class_impl(
  2077. }
  2078. #endif
  2079. this_oop->set_init_state(linked);
  2080. - if (JvmtiExport::should_post_class_prepare()) {
  2081. + // (tw) Must check for old version in order to prevent infinite loops.
  2082. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  2083. Thread *thread = THREAD;
  2084. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  2085. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  2086. @@ -454,7 +461,9 @@ void instanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) {
  2087. // If we were to use wait() instead of waitInterruptibly() then
  2088. // we might end up throwing IE from link/symbol resolution sites
  2089. // that aren't expected to throw. This would wreak havoc. See 6320309.
  2090. - while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
  2091. + // (tw) Wait also for the old class version to be fully initialized.
  2092. + while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
  2093. + || (this_oop->old_version() != NULL && ((instanceKlass*)this_oop->old_version()->klass_part())->is_being_initialized())) {
  2094. wait = true;
  2095. ol.waitUninterruptibly(CHECK);
  2096. }
  2097. @@ -673,6 +682,18 @@ bool instanceKlass::implements_interface(klassOop k) const {
  2098. return false;
  2099. }
  2100. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  2101. + k = k->klass_part()->newest_version();
  2102. + if (this->newest_version() == k) return true;
  2103. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  2104. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  2105. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  2106. + return true;
  2107. + }
  2108. + }
  2109. + return false;
  2110. +}
  2111. +
  2112. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  2113. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  2114. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  2115. @@ -949,6 +970,18 @@ void instanceKlass::methods_do(void f(methodOop method)) {
  2116. }
  2117. }
  2118. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  2119. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  2120. + for (int i=0; i<values.length(); i++) {
  2121. + arr[i] = values.at(i);
  2122. + }
  2123. + set_update_information(arr);
  2124. +}
  2125. +
  2126. +void instanceKlass::clear_update_information() {
  2127. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  2128. + set_update_information(NULL);
  2129. +}
  2130. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  2131. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  2132. @@ -1368,6 +1401,20 @@ jmethodID instanceKlass::jmethod_id_or_null(methodOop method) {
  2133. return id;
  2134. }
  2135. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  2136. + size_t idnum = (size_t)method->method_idnum();
  2137. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  2138. + size_t length; // length assigned as debugging crumb
  2139. + jmethodID id = NULL;
  2140. + if (jmeths != NULL && // If there is a cache
  2141. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  2142. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  2143. + return true;
  2144. + }
  2145. +
  2146. + return false;
  2147. +}
  2148. +
  2149. // Cache an itable index
  2150. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  2151. @@ -1527,6 +1574,13 @@ void instanceKlass::remove_dependent_nmethod(nmethod* nm) {
  2152. last = b;
  2153. b = b->next();
  2154. }
  2155. +
  2156. + // (tw) Hack as dependencies get wrong version of klassOop
  2157. + if(this->old_version() != NULL) {
  2158. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  2159. + return;
  2160. + }
  2161. +
  2162. #ifdef ASSERT
  2163. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  2164. nm->print();
  2165. @@ -1922,16 +1976,6 @@ void instanceKlass::release_C_heap_structures() {
  2166. assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2167. }
  2168. - // deallocate information about previous versions
  2169. - if (_previous_versions != NULL) {
  2170. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2171. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2172. - delete pv_node;
  2173. - }
  2174. - delete _previous_versions;
  2175. - _previous_versions = NULL;
  2176. - }
  2177. -
  2178. // deallocate the cached class file
  2179. if (_cached_class_file_bytes != NULL) {
  2180. os::free(_cached_class_file_bytes, mtClass);
  2181. @@ -2545,275 +2589,10 @@ void instanceKlass::set_init_state(ClassState state) {
  2182. }
  2183. #endif
  2184. -
  2185. -// RedefineClasses() support for previous versions:
  2186. -
  2187. -// Add an information node that contains weak references to the
  2188. -// interesting parts of the previous version of the_class.
  2189. -// This is also where we clean out any unused weak references.
  2190. -// Note that while we delete nodes from the _previous_versions
  2191. -// array, we never delete the array itself until the klass is
  2192. -// unloaded. The has_been_redefined() query depends on that fact.
  2193. -//
  2194. -void instanceKlass::add_previous_version(instanceKlassHandle ikh,
  2195. - BitMap* emcp_methods, int emcp_method_count) {
  2196. - assert(Thread::current()->is_VM_thread(),
  2197. - "only VMThread can add previous versions");
  2198. -
  2199. - if (_previous_versions == NULL) {
  2200. - // This is the first previous version so make some space.
  2201. - // Start with 2 elements under the assumption that the class
  2202. - // won't be redefined much.
  2203. - _previous_versions = new (ResourceObj::C_HEAP, mtClass)
  2204. - GrowableArray<PreviousVersionNode *>(2, true);
  2205. - }
  2206. -
  2207. - // RC_TRACE macro has an embedded ResourceMark
  2208. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  2209. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  2210. - constantPoolHandle cp_h(ikh->constants());
  2211. - jobject cp_ref;
  2212. - if (cp_h->is_shared()) {
  2213. - // a shared ConstantPool requires a regular reference; a weak
  2214. - // reference would be collectible
  2215. - cp_ref = JNIHandles::make_global(cp_h);
  2216. - } else {
  2217. - cp_ref = JNIHandles::make_weak_global(cp_h);
  2218. - }
  2219. - PreviousVersionNode * pv_node = NULL;
  2220. - objArrayOop old_methods = ikh->methods();
  2221. -
  2222. - if (emcp_method_count == 0) {
  2223. - // non-shared ConstantPool gets a weak reference
  2224. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  2225. - RC_TRACE(0x00000400,
  2226. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  2227. - } else {
  2228. - int local_count = 0;
  2229. - GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass)
  2230. - GrowableArray<jweak>(emcp_method_count, true);
  2231. - for (int i = 0; i < old_methods->length(); i++) {
  2232. - if (emcp_methods->at(i)) {
  2233. - // this old method is EMCP so save a weak ref
  2234. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2235. - methodHandle old_method_h(old_method);
  2236. - jweak method_ref = JNIHandles::make_weak_global(old_method_h);
  2237. - method_refs->append(method_ref);
  2238. - if (++local_count >= emcp_method_count) {
  2239. - // no more EMCP methods so bail out now
  2240. - break;
  2241. - }
  2242. - }
  2243. - }
  2244. - // non-shared ConstantPool gets a weak reference
  2245. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs);
  2246. - }
  2247. -
  2248. - _previous_versions->append(pv_node);
  2249. -
  2250. - // Using weak references allows the interesting parts of previous
  2251. - // classes to be GC'ed when they are no longer needed. Since the
  2252. - // caller is the VMThread and we are at a safepoint, this is a good
  2253. - // time to clear out unused weak references.
  2254. -
  2255. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  2256. - _previous_versions->length()));
  2257. -
  2258. - // skip the last entry since we just added it
  2259. - for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  2260. - // check the previous versions array for a GC'ed weak refs
  2261. - pv_node = _previous_versions->at(i);
  2262. - cp_ref = pv_node->prev_constant_pool();
  2263. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2264. - if (cp_ref == NULL) {
  2265. - delete pv_node;
  2266. - _previous_versions->remove_at(i);
  2267. - // Since we are traversing the array backwards, we don't have to
  2268. - // do anything special with the index.
  2269. - continue; // robustness
  2270. - }
  2271. -
  2272. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2273. - if (cp == NULL) {
  2274. - // this entry has been GC'ed so remove it
  2275. - delete pv_node;
  2276. - _previous_versions->remove_at(i);
  2277. - // Since we are traversing the array backwards, we don't have to
  2278. - // do anything special with the index.
  2279. - continue;
  2280. - } else {
  2281. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  2282. - }
  2283. -
  2284. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2285. - if (method_refs != NULL) {
  2286. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  2287. - method_refs->length()));
  2288. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  2289. - jweak method_ref = method_refs->at(j);
  2290. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2291. - if (method_ref == NULL) {
  2292. - method_refs->remove_at(j);
  2293. - // Since we are traversing the array backwards, we don't have to
  2294. - // do anything special with the index.
  2295. - continue; // robustness
  2296. - }
  2297. -
  2298. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2299. - if (method == NULL || emcp_method_count == 0) {
  2300. - // This method entry has been GC'ed or the current
  2301. - // RedefineClasses() call has made all methods obsolete
  2302. - // so remove it.
  2303. - JNIHandles::destroy_weak_global(method_ref);
  2304. - method_refs->remove_at(j);
  2305. - } else {
  2306. - // RC_TRACE macro has an embedded ResourceMark
  2307. - RC_TRACE(0x00000400,
  2308. - ("add: %s(%s): previous method @%d in version @%d is alive",
  2309. - method->name()->as_C_string(), method->signature()->as_C_string(),
  2310. - j, i));
  2311. - }
  2312. - }
  2313. - }
  2314. - }
  2315. -
  2316. - int obsolete_method_count = old_methods->length() - emcp_method_count;
  2317. -
  2318. - if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  2319. - _previous_versions->length() > 1) {
  2320. - // We have a mix of obsolete and EMCP methods. If there is more
  2321. - // than the previous version that we just added, then we have to
  2322. - // clear out any matching EMCP method entries the hard way.
  2323. - int local_count = 0;
  2324. - for (int i = 0; i < old_methods->length(); i++) {
  2325. - if (!emcp_methods->at(i)) {
  2326. - // only obsolete methods are interesting
  2327. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2328. - Symbol* m_name = old_method->name();
  2329. - Symbol* m_signature = old_method->signature();
  2330. -
  2331. - // skip the last entry since we just added it
  2332. - for (int j = _previous_versions->length() - 2; j >= 0; j--) {
  2333. - // check the previous versions array for a GC'ed weak refs
  2334. - pv_node = _previous_versions->at(j);
  2335. - cp_ref = pv_node->prev_constant_pool();
  2336. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2337. - if (cp_ref == NULL) {
  2338. - delete pv_node;
  2339. - _previous_versions->remove_at(j);
  2340. - // Since we are traversing the array backwards, we don't have to
  2341. - // do anything special with the index.
  2342. - continue; // robustness
  2343. - }
  2344. -
  2345. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2346. - if (cp == NULL) {
  2347. - // this entry has been GC'ed so remove it
  2348. - delete pv_node;
  2349. - _previous_versions->remove_at(j);
  2350. - // Since we are traversing the array backwards, we don't have to
  2351. - // do anything special with the index.
  2352. - continue;
  2353. - }
  2354. -
  2355. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2356. - if (method_refs == NULL) {
  2357. - // We have run into a PreviousVersion generation where
  2358. - // all methods were made obsolete during that generation's
  2359. - // RedefineClasses() operation. At the time of that
  2360. - // operation, all EMCP methods were flushed so we don't
  2361. - // have to go back any further.
  2362. - //
  2363. - // A NULL method_refs is different than an empty method_refs.
  2364. - // We cannot infer any optimizations about older generations
  2365. - // from an empty method_refs for the current generation.
  2366. - break;
  2367. - }
  2368. -
  2369. - for (int k = method_refs->length() - 1; k >= 0; k--) {
  2370. - jweak method_ref = method_refs->at(k);
  2371. - assert(method_ref != NULL,
  2372. - "weak method ref was unexpectedly cleared");
  2373. - if (method_ref == NULL) {
  2374. - method_refs->remove_at(k);
  2375. - // Since we are traversing the array backwards, we don't
  2376. - // have to do anything special with the index.
  2377. - continue; // robustness
  2378. - }
  2379. -
  2380. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2381. - if (method == NULL) {
  2382. - // this method entry has been GC'ed so skip it
  2383. - JNIHandles::destroy_weak_global(method_ref);
  2384. - method_refs->remove_at(k);
  2385. - continue;
  2386. - }
  2387. -
  2388. - if (method->name() == m_name &&
  2389. - method->signature() == m_signature) {
  2390. - // The current RedefineClasses() call has made all EMCP
  2391. - // versions of this method obsolete so mark it as obsolete
  2392. - // and remove the weak ref.
  2393. - RC_TRACE(0x00000400,
  2394. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  2395. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  2396. -
  2397. - method->set_is_obsolete();
  2398. - JNIHandles::destroy_weak_global(method_ref);
  2399. - method_refs->remove_at(k);
  2400. - break;
  2401. - }
  2402. - }
  2403. -
  2404. - // The previous loop may not find a matching EMCP method, but
  2405. - // that doesn't mean that we can optimize and not go any
  2406. - // further back in the PreviousVersion generations. The EMCP
  2407. - // method for this generation could have already been GC'ed,
  2408. - // but there still may be an older EMCP method that has not
  2409. - // been GC'ed.
  2410. - }
  2411. -
  2412. - if (++local_count >= obsolete_method_count) {
  2413. - // no more obsolete methods so bail out now
  2414. - break;
  2415. - }
  2416. - }
  2417. - }
  2418. - }
  2419. -} // end add_previous_version()
  2420. -
  2421. -
  2422. // Determine if instanceKlass has a previous version.
  2423. bool instanceKlass::has_previous_version() const {
  2424. - if (_previous_versions == NULL) {
  2425. - // no previous versions array so answer is easy
  2426. - return false;
  2427. - }
  2428. -
  2429. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2430. - // Check the previous versions array for an info node that hasn't
  2431. - // been GC'ed
  2432. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2433. -
  2434. - jobject cp_ref = pv_node->prev_constant_pool();
  2435. - assert(cp_ref != NULL, "cp reference was unexpectedly cleared");
  2436. - if (cp_ref == NULL) {
  2437. - continue; // robustness
  2438. - }
  2439. -
  2440. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2441. - if (cp != NULL) {
  2442. - // we have at least one previous version
  2443. - return true;
  2444. - }
  2445. -
  2446. - // We don't have to check the method refs. If the constant pool has
  2447. - // been GC'ed then so have the methods.
  2448. - }
  2449. -
  2450. - // all of the underlying nodes' info has been GC'ed
  2451. - return false;
  2452. -} // end has_previous_version()
  2453. + return _old_version != NULL;
  2454. +}
  2455. methodOop instanceKlass::method_with_idnum(int idnum) {
  2456. methodOop m = NULL;
  2457. @@ -2854,153 +2633,3 @@ void instanceKlass::set_methods_annotations_of(int idnum, typeArrayOop anno, obj
  2458. } // if no array and idnum isn't included there is nothing to do
  2459. }
  2460. -// Construct a PreviousVersionNode entry for the array hung off
  2461. -// the instanceKlass.
  2462. -PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool,
  2463. - bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) {
  2464. -
  2465. - _prev_constant_pool = prev_constant_pool;
  2466. - _prev_cp_is_weak = prev_cp_is_weak;
  2467. - _prev_EMCP_methods = prev_EMCP_methods;
  2468. -}
  2469. -
  2470. -
  2471. -// Destroy a PreviousVersionNode
  2472. -PreviousVersionNode::~PreviousVersionNode() {
  2473. - if (_prev_constant_pool != NULL) {
  2474. - if (_prev_cp_is_weak) {
  2475. - JNIHandles::destroy_weak_global(_prev_constant_pool);
  2476. - } else {
  2477. - JNIHandles::destroy_global(_prev_constant_pool);
  2478. - }
  2479. - }
  2480. -
  2481. - if (_prev_EMCP_methods != NULL) {
  2482. - for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) {
  2483. - jweak method_ref = _prev_EMCP_methods->at(i);
  2484. - if (method_ref != NULL) {
  2485. - JNIHandles::destroy_weak_global(method_ref);
  2486. - }
  2487. - }
  2488. - delete _prev_EMCP_methods;
  2489. - }
  2490. -}
  2491. -
  2492. -
  2493. -// Construct a PreviousVersionInfo entry
  2494. -PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) {
  2495. - _prev_constant_pool_handle = constantPoolHandle(); // NULL handle
  2496. - _prev_EMCP_method_handles = NULL;
  2497. -
  2498. - jobject cp_ref = pv_node->prev_constant_pool();
  2499. - assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared");
  2500. - if (cp_ref == NULL) {
  2501. - return; // robustness
  2502. - }
  2503. -
  2504. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2505. - if (cp == NULL) {
  2506. - // Weak reference has been GC'ed. Since the constant pool has been
  2507. - // GC'ed, the methods have also been GC'ed.
  2508. - return;
  2509. - }
  2510. -
  2511. - // make the constantPoolOop safe to return
  2512. - _prev_constant_pool_handle = constantPoolHandle(cp);
  2513. -
  2514. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2515. - if (method_refs == NULL) {
  2516. - // the instanceKlass did not have any EMCP methods
  2517. - return;
  2518. - }
  2519. -
  2520. - _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10);
  2521. -
  2522. - int n_methods = method_refs->length();
  2523. - for (int i = 0; i < n_methods; i++) {
  2524. - jweak method_ref = method_refs->at(i);
  2525. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2526. - if (method_ref == NULL) {
  2527. - continue; // robustness
  2528. - }
  2529. -
  2530. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2531. - if (method == NULL) {
  2532. - // this entry has been GC'ed so skip it
  2533. - continue;
  2534. - }
  2535. -
  2536. - // make the methodOop safe to return
  2537. - _prev_EMCP_method_handles->append(methodHandle(method));
  2538. - }
  2539. -}
  2540. -
  2541. -
  2542. -// Destroy a PreviousVersionInfo
  2543. -PreviousVersionInfo::~PreviousVersionInfo() {
  2544. - // Since _prev_EMCP_method_handles is not C-heap allocated, we
  2545. - // don't have to delete it.
  2546. -}
  2547. -
  2548. -
  2549. -// Construct a helper for walking the previous versions array
  2550. -PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) {
  2551. - _previous_versions = ik->previous_versions();
  2552. - _current_index = 0;
  2553. - // _hm needs no initialization
  2554. - _current_p = NULL;
  2555. -}
  2556. -
  2557. -
  2558. -// Destroy a PreviousVersionWalker
  2559. -PreviousVersionWalker::~PreviousVersionWalker() {
  2560. - // Delete the current info just in case the caller didn't walk to
  2561. - // the end of the previous versions list. No harm if _current_p is
  2562. - // already NULL.
  2563. - delete _current_p;
  2564. -
  2565. - // When _hm is destroyed, all the Handles returned in
  2566. - // PreviousVersionInfo objects will be destroyed.
  2567. - // Also, after this destructor is finished it will be
  2568. - // safe to delete the GrowableArray allocated in the
  2569. - // PreviousVersionInfo objects.
  2570. -}
  2571. -
  2572. -
  2573. -// Return the interesting information for the next previous version
  2574. -// of the klass. Returns NULL if there are no more previous versions.
  2575. -PreviousVersionInfo* PreviousVersionWalker::next_previous_version() {
  2576. - if (_previous_versions == NULL) {
  2577. - // no previous versions so nothing to return
  2578. - return NULL;
  2579. - }
  2580. -
  2581. - delete _current_p; // cleanup the previous info for the caller
  2582. - _current_p = NULL; // reset to NULL so we don't delete same object twice
  2583. -
  2584. - int length = _previous_versions->length();
  2585. -
  2586. - while (_current_index < length) {
  2587. - PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
  2588. - PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass)
  2589. - PreviousVersionInfo(pv_node);
  2590. -
  2591. - constantPoolHandle cp_h = pv_info->prev_constant_pool_handle();
  2592. - if (cp_h.is_null()) {
  2593. - delete pv_info;
  2594. -
  2595. - // The underlying node's info has been GC'ed so try the next one.
  2596. - // We don't have to check the methods. If the constant pool has
  2597. - // GC'ed then so have the methods.
  2598. - continue;
  2599. - }
  2600. -
  2601. - // Found a node with non GC'ed info so return it. The caller will
  2602. - // need to delete pv_info when they are done with it.
  2603. - _current_p = pv_info;
  2604. - return pv_info;
  2605. - }
  2606. -
  2607. - // all of the underlying nodes' info has been GC'ed
  2608. - return NULL;
  2609. -} // end next_previous_version()
  2610. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  2611. index 8a849cb..53163b6 100644
  2612. --- a/src/share/vm/oops/instanceKlass.hpp
  2613. +++ b/src/share/vm/oops/instanceKlass.hpp
  2614. @@ -271,9 +271,6 @@ class instanceKlass: public Klass {
  2615. nmethodBucket* _dependencies; // list of dependent nmethods
  2616. nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
  2617. BreakpointInfo* _breakpoints; // bpt lists, managed by methodOop
  2618. - // Array of interesting part(s) of the previous version(s) of this
  2619. - // instanceKlass. See PreviousVersionWalker below.
  2620. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2621. // JVMTI fields can be moved to their own structure - see 6315920
  2622. unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH
  2623. jint _cached_class_file_len; // JVMTI: length of above
  2624. @@ -571,20 +568,11 @@ class instanceKlass: public Klass {
  2625. _nonstatic_oop_map_size = words;
  2626. }
  2627. - // RedefineClasses() support for previous versions:
  2628. - void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
  2629. - int emcp_method_count);
  2630. // If the _previous_versions array is non-NULL, then this klass
  2631. // has been redefined at least once even if we aren't currently
  2632. // tracking a previous version.
  2633. - bool has_been_redefined() const { return _previous_versions != NULL; }
  2634. + bool has_been_redefined() const { return _old_version != NULL; }
  2635. bool has_previous_version() const;
  2636. - void init_previous_versions() {
  2637. - _previous_versions = NULL;
  2638. - }
  2639. - GrowableArray<PreviousVersionNode *>* previous_versions() const {
  2640. - return _previous_versions;
  2641. - }
  2642. // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
  2643. void set_cached_class_file(unsigned char *class_file_bytes,
  2644. @@ -629,6 +617,7 @@ class instanceKlass: public Klass {
  2645. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  2646. size_t *length_p, jmethodID* id_p);
  2647. jmethodID jmethod_id_or_null(methodOop method);
  2648. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  2649. // cached itable index support
  2650. void set_cached_itable_index(size_t idnum, int index);
  2651. @@ -711,6 +700,7 @@ class instanceKlass: public Klass {
  2652. // subclass/subinterface checks
  2653. bool implements_interface(klassOop k) const;
  2654. + bool implements_interface_any_version(klassOop k) const;
  2655. // Access to the implementor of an interface.
  2656. klassOop implementor() const
  2657. @@ -760,6 +750,9 @@ class instanceKlass: public Klass {
  2658. void do_local_static_fields(FieldClosure* cl);
  2659. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  2660. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  2661. + void store_update_information(GrowableArray<int> &values);
  2662. + void clear_update_information();
  2663. +
  2664. void methods_do(void f(methodOop method));
  2665. void array_klasses_do(void f(klassOop k));
  2666. @@ -895,7 +888,6 @@ class instanceKlass: public Klass {
  2667. ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
  2668. #endif // !SERIALGC
  2669. -private:
  2670. // initialization state
  2671. #ifdef ASSERT
  2672. void set_init_state(ClassState state);
  2673. @@ -1057,106 +1049,6 @@ class JNIid: public CHeapObj<mtClass> {
  2674. void verify(klassOop holder);
  2675. };
  2676. -
  2677. -// If breakpoints are more numerous than just JVMTI breakpoints,
  2678. -// consider compressing this data structure.
  2679. -// It is currently a simple linked list defined in methodOop.hpp.
  2680. -
  2681. -class BreakpointInfo;
  2682. -
  2683. -
  2684. -// A collection point for interesting information about the previous
  2685. -// version(s) of an instanceKlass. This class uses weak references to
  2686. -// the information so that the information may be collected as needed
  2687. -// by the system. If the information is shared, then a regular
  2688. -// reference must be used because a weak reference would be seen as
  2689. -// collectible. A GrowableArray of PreviousVersionNodes is attached
  2690. -// to the instanceKlass as needed. See PreviousVersionWalker below.
  2691. -class PreviousVersionNode : public CHeapObj<mtClass> {
  2692. - private:
  2693. - // A shared ConstantPool is never collected so we'll always have
  2694. - // a reference to it so we can update items in the cache. We'll
  2695. - // have a weak reference to a non-shared ConstantPool until all
  2696. - // of the methods (EMCP or obsolete) have been collected; the
  2697. - // non-shared ConstantPool becomes collectible at that point.
  2698. - jobject _prev_constant_pool; // regular or weak reference
  2699. - bool _prev_cp_is_weak; // true if not a shared ConstantPool
  2700. -
  2701. - // If the previous version of the instanceKlass doesn't have any
  2702. - // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
  2703. - // EMCP methods have been collected, then _prev_EMCP_methods can
  2704. - // have a length of zero.
  2705. - GrowableArray<jweak>* _prev_EMCP_methods;
  2706. -
  2707. -public:
  2708. - PreviousVersionNode(jobject prev_constant_pool, bool prev_cp_is_weak,
  2709. - GrowableArray<jweak>* prev_EMCP_methods);
  2710. - ~PreviousVersionNode();
  2711. - jobject prev_constant_pool() const {
  2712. - return _prev_constant_pool;
  2713. - }
  2714. - GrowableArray<jweak>* prev_EMCP_methods() const {
  2715. - return _prev_EMCP_methods;
  2716. - }
  2717. -};
  2718. -
  2719. -
  2720. -// A Handle-ized version of PreviousVersionNode.
  2721. -class PreviousVersionInfo : public ResourceObj {
  2722. - private:
  2723. - constantPoolHandle _prev_constant_pool_handle;
  2724. - // If the previous version of the instanceKlass doesn't have any
  2725. - // EMCP methods, then _prev_EMCP_methods will be NULL. Since the
  2726. - // methods cannot be collected while we hold a handle,
  2727. - // _prev_EMCP_methods should never have a length of zero.
  2728. - GrowableArray<methodHandle>* _prev_EMCP_method_handles;
  2729. -
  2730. -public:
  2731. - PreviousVersionInfo(PreviousVersionNode *pv_node);
  2732. - ~PreviousVersionInfo();
  2733. - constantPoolHandle prev_constant_pool_handle() const {
  2734. - return _prev_constant_pool_handle;
  2735. - }
  2736. - GrowableArray<methodHandle>* prev_EMCP_method_handles() const {
  2737. - return _prev_EMCP_method_handles;
  2738. - }
  2739. -};
  2740. -
  2741. -
  2742. -// Helper object for walking previous versions. This helper cleans up
  2743. -// the Handles that it allocates when the helper object is destroyed.
  2744. -// The PreviousVersionInfo object returned by next_previous_version()
  2745. -// is only valid until a subsequent call to next_previous_version() or
  2746. -// the helper object is destroyed.
  2747. -class PreviousVersionWalker : public StackObj {
  2748. - private:
  2749. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2750. - int _current_index;
  2751. - // Fields for cleaning up when we are done walking the previous versions:
  2752. - // A HandleMark for the PreviousVersionInfo handles:
  2753. - HandleMark _hm;
  2754. -
  2755. - // It would be nice to have a ResourceMark field in this helper also,
  2756. - // but the ResourceMark code says to be careful to delete handles held
  2757. - // in GrowableArrays _before_ deleting the GrowableArray. Since we
  2758. - // can't guarantee the order in which the fields are destroyed, we
  2759. - // have to let the creator of the PreviousVersionWalker object do
  2760. - // the right thing. Also, adding a ResourceMark here causes an
  2761. - // include loop.
  2762. -
  2763. - // A pointer to the current info object so we can handle the deletes.
  2764. - PreviousVersionInfo * _current_p;
  2765. -
  2766. - public:
  2767. - PreviousVersionWalker(instanceKlass *ik);
  2768. - ~PreviousVersionWalker();
  2769. -
  2770. - // Return the interesting information for the next previous version
  2771. - // of the klass. Returns NULL if there are no more previous versions.
  2772. - PreviousVersionInfo* next_previous_version();
  2773. -};
  2774. -
  2775. -
  2776. //
  2777. // nmethodBucket is used to record dependent nmethods for
  2778. // deoptimization. nmethod dependencies are actually <klass, method>
  2779. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  2780. index 8e7dc12..5b9b266 100644
  2781. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  2782. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  2783. @@ -358,7 +358,7 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it
  2784. unsigned nonstatic_oop_map_count,
  2785. AccessFlags access_flags,
  2786. ReferenceType rt,
  2787. - KlassHandle host_klass, TRAPS) {
  2788. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  2789. const int nonstatic_oop_map_size =
  2790. instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count);
  2791. @@ -435,7 +435,6 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it
  2792. ik->set_jni_ids(NULL);
  2793. ik->set_osr_nmethods_head(NULL);
  2794. ik->set_breakpoints(NULL);
  2795. - ik->init_previous_versions();
  2796. ik->set_generic_signature(NULL);
  2797. ik->release_set_methods_jmethod_ids(NULL);
  2798. ik->release_set_methods_cached_itable_indices(NULL);
  2799. @@ -480,6 +479,28 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  2800. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  2801. klassKlass::oop_print_on(obj, st);
  2802. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  2803. +
  2804. + st->print(BULLET"revision: %d", ik->revision_number());
  2805. +
  2806. + if (ik->new_version() != NULL) {
  2807. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  2808. + }
  2809. +
  2810. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  2811. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  2812. + }
  2813. +
  2814. + if (ik->old_version() != NULL) {
  2815. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  2816. + }
  2817. +
  2818. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  2819. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  2820. + }
  2821. +
  2822. + st->cr();
  2823. +
  2824. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  2825. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  2826. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  2827. @@ -537,26 +558,6 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  2828. st->cr();
  2829. }
  2830. - {
  2831. - ResourceMark rm;
  2832. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  2833. - // contain a GrowableArray of handles. We have to clean up the
  2834. - // GrowableArray _after_ the PreviousVersionWalker destructor
  2835. - // has destroyed the handles.
  2836. - {
  2837. - bool have_pv = false;
  2838. - PreviousVersionWalker pvw(ik);
  2839. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  2840. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  2841. - if (!have_pv)
  2842. - st->print(BULLET"previous version: ");
  2843. - have_pv = true;
  2844. - pv_info->prev_constant_pool_handle()()->print_value_on(st);
  2845. - }
  2846. - if (have_pv) st->cr();
  2847. - } // pvw is cleaned up
  2848. - } // rm is cleaned up
  2849. -
  2850. if (ik->generic_signature() != NULL) {
  2851. st->print(BULLET"generic signature: ");
  2852. ik->generic_signature()->print_value_on(st);
  2853. @@ -663,7 +664,7 @@ void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
  2854. }
  2855. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  2856. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  2857. - guarantee(sib->super() == super, "siblings should have same superklass");
  2858. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  2859. sib = sib->next_sibling();
  2860. }
  2861. diff --git a/src/share/vm/oops/instanceKlassKlass.hpp b/src/share/vm/oops/instanceKlassKlass.hpp
  2862. index df674a9..45d0b66 100644
  2863. --- a/src/share/vm/oops/instanceKlassKlass.hpp
  2864. +++ b/src/share/vm/oops/instanceKlassKlass.hpp
  2865. @@ -50,6 +50,7 @@ class instanceKlassKlass : public klassKlass {
  2866. AccessFlags access_flags,
  2867. ReferenceType rt,
  2868. KlassHandle host_klass,
  2869. + KlassHandle old_klass,
  2870. TRAPS);
  2871. // Casting from klassOop
  2872. diff --git a/src/share/vm/oops/instanceMirrorKlass.cpp b/src/share/vm/oops/instanceMirrorKlass.cpp
  2873. index e0dd7d7..a7eec08 100644
  2874. --- a/src/share/vm/oops/instanceMirrorKlass.cpp
  2875. +++ b/src/share/vm/oops/instanceMirrorKlass.cpp
  2876. @@ -156,6 +156,13 @@ void instanceMirrorKlass::oop_follow_contents(oop obj) {
  2877. assert_is_in_closed_subset)
  2878. }
  2879. +void instanceMirrorKlass::oop_fields_iterate(oop obj, OopClosure* blk) {
  2880. + InstanceMirrorKlass_OOP_ITERATE( \
  2881. + start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
  2882. + blk->do_oop(p), \
  2883. + assert_is_in_closed_subset)
  2884. +}
  2885. +
  2886. #ifndef SERIALGC
  2887. void instanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm,
  2888. oop obj) {
  2889. diff --git a/src/share/vm/oops/instanceMirrorKlass.hpp b/src/share/vm/oops/instanceMirrorKlass.hpp
  2890. index 2b8b2f4..31969c7 100644
  2891. --- a/src/share/vm/oops/instanceMirrorKlass.hpp
  2892. +++ b/src/share/vm/oops/instanceMirrorKlass.hpp
  2893. @@ -79,6 +79,9 @@ class instanceMirrorKlass: public instanceKlass {
  2894. DEFINE_ALLOCATE_PERMANENT(instanceMirrorKlass);
  2895. instanceOop allocate_instance(KlassHandle k, TRAPS);
  2896. + // Class redefinition, iterate static fields
  2897. + static void oop_fields_iterate(oop obj, OopClosure* blk);
  2898. +
  2899. // Garbage collection
  2900. int oop_adjust_pointers(oop obj);
  2901. void oop_follow_contents(oop obj);
  2902. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  2903. index 7db4f03..1171487 100644
  2904. --- a/src/share/vm/oops/instanceRefKlass.cpp
  2905. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  2906. @@ -455,10 +455,13 @@ void instanceRefKlass::update_nonstatic_oop_maps(klassOop k) {
  2907. instanceKlass* ik = instanceKlass::cast(k);
  2908. // Check that we have the right class
  2909. - debug_only(static bool first_time = true);
  2910. - assert(k == SystemDictionary::Reference_klass() && first_time,
  2911. - "Invalid update of maps");
  2912. - debug_only(first_time = false);
  2913. +
  2914. + // (tw) Asserts no longer valid for class redefinition
  2915. + // debug_only(static bool first_time = true);
  2916. +
  2917. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  2918. + // "Invalid update of maps");
  2919. + //debug_only(first_time = false);
  2920. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  2921. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  2922. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  2923. index 596d5ad..a928777 100644
  2924. --- a/src/share/vm/oops/klass.cpp
  2925. +++ b/src/share/vm/oops/klass.cpp
  2926. @@ -161,6 +161,13 @@ klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
  2927. kl->set_alloc_size(0);
  2928. TRACE_INIT_ID(kl);
  2929. + kl->set_redefinition_flags(Klass::NoRedefinition);
  2930. + kl->set_redefining(false);
  2931. + kl->set_new_version(NULL);
  2932. + kl->set_old_version(NULL);
  2933. + kl->set_redefinition_index(-1);
  2934. + kl->set_revision_number(-1);
  2935. +
  2936. kl->set_prototype_header(markOopDesc::prototype());
  2937. kl->set_biased_lock_revocation_count(0);
  2938. kl->set_last_biased_lock_bulk_revocation_time(0);
  2939. @@ -232,7 +239,7 @@ void Klass::initialize_supers(klassOop k, TRAPS) {
  2940. set_super(NULL);
  2941. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  2942. assert(super_depth() == 0, "Object must already be initialized properly");
  2943. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  2944. + } else if (k != super() || k->klass_part()->super() == NULL) {
  2945. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  2946. "initialize this only once to a non-trivial value");
  2947. set_super(k);
  2948. @@ -385,7 +392,7 @@ void Klass::append_to_sibling_list() {
  2949. void Klass::remove_from_sibling_list() {
  2950. // remove receiver from sibling list
  2951. instanceKlass* super = superklass();
  2952. - assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
  2953. + assert(super != NULL || as_klassOop()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version(), "should have super");
  2954. if (super == NULL) return; // special case: class Object
  2955. if (super->subklass() == this) {
  2956. // first subklass
  2957. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  2958. index bcbd4e7..bf242d9 100644
  2959. --- a/src/share/vm/oops/klass.hpp
  2960. +++ b/src/share/vm/oops/klass.hpp
  2961. @@ -170,6 +170,7 @@ class Klass_vtbl {
  2962. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  2963. };
  2964. +template<class L, class R> class Pair;
  2965. class Klass : public Klass_vtbl {
  2966. friend class VMStructs;
  2967. @@ -222,6 +223,31 @@ class Klass : public Klass_vtbl {
  2968. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  2969. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  2970. + // (tw) Different class redefinition flags of code evolution.
  2971. + enum RedefinitionFlags {
  2972. +
  2973. + // This class is not redefined at all!
  2974. + NoRedefinition,
  2975. +
  2976. + // There are changes to the class meta data.
  2977. + ModifyClass = 1,
  2978. +
  2979. + // The size of the class meta data changes.
  2980. + ModifyClassSize = ModifyClass << 1,
  2981. +
  2982. + // There are change to the instance format.
  2983. + ModifyInstances = ModifyClassSize << 1,
  2984. +
  2985. + // The size of instances changes.
  2986. + ModifyInstanceSize = ModifyInstances << 1,
  2987. +
  2988. + // A super type of this class is removed.
  2989. + RemoveSuperType = ModifyInstanceSize << 1,
  2990. +
  2991. + // This class has been marked as an affected class.
  2992. + MarkedAsAffected = RemoveSuperType << 1
  2993. + };
  2994. +
  2995. protected:
  2996. //
  2997. // The oop block. All oop fields must be declared here and only oop fields
  2998. @@ -241,6 +267,10 @@ class Klass : public Klass_vtbl {
  2999. oop _java_mirror;
  3000. // Superclass
  3001. klassOop _super;
  3002. + // Old class
  3003. + klassOop _old_version;
  3004. + // New class
  3005. + klassOop _new_version;
  3006. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3007. klassOop _subklass;
  3008. // Sibling link (or NULL); links all subklasses of a klass
  3009. @@ -253,6 +283,16 @@ class Klass : public Klass_vtbl {
  3010. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3011. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3012. + // (tw) Non-oop fields for enhanced class redefinition
  3013. + jint _revision_number; // The revision number for redefined classes
  3014. + jint _redefinition_index; // Index of this class when performing the redefinition
  3015. + bool _subtype_changed;
  3016. + int _redefinition_flags; // Level of class redefinition
  3017. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3018. + bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
  3019. + int * _update_information; // Update information
  3020. + bool _is_redefining;
  3021. +
  3022. #ifndef PRODUCT
  3023. int _verify_count; // to avoid redundant verifies
  3024. #endif
  3025. @@ -301,6 +341,75 @@ class Klass : public Klass_vtbl {
  3026. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3027. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3028. + // BEGIN class redefinition utilities
  3029. +
  3030. + // double links between new and old version of a class
  3031. + klassOop old_version() const { return _old_version; }
  3032. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3033. + klassOop new_version() const { return _new_version; }
  3034. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3035. +
  3036. + // A subtype of this class is no longer a subtype
  3037. + bool has_subtype_changed() const { return _subtype_changed; }
  3038. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3039. + _subtype_changed = b; }
  3040. + // state of being redefined
  3041. + int redefinition_index() const { return _redefinition_index; }
  3042. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3043. + void set_redefining(bool b) { _is_redefining = b; }
  3044. + bool is_redefining() const { return _is_redefining; }
  3045. + int redefinition_flags() const { return _redefinition_flags; }
  3046. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3047. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3048. + void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
  3049. + void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
  3050. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3051. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3052. +
  3053. + // update information
  3054. + int *update_information() const { return _update_information; }
  3055. + void set_update_information(int *info) { _update_information = info; }
  3056. +
  3057. + bool is_same_or_older_version(klassOop klass) const {
  3058. + if (Klass::cast(klass) == this) { return true; }
  3059. + else if (_old_version == NULL) { return false; }
  3060. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3061. + }
  3062. +
  3063. + // Revision number for redefined classes, -1 for originally loaded classes
  3064. + jint revision_number() const {
  3065. + return _revision_number;
  3066. + }
  3067. +
  3068. + bool was_redefined() const {
  3069. + return _revision_number != -1;
  3070. + }
  3071. +
  3072. + void set_revision_number(jint number) {
  3073. + _revision_number = number;
  3074. + }
  3075. +
  3076. + klassOop oldest_version() const {
  3077. + if (_old_version == NULL) { return this->as_klassOop(); }
  3078. + else { return _old_version->klass_part()->oldest_version(); };
  3079. + }
  3080. +
  3081. + klassOop newest_version() const {
  3082. + if (_new_version == NULL) { return this->as_klassOop(); }
  3083. + else { return _new_version->klass_part()->newest_version(); };
  3084. + }
  3085. +
  3086. + klassOop active_version() const {
  3087. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3088. + else { return _new_version->klass_part()->active_version(); };
  3089. + }
  3090. +
  3091. + bool is_newest_version() const {
  3092. + return _new_version == NULL;
  3093. + }
  3094. +
  3095. + // END class redefinition utilities
  3096. +
  3097. objArrayOop secondary_supers() const { return _secondary_supers; }
  3098. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3099. @@ -361,6 +470,8 @@ class Klass : public Klass_vtbl {
  3100. void set_next_sibling(klassOop s);
  3101. oop* adr_super() const { return (oop*)&_super; }
  3102. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3103. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3104. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3105. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3106. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3107. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3108. index 06809d5..1050eda 100644
  3109. --- a/src/share/vm/oops/klassKlass.cpp
  3110. +++ b/src/share/vm/oops/klassKlass.cpp
  3111. @@ -68,6 +68,8 @@ void klassKlass::oop_follow_contents(oop obj) {
  3112. Klass* k = Klass::cast(klassOop(obj));
  3113. // If we are alive it is valid to keep our superclass and subtype caches alive
  3114. MarkSweep::mark_and_push(k->adr_super());
  3115. + MarkSweep::mark_and_push(k->adr_old_version());
  3116. + MarkSweep::mark_and_push(k->adr_new_version());
  3117. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3118. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3119. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3120. @@ -87,6 +89,8 @@ void klassKlass::oop_follow_contents(ParCompactionManager* cm,
  3121. Klass* k = Klass::cast(klassOop(obj));
  3122. // If we are alive it is valid to keep our superclass and subtype caches alive
  3123. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3124. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3125. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3126. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3127. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3128. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3129. @@ -106,6 +110,8 @@ int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  3130. int size = oop_size(obj);
  3131. Klass* k = Klass::cast(klassOop(obj));
  3132. blk->do_oop(k->adr_super());
  3133. + blk->do_oop(k->adr_old_version());
  3134. + blk->do_oop(k->adr_new_version());
  3135. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3136. blk->do_oop(k->adr_primary_supers()+i);
  3137. blk->do_oop(k->adr_secondary_super_cache());
  3138. @@ -134,6 +140,10 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  3139. oop* adr;
  3140. adr = k->adr_super();
  3141. if (mr.contains(adr)) blk->do_oop(adr);
  3142. + adr = k->adr_old_version();
  3143. + if (mr.contains(adr)) blk->do_oop(adr);
  3144. + adr = k->adr_new_version();
  3145. + if (mr.contains(adr)) blk->do_oop(adr);
  3146. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3147. adr = k->adr_primary_supers()+i;
  3148. if (mr.contains(adr)) blk->do_oop(adr);
  3149. @@ -167,6 +177,8 @@ int klassKlass::oop_adjust_pointers(oop obj) {
  3150. Klass* k = Klass::cast(klassOop(obj));
  3151. MarkSweep::adjust_pointer(k->adr_super());
  3152. + MarkSweep::adjust_pointer(k->adr_new_version());
  3153. + MarkSweep::adjust_pointer(k->adr_old_version());
  3154. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3155. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3156. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3157. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  3158. index 94e2e04..a683a4b 100644
  3159. --- a/src/share/vm/oops/klassVtable.cpp
  3160. +++ b/src/share/vm/oops/klassVtable.cpp
  3161. @@ -628,17 +628,13 @@ void klassVtable::adjust_method_entries(methodOop* old_methods, methodOop* new_m
  3162. if (unchecked_method_at(index) == old_method) {
  3163. put_method_at(new_method, index);
  3164. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3165. + IF_TRACE_RC4 {
  3166. if (!(*trace_name_printed)) {
  3167. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3168. - RC_TRACE_MESG(("adjust: name=%s",
  3169. - Klass::cast(old_method->method_holder())->external_name()));
  3170. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3171. *trace_name_printed = true;
  3172. }
  3173. - // RC_TRACE macro has an embedded ResourceMark
  3174. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  3175. - new_method->name()->as_C_string(),
  3176. - new_method->signature()->as_C_string()));
  3177. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  3178. + new_method->signature()->as_C_string());
  3179. }
  3180. // cannot 'break' here; see for-loop comment above.
  3181. }
  3182. @@ -1008,17 +1004,13 @@ void klassItable::adjust_method_entries(methodOop* old_methods, methodOop* new_m
  3183. if (ime->method() == old_method) {
  3184. ime->initialize(new_method);
  3185. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3186. + IF_TRACE_RC4 {
  3187. if (!(*trace_name_printed)) {
  3188. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3189. - RC_TRACE_MESG(("adjust: name=%s",
  3190. - Klass::cast(old_method->method_holder())->external_name()));
  3191. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3192. *trace_name_printed = true;
  3193. }
  3194. - // RC_TRACE macro has an embedded ResourceMark
  3195. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  3196. - new_method->name()->as_C_string(),
  3197. - new_method->signature()->as_C_string()));
  3198. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  3199. + new_method->signature()->as_C_string());
  3200. }
  3201. // cannot 'break' here; see for-loop comment above.
  3202. }
  3203. @@ -1241,6 +1233,7 @@ void klassVtable::verify(outputStream* st, bool forced) {
  3204. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  3205. vtableEntry* vte = &vt->table()[index];
  3206. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  3207. if (vte->method()->name() != table()[index].method()->name() ||
  3208. vte->method()->signature() != table()[index].method()->signature()) {
  3209. fatal("mismatched name/signature of vtable entries");
  3210. @@ -1260,6 +1253,8 @@ void klassVtable::print() {
  3211. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3212. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  3213. + // (tw) TODO: Check: Does not hold?
  3214. + if (method() != NULL) {
  3215. assert(method() != NULL, "must have set method");
  3216. method()->verify();
  3217. // we sub_type, because it could be a miranda method
  3218. @@ -1267,7 +1262,13 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3219. #ifndef PRODUCT
  3220. print();
  3221. #endif
  3222. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  3223. + klassOop first_klass = vt->klass()();
  3224. + klassOop second_klass = method()->method_holder();
  3225. + // (tw) the following fatal does not work for old versions of classes
  3226. + if (first_klass->klass_part()->is_newest_version()) {
  3227. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  3228. + }
  3229. + }
  3230. }
  3231. }
  3232. @@ -1275,8 +1276,8 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3233. void vtableEntry::print() {
  3234. ResourceMark rm;
  3235. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  3236. if (Verbose) {
  3237. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  3238. tty->print("m %#lx ", (address)method());
  3239. }
  3240. }
  3241. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  3242. index 75d0b09..c4be146 100644
  3243. --- a/src/share/vm/oops/methodKlass.cpp
  3244. +++ b/src/share/vm/oops/methodKlass.cpp
  3245. @@ -93,6 +93,9 @@ methodOop methodKlass::allocate(constMethodHandle xconst,
  3246. m->set_adapter_entry(NULL);
  3247. m->clear_code(); // from_c/from_i get set to c2i/i2i
  3248. + m->set_new_version(NULL);
  3249. + m->set_old_version(NULL);
  3250. +
  3251. if (access_flags.is_native()) {
  3252. m->clear_native_function();
  3253. m->set_signature_handler(NULL);
  3254. @@ -122,6 +125,8 @@ void methodKlass::oop_follow_contents(oop obj) {
  3255. // Performance tweak: We skip iterating over the klass pointer since we
  3256. // know that Universe::methodKlassObj never moves.
  3257. MarkSweep::mark_and_push(m->adr_constMethod());
  3258. + MarkSweep::mark_and_push(m->adr_new_version());
  3259. + MarkSweep::mark_and_push(m->adr_old_version());
  3260. if (m->method_data() != NULL) {
  3261. MarkSweep::mark_and_push(m->adr_method_data());
  3262. }
  3263. @@ -135,6 +140,8 @@ void methodKlass::oop_follow_contents(ParCompactionManager* cm,
  3264. // Performance tweak: We skip iterating over the klass pointer since we
  3265. // know that Universe::methodKlassObj never moves.
  3266. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  3267. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  3268. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  3269. #ifdef COMPILER2
  3270. if (m->method_data() != NULL) {
  3271. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  3272. @@ -152,6 +159,8 @@ int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  3273. // Performance tweak: We skip iterating over the klass pointer since we
  3274. // know that Universe::methodKlassObj never moves
  3275. blk->do_oop(m->adr_constMethod());
  3276. + blk->do_oop(m->adr_new_version());
  3277. + blk->do_oop(m->adr_old_version());
  3278. if (m->method_data() != NULL) {
  3279. blk->do_oop(m->adr_method_data());
  3280. }
  3281. @@ -170,6 +179,10 @@ int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  3282. oop* adr;
  3283. adr = m->adr_constMethod();
  3284. if (mr.contains(adr)) blk->do_oop(adr);
  3285. + adr = m->adr_new_version();
  3286. + if (mr.contains(adr)) blk->do_oop(adr);
  3287. + adr = m->adr_old_version();
  3288. + if (mr.contains(adr)) blk->do_oop(adr);
  3289. if (m->method_data() != NULL) {
  3290. adr = m->adr_method_data();
  3291. if (mr.contains(adr)) blk->do_oop(adr);
  3292. @@ -187,6 +200,8 @@ int methodKlass::oop_adjust_pointers(oop obj) {
  3293. // Performance tweak: We skip iterating over the klass pointer since we
  3294. // know that Universe::methodKlassObj never moves.
  3295. MarkSweep::adjust_pointer(m->adr_constMethod());
  3296. + MarkSweep::adjust_pointer(m->adr_new_version());
  3297. + MarkSweep::adjust_pointer(m->adr_old_version());
  3298. if (m->method_data() != NULL) {
  3299. MarkSweep::adjust_pointer(m->adr_method_data());
  3300. }
  3301. @@ -202,6 +217,8 @@ int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
  3302. assert(obj->is_method(), "should be method");
  3303. methodOop m = methodOop(obj);
  3304. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  3305. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  3306. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  3307. #ifdef COMPILER2
  3308. if (m->method_data() != NULL) {
  3309. PSParallelCompact::adjust_pointer(m->adr_method_data());
  3310. @@ -222,7 +239,18 @@ void methodKlass::oop_print_on(oop obj, outputStream* st) {
  3311. methodOop m = methodOop(obj);
  3312. // get the effect of PrintOopAddress, always, for methods:
  3313. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  3314. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  3315. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  3316. +
  3317. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  3318. + st->print(" (old)");
  3319. + }
  3320. + st->cr();
  3321. +
  3322. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  3323. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  3324. + st->print_cr(" - new version: "INTPTR_FORMAT, (address)m->new_version());
  3325. + st->print_cr(" - old version: "INTPTR_FORMAT, (address)m->old_version());
  3326. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  3327. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  3328. m->constants()->print_value_on(st); st->cr();
  3329. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  3330. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  3331. index 4f59d3a..32cb4cf 100644
  3332. --- a/src/share/vm/oops/methodOop.cpp
  3333. +++ b/src/share/vm/oops/methodOop.cpp
  3334. @@ -1061,6 +1061,8 @@ methodHandle methodOopDesc::clone_with_new_data(methodHandle m, u_char* new_code
  3335. // Reset correct method/const method, method size, and parameter info
  3336. newm->set_constMethod(newcm);
  3337. + newm->set_new_version(newm->new_version());
  3338. + newm->set_old_version(newm->old_version());
  3339. newm->constMethod()->set_code_size(new_code_length);
  3340. newm->constMethod()->set_constMethod_size(new_const_method_size);
  3341. newm->set_method_size(new_method_size);
  3342. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  3343. index 486e106..e35d5ed 100644
  3344. --- a/src/share/vm/oops/methodOop.hpp
  3345. +++ b/src/share/vm/oops/methodOop.hpp
  3346. @@ -114,6 +114,10 @@ class methodOopDesc : public oopDesc {
  3347. AccessFlags _access_flags; // Access flags
  3348. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  3349. // note: can have vtables with >2**16 elements (because of inheritance)
  3350. + // (tw) Newer version of method available?
  3351. + methodOop _new_version;
  3352. + methodOop _old_version;
  3353. +
  3354. #ifdef CC_INTERP
  3355. int _result_index; // C++ interpreter needs for converting results to/from stack
  3356. #endif
  3357. @@ -175,6 +179,29 @@ class methodOopDesc : public oopDesc {
  3358. int name_index() const { return constMethod()->name_index(); }
  3359. void set_name_index(int index) { constMethod()->set_name_index(index); }
  3360. + methodOop new_version() const {return _new_version; }
  3361. + void set_new_version(methodOop m) { _new_version = m; }
  3362. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  3363. +
  3364. + methodOop old_version() const {return _old_version; };
  3365. + void set_old_version(methodOop m) {
  3366. + if (m == NULL) {
  3367. + _old_version = NULL;
  3368. + return;
  3369. + }
  3370. +
  3371. + assert(_old_version == NULL, "may only be set once");
  3372. + assert(this->code_size() == m->code_size(), "must have same code length");
  3373. + _old_version = m;
  3374. + }
  3375. +
  3376. + methodOop oldest_version() const {
  3377. + if(_old_version == NULL) return (methodOop)this;
  3378. + else {
  3379. + return old_version()->oldest_version();
  3380. + }
  3381. + }
  3382. +
  3383. // signature
  3384. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  3385. int signature_index() const { return constMethod()->signature_index(); }
  3386. @@ -734,6 +761,8 @@ class methodOopDesc : public oopDesc {
  3387. // Garbage collection support
  3388. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  3389. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3390. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3391. oop* adr_method_data() const { return (oop*)&_method_data; }
  3392. };
  3393. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  3394. index 5982c88..4873fca 100644
  3395. --- a/src/share/vm/oops/oop.hpp
  3396. +++ b/src/share/vm/oops/oop.hpp
  3397. @@ -95,6 +95,7 @@ class oopDesc {
  3398. narrowOop* compressed_klass_addr();
  3399. void set_klass(klassOop k);
  3400. + void set_klass_no_check(klassOop k);
  3401. // For klass field compression
  3402. int klass_gap() const;
  3403. @@ -135,6 +136,7 @@ class oopDesc {
  3404. bool is_array() const;
  3405. bool is_objArray() const;
  3406. bool is_klass() const;
  3407. + bool is_instanceKlass() const;
  3408. bool is_thread() const;
  3409. bool is_method() const;
  3410. bool is_constMethod() const;
  3411. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  3412. index f4eb2f7..0acb346 100644
  3413. --- a/src/share/vm/oops/oop.inline.hpp
  3414. +++ b/src/share/vm/oops/oop.inline.hpp
  3415. @@ -123,6 +123,14 @@ inline void oopDesc::set_klass(klassOop k) {
  3416. }
  3417. }
  3418. +inline void oopDesc::set_klass_no_check(klassOop k) {
  3419. + if (UseCompressedOops) {
  3420. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  3421. + } else {
  3422. + oop_store_without_check(klass_addr(), (oop) k);
  3423. + }
  3424. +}
  3425. +
  3426. inline int oopDesc::klass_gap() const {
  3427. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  3428. }
  3429. @@ -156,6 +164,7 @@ inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_
  3430. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  3431. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  3432. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  3433. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  3434. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  3435. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  3436. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  3437. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  3438. index 2123991..6cbd78c 100644
  3439. --- a/src/share/vm/prims/jni.cpp
  3440. +++ b/src/share/vm/prims/jni.cpp
  3441. @@ -406,7 +406,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
  3442. }
  3443. }
  3444. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3445. - Handle(), &st, true,
  3446. + Handle(), &st, true, KlassHandle(),
  3447. CHECK_NULL);
  3448. if (TraceClassResolution && k != NULL) {
  3449. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  3450. index 7dcd968..d59052f 100644
  3451. --- a/src/share/vm/prims/jvm.cpp
  3452. +++ b/src/share/vm/prims/jvm.cpp
  3453. @@ -872,7 +872,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
  3454. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  3455. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3456. protection_domain, &st,
  3457. - verify != 0,
  3458. + verify != 0, KlassHandle(),
  3459. CHECK_NULL);
  3460. if (TraceClassResolution && k != NULL) {
  3461. diff --git a/src/share/vm/prims/jvm_misc.hpp b/src/share/vm/prims/jvm_misc.hpp
  3462. index 2b46e36..549e949 100644
  3463. --- a/src/share/vm/prims/jvm_misc.hpp
  3464. +++ b/src/share/vm/prims/jvm_misc.hpp
  3465. @@ -84,6 +84,7 @@ extern "C" {
  3466. (JNIEnv *env, jobject obj, jfieldID fieldID);
  3467. }
  3468. +// TODO(tw): Check if we need to "unquicken" because of class redefinition.
  3469. void quicken_jni_functions();
  3470. address jni_GetBooleanField_addr();
  3471. address jni_GetByteField_addr();
  3472. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  3473. index 4ac6b82..30b8e84 100644
  3474. --- a/src/share/vm/prims/jvmtiEnv.cpp
  3475. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  3476. @@ -290,7 +290,10 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  3477. class_definitions[index].klass = jcls;
  3478. }
  3479. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  3480. - VMThread::execute(&op);
  3481. + {
  3482. + MutexLocker sd_mutex(RedefineClasses_lock);
  3483. + VMThread::execute(&op);
  3484. + }
  3485. return (op.check_error());
  3486. } /* end RetransformClasses */
  3487. @@ -299,9 +302,12 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  3488. // class_definitions - pre-checked for NULL
  3489. jvmtiError
  3490. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  3491. -//TODO: add locking
  3492. +
  3493. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  3494. - VMThread::execute(&op);
  3495. + {
  3496. + MutexLocker sd_mutex(RedefineClasses_lock);
  3497. + VMThread::execute(&op);
  3498. + }
  3499. return (op.check_error());
  3500. } /* end RedefineClasses */
  3501. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  3502. index ec8ede3..2bd5983 100644
  3503. --- a/src/share/vm/prims/jvmtiExport.cpp
  3504. +++ b/src/share/vm/prims/jvmtiExport.cpp
  3505. @@ -2296,7 +2296,7 @@ JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(N
  3506. // iterate over any code blob descriptors collected and post a
  3507. // DYNAMIC_CODE_GENERATED event to the profiler.
  3508. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  3509. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  3510. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  3511. // iterate over any code blob descriptors that we collected
  3512. if (_code_blobs != NULL) {
  3513. for (int i=0; i<_code_blobs->length(); i++) {
  3514. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  3515. index d3fa140..31a8a19 100644
  3516. --- a/src/share/vm/prims/jvmtiImpl.cpp
  3517. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  3518. @@ -284,60 +284,11 @@ address JvmtiBreakpoint::getBcp() {
  3519. }
  3520. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  3521. - ((methodOopDesc*)_method->*meth_act)(_bci);
  3522. -
  3523. - // add/remove breakpoint to/from versions of the method that
  3524. - // are EMCP. Directly or transitively obsolete methods are
  3525. - // not saved in the PreviousVersionInfo.
  3526. - Thread *thread = Thread::current();
  3527. - instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder());
  3528. - Symbol* m_name = _method->name();
  3529. - Symbol* m_signature = _method->signature();
  3530. -
  3531. - {
  3532. - ResourceMark rm(thread);
  3533. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  3534. - // contain a GrowableArray of handles. We have to clean up the
  3535. - // GrowableArray _after_ the PreviousVersionWalker destructor
  3536. - // has destroyed the handles.
  3537. - {
  3538. - // search previous versions if they exist
  3539. - PreviousVersionWalker pvw((instanceKlass *)ikh()->klass_part());
  3540. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  3541. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  3542. - GrowableArray<methodHandle>* methods =
  3543. - pv_info->prev_EMCP_method_handles();
  3544. -
  3545. - if (methods == NULL) {
  3546. - // We have run into a PreviousVersion generation where
  3547. - // all methods were made obsolete during that generation's
  3548. - // RedefineClasses() operation. At the time of that
  3549. - // operation, all EMCP methods were flushed so we don't
  3550. - // have to go back any further.
  3551. - //
  3552. - // A NULL methods array is different than an empty methods
  3553. - // array. We cannot infer any optimizations about older
  3554. - // generations from an empty methods array for the current
  3555. - // generation.
  3556. - break;
  3557. - }
  3558. -
  3559. - for (int i = methods->length() - 1; i >= 0; i--) {
  3560. - methodHandle method = methods->at(i);
  3561. - if (method->name() == m_name && method->signature() == m_signature) {
  3562. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  3563. - meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  3564. - method->name()->as_C_string(),
  3565. - method->signature()->as_C_string()));
  3566. - assert(!method->is_obsolete(), "only EMCP methods here");
  3567. -
  3568. - ((methodOopDesc*)method()->*meth_act)(_bci);
  3569. - break;
  3570. - }
  3571. - }
  3572. - }
  3573. - } // pvw is cleaned up
  3574. - } // rm is cleaned up
  3575. + methodOop method = _method;
  3576. + while (method != NULL) {
  3577. + ((methodOopDesc*)method->*meth_act)(_bci);
  3578. + method = method->old_version();
  3579. + }
  3580. }
  3581. void JvmtiBreakpoint::set() {
  3582. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3583. index eb52388..432e15a 100644
  3584. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3585. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3586. @@ -1,5 +1,5 @@
  3587. /*
  3588. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  3589. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  3590. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3591. *
  3592. * This code is free software; you can redistribute it and/or modify it
  3593. @@ -38,490 +38,669 @@
  3594. #include "runtime/deoptimization.hpp"
  3595. #include "runtime/relocator.hpp"
  3596. #include "utilities/bitMap.inline.hpp"
  3597. +#include "prims/jvmtiClassFileReconstituter.hpp"
  3598. +#include "compiler/compileBroker.hpp"
  3599. +#include "oops/instanceMirrorKlass.hpp"
  3600. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  3601. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  3602. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  3603. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  3604. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  3605. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  3606. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  3607. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  3608. +int* VM_RedefineClasses::_deleted_methods = NULL;
  3609. +int* VM_RedefineClasses::_added_methods = NULL;
  3610. int VM_RedefineClasses::_matching_methods_length = 0;
  3611. int VM_RedefineClasses::_deleted_methods_length = 0;
  3612. int VM_RedefineClasses::_added_methods_length = 0;
  3613. -klassOop VM_RedefineClasses::_the_class_oop = NULL;
  3614. +GrowableArray<instanceKlassHandle>* VM_RedefineClasses::_affected_klasses = NULL;
  3615. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  3616. - const jvmtiClassDefinition *class_defs,
  3617. - JvmtiClassLoadKind class_load_kind) {
  3618. +// Holds the revision number of the current class redefinition
  3619. +int VM_RedefineClasses::_revision_number = -1;
  3620. +
  3621. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  3622. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
  3623. + RC_TIMER_START(_timer_total);
  3624. _class_count = class_count;
  3625. _class_defs = class_defs;
  3626. _class_load_kind = class_load_kind;
  3627. - _res = JVMTI_ERROR_NONE;
  3628. + _result = JVMTI_ERROR_NONE;
  3629. }
  3630. -bool VM_RedefineClasses::doit_prologue() {
  3631. - if (_class_count == 0) {
  3632. - _res = JVMTI_ERROR_NONE;
  3633. - return false;
  3634. +VM_RedefineClasses::~VM_RedefineClasses() {
  3635. + unlock_threads();
  3636. + RC_TIMER_STOP(_timer_total);
  3637. +
  3638. + if (TimeRedefineClasses) {
  3639. + tty->print_cr("");
  3640. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  3641. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  3642. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  3643. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  3644. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  3645. + tty->print_cr("Timing Heap Iteration: %d", _timer_heap_iteration.milliseconds());
  3646. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  3647. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  3648. + tty->print_cr("------------------------------------------------------------------");
  3649. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  3650. + tty->print_cr("");
  3651. }
  3652. - if (_class_defs == NULL) {
  3653. - _res = JVMTI_ERROR_NULL_POINTER;
  3654. - return false;
  3655. +}
  3656. +
  3657. +void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  3658. + typeArrayOop save;
  3659. +
  3660. + save = scratch_class->get_method_annotations_of(i);
  3661. + scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  3662. + scratch_class->set_method_annotations_of(j, save);
  3663. +
  3664. + save = scratch_class->get_method_parameter_annotations_of(i);
  3665. + scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  3666. + scratch_class->set_method_parameter_annotations_of(j, save);
  3667. +
  3668. + save = scratch_class->get_method_default_annotations_of(i);
  3669. + scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  3670. + scratch_class->set_method_default_annotations_of(j, save);
  3671. +}
  3672. +
  3673. +void VM_RedefineClasses::add_affected_klasses( klassOop klass )
  3674. +{
  3675. + assert(!_affected_klasses->contains(klass), "must not occur more than once!");
  3676. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  3677. +
  3678. + Klass* k = klass->klass_part();
  3679. +
  3680. + if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3681. + _affected_klasses->append(klass);
  3682. + return;
  3683. }
  3684. - for (int i = 0; i < _class_count; i++) {
  3685. - if (_class_defs[i].klass == NULL) {
  3686. - _res = JVMTI_ERROR_INVALID_CLASS;
  3687. - return false;
  3688. - }
  3689. - if (_class_defs[i].class_byte_count == 0) {
  3690. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3691. - return false;
  3692. +
  3693. + for (juint i = 0; i < k->super_depth(); i++) {
  3694. + klassOop primary_oop = k->primary_super_of_depth(i);
  3695. + // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
  3696. + if (primary_oop == NULL) break;
  3697. + Klass* primary = Klass::cast(primary_oop);
  3698. + if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3699. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  3700. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  3701. + _affected_klasses->append(klass);
  3702. + return;
  3703. }
  3704. - if (_class_defs[i].class_bytes == NULL) {
  3705. - _res = JVMTI_ERROR_NULL_POINTER;
  3706. - return false;
  3707. + }
  3708. +
  3709. + // Check secondary supers
  3710. + int cnt = k->secondary_supers()->length();
  3711. + for (int i = 0; i < cnt; i++) {
  3712. + Klass* secondary = Klass::cast((klassOop) k->secondary_supers()->obj_at(i));
  3713. + if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3714. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  3715. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  3716. + _affected_klasses->append(klass);
  3717. + return;
  3718. }
  3719. }
  3720. +}
  3721. - // Start timer after all the sanity checks; not quite accurate, but
  3722. - // better than adding a bunch of stop() calls.
  3723. - RC_TIMER_START(_timer_vm_op_prologue);
  3724. - // We first load new class versions in the prologue, because somewhere down the
  3725. - // call chain it is required that the current thread is a Java thread.
  3726. - _res = load_new_class_versions(Thread::current());
  3727. - if (_res != JVMTI_ERROR_NONE) {
  3728. - // Free os::malloc allocated memory in load_new_class_version.
  3729. - os::free(_scratch_classes);
  3730. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3731. - return false;
  3732. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  3733. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes() {
  3734. +
  3735. + assert(_affected_klasses, "");
  3736. + for (int i = 0; i < _class_count; i++) {
  3737. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  3738. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  3739. + klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
  3740. + assert(klass_handle->new_version() == NULL, "Must be new class");
  3741. }
  3742. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3743. - return true;
  3744. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  3745. + SystemDictionary::classes_do(VM_RedefineClasses::add_affected_klasses);
  3746. + TRACE_RC1("%d classes affected", _affected_klasses->length());
  3747. +
  3748. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  3749. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
  3750. + IF_TRACE_RC2 {
  3751. + TRACE_RC2("Redefine order: ");
  3752. + for (int i = 0; i < _affected_klasses->length(); i++) {
  3753. + TRACE_RC2("%s", _affected_klasses->at(i)->name()->as_C_string());
  3754. + }
  3755. + }
  3756. +
  3757. + return result;
  3758. }
  3759. -void VM_RedefineClasses::doit() {
  3760. - Thread *thread = Thread::current();
  3761. +// Searches for the class bytes of the given class and returns them as a byte array.
  3762. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  3763. - if (UseSharedSpaces) {
  3764. - // Sharing is enabled so we remap the shared readonly space to
  3765. - // shared readwrite, private just in case we need to redefine
  3766. - // a shared class. We do the remap during the doit() phase of
  3767. - // the safepoint to be safer.
  3768. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  3769. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  3770. - ("failed to remap shared readonly space to readwrite, private"));
  3771. - _res = JVMTI_ERROR_INTERNAL;
  3772. - return;
  3773. + *not_changed = false;
  3774. +
  3775. + // Search for the index in the redefinition array that corresponds to the current class
  3776. + int j;
  3777. + for (j=0; j<_class_count; j++) {
  3778. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  3779. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  3780. + if (the_class_oop == the_class()) {
  3781. + break;
  3782. }
  3783. }
  3784. - for (int i = 0; i < _class_count; i++) {
  3785. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  3786. - }
  3787. - // Disable any dependent concurrent compilations
  3788. - SystemDictionary::notice_modification();
  3789. + if (j == _class_count) {
  3790. - // Set flag indicating that some invariants are no longer true.
  3791. - // See jvmtiExport.hpp for detailed explanation.
  3792. - JvmtiExport::set_has_redefined_a_class();
  3793. + *not_changed = true;
  3794. -// check_class() is optionally called for product bits, but is
  3795. -// always called for non-product bits.
  3796. -#ifdef PRODUCT
  3797. - if (RC_TRACE_ENABLED(0x00004000)) {
  3798. -#endif
  3799. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  3800. - SystemDictionary::classes_do(check_class, thread);
  3801. -#ifdef PRODUCT
  3802. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  3803. + // so the user did not specify a different bytecode for that class.
  3804. +
  3805. + if (the_class->get_cached_class_file_bytes() == NULL) {
  3806. + // not cached, we need to reconstitute the class file from VM representation
  3807. + constantPoolHandle constants(Thread::current(), the_class->constants());
  3808. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  3809. +
  3810. + JvmtiClassFileReconstituter reconstituter(the_class);
  3811. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  3812. + return reconstituter.get_error();
  3813. + }
  3814. +
  3815. + *class_byte_count = (jint)reconstituter.class_file_size();
  3816. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  3817. +
  3818. + TRACE_RC3("Reconstituted class bytes");
  3819. +
  3820. + } else {
  3821. +
  3822. + // it is cached, get it from the cache
  3823. + *class_byte_count = the_class->get_cached_class_file_len();
  3824. + *class_bytes = the_class->get_cached_class_file_bytes();
  3825. +
  3826. +
  3827. + TRACE_RC3("Retrieved cached class bytes");
  3828. + }
  3829. +
  3830. + } else {
  3831. +
  3832. + // Redefine with bytecodes at index j
  3833. + *class_bytes = _class_defs[j].class_bytes;
  3834. + *class_byte_count = _class_defs[j].class_byte_count;
  3835. }
  3836. -#endif
  3837. +
  3838. + return JVMTI_ERROR_NONE;
  3839. }
  3840. -void VM_RedefineClasses::doit_epilogue() {
  3841. - // Free os::malloc allocated memory.
  3842. - // The memory allocated in redefine will be free'ed in next VM operation.
  3843. - os::free(_scratch_classes);
  3844. -
  3845. - if (RC_TRACE_ENABLED(0x00000004)) {
  3846. - // Used to have separate timers for "doit" and "all", but the timer
  3847. - // overhead skewed the measurements.
  3848. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  3849. - _timer_rsc_phase2.milliseconds();
  3850. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  3851. -
  3852. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  3853. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  3854. - _timer_vm_op_prologue.milliseconds(), doit_time));
  3855. - RC_TRACE(0x00000004,
  3856. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  3857. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  3858. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  3859. +bool VM_RedefineClasses::doit_prologue() {
  3860. +
  3861. + _revision_number++;
  3862. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  3863. + lock_threads();
  3864. +
  3865. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  3866. + RC_TIMER_START(_timer_prologue);
  3867. +
  3868. + if (!check_arguments()) {
  3869. + RC_TIMER_STOP(_timer_prologue);
  3870. + return false;
  3871. }
  3872. -}
  3873. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  3874. - // classes for primitives cannot be redefined
  3875. - if (java_lang_Class::is_primitive(klass_mirror)) {
  3876. + // We first load new class versions in the prologue, because somewhere down the
  3877. + // call chain it is required that the current thread is a Java thread.
  3878. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  3879. +
  3880. + assert(_affected_klasses == NULL, "");
  3881. + _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
  3882. +
  3883. +
  3884. + _result = load_new_class_versions(Thread::current());
  3885. +
  3886. + TRACE_RC1("Loaded new class versions!");
  3887. + if (_result != JVMTI_ERROR_NONE) {
  3888. + TRACE_RC1("error occured: %d!", _result);
  3889. + delete _new_classes;
  3890. + _new_classes = NULL;
  3891. + delete _affected_klasses;
  3892. + _affected_klasses = NULL;
  3893. + RC_TIMER_STOP(_timer_prologue);
  3894. return false;
  3895. }
  3896. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  3897. - // classes for arrays cannot be redefined
  3898. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  3899. +
  3900. + TRACE_RC2("nearly finished");
  3901. + VM_GC_Operation::doit_prologue();
  3902. + RC_TIMER_STOP(_timer_prologue);
  3903. + TRACE_RC2("doit_prologue finished!");
  3904. + return true;
  3905. +}
  3906. +
  3907. +// Checks basic properties of the arguments of the redefinition command.
  3908. +jvmtiError VM_RedefineClasses::check_arguments_error() {
  3909. + if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
  3910. + for (int i = 0; i < _class_count; i++) {
  3911. + if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
  3912. + if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3913. + if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
  3914. + }
  3915. + return JVMTI_ERROR_NONE;
  3916. +}
  3917. +
  3918. +// Returns false and sets an result error code if the redefinition should be aborted.
  3919. +bool VM_RedefineClasses::check_arguments() {
  3920. + jvmtiError error = check_arguments_error();
  3921. + if (error != JVMTI_ERROR_NONE || _class_count == 0) {
  3922. + _result = error;
  3923. return false;
  3924. }
  3925. return true;
  3926. }
  3927. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  3928. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  3929. -// direct CP entries, there is just the current entry to append. For
  3930. -// indirect and double-indirect CP entries, there are zero or more
  3931. -// referenced CP entries along with the current entry to append.
  3932. -// Indirect and double-indirect CP entries are handled by recursive
  3933. -// calls to append_entry() as needed. The referenced CP entries are
  3934. -// always appended to *merge_cp_p before the referee CP entry. These
  3935. -// referenced CP entries may already exist in *merge_cp_p in which case
  3936. -// there is nothing extra to append and only the current entry is
  3937. -// appended.
  3938. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  3939. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  3940. - TRAPS) {
  3941. -
  3942. - // append is different depending on entry tag type
  3943. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3944. -
  3945. - // The old verifier is implemented outside the VM. It loads classes,
  3946. - // but does not resolve constant pool entries directly so we never
  3947. - // see Class entries here with the old verifier. Similarly the old
  3948. - // verifier does not like Class entries in the input constant pool.
  3949. - // The split-verifier is implemented in the VM so it can optionally
  3950. - // and directly resolve constant pool entries to load classes. The
  3951. - // split-verifier can accept either Class entries or UnresolvedClass
  3952. - // entries in the input constant pool. We revert the appended copy
  3953. - // back to UnresolvedClass so that either verifier will be happy
  3954. - // with the constant pool entry.
  3955. - case JVM_CONSTANT_Class:
  3956. - {
  3957. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  3958. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  3959. - scratch_cp->klass_name_at(scratch_i));
  3960. -
  3961. - if (scratch_i != *merge_cp_length_p) {
  3962. - // The new entry in *merge_cp_p is at a different index than
  3963. - // the new entry in scratch_cp so we need to map the index values.
  3964. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3965. - }
  3966. - (*merge_cp_length_p)++;
  3967. - } break;
  3968. +jvmtiError VM_RedefineClasses::check_exception() const {
  3969. + Thread* THREAD = Thread::current();
  3970. + if (HAS_PENDING_EXCEPTION) {
  3971. +
  3972. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  3973. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  3974. + if (TraceRedefineClasses >= 1) {
  3975. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  3976. + tty->print_cr("");
  3977. + }
  3978. + CLEAR_PENDING_EXCEPTION;
  3979. +
  3980. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  3981. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  3982. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  3983. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3984. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  3985. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  3986. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  3987. + // The message will be "XXX (wrong name: YYY)"
  3988. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  3989. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  3990. + return JVMTI_ERROR_OUT_OF_MEMORY;
  3991. + } else {
  3992. + // Just in case more exceptions can be thrown..
  3993. + return JVMTI_ERROR_FAILS_VERIFICATION;
  3994. + }
  3995. + }
  3996. - // these are direct CP entries so they can be directly appended,
  3997. - // but double and long take two constant pool entries
  3998. - case JVM_CONSTANT_Double: // fall through
  3999. - case JVM_CONSTANT_Long:
  4000. - {
  4001. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4002. - THREAD);
  4003. + return JVMTI_ERROR_NONE;
  4004. +}
  4005. - if (scratch_i != *merge_cp_length_p) {
  4006. - // The new entry in *merge_cp_p is at a different index than
  4007. - // the new entry in scratch_cp so we need to map the index values.
  4008. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4009. - }
  4010. - (*merge_cp_length_p) += 2;
  4011. - } break;
  4012. -
  4013. - // these are direct CP entries so they can be directly appended
  4014. - case JVM_CONSTANT_Float: // fall through
  4015. - case JVM_CONSTANT_Integer: // fall through
  4016. - case JVM_CONSTANT_Utf8: // fall through
  4017. -
  4018. - // This was an indirect CP entry, but it has been changed into
  4019. - // an interned string so this entry can be directly appended.
  4020. - case JVM_CONSTANT_String: // fall through
  4021. -
  4022. - // These were indirect CP entries, but they have been changed into
  4023. - // Symbol*s so these entries can be directly appended.
  4024. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4025. - case JVM_CONSTANT_UnresolvedString:
  4026. - {
  4027. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4028. - THREAD);
  4029. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4030. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4031. - if (scratch_i != *merge_cp_length_p) {
  4032. - // The new entry in *merge_cp_p is at a different index than
  4033. - // the new entry in scratch_cp so we need to map the index values.
  4034. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4035. - }
  4036. - (*merge_cp_length_p)++;
  4037. - } break;
  4038. + ResourceMark rm(THREAD);
  4039. - // this is an indirect CP entry so it needs special handling
  4040. - case JVM_CONSTANT_NameAndType:
  4041. - {
  4042. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4043. - int new_name_ref_i = 0;
  4044. - bool match = (name_ref_i < *merge_cp_length_p) &&
  4045. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  4046. - THREAD);
  4047. - if (!match) {
  4048. - // forward reference in *merge_cp_p or not a direct match
  4049. -
  4050. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  4051. - THREAD);
  4052. - if (found_i != 0) {
  4053. - guarantee(found_i != name_ref_i,
  4054. - "compare_entry_to() and find_matching_entry() do not agree");
  4055. -
  4056. - // Found a matching entry somewhere else in *merge_cp_p so
  4057. - // just need a mapping entry.
  4058. - new_name_ref_i = found_i;
  4059. - map_index(scratch_cp, name_ref_i, found_i);
  4060. - } else {
  4061. - // no match found so we have to append this entry to *merge_cp_p
  4062. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  4063. - THREAD);
  4064. - // The above call to append_entry() can only append one entry
  4065. - // so the post call query of *merge_cp_length_p is only for
  4066. - // the sake of consistency.
  4067. - new_name_ref_i = *merge_cp_length_p - 1;
  4068. + TRACE_RC1("===================================================================");
  4069. + TRACE_RC1("redefinition started by thread \"%s\"", THREAD->name());
  4070. + TRACE_RC1("load new class versions (%d)", _class_count);
  4071. +
  4072. + // Retrieve an array of all classes that need to be redefined
  4073. + jvmtiError err = find_sorted_affected_classes();
  4074. + if (err != JVMTI_ERROR_NONE) {
  4075. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  4076. + return err;
  4077. + }
  4078. +
  4079. +
  4080. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4081. +
  4082. + _max_redefinition_flags = Klass::NoRedefinition;
  4083. + jvmtiError result = JVMTI_ERROR_NONE;
  4084. +
  4085. + for (int i=0; i<_affected_klasses->length(); i++) {
  4086. + TRACE_RC2("Processing affected class %d of %d", i+1, _affected_klasses->length());
  4087. +
  4088. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4089. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  4090. +
  4091. + the_class->link_class(THREAD);
  4092. + result = check_exception();
  4093. + if (result != JVMTI_ERROR_NONE) break;
  4094. +
  4095. + // Find new class bytes
  4096. + const unsigned char* class_bytes;
  4097. + jint class_byte_count;
  4098. + jvmtiError error;
  4099. + jboolean not_changed;
  4100. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4101. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  4102. + result = error;
  4103. + break;
  4104. + }
  4105. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4106. +
  4107. +
  4108. + // Set redefined class handle in JvmtiThreadState class.
  4109. + // This redefined class is sent to agent event handler for class file
  4110. + // load hook event.
  4111. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4112. +
  4113. + TRACE_RC2("Before resolving from stream");
  4114. +
  4115. + RC_TIMER_STOP(_timer_prologue);
  4116. + RC_TIMER_START(_timer_class_loading);
  4117. +
  4118. +
  4119. + // Parse the stream.
  4120. + Handle the_class_loader(THREAD, the_class->class_loader());
  4121. + Handle protection_domain(THREAD, the_class->protection_domain());
  4122. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4123. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class->name(),
  4124. + the_class_loader,
  4125. + protection_domain,
  4126. + &st,
  4127. + true,
  4128. + the_class,
  4129. + THREAD));
  4130. +
  4131. + RC_TIMER_STOP(_timer_class_loading);
  4132. + RC_TIMER_START(_timer_prologue);
  4133. +
  4134. + TRACE_RC2("After resolving class from stream!");
  4135. + // Clear class_being_redefined just to be sure.
  4136. + state->clear_class_being_redefined();
  4137. +
  4138. + result = check_exception();
  4139. + if (result != JVMTI_ERROR_NONE) break;
  4140. +
  4141. + not_changed = false;
  4142. +
  4143. +#ifdef ASSERT
  4144. +
  4145. + assert(new_class() != NULL, "Class could not be loaded!");
  4146. + assert(new_class() != the_class(), "must be different");
  4147. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4148. +
  4149. +
  4150. + objArrayOop k_interfaces = new_class->local_interfaces();
  4151. + for (int j=0; j<k_interfaces->length(); j++) {
  4152. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4153. + }
  4154. +
  4155. + if (!THREAD->is_Compiler_thread()) {
  4156. +
  4157. + 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());
  4158. + // If we are on the compiler thread, we must not try to resolve a class.
  4159. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4160. +
  4161. + if (systemLookup != NULL) {
  4162. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4163. +
  4164. +
  4165. + Klass *subklass = new_class()->klass_part()->subklass();
  4166. + while (subklass != NULL) {
  4167. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4168. + subklass = subklass->next_sibling();
  4169. }
  4170. + } else {
  4171. + // This can happen for reflection generated classes.. ?
  4172. + CLEAR_PENDING_EXCEPTION;
  4173. }
  4174. + }
  4175. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  4176. - int new_signature_ref_i = 0;
  4177. - match = (signature_ref_i < *merge_cp_length_p) &&
  4178. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  4179. - signature_ref_i, THREAD);
  4180. - if (!match) {
  4181. - // forward reference in *merge_cp_p or not a direct match
  4182. -
  4183. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  4184. - *merge_cp_p, THREAD);
  4185. - if (found_i != 0) {
  4186. - guarantee(found_i != signature_ref_i,
  4187. - "compare_entry_to() and find_matching_entry() do not agree");
  4188. -
  4189. - // Found a matching entry somewhere else in *merge_cp_p so
  4190. - // just need a mapping entry.
  4191. - new_signature_ref_i = found_i;
  4192. - map_index(scratch_cp, signature_ref_i, found_i);
  4193. - } else {
  4194. - // no match found so we have to append this entry to *merge_cp_p
  4195. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  4196. - merge_cp_length_p, THREAD);
  4197. - // The above call to append_entry() can only append one entry
  4198. - // so the post call query of *merge_cp_length_p is only for
  4199. - // the sake of consistency.
  4200. - new_signature_ref_i = *merge_cp_length_p - 1;
  4201. - }
  4202. +#endif
  4203. +
  4204. + IF_TRACE_RC1 {
  4205. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4206. + 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());
  4207. }
  4208. + }
  4209. - // If the referenced entries already exist in *merge_cp_p, then
  4210. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  4211. - // In that case, all we are appending is the current entry.
  4212. - if (new_name_ref_i == 0) {
  4213. - new_name_ref_i = name_ref_i;
  4214. - } else {
  4215. - RC_TRACE(0x00080000,
  4216. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  4217. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  4218. + // Set the new version of the class
  4219. + new_class->set_revision_number(_revision_number);
  4220. + new_class->set_redefinition_index(i);
  4221. + the_class->set_new_version(new_class());
  4222. + _new_classes->append(new_class);
  4223. +
  4224. + assert(new_class->new_version() == NULL, "");
  4225. +
  4226. + int redefinition_flags = Klass::NoRedefinition;
  4227. +
  4228. + if (not_changed) {
  4229. + redefinition_flags = Klass::NoRedefinition;
  4230. + } else if (AllowAdvancedClassRedefinition) {
  4231. + redefinition_flags = calculate_redefinition_flags(new_class);
  4232. + if (redefinition_flags >= Klass::RemoveSuperType) {
  4233. + TRACE_RC1("Remove super type is not allowed");
  4234. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4235. + break;
  4236. }
  4237. - if (new_signature_ref_i == 0) {
  4238. - new_signature_ref_i = signature_ref_i;
  4239. - } else {
  4240. - RC_TRACE(0x00080000,
  4241. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  4242. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  4243. + } else {
  4244. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4245. + if (allowed != JVMTI_ERROR_NONE) {
  4246. + TRACE_RC1("Error redefinition not allowed!");
  4247. + result = allowed;
  4248. + break;
  4249. }
  4250. + redefinition_flags = Klass::ModifyClass;
  4251. + }
  4252. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  4253. - new_name_ref_i, new_signature_ref_i);
  4254. - if (scratch_i != *merge_cp_length_p) {
  4255. - // The new entry in *merge_cp_p is at a different index than
  4256. - // the new entry in scratch_cp so we need to map the index values.
  4257. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4258. + if (new_class->super() != NULL) {
  4259. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4260. + }
  4261. +
  4262. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4263. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4264. + }
  4265. +
  4266. + new_class->set_redefinition_flags(redefinition_flags);
  4267. +
  4268. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4269. +
  4270. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4271. + // TODO: Check if watch access flags of static fields are updated correctly.
  4272. + calculate_instance_update_information(_new_classes->at(i)());
  4273. + } else {
  4274. + // Fields were not changed, transfer special flags only
  4275. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4276. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4277. +
  4278. + JavaFieldStream old_fs(the_class);
  4279. + JavaFieldStream new_fs(new_class);
  4280. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4281. + AccessFlags flags = new_fs.access_flags();
  4282. + flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
  4283. + flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
  4284. + new_fs.set_access_flags(flags);
  4285. }
  4286. - (*merge_cp_length_p)++;
  4287. - } break;
  4288. + }
  4289. - // this is a double-indirect CP entry so it needs special handling
  4290. - case JVM_CONSTANT_Fieldref: // fall through
  4291. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  4292. - case JVM_CONSTANT_Methodref:
  4293. - {
  4294. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  4295. - int new_klass_ref_i = 0;
  4296. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  4297. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  4298. - THREAD);
  4299. - if (!match) {
  4300. - // forward reference in *merge_cp_p or not a direct match
  4301. -
  4302. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  4303. - THREAD);
  4304. - if (found_i != 0) {
  4305. - guarantee(found_i != klass_ref_i,
  4306. - "compare_entry_to() and find_matching_entry() do not agree");
  4307. -
  4308. - // Found a matching entry somewhere else in *merge_cp_p so
  4309. - // just need a mapping entry.
  4310. - new_klass_ref_i = found_i;
  4311. - map_index(scratch_cp, klass_ref_i, found_i);
  4312. - } else {
  4313. - // no match found so we have to append this entry to *merge_cp_p
  4314. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  4315. - THREAD);
  4316. - // The above call to append_entry() can only append one entry
  4317. - // so the post call query of *merge_cp_length_p is only for
  4318. - // the sake of consistency. Without the optimization where we
  4319. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  4320. - // could be appended.
  4321. - new_klass_ref_i = *merge_cp_length_p - 1;
  4322. - }
  4323. + IF_TRACE_RC3 {
  4324. + if (new_class->super() != NULL) {
  4325. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  4326. }
  4327. + }
  4328. - int name_and_type_ref_i =
  4329. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  4330. - int new_name_and_type_ref_i = 0;
  4331. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  4332. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  4333. - name_and_type_ref_i, THREAD);
  4334. - if (!match) {
  4335. - // forward reference in *merge_cp_p or not a direct match
  4336. -
  4337. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  4338. - *merge_cp_p, THREAD);
  4339. - if (found_i != 0) {
  4340. - guarantee(found_i != name_and_type_ref_i,
  4341. - "compare_entry_to() and find_matching_entry() do not agree");
  4342. -
  4343. - // Found a matching entry somewhere else in *merge_cp_p so
  4344. - // just need a mapping entry.
  4345. - new_name_and_type_ref_i = found_i;
  4346. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  4347. - } else {
  4348. - // no match found so we have to append this entry to *merge_cp_p
  4349. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  4350. - merge_cp_length_p, THREAD);
  4351. - // The above call to append_entry() can append more than
  4352. - // one entry so the post call query of *merge_cp_length_p
  4353. - // is required in order to get the right index for the
  4354. - // JVM_CONSTANT_NameAndType entry.
  4355. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  4356. +#ifdef ASSERT
  4357. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4358. +
  4359. + the_class->vtable()->verify(tty);
  4360. + new_class->vtable()->verify(tty);
  4361. +#endif
  4362. +
  4363. + TRACE_RC2("Verification done!");
  4364. +
  4365. + if (i == _affected_klasses->length() - 1) {
  4366. +
  4367. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4368. +
  4369. + for (int j=0; j<_affected_klasses->length(); j++) {
  4370. +
  4371. + klassOop initial_klass = _affected_klasses->at(j)();
  4372. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4373. + Klass *cur_klass = initial_subklass;
  4374. + while(cur_klass != NULL) {
  4375. +
  4376. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
  4377. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4378. + if (!_affected_klasses->contains(handle)) {
  4379. +
  4380. + int k = i + 1;
  4381. + for (; k<_affected_klasses->length(); k++) {
  4382. + if (_affected_klasses->at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4383. + break;
  4384. + }
  4385. + }
  4386. + _affected_klasses->insert_before(k, handle);
  4387. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  4388. + }
  4389. + }
  4390. +
  4391. + cur_klass = cur_klass->next_sibling();
  4392. }
  4393. }
  4394. - // If the referenced entries already exist in *merge_cp_p, then
  4395. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  4396. - // 0. In that case, all we are appending is the current entry.
  4397. - if (new_klass_ref_i == 0) {
  4398. - new_klass_ref_i = klass_ref_i;
  4399. - }
  4400. - if (new_name_and_type_ref_i == 0) {
  4401. - new_name_and_type_ref_i = name_and_type_ref_i;
  4402. - }
  4403. + int new_count = _affected_klasses->length() - 1 - i;
  4404. + if (new_count != 0) {
  4405. - const char *entry_name;
  4406. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4407. - case JVM_CONSTANT_Fieldref:
  4408. - entry_name = "Fieldref";
  4409. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  4410. - new_name_and_type_ref_i);
  4411. - break;
  4412. - case JVM_CONSTANT_InterfaceMethodref:
  4413. - entry_name = "IFMethodref";
  4414. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  4415. - new_klass_ref_i, new_name_and_type_ref_i);
  4416. - break;
  4417. - case JVM_CONSTANT_Methodref:
  4418. - entry_name = "Methodref";
  4419. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  4420. - new_name_and_type_ref_i);
  4421. - break;
  4422. - default:
  4423. - guarantee(false, "bad switch");
  4424. - break;
  4425. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  4426. }
  4427. + }
  4428. + }
  4429. - if (klass_ref_i != new_klass_ref_i) {
  4430. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  4431. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  4432. - }
  4433. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  4434. - RC_TRACE(0x00080000,
  4435. - ("%s entry@%d name_and_type_index changed: %d to %d",
  4436. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  4437. - new_name_and_type_ref_i));
  4438. - }
  4439. + if (result != JVMTI_ERROR_NONE) {
  4440. + rollback();
  4441. + return result;
  4442. + }
  4443. - if (scratch_i != *merge_cp_length_p) {
  4444. - // The new entry in *merge_cp_p is at a different index than
  4445. - // the new entry in scratch_cp so we need to map the index values.
  4446. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4447. - }
  4448. - (*merge_cp_length_p)++;
  4449. - } break;
  4450. + RC_TIMER_STOP(_timer_prologue);
  4451. + RC_TIMER_START(_timer_class_linking);
  4452. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4453. + for (int i=0; i<_affected_klasses->length(); i++) {
  4454. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4455. + instanceKlassHandle new_class(the_class->new_version());
  4456. - // At this stage, Class or UnresolvedClass could be here, but not
  4457. - // ClassIndex
  4458. - case JVM_CONSTANT_ClassIndex: // fall through
  4459. + TRACE_RC2("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string());
  4460. + new_class->link_class(THREAD);
  4461. - // Invalid is used as the tag for the second constant pool entry
  4462. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  4463. - // not be seen by itself.
  4464. - case JVM_CONSTANT_Invalid: // fall through
  4465. + result = check_exception();
  4466. + if (result != JVMTI_ERROR_NONE) break;
  4467. + }
  4468. + RC_TIMER_STOP(_timer_class_linking);
  4469. + RC_TIMER_START(_timer_prologue);
  4470. - // At this stage, String or UnresolvedString could be here, but not
  4471. - // StringIndex
  4472. - case JVM_CONSTANT_StringIndex: // fall through
  4473. + if (result != JVMTI_ERROR_NONE) {
  4474. + rollback();
  4475. + return result;
  4476. + }
  4477. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  4478. - // here
  4479. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  4480. + TRACE_RC2("All classes loaded!");
  4481. - default:
  4482. - {
  4483. - // leave a breadcrumb
  4484. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  4485. - ShouldNotReachHere();
  4486. - } break;
  4487. - } // end switch tag value
  4488. -} // end append_entry()
  4489. +#ifdef ASSERT
  4490. + for (int i=0; i<_affected_klasses->length(); i++) {
  4491. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4492. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4493. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  4494. + assert(new_version->new_version() == NULL, "Must be newest version");
  4495. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  4496. + new_version()->print();
  4497. + new_version->super()->print();
  4498. + }
  4499. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  4500. + }
  4501. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  4502. - typeArrayOop save;
  4503. + SystemDictionary::classes_do(check_class, THREAD);
  4504. - save = scratch_class->get_method_annotations_of(i);
  4505. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  4506. - scratch_class->set_method_annotations_of(j, save);
  4507. +#endif
  4508. - save = scratch_class->get_method_parameter_annotations_of(i);
  4509. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  4510. - scratch_class->set_method_parameter_annotations_of(j, save);
  4511. + TRACE_RC1("Finished verification!");
  4512. + return JVMTI_ERROR_NONE;
  4513. +}
  4514. - save = scratch_class->get_method_default_annotations_of(i);
  4515. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  4516. - scratch_class->set_method_default_annotations_of(j, save);
  4517. +void VM_RedefineClasses::lock_threads() {
  4518. +
  4519. + RC_TIMER_START(_timer_wait_for_locks);
  4520. +
  4521. +
  4522. + JavaThread *javaThread = Threads::first();
  4523. + while (javaThread != NULL) {
  4524. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4525. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4526. + compilerThread->set_should_bailout(true);
  4527. + }
  4528. + javaThread = javaThread->next();
  4529. + }
  4530. +
  4531. + int cnt = 0;
  4532. + javaThread = Threads::first();
  4533. + while (javaThread != NULL) {
  4534. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4535. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4536. + compilerThread->compilation_mutex()->lock();
  4537. + cnt++;
  4538. + }
  4539. + javaThread = javaThread->next();
  4540. + }
  4541. +
  4542. + TRACE_RC2("Locked %d compiler threads", cnt);
  4543. +
  4544. + cnt = 0;
  4545. + javaThread = Threads::first();
  4546. + while (javaThread != NULL) {
  4547. + if (javaThread != Thread::current()) {
  4548. + javaThread->redefine_classes_mutex()->lock();
  4549. + cnt++;
  4550. + }
  4551. + javaThread = javaThread->next();
  4552. + }
  4553. +
  4554. +
  4555. + TRACE_RC2("Locked %d threads", cnt);
  4556. +
  4557. + RC_TIMER_STOP(_timer_wait_for_locks);
  4558. +}
  4559. +
  4560. +void VM_RedefineClasses::unlock_threads() {
  4561. +
  4562. + int cnt = 0;
  4563. + JavaThread *javaThread = Threads::first();
  4564. + Thread *thread = Thread::current();
  4565. + while (javaThread != NULL) {
  4566. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4567. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4568. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  4569. + compilerThread->compilation_mutex()->unlock();
  4570. + cnt++;
  4571. + }
  4572. + }
  4573. + javaThread = javaThread->next();
  4574. + }
  4575. +
  4576. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  4577. +
  4578. + cnt = 0;
  4579. + javaThread = Threads::first();
  4580. + while (javaThread != NULL) {
  4581. + if (javaThread != Thread::current()) {
  4582. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  4583. + javaThread->redefine_classes_mutex()->unlock();
  4584. + cnt++;
  4585. + }
  4586. + }
  4587. + javaThread = javaThread->next();
  4588. + }
  4589. +
  4590. + TRACE_RC2("Unlocked %d threads", cnt);
  4591. }
  4592. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  4593. +
  4594. +
  4595. +
  4596. + // Compatibility mode => check for unsupported modification
  4597. +
  4598. +
  4599. + assert(scratch_class->old_version() != NULL, "must have old version");
  4600. + instanceKlassHandle the_class(scratch_class->old_version());
  4601. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4602. - instanceKlassHandle the_class,
  4603. - instanceKlassHandle scratch_class) {
  4604. int i;
  4605. // Check superclasses, or rather their names, since superclasses themselves can be
  4606. // requested to replace.
  4607. // Check for NULL superclass first since this might be java.lang.Object
  4608. if (the_class->super() != scratch_class->super() &&
  4609. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  4610. - Klass::cast(the_class->super())->name() !=
  4611. - Klass::cast(scratch_class->super())->name())) {
  4612. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4613. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  4614. + Klass::cast(the_class->super())->name() !=
  4615. + Klass::cast(scratch_class->super())->name())) {
  4616. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4617. }
  4618. // Check if the number, names and order of directly implemented interfaces are the same.
  4619. @@ -539,8 +718,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4620. }
  4621. for (i = 0; i < n_intfs; i++) {
  4622. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  4623. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4624. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4625. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4626. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4627. }
  4628. }
  4629. @@ -578,14 +757,283 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4630. Symbol* name_sym2 = scratch_class->constants()->symbol_at(new_fs.name_index());
  4631. Symbol* sig_sym2 = scratch_class->constants()->symbol_at(new_fs.signature_index());
  4632. if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  4633. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4634. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4635. + }
  4636. + }
  4637. +
  4638. + // If both streams aren't done then we have a differing number of
  4639. + // fields.
  4640. + if (!old_fs.done() || !new_fs.done()) {
  4641. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4642. + }
  4643. +
  4644. + // Do a parallel walk through the old and new methods. Detect
  4645. + // cases where they match (exist in both), have been added in
  4646. + // the new methods, or have been deleted (exist only in the
  4647. + // old methods). The class file parser places methods in order
  4648. + // by method name, but does not order overloaded methods by
  4649. + // signature. In order to determine what fate befell the methods,
  4650. + // this code places the overloaded new methods that have matching
  4651. + // old methods in the same order as the old methods and places
  4652. + // new overloaded methods at the end of overloaded methods of
  4653. + // that name. The code for this order normalization is adapted
  4654. + // from the algorithm used in instanceKlass::find_method().
  4655. + // Since we are swapping out of order entries as we find them,
  4656. + // we only have to search forward through the overloaded methods.
  4657. + // Methods which are added and have the same name as an existing
  4658. + // method (but different signature) will be put at the end of
  4659. + // the methods with that name, and the name mismatch code will
  4660. + // handle them.
  4661. + objArrayHandle k_old_methods(the_class->methods());
  4662. + objArrayHandle k_new_methods(scratch_class->methods());
  4663. + int n_old_methods = k_old_methods->length();
  4664. + int n_new_methods = k_new_methods->length();
  4665. +
  4666. + int ni = 0;
  4667. + int oi = 0;
  4668. + while (true) {
  4669. + methodOop k_old_method;
  4670. + methodOop k_new_method;
  4671. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  4672. +
  4673. + if (oi >= n_old_methods) {
  4674. + if (ni >= n_new_methods) {
  4675. + break; // we've looked at everything, done
  4676. + }
  4677. + // New method at the end
  4678. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4679. + method_was = added;
  4680. + } else if (ni >= n_new_methods) {
  4681. + // Old method, at the end, is deleted
  4682. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4683. + method_was = deleted;
  4684. + } else {
  4685. + // There are more methods in both the old and new lists
  4686. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4687. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4688. + if (k_old_method->name() != k_new_method->name()) {
  4689. + // Methods are sorted by method name, so a mismatch means added
  4690. + // or deleted
  4691. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  4692. + method_was = added;
  4693. + } else {
  4694. + method_was = deleted;
  4695. + }
  4696. + } else if (k_old_method->signature() == k_new_method->signature()) {
  4697. + // Both the name and signature match
  4698. + method_was = matched;
  4699. + } else {
  4700. + // The name matches, but the signature doesn't, which means we have to
  4701. + // search forward through the new overloaded methods.
  4702. + int nj; // outside the loop for post-loop check
  4703. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  4704. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  4705. + if (k_old_method->name() != m->name()) {
  4706. + // reached another method name so no more overloaded methods
  4707. + method_was = deleted;
  4708. + break;
  4709. + }
  4710. + if (k_old_method->signature() == m->signature()) {
  4711. + // found a match so swap the methods
  4712. + k_new_methods->obj_at_put(ni, m);
  4713. + k_new_methods->obj_at_put(nj, k_new_method);
  4714. + k_new_method = m;
  4715. + method_was = matched;
  4716. + break;
  4717. + }
  4718. + }
  4719. +
  4720. + if (nj >= n_new_methods) {
  4721. + // reached the end without a match; so method was deleted
  4722. + method_was = deleted;
  4723. + }
  4724. + }
  4725. + }
  4726. +
  4727. + switch (method_was) {
  4728. + case matched:
  4729. + // methods match, be sure modifiers do too
  4730. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4731. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4732. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4733. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED;
  4734. + }
  4735. + {
  4736. + u2 new_num = k_new_method->method_idnum();
  4737. + u2 old_num = k_old_method->method_idnum();
  4738. + if (new_num != old_num) {
  4739. + methodOop idnum_owner = scratch_class->method_with_idnum(old_num);
  4740. + if (idnum_owner != NULL) {
  4741. + // There is already a method assigned this idnum -- switch them
  4742. + idnum_owner->set_method_idnum(new_num);
  4743. + }
  4744. + k_new_method->set_method_idnum(old_num);
  4745. + }
  4746. + }
  4747. + // advance to next pair of methods
  4748. + ++oi;
  4749. + ++ni;
  4750. + break;
  4751. + case added:
  4752. + // method added, see if it is OK
  4753. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4754. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  4755. + // hack: private should be treated as final, but alas
  4756. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4757. + ) {
  4758. + // new methods must be private
  4759. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4760. + }
  4761. + {
  4762. + u2 num = the_class->next_method_idnum();
  4763. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  4764. + // cannot add any more methods
  4765. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4766. + }
  4767. + u2 new_num = k_new_method->method_idnum();
  4768. + methodOop idnum_owner = scratch_class->method_with_idnum(num);
  4769. + if (idnum_owner != NULL) {
  4770. + // There is already a method assigned this idnum -- switch them
  4771. + idnum_owner->set_method_idnum(new_num);
  4772. + }
  4773. + k_new_method->set_method_idnum(num);
  4774. + }
  4775. + ++ni; // advance to next new method
  4776. + break;
  4777. + case deleted:
  4778. + // method deleted, see if it is OK
  4779. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4780. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  4781. + // hack: private should be treated as final, but alas
  4782. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4783. + ) {
  4784. + // deleted methods must be private
  4785. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4786. + }
  4787. + ++oi; // advance to next old method
  4788. + break;
  4789. + default:
  4790. + ShouldNotReachHere();
  4791. + }
  4792. + }
  4793. +
  4794. + return JVMTI_ERROR_NONE;
  4795. +}
  4796. +
  4797. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  4798. +
  4799. + int result = Klass::NoRedefinition;
  4800. +
  4801. +
  4802. +
  4803. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  4804. +
  4805. + assert(new_class->old_version() != NULL, "must have old version");
  4806. + instanceKlassHandle the_class(new_class->old_version());
  4807. +
  4808. + // Check whether class is in the error init state.
  4809. + if (the_class->is_in_error_state()) {
  4810. + // TBD #5057930: special error code is needed in 1.6
  4811. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  4812. + }
  4813. +
  4814. + int i;
  4815. +
  4816. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4817. + // Check superclasses
  4818. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  4819. + if (the_class->super() != new_class->super()) {
  4820. + // Super class changed
  4821. +
  4822. + klassOop cur_klass = the_class->super();
  4823. + while (cur_klass != NULL) {
  4824. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  4825. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  4826. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  4827. +
  4828. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  4829. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  4830. + cur_klass->klass_part()->set_subtype_changed(true);
  4831. + }
  4832. + }
  4833. +
  4834. + cur_klass = cur_klass->klass_part()->super();
  4835. + }
  4836. +
  4837. + cur_klass = new_class->super();
  4838. + while (cur_klass != NULL) {
  4839. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  4840. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  4841. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  4842. + }
  4843. + cur_klass = cur_klass->klass_part()->super();
  4844. + }
  4845. + }
  4846. +
  4847. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4848. + // Check interfaces
  4849. +
  4850. + // Interfaces removed?
  4851. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  4852. + for (i = 0; i<old_interfaces->length(); i++) {
  4853. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  4854. + if (!new_class->implements_interface_any_version(old_interface())) {
  4855. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  4856. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  4857. +
  4858. + if (!old_interface->has_subtype_changed()) {
  4859. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  4860. + old_interface->set_subtype_changed(true);
  4861. + }
  4862. + }
  4863. + }
  4864. +
  4865. + // Interfaces added?
  4866. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  4867. + for (i = 0; i<new_interfaces->length(); i++) {
  4868. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  4869. + result = result | Klass::ModifyClass;
  4870. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  4871. + }
  4872. + }
  4873. +
  4874. +
  4875. + // Check whether class modifiers are the same.
  4876. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  4877. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  4878. + if (old_flags != new_flags) {
  4879. + // TODO (tw): Can this have any effects?
  4880. + }
  4881. +
  4882. + // Check if the number, names, types and order of fields declared in these classes
  4883. + // are the same.
  4884. + JavaFieldStream old_fs(the_class);
  4885. + JavaFieldStream new_fs(new_class);
  4886. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4887. + // access
  4888. + old_flags = old_fs.access_flags().as_short();
  4889. + new_flags = new_fs.access_flags().as_short();
  4890. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  4891. + // TODO (tw) can this have any effect?
  4892. + }
  4893. + // offset
  4894. + if (old_fs.offset() != new_fs.offset()) {
  4895. + result = result | Klass::ModifyInstances;
  4896. + }
  4897. + // name and signature
  4898. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  4899. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  4900. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  4901. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  4902. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  4903. + result = result | Klass::ModifyInstances;
  4904. }
  4905. }
  4906. // If both streams aren't done then we have a differing number of
  4907. // fields.
  4908. if (!old_fs.done() || !new_fs.done()) {
  4909. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4910. + result = result | Klass::ModifyInstances;
  4911. }
  4912. // Do a parallel walk through the old and new methods. Detect
  4913. @@ -606,7 +1054,7 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4914. // the methods with that name, and the name mismatch code will
  4915. // handle them.
  4916. objArrayHandle k_old_methods(the_class->methods());
  4917. - objArrayHandle k_new_methods(scratch_class->methods());
  4918. + objArrayHandle k_new_methods(new_class->methods());
  4919. int n_old_methods = k_old_methods->length();
  4920. int n_new_methods = k_new_methods->length();
  4921. @@ -672,2278 +1120,701 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4922. }
  4923. switch (method_was) {
  4924. - case matched:
  4925. - // methods match, be sure modifiers do too
  4926. - old_flags = (jushort) k_old_method->access_flags().get_flags();
  4927. - new_flags = (jushort) k_new_method->access_flags().get_flags();
  4928. - if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4929. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED;
  4930. - }
  4931. - {
  4932. - u2 new_num = k_new_method->method_idnum();
  4933. - u2 old_num = k_old_method->method_idnum();
  4934. - if (new_num != old_num) {
  4935. - methodOop idnum_owner = scratch_class->method_with_idnum(old_num);
  4936. - if (idnum_owner != NULL) {
  4937. - // There is already a method assigned this idnum -- switch them
  4938. - idnum_owner->set_method_idnum(new_num);
  4939. - }
  4940. - k_new_method->set_method_idnum(old_num);
  4941. - swap_all_method_annotations(old_num, new_num, scratch_class);
  4942. - }
  4943. - }
  4944. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  4945. - k_new_method->name_and_sig_as_C_string(), ni,
  4946. - k_old_method->name_and_sig_as_C_string(), oi));
  4947. - // advance to next pair of methods
  4948. - ++oi;
  4949. - ++ni;
  4950. - break;
  4951. - case added:
  4952. - // method added, see if it is OK
  4953. - new_flags = (jushort) k_new_method->access_flags().get_flags();
  4954. - if ((new_flags & JVM_ACC_PRIVATE) == 0
  4955. - // hack: private should be treated as final, but alas
  4956. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4957. - ) {
  4958. - // new methods must be private
  4959. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4960. - }
  4961. - {
  4962. - u2 num = the_class->next_method_idnum();
  4963. - if (num == constMethodOopDesc::UNSET_IDNUM) {
  4964. - // cannot add any more methods
  4965. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4966. - }
  4967. - u2 new_num = k_new_method->method_idnum();
  4968. - methodOop idnum_owner = scratch_class->method_with_idnum(num);
  4969. + case matched:
  4970. + // methods match, be sure modifiers do too
  4971. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4972. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4973. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4974. + // (tw) Can this have any effects? Probably yes on vtables?
  4975. + result = result | Klass::ModifyClass;
  4976. + }
  4977. + {
  4978. + u2 new_num = k_new_method->method_idnum();
  4979. + u2 old_num = k_old_method->method_idnum();
  4980. + if (new_num != old_num) {
  4981. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  4982. if (idnum_owner != NULL) {
  4983. // There is already a method assigned this idnum -- switch them
  4984. idnum_owner->set_method_idnum(new_num);
  4985. }
  4986. - k_new_method->set_method_idnum(num);
  4987. - swap_all_method_annotations(new_num, num, scratch_class);
  4988. - }
  4989. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  4990. - k_new_method->name_and_sig_as_C_string(), ni));
  4991. - ++ni; // advance to next new method
  4992. - break;
  4993. - case deleted:
  4994. - // method deleted, see if it is OK
  4995. - old_flags = (jushort) k_old_method->access_flags().get_flags();
  4996. - if ((old_flags & JVM_ACC_PRIVATE) == 0
  4997. - // hack: private should be treated as final, but alas
  4998. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4999. - ) {
  5000. - // deleted methods must be private
  5001. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5002. - }
  5003. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5004. - k_old_method->name_and_sig_as_C_string(), oi));
  5005. - ++oi; // advance to next old method
  5006. - break;
  5007. - default:
  5008. - ShouldNotReachHere();
  5009. - }
  5010. - }
  5011. -
  5012. - return JVMTI_ERROR_NONE;
  5013. -}
  5014. -
  5015. -
  5016. -// Find new constant pool index value for old constant pool index value
  5017. -// by seaching the index map. Returns zero (0) if there is no mapped
  5018. -// value for the old constant pool index.
  5019. -int VM_RedefineClasses::find_new_index(int old_index) {
  5020. - if (_index_map_count == 0) {
  5021. - // map is empty so nothing can be found
  5022. - return 0;
  5023. - }
  5024. -
  5025. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5026. - // The old_index is out of range so it is not mapped. This should
  5027. - // not happen in regular constant pool merging use, but it can
  5028. - // happen if a corrupt annotation is processed.
  5029. - return 0;
  5030. - }
  5031. -
  5032. - int value = _index_map_p->at(old_index);
  5033. - if (value == -1) {
  5034. - // the old_index is not mapped
  5035. - return 0;
  5036. - }
  5037. -
  5038. - return value;
  5039. -} // end find_new_index()
  5040. -
  5041. -
  5042. -// Returns true if the current mismatch is due to a resolved/unresolved
  5043. -// class pair. Otherwise, returns false.
  5044. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5045. - int index1, constantPoolHandle cp2, int index2) {
  5046. -
  5047. - jbyte t1 = cp1->tag_at(index1).value();
  5048. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5049. - return false; // wrong entry type; not our special case
  5050. - }
  5051. -
  5052. - jbyte t2 = cp2->tag_at(index2).value();
  5053. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5054. - return false; // wrong entry type; not our special case
  5055. - }
  5056. -
  5057. - if (t1 == t2) {
  5058. - return false; // not a mismatch; not our special case
  5059. - }
  5060. -
  5061. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5062. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5063. - if (strcmp(s1, s2) != 0) {
  5064. - return false; // strings don't match; not our special case
  5065. - }
  5066. -
  5067. - return true; // made it through the gauntlet; this is our special case
  5068. -} // end is_unresolved_class_mismatch()
  5069. -
  5070. -
  5071. -// Returns true if the current mismatch is due to a resolved/unresolved
  5072. -// string pair. Otherwise, returns false.
  5073. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5074. - int index1, constantPoolHandle cp2, int index2) {
  5075. -
  5076. - jbyte t1 = cp1->tag_at(index1).value();
  5077. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5078. - return false; // wrong entry type; not our special case
  5079. - }
  5080. -
  5081. - jbyte t2 = cp2->tag_at(index2).value();
  5082. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5083. - return false; // wrong entry type; not our special case
  5084. - }
  5085. -
  5086. - if (t1 == t2) {
  5087. - return false; // not a mismatch; not our special case
  5088. - }
  5089. -
  5090. - char *s1 = cp1->string_at_noresolve(index1);
  5091. - char *s2 = cp2->string_at_noresolve(index2);
  5092. - if (strcmp(s1, s2) != 0) {
  5093. - return false; // strings don't match; not our special case
  5094. - }
  5095. -
  5096. - return true; // made it through the gauntlet; this is our special case
  5097. -} // end is_unresolved_string_mismatch()
  5098. -
  5099. -
  5100. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5101. - // For consistency allocate memory using os::malloc wrapper.
  5102. - _scratch_classes = (instanceKlassHandle *)
  5103. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5104. - if (_scratch_classes == NULL) {
  5105. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5106. - }
  5107. -
  5108. - ResourceMark rm(THREAD);
  5109. -
  5110. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5111. - // state can only be NULL if the current thread is exiting which
  5112. - // should not happen since we're trying to do a RedefineClasses
  5113. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5114. - for (int i = 0; i < _class_count; i++) {
  5115. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5116. - // classes for primitives cannot be redefined
  5117. - if (!is_modifiable_class(mirror)) {
  5118. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5119. - }
  5120. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5121. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5122. - Symbol* the_class_sym = the_class->name();
  5123. -
  5124. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5125. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5126. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5127. - the_class->external_name(), _class_load_kind,
  5128. - os::available_memory() >> 10));
  5129. -
  5130. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5131. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5132. -
  5133. - // Parse the stream.
  5134. - Handle the_class_loader(THREAD, the_class->class_loader());
  5135. - Handle protection_domain(THREAD, the_class->protection_domain());
  5136. - // Set redefined class handle in JvmtiThreadState class.
  5137. - // This redefined class is sent to agent event handler for class file
  5138. - // load hook event.
  5139. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5140. -
  5141. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5142. - the_class_loader,
  5143. - protection_domain,
  5144. - &st,
  5145. - THREAD);
  5146. - // Clear class_being_redefined just to be sure.
  5147. - state->clear_class_being_redefined();
  5148. -
  5149. - // TODO: if this is retransform, and nothing changed we can skip it
  5150. -
  5151. - instanceKlassHandle scratch_class (THREAD, k);
  5152. -
  5153. - if (HAS_PENDING_EXCEPTION) {
  5154. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5155. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5156. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5157. - ex_name->as_C_string()));
  5158. - CLEAR_PENDING_EXCEPTION;
  5159. -
  5160. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5161. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5162. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5163. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5164. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5165. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5166. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5167. - // The message will be "XXX (wrong name: YYY)"
  5168. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5169. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5170. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5171. - } else { // Just in case more exceptions can be thrown..
  5172. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5173. - }
  5174. - }
  5175. -
  5176. - // Ensure class is linked before redefine
  5177. - if (!the_class->is_linked()) {
  5178. - the_class->link_class(THREAD);
  5179. - if (HAS_PENDING_EXCEPTION) {
  5180. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5181. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5182. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5183. - ex_name->as_C_string()));
  5184. - CLEAR_PENDING_EXCEPTION;
  5185. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5186. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5187. - } else {
  5188. - return JVMTI_ERROR_INTERNAL;
  5189. - }
  5190. + k_new_method->set_method_idnum(old_num);
  5191. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  5192. + swap_all_method_annotations(old_num, new_num, new_class);
  5193. }
  5194. }
  5195. -
  5196. - // Do the validity checks in compare_and_normalize_class_versions()
  5197. - // before verifying the byte codes. By doing these checks first, we
  5198. - // limit the number of functions that require redirection from
  5199. - // the_class to scratch_class. In particular, we don't have to
  5200. - // modify JNI GetSuperclass() and thus won't change its performance.
  5201. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5202. - scratch_class);
  5203. - if (res != JVMTI_ERROR_NONE) {
  5204. - return res;
  5205. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  5206. + k_new_method->name_and_sig_as_C_string(), ni,
  5207. + k_old_method->name_and_sig_as_C_string(), oi);
  5208. + // advance to next pair of methods
  5209. + ++oi;
  5210. + ++ni;
  5211. + break;
  5212. + case added:
  5213. + // method added, see if it is OK
  5214. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5215. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5216. + // hack: private should be treated as final, but alas
  5217. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5218. + ) {
  5219. + // new methods must be private
  5220. + result = result | Klass::ModifyClass;
  5221. }
  5222. -
  5223. - // verify what the caller passed us
  5224. {
  5225. - // The bug 6214132 caused the verification to fail.
  5226. - // Information about the_class and scratch_class is temporarily
  5227. - // recorded into jvmtiThreadState. This data is used to redirect
  5228. - // the_class to scratch_class in the JVM_* functions called by the
  5229. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5230. - // description.
  5231. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5232. - Verifier::verify(
  5233. - scratch_class, Verifier::ThrowException, true, THREAD);
  5234. - }
  5235. -
  5236. - if (HAS_PENDING_EXCEPTION) {
  5237. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5238. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5239. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5240. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5241. - CLEAR_PENDING_EXCEPTION;
  5242. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5243. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5244. - } else {
  5245. - // tell the caller the bytecodes are bad
  5246. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5247. - }
  5248. - }
  5249. -
  5250. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5251. - if (res != JVMTI_ERROR_NONE) {
  5252. - return res;
  5253. - }
  5254. -
  5255. - if (VerifyMergedCPBytecodes) {
  5256. - // verify what we have done during constant pool merging
  5257. - {
  5258. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5259. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  5260. - }
  5261. -
  5262. - if (HAS_PENDING_EXCEPTION) {
  5263. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5264. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5265. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5266. - ("verify_byte_codes post merge-CP exception: '%s'",
  5267. - ex_name->as_C_string()));
  5268. - CLEAR_PENDING_EXCEPTION;
  5269. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5270. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5271. - } else {
  5272. - // tell the caller that constant pool merging screwed up
  5273. - return JVMTI_ERROR_INTERNAL;
  5274. - }
  5275. - }
  5276. - }
  5277. -
  5278. - Rewriter::rewrite(scratch_class, THREAD);
  5279. - if (!HAS_PENDING_EXCEPTION) {
  5280. - Rewriter::relocate_and_link(scratch_class, THREAD);
  5281. - }
  5282. - if (HAS_PENDING_EXCEPTION) {
  5283. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5284. - CLEAR_PENDING_EXCEPTION;
  5285. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5286. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5287. - } else {
  5288. - return JVMTI_ERROR_INTERNAL;
  5289. - }
  5290. - }
  5291. -
  5292. - _scratch_classes[i] = scratch_class;
  5293. -
  5294. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5295. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5296. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  5297. - the_class->external_name(), os::available_memory() >> 10));
  5298. - }
  5299. -
  5300. - return JVMTI_ERROR_NONE;
  5301. -}
  5302. -
  5303. -
  5304. -// Map old_index to new_index as needed. scratch_cp is only needed
  5305. -// for RC_TRACE() calls.
  5306. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  5307. - int old_index, int new_index) {
  5308. - if (find_new_index(old_index) != 0) {
  5309. - // old_index is already mapped
  5310. - return;
  5311. - }
  5312. -
  5313. - if (old_index == new_index) {
  5314. - // no mapping is needed
  5315. - return;
  5316. - }
  5317. -
  5318. - _index_map_p->at_put(old_index, new_index);
  5319. - _index_map_count++;
  5320. -
  5321. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  5322. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  5323. -} // end map_index()
  5324. -
  5325. -
  5326. -// Merge old_cp and scratch_cp and return the results of the merge via
  5327. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  5328. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  5329. -// in *merge_cp_p. Also creates a map of indices from entries in
  5330. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  5331. -// entries are only created for entries in scratch_cp that occupy a
  5332. -// different location in *merged_cp_p.
  5333. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  5334. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  5335. - int *merge_cp_length_p, TRAPS) {
  5336. -
  5337. - if (merge_cp_p == NULL) {
  5338. - assert(false, "caller must provide scatch constantPool");
  5339. - return false; // robustness
  5340. - }
  5341. - if (merge_cp_length_p == NULL) {
  5342. - assert(false, "caller must provide scatch CP length");
  5343. - return false; // robustness
  5344. - }
  5345. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  5346. - // but the caller might be smart so make sure we have at least
  5347. - // the minimum.
  5348. - if ((*merge_cp_p)->length() < old_cp->length()) {
  5349. - assert(false, "merge area too small");
  5350. - return false; // robustness
  5351. - }
  5352. -
  5353. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5354. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  5355. - scratch_cp->length()));
  5356. -
  5357. - {
  5358. - // Pass 0:
  5359. - // The old_cp is copied to *merge_cp_p; this means that any code
  5360. - // using old_cp does not have to change. This work looks like a
  5361. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  5362. - // handle one special case:
  5363. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  5364. - // This will make verification happy.
  5365. -
  5366. - int old_i; // index into old_cp
  5367. -
  5368. - // index zero (0) is not used in constantPools
  5369. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  5370. - // leave debugging crumb
  5371. - jbyte old_tag = old_cp->tag_at(old_i).value();
  5372. - switch (old_tag) {
  5373. - case JVM_CONSTANT_Class:
  5374. - case JVM_CONSTANT_UnresolvedClass:
  5375. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5376. - // May be resolving while calling this so do the same for
  5377. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  5378. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  5379. - old_cp->klass_name_at(old_i));
  5380. - break;
  5381. -
  5382. - case JVM_CONSTANT_Double:
  5383. - case JVM_CONSTANT_Long:
  5384. - // just copy the entry to *merge_cp_p, but double and long take
  5385. - // two constant pool entries
  5386. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5387. - old_i++;
  5388. - break;
  5389. -
  5390. - default:
  5391. - // just copy the entry to *merge_cp_p
  5392. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5393. - break;
  5394. - }
  5395. - } // end for each old_cp entry
  5396. -
  5397. - // We don't need to sanity check that *merge_cp_length_p is within
  5398. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  5399. - (*merge_cp_length_p) = old_i;
  5400. - }
  5401. -
  5402. - // merge_cp_len should be the same as old_cp->length() at this point
  5403. - // so this trace message is really a "warm-and-breathing" message.
  5404. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5405. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  5406. -
  5407. - int scratch_i; // index into scratch_cp
  5408. - {
  5409. - // Pass 1a:
  5410. - // Compare scratch_cp entries to the old_cp entries that we have
  5411. - // already copied to *merge_cp_p. In this pass, we are eliminating
  5412. - // exact duplicates (matching entry at same index) so we only
  5413. - // compare entries in the common indice range.
  5414. - int increment = 1;
  5415. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  5416. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  5417. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5418. - case JVM_CONSTANT_Double:
  5419. - case JVM_CONSTANT_Long:
  5420. - // double and long take two constant pool entries
  5421. - increment = 2;
  5422. - break;
  5423. -
  5424. - default:
  5425. - increment = 1;
  5426. - break;
  5427. - }
  5428. -
  5429. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  5430. - scratch_i, CHECK_0);
  5431. - if (match) {
  5432. - // found a match at the same index so nothing more to do
  5433. - continue;
  5434. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  5435. - *merge_cp_p, scratch_i)) {
  5436. - // The mismatch in compare_entry_to() above is because of a
  5437. - // resolved versus unresolved class entry at the same index
  5438. - // with the same string value. Since Pass 0 reverted any
  5439. - // class entries to unresolved class entries in *merge_cp_p,
  5440. - // we go with the unresolved class entry.
  5441. - continue;
  5442. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  5443. - *merge_cp_p, scratch_i)) {
  5444. - // The mismatch in compare_entry_to() above is because of a
  5445. - // resolved versus unresolved string entry at the same index
  5446. - // with the same string value. We can live with whichever
  5447. - // happens to be at scratch_i in *merge_cp_p.
  5448. - continue;
  5449. - }
  5450. -
  5451. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  5452. - CHECK_0);
  5453. - if (found_i != 0) {
  5454. - guarantee(found_i != scratch_i,
  5455. - "compare_entry_to() and find_matching_entry() do not agree");
  5456. -
  5457. - // Found a matching entry somewhere else in *merge_cp_p so
  5458. - // just need a mapping entry.
  5459. - map_index(scratch_cp, scratch_i, found_i);
  5460. - continue;
  5461. - }
  5462. -
  5463. - // The find_matching_entry() call above could fail to find a match
  5464. - // due to a resolved versus unresolved class or string entry situation
  5465. - // like we solved above with the is_unresolved_*_mismatch() calls.
  5466. - // However, we would have to call is_unresolved_*_mismatch() over
  5467. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  5468. - // worth the time.
  5469. -
  5470. - // No match found so we have to append this entry and any unique
  5471. - // referenced entries to *merge_cp_p.
  5472. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5473. - CHECK_0);
  5474. - }
  5475. - }
  5476. -
  5477. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5478. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5479. - *merge_cp_length_p, scratch_i, _index_map_count));
  5480. -
  5481. - if (scratch_i < scratch_cp->length()) {
  5482. - // Pass 1b:
  5483. - // old_cp is smaller than scratch_cp so there are entries in
  5484. - // scratch_cp that we have not yet processed. We take care of
  5485. - // those now.
  5486. - int increment = 1;
  5487. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  5488. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5489. - case JVM_CONSTANT_Double:
  5490. - case JVM_CONSTANT_Long:
  5491. - // double and long take two constant pool entries
  5492. - increment = 2;
  5493. - break;
  5494. -
  5495. - default:
  5496. - increment = 1;
  5497. - break;
  5498. - }
  5499. -
  5500. - int found_i =
  5501. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  5502. - if (found_i != 0) {
  5503. - // Found a matching entry somewhere else in *merge_cp_p so
  5504. - // just need a mapping entry.
  5505. - map_index(scratch_cp, scratch_i, found_i);
  5506. - continue;
  5507. - }
  5508. -
  5509. - // No match found so we have to append this entry and any unique
  5510. - // referenced entries to *merge_cp_p.
  5511. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5512. - CHECK_0);
  5513. - }
  5514. -
  5515. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5516. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5517. - *merge_cp_length_p, scratch_i, _index_map_count));
  5518. - }
  5519. -
  5520. - return true;
  5521. -} // end merge_constant_pools()
  5522. -
  5523. -
  5524. -// Merge constant pools between the_class and scratch_class and
  5525. -// potentially rewrite bytecodes in scratch_class to use the merged
  5526. -// constant pool.
  5527. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  5528. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  5529. - TRAPS) {
  5530. - // worst case merged constant pool length is old and new combined
  5531. - int merge_cp_length = the_class->constants()->length()
  5532. - + scratch_class->constants()->length();
  5533. -
  5534. - constantPoolHandle old_cp(THREAD, the_class->constants());
  5535. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  5536. -
  5537. - // Constant pools are not easily reused so we allocate a new one
  5538. - // each time.
  5539. - // merge_cp is created unsafe for concurrent GC processing. It
  5540. - // should be marked safe before discarding it. Even though
  5541. - // garbage, if it crosses a card boundary, it may be scanned
  5542. - // in order to find the start of the first complete object on the card.
  5543. - constantPoolHandle merge_cp(THREAD,
  5544. - oopFactory::new_constantPool(merge_cp_length,
  5545. - oopDesc::IsUnsafeConc,
  5546. - THREAD));
  5547. - int orig_length = old_cp->orig_length();
  5548. - if (orig_length == 0) {
  5549. - // This old_cp is an actual original constant pool. We save
  5550. - // the original length in the merged constant pool so that
  5551. - // merge_constant_pools() can be more efficient. If a constant
  5552. - // pool has a non-zero orig_length() value, then that constant
  5553. - // pool was created by a merge operation in RedefineClasses.
  5554. - merge_cp->set_orig_length(old_cp->length());
  5555. - } else {
  5556. - // This old_cp is a merged constant pool from a previous
  5557. - // RedefineClasses() calls so just copy the orig_length()
  5558. - // value.
  5559. - merge_cp->set_orig_length(old_cp->orig_length());
  5560. - }
  5561. -
  5562. - ResourceMark rm(THREAD);
  5563. - _index_map_count = 0;
  5564. - _index_map_p = new intArray(scratch_cp->length(), -1);
  5565. -
  5566. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  5567. - &merge_cp_length, THREAD);
  5568. - if (!result) {
  5569. - // The merge can fail due to memory allocation failure or due
  5570. - // to robustness checks.
  5571. - return JVMTI_ERROR_INTERNAL;
  5572. - }
  5573. -
  5574. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5575. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  5576. -
  5577. - if (_index_map_count == 0) {
  5578. - // there is nothing to map between the new and merged constant pools
  5579. -
  5580. - if (old_cp->length() == scratch_cp->length()) {
  5581. - // The old and new constant pools are the same length and the
  5582. - // index map is empty. This means that the three constant pools
  5583. - // are equivalent (but not the same). Unfortunately, the new
  5584. - // constant pool has not gone through link resolution nor have
  5585. - // the new class bytecodes gone through constant pool cache
  5586. - // rewriting so we can't use the old constant pool with the new
  5587. - // class.
  5588. -
  5589. - merge_cp()->set_is_conc_safe(true);
  5590. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5591. - } else if (old_cp->length() < scratch_cp->length()) {
  5592. - // The old constant pool has fewer entries than the new constant
  5593. - // pool and the index map is empty. This means the new constant
  5594. - // pool is a superset of the old constant pool. However, the old
  5595. - // class bytecodes have already gone through constant pool cache
  5596. - // rewriting so we can't use the new constant pool with the old
  5597. - // class.
  5598. -
  5599. - merge_cp()->set_is_conc_safe(true);
  5600. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5601. - } else {
  5602. - // The old constant pool has more entries than the new constant
  5603. - // pool and the index map is empty. This means that both the old
  5604. - // and merged constant pools are supersets of the new constant
  5605. - // pool.
  5606. -
  5607. - // Replace the new constant pool with a shrunken copy of the
  5608. - // merged constant pool; the previous new constant pool will
  5609. - // get GCed.
  5610. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  5611. - THREAD);
  5612. - // drop local ref to the merged constant pool
  5613. - merge_cp()->set_is_conc_safe(true);
  5614. - merge_cp = constantPoolHandle();
  5615. - }
  5616. - } else {
  5617. - if (RC_TRACE_ENABLED(0x00040000)) {
  5618. - // don't want to loop unless we are tracing
  5619. - int count = 0;
  5620. - for (int i = 1; i < _index_map_p->length(); i++) {
  5621. - int value = _index_map_p->at(i);
  5622. -
  5623. - if (value != -1) {
  5624. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5625. - ("index_map[%d]: old=%d new=%d", count, i, value));
  5626. - count++;
  5627. - }
  5628. - }
  5629. - }
  5630. -
  5631. - // We have entries mapped between the new and merged constant pools
  5632. - // so we have to rewrite some constant pool references.
  5633. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  5634. - return JVMTI_ERROR_INTERNAL;
  5635. - }
  5636. -
  5637. - // Replace the new constant pool with a shrunken copy of the
  5638. - // merged constant pool so now the rewritten bytecodes have
  5639. - // valid references; the previous new constant pool will get
  5640. - // GCed.
  5641. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  5642. - THREAD);
  5643. - merge_cp()->set_is_conc_safe(true);
  5644. - }
  5645. - assert(old_cp()->is_conc_safe(), "Just checking");
  5646. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  5647. -
  5648. - return JVMTI_ERROR_NONE;
  5649. -} // end merge_cp_and_rewrite()
  5650. -
  5651. -
  5652. -// Rewrite constant pool references in klass scratch_class.
  5653. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  5654. - TRAPS) {
  5655. -
  5656. - // rewrite constant pool references in the methods:
  5657. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  5658. - // propagate failure back to caller
  5659. - return false;
  5660. - }
  5661. -
  5662. - // rewrite constant pool references in the class_annotations:
  5663. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  5664. - // propagate failure back to caller
  5665. - return false;
  5666. - }
  5667. -
  5668. - // rewrite constant pool references in the fields_annotations:
  5669. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  5670. - // propagate failure back to caller
  5671. - return false;
  5672. - }
  5673. -
  5674. - // rewrite constant pool references in the methods_annotations:
  5675. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  5676. - // propagate failure back to caller
  5677. - return false;
  5678. - }
  5679. -
  5680. - // rewrite constant pool references in the methods_parameter_annotations:
  5681. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  5682. - THREAD)) {
  5683. - // propagate failure back to caller
  5684. - return false;
  5685. - }
  5686. -
  5687. - // rewrite constant pool references in the methods_default_annotations:
  5688. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  5689. - THREAD)) {
  5690. - // propagate failure back to caller
  5691. - return false;
  5692. - }
  5693. -
  5694. - return true;
  5695. -} // end rewrite_cp_refs()
  5696. -
  5697. -
  5698. -// Rewrite constant pool references in the methods.
  5699. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  5700. - instanceKlassHandle scratch_class, TRAPS) {
  5701. -
  5702. - objArrayHandle methods(THREAD, scratch_class->methods());
  5703. -
  5704. - if (methods.is_null() || methods->length() == 0) {
  5705. - // no methods so nothing to do
  5706. - return true;
  5707. - }
  5708. -
  5709. - // rewrite constant pool references in the methods:
  5710. - for (int i = methods->length() - 1; i >= 0; i--) {
  5711. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  5712. - methodHandle new_method;
  5713. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  5714. - if (!new_method.is_null()) {
  5715. - // the method has been replaced so save the new method version
  5716. - methods->obj_at_put(i, new_method());
  5717. - }
  5718. - }
  5719. -
  5720. - return true;
  5721. -}
  5722. -
  5723. -
  5724. -// Rewrite constant pool references in the specific method. This code
  5725. -// was adapted from Rewriter::rewrite_method().
  5726. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  5727. - methodHandle *new_method_p, TRAPS) {
  5728. -
  5729. - *new_method_p = methodHandle(); // default is no new method
  5730. -
  5731. - // We cache a pointer to the bytecodes here in code_base. If GC
  5732. - // moves the methodOop, then the bytecodes will also move which
  5733. - // will likely cause a crash. We create a No_Safepoint_Verifier
  5734. - // object to detect whether we pass a possible safepoint in this
  5735. - // code block.
  5736. - No_Safepoint_Verifier nsv;
  5737. -
  5738. - // Bytecodes and their length
  5739. - address code_base = method->code_base();
  5740. - int code_length = method->code_size();
  5741. -
  5742. - int bc_length;
  5743. - for (int bci = 0; bci < code_length; bci += bc_length) {
  5744. - address bcp = code_base + bci;
  5745. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  5746. -
  5747. - bc_length = Bytecodes::length_for(c);
  5748. - if (bc_length == 0) {
  5749. - // More complicated bytecodes report a length of zero so
  5750. - // we have to try again a slightly different way.
  5751. - bc_length = Bytecodes::length_at(method(), bcp);
  5752. - }
  5753. -
  5754. - assert(bc_length != 0, "impossible bytecode length");
  5755. -
  5756. - switch (c) {
  5757. - case Bytecodes::_ldc:
  5758. - {
  5759. - int cp_index = *(bcp + 1);
  5760. - int new_index = find_new_index(cp_index);
  5761. -
  5762. - if (StressLdcRewrite && new_index == 0) {
  5763. - // If we are stressing ldc -> ldc_w rewriting, then we
  5764. - // always need a new_index value.
  5765. - new_index = cp_index;
  5766. - }
  5767. - if (new_index != 0) {
  5768. - // the original index is mapped so we have more work to do
  5769. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  5770. - // The new value can still use ldc instead of ldc_w
  5771. - // unless we are trying to stress ldc -> ldc_w rewriting
  5772. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5773. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  5774. - bcp, cp_index, new_index));
  5775. - *(bcp + 1) = new_index;
  5776. - } else {
  5777. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5778. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  5779. - Bytecodes::name(c), bcp, cp_index, new_index));
  5780. - // the new value needs ldc_w instead of ldc
  5781. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  5782. - bcp = (address)inst_buffer;
  5783. - // construct new instruction sequence
  5784. - *bcp = Bytecodes::_ldc_w;
  5785. - bcp++;
  5786. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  5787. - // See comment below for difference between put_Java_u2()
  5788. - // and put_native_u2().
  5789. - Bytes::put_Java_u2(bcp, new_index);
  5790. -
  5791. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  5792. - methodHandle m;
  5793. - {
  5794. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  5795. -
  5796. - // ldc is 2 bytes and ldc_w is 3 bytes
  5797. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  5798. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  5799. - guarantee(false, "insert_space_at() failed");
  5800. - }
  5801. - }
  5802. -
  5803. - // return the new method so that the caller can update
  5804. - // the containing class
  5805. - *new_method_p = method = m;
  5806. - // switch our bytecode processing loop from the old method
  5807. - // to the new method
  5808. - code_base = method->code_base();
  5809. - code_length = method->code_size();
  5810. - bcp = code_base + bci;
  5811. - c = (Bytecodes::Code)(*bcp);
  5812. - bc_length = Bytecodes::length_for(c);
  5813. - assert(bc_length != 0, "sanity check");
  5814. - } // end we need ldc_w instead of ldc
  5815. - } // end if there is a mapped index
  5816. - } break;
  5817. -
  5818. - // these bytecodes have a two-byte constant pool index
  5819. - case Bytecodes::_anewarray : // fall through
  5820. - case Bytecodes::_checkcast : // fall through
  5821. - case Bytecodes::_getfield : // fall through
  5822. - case Bytecodes::_getstatic : // fall through
  5823. - case Bytecodes::_instanceof : // fall through
  5824. - case Bytecodes::_invokeinterface: // fall through
  5825. - case Bytecodes::_invokespecial : // fall through
  5826. - case Bytecodes::_invokestatic : // fall through
  5827. - case Bytecodes::_invokevirtual : // fall through
  5828. - case Bytecodes::_ldc_w : // fall through
  5829. - case Bytecodes::_ldc2_w : // fall through
  5830. - case Bytecodes::_multianewarray : // fall through
  5831. - case Bytecodes::_new : // fall through
  5832. - case Bytecodes::_putfield : // fall through
  5833. - case Bytecodes::_putstatic :
  5834. - {
  5835. - address p = bcp + 1;
  5836. - int cp_index = Bytes::get_Java_u2(p);
  5837. - int new_index = find_new_index(cp_index);
  5838. - if (new_index != 0) {
  5839. - // the original index is mapped so update w/ new value
  5840. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5841. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  5842. - bcp, cp_index, new_index));
  5843. - // Rewriter::rewrite_method() uses put_native_u2() in this
  5844. - // situation because it is reusing the constant pool index
  5845. - // location for a native index into the constantPoolCache.
  5846. - // Since we are updating the constant pool index prior to
  5847. - // verification and constantPoolCache initialization, we
  5848. - // need to keep the new index in Java byte order.
  5849. - Bytes::put_Java_u2(p, new_index);
  5850. - }
  5851. - } break;
  5852. + u2 num = the_class->next_method_idnum();
  5853. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5854. + // cannot add any more methods
  5855. + result = result | Klass::ModifyClass;
  5856. + }
  5857. + u2 new_num = k_new_method->method_idnum();
  5858. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5859. + if (idnum_owner != NULL) {
  5860. + // There is already a method assigned this idnum -- switch them
  5861. + idnum_owner->set_method_idnum(new_num);
  5862. + }
  5863. + k_new_method->set_method_idnum(num);
  5864. + swap_all_method_annotations(new_num, num, new_class);
  5865. }
  5866. - } // end for each bytecode
  5867. -} // end rewrite_cp_refs_in_method()
  5868. -
  5869. -
  5870. -// Rewrite constant pool references in the class_annotations field.
  5871. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  5872. - instanceKlassHandle scratch_class, TRAPS) {
  5873. + TRACE_RC1("Method added: new: %s [%d]",
  5874. + k_new_method->name_and_sig_as_C_string(), ni);
  5875. + ++ni; // advance to next new method
  5876. + break;
  5877. + case deleted:
  5878. + // method deleted, see if it is OK
  5879. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5880. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5881. + // hack: private should be treated as final, but alas
  5882. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5883. + ) {
  5884. + // deleted methods must be private
  5885. + result = result | Klass::ModifyClass;
  5886. + }
  5887. + TRACE_RC1("Method deleted: old: %s [%d]",
  5888. + k_old_method->name_and_sig_as_C_string(), oi);
  5889. + ++oi; // advance to next old method
  5890. + break;
  5891. + default:
  5892. + ShouldNotReachHere();
  5893. + }
  5894. + }
  5895. - typeArrayHandle class_annotations(THREAD,
  5896. - scratch_class->class_annotations());
  5897. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  5898. - // no class_annotations so nothing to do
  5899. - return true;
  5900. + if (new_class()->size() != new_class->old_version()->size()) {
  5901. + result |= Klass::ModifyClassSize;
  5902. }
  5903. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5904. - ("class_annotations length=%d", class_annotations->length()));
  5905. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  5906. + result |= Klass::ModifyInstanceSize;
  5907. + }
  5908. - int byte_i = 0; // byte index into class_annotations
  5909. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  5910. - THREAD);
  5911. + // (tw) Check method bodies to be able to return NoChange?
  5912. + return result;
  5913. }
  5914. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  5915. -// Rewrite constant pool references in an annotations typeArray. This
  5916. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  5917. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  5918. -//
  5919. -// annotations_typeArray {
  5920. -// u2 num_annotations;
  5921. -// annotation annotations[num_annotations];
  5922. -// }
  5923. -//
  5924. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  5925. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  5926. -
  5927. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  5928. - // not enough room for num_annotations field
  5929. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5930. - ("length() is too small for num_annotations field"));
  5931. - return false;
  5932. - }
  5933. + class CalculateFieldUpdates : public FieldClosure {
  5934. - u2 num_annotations = Bytes::get_Java_u2((address)
  5935. - annotations_typeArray->byte_at_addr(byte_i_ref));
  5936. - byte_i_ref += 2;
  5937. + private:
  5938. + instanceKlass* _old_ik;
  5939. + GrowableArray<int> _update_info;
  5940. + int _position;
  5941. + bool _copy_backwards;
  5942. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5943. - ("num_annotations=%d", num_annotations));
  5944. + public:
  5945. - int calc_num_annotations = 0;
  5946. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  5947. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  5948. - byte_i_ref, THREAD)) {
  5949. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5950. - ("bad annotation_struct at %d", calc_num_annotations));
  5951. - // propagate failure back to caller
  5952. - return false;
  5953. + bool does_copy_backwards() {
  5954. + return _copy_backwards;
  5955. }
  5956. - }
  5957. - assert(num_annotations == calc_num_annotations, "sanity check");
  5958. - return true;
  5959. -} // end rewrite_cp_refs_in_annotations_typeArray()
  5960. + CalculateFieldUpdates(instanceKlass* old_ik) :
  5961. + _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
  5962. + _update_info.append(_position);
  5963. + _update_info.append(0);
  5964. + }
  5965. + GrowableArray<int> &finish() {
  5966. + _update_info.append(0);
  5967. + return _update_info;
  5968. + }
  5969. -// Rewrite constant pool references in the annotation struct portion of
  5970. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  5971. -// the 2nd-edition of the VM spec:
  5972. -//
  5973. -// struct annotation {
  5974. -// u2 type_index;
  5975. -// u2 num_element_value_pairs;
  5976. -// {
  5977. -// u2 element_name_index;
  5978. -// element_value value;
  5979. -// } element_value_pairs[num_element_value_pairs];
  5980. -// }
  5981. -//
  5982. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  5983. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  5984. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  5985. - // not enough room for smallest annotation_struct
  5986. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5987. - ("length() is too small for annotation_struct"));
  5988. - return false;
  5989. - }
  5990. + void do_field(fieldDescriptor* fd) {
  5991. + int alignment = fd->offset() - _position;
  5992. + if (alignment > 0) {
  5993. + // This field was aligned, so we need to make sure that we fill the gap
  5994. + fill(alignment);
  5995. + }
  5996. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  5997. - byte_i_ref, "mapped old type_index=%d", THREAD);
  5998. + assert(_position == fd->offset(), "must be correct offset!");
  5999. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  6000. - annotations_typeArray->byte_at_addr(
  6001. - byte_i_ref));
  6002. - byte_i_ref += 2;
  6003. + fieldDescriptor old_fd;
  6004. + if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
  6005. + // Found field in the old class, copy
  6006. + copy(old_fd.offset(), type2aelembytes(fd->field_type()));
  6007. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6008. - ("type_index=%d num_element_value_pairs=%d", type_index,
  6009. - num_element_value_pairs));
  6010. + if (old_fd.offset() < fd->offset()) {
  6011. + _copy_backwards = true;
  6012. + }
  6013. - int calc_num_element_value_pairs = 0;
  6014. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  6015. - calc_num_element_value_pairs++) {
  6016. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6017. - // not enough room for another element_name_index, let alone
  6018. - // the rest of another component
  6019. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6020. - ("length() is too small for element_name_index"));
  6021. - return false;
  6022. + // Transfer special flags
  6023. + fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
  6024. + fd->set_is_field_access_watched(old_fd.is_field_access_watched());
  6025. + } else {
  6026. + // New field, fill
  6027. + fill(type2aelembytes(fd->field_type()));
  6028. + }
  6029. }
  6030. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  6031. - annotations_typeArray, byte_i_ref,
  6032. - "mapped old element_name_index=%d", THREAD);
  6033. + private:
  6034. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6035. - ("element_name_index=%d", element_name_index));
  6036. -
  6037. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  6038. - byte_i_ref, THREAD)) {
  6039. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6040. - ("bad element_value at %d", calc_num_element_value_pairs));
  6041. - // propagate failure back to caller
  6042. - return false;
  6043. + void fill(int size) {
  6044. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
  6045. + (*_update_info.adr_at(_update_info.length() - 1)) -= size;
  6046. + } else {
  6047. + _update_info.append(-size);
  6048. + }
  6049. + _position += size;
  6050. }
  6051. - } // end for each component
  6052. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  6053. - "sanity check");
  6054. -
  6055. - return true;
  6056. -} // end rewrite_cp_refs_in_annotation_struct()
  6057. -
  6058. -
  6059. -// Rewrite a constant pool reference at the current position in
  6060. -// annotations_typeArray if needed. Returns the original constant
  6061. -// pool reference if a rewrite was not needed or the new constant
  6062. -// pool reference if a rewrite was needed.
  6063. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  6064. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  6065. - const char * trace_mesg, TRAPS) {
  6066. -
  6067. - address cp_index_addr = (address)
  6068. - annotations_typeArray->byte_at_addr(byte_i_ref);
  6069. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  6070. - u2 new_cp_index = find_new_index(old_cp_index);
  6071. - if (new_cp_index != 0) {
  6072. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  6073. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  6074. - old_cp_index = new_cp_index;
  6075. - }
  6076. - byte_i_ref += 2;
  6077. - return old_cp_index;
  6078. -}
  6079. -
  6080. -
  6081. -// Rewrite constant pool references in the element_value portion of an
  6082. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  6083. -// the 2nd-edition of the VM spec:
  6084. -//
  6085. -// struct element_value {
  6086. -// u1 tag;
  6087. -// union {
  6088. -// u2 const_value_index;
  6089. -// {
  6090. -// u2 type_name_index;
  6091. -// u2 const_name_index;
  6092. -// } enum_const_value;
  6093. -// u2 class_info_index;
  6094. -// annotation annotation_value;
  6095. -// struct {
  6096. -// u2 num_values;
  6097. -// element_value values[num_values];
  6098. -// } array_value;
  6099. -// } value;
  6100. -// }
  6101. -//
  6102. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  6103. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6104. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  6105. - // not enough room for a tag let alone the rest of an element_value
  6106. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6107. - ("length() is too small for a tag"));
  6108. - return false;
  6109. - }
  6110. + void copy(int offset, int size) {
  6111. + int prev_end = -1;
  6112. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
  6113. + prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
  6114. + }
  6115. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  6116. - byte_i_ref++;
  6117. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  6118. -
  6119. - switch (tag) {
  6120. - // These BaseType tag values are from Table 4.2 in VM spec:
  6121. - case 'B': // byte
  6122. - case 'C': // char
  6123. - case 'D': // double
  6124. - case 'F': // float
  6125. - case 'I': // int
  6126. - case 'J': // long
  6127. - case 'S': // short
  6128. - case 'Z': // boolean
  6129. -
  6130. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  6131. - // the VM spec:
  6132. - case 's':
  6133. - {
  6134. - // For the above tag values (including the BaseType values),
  6135. - // value.const_value_index is right union field.
  6136. -
  6137. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6138. - // not enough room for a const_value_index
  6139. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6140. - ("length() is too small for a const_value_index"));
  6141. - return false;
  6142. + if (prev_end == offset) {
  6143. + (*_update_info.adr_at(_update_info.length() - 2)) += size;
  6144. + } else {
  6145. + _update_info.append(size);
  6146. + _update_info.append(offset);
  6147. }
  6148. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  6149. - annotations_typeArray, byte_i_ref,
  6150. - "mapped old const_value_index=%d", THREAD);
  6151. + _position += size;
  6152. + }
  6153. + };
  6154. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6155. - ("const_value_index=%d", const_value_index));
  6156. - } break;
  6157. + instanceKlass* ik = instanceKlass::cast(new_version);
  6158. + instanceKlass* old_ik = instanceKlass::cast(new_version->klass_part()->old_version());
  6159. + CalculateFieldUpdates cl(old_ik);
  6160. + ik->do_nonstatic_fields(&cl);
  6161. - case 'e':
  6162. - {
  6163. - // for the above tag value, value.enum_const_value is right union field
  6164. + GrowableArray<int> result = cl.finish();
  6165. + ik->store_update_information(result);
  6166. + ik->set_copying_backwards(cl.does_copy_backwards());
  6167. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  6168. - // not enough room for a enum_const_value
  6169. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6170. - ("length() is too small for a enum_const_value"));
  6171. - return false;
  6172. + IF_TRACE_RC2 {
  6173. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  6174. + if (cl.does_copy_backwards()) {
  6175. + TRACE_RC2("\tDoes copy backwards!");
  6176. + }
  6177. + for (int i=0; i<result.length(); i++) {
  6178. + int curNum = result.at(i);
  6179. + if (curNum < 0) {
  6180. + TRACE_RC2("\t%d CLEAN", curNum);
  6181. + } else if (curNum > 0) {
  6182. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  6183. + i++;
  6184. + } else {
  6185. + TRACE_RC2("\tEND");
  6186. }
  6187. + }
  6188. + }
  6189. +}
  6190. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  6191. - annotations_typeArray, byte_i_ref,
  6192. - "mapped old type_name_index=%d", THREAD);
  6193. -
  6194. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  6195. - annotations_typeArray, byte_i_ref,
  6196. - "mapped old const_name_index=%d", THREAD);
  6197. +void VM_RedefineClasses::rollback() {
  6198. + TRACE_RC1("Rolling back redefinition!");
  6199. + SystemDictionary::rollback_redefinition();
  6200. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6201. - ("type_name_index=%d const_name_index=%d", type_name_index,
  6202. - const_name_index));
  6203. - } break;
  6204. + TRACE_RC1("After rolling back system dictionary!");
  6205. + for (int i=0; i<_new_classes->length(); i++) {
  6206. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  6207. + }
  6208. - case 'c':
  6209. - {
  6210. - // for the above tag value, value.class_info_index is right union field
  6211. + for (int i=0; i<_new_classes->length(); i++) {
  6212. + instanceKlassHandle new_class = _new_classes->at(i);
  6213. + new_class->set_redefining(false);
  6214. + new_class->old_version()->klass_part()->set_new_version(NULL);
  6215. + new_class->set_old_version(NULL);
  6216. + }
  6217. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6218. - // not enough room for a class_info_index
  6219. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6220. - ("length() is too small for a class_info_index"));
  6221. - return false;
  6222. - }
  6223. +}
  6224. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  6225. - annotations_typeArray, byte_i_ref,
  6226. - "mapped old class_info_index=%d", THREAD);
  6227. -
  6228. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6229. - ("class_info_index=%d", class_info_index));
  6230. - } break;
  6231. -
  6232. - case '@':
  6233. - // For the above tag value, value.attr_value is the right union
  6234. - // field. This is a nested annotation.
  6235. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6236. - byte_i_ref, THREAD)) {
  6237. - // propagate failure back to caller
  6238. - return false;
  6239. - }
  6240. - break;
  6241. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  6242. + markOop first_mark = first->mark();
  6243. + markOop second_mark = second->mark();
  6244. + first->set_mark(second_mark);
  6245. + second->set_mark(first_mark);
  6246. +}
  6247. - case '[':
  6248. - {
  6249. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6250. - // not enough room for a num_values field
  6251. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6252. - ("length() is too small for a num_values field"));
  6253. - return false;
  6254. - }
  6255. - // For the above tag value, value.array_value is the right union
  6256. - // field. This is an array of nested element_value.
  6257. - u2 num_values = Bytes::get_Java_u2((address)
  6258. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6259. - byte_i_ref += 2;
  6260. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  6261. -
  6262. - int calc_num_values = 0;
  6263. - for (; calc_num_values < num_values; calc_num_values++) {
  6264. - if (!rewrite_cp_refs_in_element_value(
  6265. - annotations_typeArray, byte_i_ref, THREAD)) {
  6266. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6267. - ("bad nested element_value at %d", calc_num_values));
  6268. - // propagate failure back to caller
  6269. - return false;
  6270. +class FieldCopier : public FieldClosure {
  6271. + public:
  6272. + void do_field(fieldDescriptor* fd) {
  6273. + instanceKlass* cur = instanceKlass::cast(fd->field_holder());
  6274. + oop cur_oop = cur->java_mirror();
  6275. +
  6276. + instanceKlass* old = instanceKlass::cast(cur->old_version());
  6277. + oop old_oop = old->java_mirror();
  6278. +
  6279. + fieldDescriptor result;
  6280. + bool found = old->find_local_field(fd->name(), fd->signature(), &result);
  6281. + if (found && result.is_static()) {
  6282. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d",
  6283. + fd->name()->as_C_string(), result.offset(), fd->offset());
  6284. + memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
  6285. + old_oop->obj_field_addr<HeapWord>(result.offset()),
  6286. + type2aelembytes(fd->field_type()));
  6287. +
  6288. + // Static fields may have references to java.lang.Class
  6289. + if (fd->field_type() == T_OBJECT) {
  6290. + oop oop = cur_oop->obj_field(fd->offset());
  6291. + if (oop != NULL && oop->is_instanceMirror()) {
  6292. + klassOop klass = java_lang_Class::as_klassOop(oop);
  6293. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  6294. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  6295. + if (klass->klass_part()->new_version() != NULL) {
  6296. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  6297. +
  6298. + cur_oop->obj_field_put(fd->offset(), oop);
  6299. + }
  6300. + }
  6301. }
  6302. }
  6303. - assert(num_values == calc_num_values, "sanity check");
  6304. - } break;
  6305. -
  6306. - default:
  6307. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  6308. - return false;
  6309. - } // end decode tag field
  6310. -
  6311. - return true;
  6312. -} // end rewrite_cp_refs_in_element_value()
  6313. -
  6314. -
  6315. -// Rewrite constant pool references in a fields_annotations field.
  6316. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  6317. - instanceKlassHandle scratch_class, TRAPS) {
  6318. -
  6319. - objArrayHandle fields_annotations(THREAD,
  6320. - scratch_class->fields_annotations());
  6321. + }
  6322. + }
  6323. +};
  6324. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  6325. - // no fields_annotations so nothing to do
  6326. - return true;
  6327. +void VM_RedefineClasses::mark_as_scavengable(nmethod* nm) {
  6328. + if (!nm->on_scavenge_root_list()) {
  6329. + CodeCache::add_scavenge_root_nmethod(nm);
  6330. }
  6331. +}
  6332. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6333. - ("fields_annotations length=%d", fields_annotations->length()));
  6334. +struct StoreBarrier {
  6335. + template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
  6336. +};
  6337. - for (int i = 0; i < fields_annotations->length(); i++) {
  6338. - typeArrayHandle field_annotations(THREAD,
  6339. - (typeArrayOop)fields_annotations->obj_at(i));
  6340. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  6341. - // this field does not have any annotations so skip it
  6342. - continue;
  6343. - }
  6344. +struct StoreNoBarrier {
  6345. + template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
  6346. +};
  6347. - int byte_i = 0; // byte index into field_annotations
  6348. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  6349. - THREAD)) {
  6350. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6351. - ("bad field_annotations at %d", i));
  6352. - // propagate failure back to caller
  6353. - return false;
  6354. +template <class S>
  6355. +class ChangePointersOopClosure : public OopClosureNoHeader {
  6356. + // Forward pointers to instanceKlass and mirror class to new versions
  6357. + template <class T>
  6358. + inline void do_oop_work(T* p) {
  6359. + oop oop = oopDesc::load_decode_heap_oop(p);
  6360. + if (oop == NULL) {
  6361. + return;
  6362. + }
  6363. + if (oop->is_instanceKlass()) {
  6364. + klassOop klass = (klassOop) oop;
  6365. + if (klass->klass_part()->new_version() != NULL) {
  6366. + oop = klass->klass_part()->new_version();
  6367. + S::oop_store(p, oop);
  6368. + }
  6369. + } else if (oop->is_instanceMirror()) {
  6370. + klassOop klass = java_lang_Class::as_klassOop(oop);
  6371. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  6372. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  6373. + if (klass->klass_part()->new_version() != NULL) {
  6374. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  6375. + S::oop_store(p, oop);
  6376. + }
  6377. + }
  6378. }
  6379. }
  6380. - return true;
  6381. -} // end rewrite_cp_refs_in_fields_annotations()
  6382. -
  6383. -
  6384. -// Rewrite constant pool references in a methods_annotations field.
  6385. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  6386. - instanceKlassHandle scratch_class, TRAPS) {
  6387. -
  6388. - objArrayHandle methods_annotations(THREAD,
  6389. - scratch_class->methods_annotations());
  6390. + virtual void do_oop(oop* o) {
  6391. + do_oop_work(o);
  6392. + }
  6393. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  6394. - // no methods_annotations so nothing to do
  6395. - return true;
  6396. + virtual void do_oop(narrowOop* o) {
  6397. + do_oop_work(o);
  6398. }
  6399. +};
  6400. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6401. - ("methods_annotations length=%d", methods_annotations->length()));
  6402. +void VM_RedefineClasses::doit() {
  6403. + Thread *thread = Thread::current();
  6404. +
  6405. + TRACE_RC1("Entering doit!");
  6406. - for (int i = 0; i < methods_annotations->length(); i++) {
  6407. - typeArrayHandle method_annotations(THREAD,
  6408. - (typeArrayOop)methods_annotations->obj_at(i));
  6409. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  6410. - // this method does not have any annotations so skip it
  6411. - continue;
  6412. - }
  6413. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  6414. - int byte_i = 0; // byte index into method_annotations
  6415. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  6416. - THREAD)) {
  6417. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6418. - ("bad method_annotations at %d", i));
  6419. - // propagate failure back to caller
  6420. - return false;
  6421. + if (UseSharedSpaces) {
  6422. + // Sharing is enabled so we remap the shared readonly space to
  6423. + // shared readwrite, private just in case we need to redefine
  6424. + // a shared class. We do the remap during the doit() phase of
  6425. + // the safepoint to be safer.
  6426. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  6427. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  6428. + _result = JVMTI_ERROR_INTERNAL;
  6429. + return;
  6430. }
  6431. }
  6432. +
  6433. + RC_TIMER_START(_timer_prepare_redefinition);
  6434. + for (int i = 0; i < _new_classes->length(); i++) {
  6435. + redefine_single_class(_new_classes->at(i), thread);
  6436. + }
  6437. +
  6438. + // Deoptimize all compiled code that depends on this class
  6439. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  6440. - return true;
  6441. -} // end rewrite_cp_refs_in_methods_annotations()
  6442. + // Adjust constantpool caches and vtables for all classes
  6443. + // that reference methods of the evolved class.
  6444. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  6445. + RC_TIMER_STOP(_timer_prepare_redefinition);
  6446. + RC_TIMER_START(_timer_heap_iteration);
  6447. -// Rewrite constant pool references in a methods_parameter_annotations
  6448. -// field. This "structure" is adapted from the
  6449. -// RuntimeVisibleParameterAnnotations_attribute described in section
  6450. -// 4.8.17 of the 2nd-edition of the VM spec:
  6451. -//
  6452. -// methods_parameter_annotations_typeArray {
  6453. -// u1 num_parameters;
  6454. -// {
  6455. -// u2 num_annotations;
  6456. -// annotation annotations[num_annotations];
  6457. -// } parameter_annotations[num_parameters];
  6458. -// }
  6459. -//
  6460. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  6461. - instanceKlassHandle scratch_class, TRAPS) {
  6462. + class ChangePointersObjectClosure : public ObjectClosure {
  6463. - objArrayHandle methods_parameter_annotations(THREAD,
  6464. - scratch_class->methods_parameter_annotations());
  6465. + private:
  6466. - if (methods_parameter_annotations.is_null()
  6467. - || methods_parameter_annotations->length() == 0) {
  6468. - // no methods_parameter_annotations so nothing to do
  6469. - return true;
  6470. - }
  6471. + OopClosureNoHeader *_closure;
  6472. + bool _needs_instance_update;
  6473. + oop _tmp_obj;
  6474. + int _tmp_obj_size;
  6475. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6476. - ("methods_parameter_annotations length=%d",
  6477. - methods_parameter_annotations->length()));
  6478. + public:
  6479. + ChangePointersObjectClosure(OopClosureNoHeader *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
  6480. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  6481. - typeArrayHandle method_parameter_annotations(THREAD,
  6482. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  6483. - if (method_parameter_annotations.is_null()
  6484. - || method_parameter_annotations->length() == 0) {
  6485. - // this method does not have any parameter annotations so skip it
  6486. - continue;
  6487. - }
  6488. + bool needs_instance_update() {
  6489. + return _needs_instance_update;
  6490. + }
  6491. - if (method_parameter_annotations->length() < 1) {
  6492. - // not enough room for a num_parameters field
  6493. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6494. - ("length() is too small for a num_parameters field at %d", i));
  6495. - return false;
  6496. - }
  6497. + void copy_to_tmp(oop o) {
  6498. + int size = o->size();
  6499. + if (_tmp_obj_size < size) {
  6500. + _tmp_obj_size = size;
  6501. + _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  6502. + }
  6503. + Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
  6504. + }
  6505. - int byte_i = 0; // byte index into method_parameter_annotations
  6506. + virtual void do_object(oop obj) {
  6507. + if (obj->is_instanceKlass()) return;
  6508. + if (obj->is_instanceMirror()) {
  6509. + // static fields may have references to old java.lang.Class instances, update them
  6510. + // at the same time, we don't want to update other oops in the java.lang.Class
  6511. + // Causes SIGSEGV?
  6512. + //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
  6513. + } else {
  6514. + obj->oop_iterate(_closure);
  6515. + }
  6516. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  6517. - byte_i++;
  6518. + if (obj->blueprint()->new_version() != NULL) {
  6519. + Klass* new_klass = obj->blueprint()->new_version()->klass_part();
  6520. + if (obj->is_perm()) {
  6521. + _needs_instance_update = true;
  6522. + } else if(new_klass->update_information() != NULL) {
  6523. + int size_diff = obj->size() - obj->size_given_klass(new_klass);
  6524. +
  6525. + // Either new size is bigger or gap is to small to be filled
  6526. + if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
  6527. + // We need an instance update => set back to old klass
  6528. + _needs_instance_update = true;
  6529. + } else {
  6530. + oop src = obj;
  6531. + if (new_klass->is_copying_backwards()) {
  6532. + copy_to_tmp(obj);
  6533. + src = _tmp_obj;
  6534. + }
  6535. + src->set_klass_no_check(obj->blueprint()->new_version());
  6536. + MarkSweep::update_fields(obj, src, new_klass->update_information());
  6537. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6538. - ("num_parameters=%d", num_parameters));
  6539. + if (size_diff > 0) {
  6540. + HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
  6541. + CollectedHeap::fill_with_object(dead_space, size_diff);
  6542. + }
  6543. + }
  6544. + } else {
  6545. + obj->set_klass_no_check(obj->blueprint()->new_version());
  6546. + }
  6547. + }
  6548. + }
  6549. + };
  6550. +
  6551. + ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
  6552. + ChangePointersOopClosure<StoreBarrier> oopClosure;
  6553. + ChangePointersObjectClosure objectClosure(&oopClosure);
  6554. - int calc_num_parameters = 0;
  6555. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  6556. - if (!rewrite_cp_refs_in_annotations_typeArray(
  6557. - method_parameter_annotations, byte_i, THREAD)) {
  6558. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6559. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  6560. - // propagate failure back to caller
  6561. - return false;
  6562. + {
  6563. + // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
  6564. + // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
  6565. + // mark such nmethod's as "scavengable".
  6566. + // For now, mark all nmethod's as scavengable that are not scavengable already
  6567. + if (ScavengeRootsInCode) {
  6568. + CodeCache::nmethods_do(mark_as_scavengable);
  6569. }
  6570. +
  6571. + SharedHeap::heap()->gc_prologue(true);
  6572. + Universe::heap()->object_iterate(&objectClosure);
  6573. + Universe::root_oops_do(&oopClosureNoBarrier);
  6574. + SharedHeap::heap()->gc_epilogue(false);
  6575. }
  6576. - assert(num_parameters == calc_num_parameters, "sanity check");
  6577. - }
  6578. - return true;
  6579. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  6580. + for (int i=0; i<_new_classes->length(); i++) {
  6581. + klassOop cur_oop = _new_classes->at(i)();
  6582. + instanceKlass* cur = instanceKlass::cast(cur_oop);
  6583. + klassOop old_oop = cur->old_version();
  6584. + instanceKlass* old = instanceKlass::cast(old_oop);
  6585. -// Rewrite constant pool references in a methods_default_annotations
  6586. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  6587. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  6588. -//
  6589. -// methods_default_annotations_typeArray {
  6590. -// element_value default_value;
  6591. -// }
  6592. -//
  6593. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  6594. - instanceKlassHandle scratch_class, TRAPS) {
  6595. + // Swap marks to have same hashcodes
  6596. + swap_marks(cur_oop, old_oop);
  6597. + swap_marks(cur->java_mirror(), old->java_mirror());
  6598. - objArrayHandle methods_default_annotations(THREAD,
  6599. - scratch_class->methods_default_annotations());
  6600. + // Revert pool holder for old version of klass (it was updated by one of ours closure!)
  6601. + old->constants()->set_pool_holder(old_oop);
  6602. - if (methods_default_annotations.is_null()
  6603. - || methods_default_annotations->length() == 0) {
  6604. - // no methods_default_annotations so nothing to do
  6605. - return true;
  6606. - }
  6607. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6608. - ("methods_default_annotations length=%d",
  6609. - methods_default_annotations->length()));
  6610. + if (old->array_klasses() != NULL) {
  6611. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  6612. + assert(cur->array_klasses() == NULL, "just checking");
  6613. + cur->set_array_klasses(old->array_klasses());
  6614. + }
  6615. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  6616. - typeArrayHandle method_default_annotations(THREAD,
  6617. - (typeArrayOop)methods_default_annotations->obj_at(i));
  6618. - if (method_default_annotations.is_null()
  6619. - || method_default_annotations->length() == 0) {
  6620. - // this method does not have any default annotations so skip it
  6621. - continue;
  6622. + // Initialize the new class! Special static initialization that does not execute the
  6623. + // static constructor but copies static field values from the old class if name
  6624. + // and signature of a static field match.
  6625. + FieldCopier copier;
  6626. + cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
  6627. + old->set_java_mirror(cur->java_mirror());
  6628. +
  6629. + // Transfer init state
  6630. + instanceKlass::ClassState state = old->init_state();
  6631. + if (state > instanceKlass::linked) {
  6632. + cur->set_init_state(state);
  6633. + }
  6634. }
  6635. - int byte_i = 0; // byte index into method_default_annotations
  6636. + RC_TIMER_STOP(_timer_heap_iteration);
  6637. + RC_TIMER_START(_timer_redefinition);
  6638. + if (objectClosure.needs_instance_update()){
  6639. - if (!rewrite_cp_refs_in_element_value(
  6640. - method_default_annotations, byte_i, THREAD)) {
  6641. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6642. - ("bad default element_value at %d", i));
  6643. - // propagate failure back to caller
  6644. - return false;
  6645. - }
  6646. + // Do a full garbage collection to update the instance sizes accordingly
  6647. + TRACE_RC1("Before performing full GC!");
  6648. + Universe::set_redefining_gc_run(true);
  6649. + notify_gc_begin(true);
  6650. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  6651. + notify_gc_end();
  6652. + Universe::set_redefining_gc_run(false);
  6653. + TRACE_RC1("GC done!");
  6654. }
  6655. - return true;
  6656. -} // end rewrite_cp_refs_in_methods_default_annotations()
  6657. + // Unmark klassOops as "redefining"
  6658. + for (int i=0; i<_new_classes->length(); i++) {
  6659. + klassOop cur_klass = _new_classes->at(i)();
  6660. + instanceKlass* cur = (instanceKlass*)cur_klass->klass_part();
  6661. + cur->set_redefining(false);
  6662. + cur->clear_update_information();
  6663. + }
  6664. + // Disable any dependent concurrent compilations
  6665. + SystemDictionary::notice_modification();
  6666. -// Rewrite constant pool references in the method's stackmap table.
  6667. -// These "structures" are adapted from the StackMapTable_attribute that
  6668. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  6669. -// (dated 2005.10.26):
  6670. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6671. -//
  6672. -// stack_map {
  6673. -// u2 number_of_entries;
  6674. -// stack_map_frame entries[number_of_entries];
  6675. -// }
  6676. -//
  6677. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  6678. - methodHandle method, TRAPS) {
  6679. + // Set flag indicating that some invariants are no longer true.
  6680. + // See jvmtiExport.hpp for detailed explanation.
  6681. + JvmtiExport::set_has_redefined_a_class();
  6682. - if (!method->has_stackmap_table()) {
  6683. - return;
  6684. - }
  6685. + // Clean up caches in the compiler interface and compiler threads
  6686. + ciObjectFactory::resort_shared_ci_objects();
  6687. - typeArrayOop stackmap_data = method->stackmap_data();
  6688. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  6689. - address stackmap_end = stackmap_p + stackmap_data->length();
  6690. -
  6691. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  6692. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  6693. - stackmap_p += 2;
  6694. -
  6695. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6696. - ("number_of_entries=%u", number_of_entries));
  6697. -
  6698. - // walk through each stack_map_frame
  6699. - u2 calc_number_of_entries = 0;
  6700. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  6701. - // The stack_map_frame structure is a u1 frame_type followed by
  6702. - // 0 or more bytes of data:
  6703. - //
  6704. - // union stack_map_frame {
  6705. - // same_frame;
  6706. - // same_locals_1_stack_item_frame;
  6707. - // same_locals_1_stack_item_frame_extended;
  6708. - // chop_frame;
  6709. - // same_frame_extended;
  6710. - // append_frame;
  6711. - // full_frame;
  6712. - // }
  6713. -
  6714. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  6715. - // The Linux compiler does not like frame_type to be u1 or u2. It
  6716. - // issues the following warning for the first if-statement below:
  6717. - //
  6718. - // "warning: comparison is always true due to limited range of data type"
  6719. - //
  6720. - u4 frame_type = *stackmap_p;
  6721. - stackmap_p++;
  6722. -
  6723. - // same_frame {
  6724. - // u1 frame_type = SAME; /* 0-63 */
  6725. - // }
  6726. - if (frame_type >= 0 && frame_type <= 63) {
  6727. - // nothing more to do for same_frame
  6728. - }
  6729. -
  6730. - // same_locals_1_stack_item_frame {
  6731. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  6732. - // verification_type_info stack[1];
  6733. - // }
  6734. - else if (frame_type >= 64 && frame_type <= 127) {
  6735. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6736. - calc_number_of_entries, frame_type, THREAD);
  6737. - }
  6738. -
  6739. - // reserved for future use
  6740. - else if (frame_type >= 128 && frame_type <= 246) {
  6741. - // nothing more to do for reserved frame_types
  6742. - }
  6743. -
  6744. - // same_locals_1_stack_item_frame_extended {
  6745. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  6746. - // u2 offset_delta;
  6747. - // verification_type_info stack[1];
  6748. - // }
  6749. - else if (frame_type == 247) {
  6750. - stackmap_p += 2;
  6751. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6752. - calc_number_of_entries, frame_type, THREAD);
  6753. - }
  6754. -
  6755. - // chop_frame {
  6756. - // u1 frame_type = CHOP; /* 248-250 */
  6757. - // u2 offset_delta;
  6758. - // }
  6759. - else if (frame_type >= 248 && frame_type <= 250) {
  6760. - stackmap_p += 2;
  6761. - }
  6762. -
  6763. - // same_frame_extended {
  6764. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  6765. - // u2 offset_delta;
  6766. - // }
  6767. - else if (frame_type == 251) {
  6768. - stackmap_p += 2;
  6769. - }
  6770. -
  6771. - // append_frame {
  6772. - // u1 frame_type = APPEND; /* 252-254 */
  6773. - // u2 offset_delta;
  6774. - // verification_type_info locals[frame_type - 251];
  6775. - // }
  6776. - else if (frame_type >= 252 && frame_type <= 254) {
  6777. - assert(stackmap_p + 2 <= stackmap_end,
  6778. - "no room for offset_delta");
  6779. - stackmap_p += 2;
  6780. - u1 len = frame_type - 251;
  6781. - for (u1 i = 0; i < len; i++) {
  6782. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6783. - calc_number_of_entries, frame_type, THREAD);
  6784. - }
  6785. - }
  6786. +#ifdef ASSERT
  6787. - // full_frame {
  6788. - // u1 frame_type = FULL_FRAME; /* 255 */
  6789. - // u2 offset_delta;
  6790. - // u2 number_of_locals;
  6791. - // verification_type_info locals[number_of_locals];
  6792. - // u2 number_of_stack_items;
  6793. - // verification_type_info stack[number_of_stack_items];
  6794. - // }
  6795. - else if (frame_type == 255) {
  6796. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  6797. - "no room for smallest full_frame");
  6798. - stackmap_p += 2;
  6799. -
  6800. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  6801. - stackmap_p += 2;
  6802. -
  6803. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  6804. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6805. - calc_number_of_entries, frame_type, THREAD);
  6806. - }
  6807. + // Universe::verify();
  6808. + // JNIHandles::verify();
  6809. - // Use the largest size for the number_of_stack_items, but only get
  6810. - // the right number of bytes.
  6811. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  6812. - stackmap_p += 2;
  6813. + SystemDictionary::classes_do(check_class, thread);
  6814. +#endif
  6815. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  6816. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6817. - calc_number_of_entries, frame_type, THREAD);
  6818. - }
  6819. - }
  6820. - } // end while there is a stack_map_frame
  6821. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  6822. -} // end rewrite_cp_refs_in_stack_map_table()
  6823. + RC_TIMER_STOP(_timer_redefinition);
  6824. + if (TraceRedefineClasses > 0) {
  6825. + tty->flush();
  6826. + }
  6827. +}
  6828. -// Rewrite constant pool references in the verification type info
  6829. -// portion of the method's stackmap table. These "structures" are
  6830. -// adapted from the StackMapTable_attribute that is described in
  6831. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  6832. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6833. -//
  6834. -// The verification_type_info structure is a u1 tag followed by 0 or
  6835. -// more bytes of data:
  6836. -//
  6837. -// union verification_type_info {
  6838. -// Top_variable_info;
  6839. -// Integer_variable_info;
  6840. -// Float_variable_info;
  6841. -// Long_variable_info;
  6842. -// Double_variable_info;
  6843. -// Null_variable_info;
  6844. -// UninitializedThis_variable_info;
  6845. -// Object_variable_info;
  6846. -// Uninitialized_variable_info;
  6847. -// }
  6848. -//
  6849. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  6850. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  6851. - u1 frame_type, TRAPS) {
  6852. -
  6853. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  6854. - u1 tag = *stackmap_p_ref;
  6855. - stackmap_p_ref++;
  6856. -
  6857. - switch (tag) {
  6858. - // Top_variable_info {
  6859. - // u1 tag = ITEM_Top; /* 0 */
  6860. - // }
  6861. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  6862. - case 0: // fall through
  6863. -
  6864. - // Integer_variable_info {
  6865. - // u1 tag = ITEM_Integer; /* 1 */
  6866. - // }
  6867. - case ITEM_Integer: // fall through
  6868. -
  6869. - // Float_variable_info {
  6870. - // u1 tag = ITEM_Float; /* 2 */
  6871. - // }
  6872. - case ITEM_Float: // fall through
  6873. -
  6874. - // Double_variable_info {
  6875. - // u1 tag = ITEM_Double; /* 3 */
  6876. - // }
  6877. - case ITEM_Double: // fall through
  6878. -
  6879. - // Long_variable_info {
  6880. - // u1 tag = ITEM_Long; /* 4 */
  6881. - // }
  6882. - case ITEM_Long: // fall through
  6883. -
  6884. - // Null_variable_info {
  6885. - // u1 tag = ITEM_Null; /* 5 */
  6886. - // }
  6887. - case ITEM_Null: // fall through
  6888. -
  6889. - // UninitializedThis_variable_info {
  6890. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  6891. - // }
  6892. - case ITEM_UninitializedThis:
  6893. - // nothing more to do for the above tag types
  6894. - break;
  6895. +void VM_RedefineClasses::doit_epilogue() {
  6896. - // Object_variable_info {
  6897. - // u1 tag = ITEM_Object; /* 7 */
  6898. - // u2 cpool_index;
  6899. - // }
  6900. - case ITEM_Object:
  6901. - {
  6902. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  6903. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  6904. - u2 new_cp_index = find_new_index(cpool_index);
  6905. - if (new_cp_index != 0) {
  6906. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6907. - ("mapped old cpool_index=%d", cpool_index));
  6908. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  6909. - cpool_index = new_cp_index;
  6910. - }
  6911. - stackmap_p_ref += 2;
  6912. -
  6913. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6914. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  6915. - frame_type, cpool_index));
  6916. - } break;
  6917. -
  6918. - // Uninitialized_variable_info {
  6919. - // u1 tag = ITEM_Uninitialized; /* 8 */
  6920. - // u2 offset;
  6921. - // }
  6922. - case ITEM_Uninitialized:
  6923. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  6924. - stackmap_p_ref += 2;
  6925. - break;
  6926. + RC_TIMER_START(_timer_vm_op_epilogue);
  6927. - default:
  6928. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6929. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  6930. - ShouldNotReachHere();
  6931. - break;
  6932. - } // end switch (tag)
  6933. -} // end rewrite_cp_refs_in_verification_type_info()
  6934. -
  6935. -
  6936. -// Change the constant pool associated with klass scratch_class to
  6937. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  6938. -// are copied from scratch_cp to a smaller constant pool and the
  6939. -// smaller constant pool is associated with scratch_class.
  6940. -void VM_RedefineClasses::set_new_constant_pool(
  6941. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  6942. - int scratch_cp_length, bool shrink, TRAPS) {
  6943. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  6944. -
  6945. - if (shrink) {
  6946. - // scratch_cp is a merged constant pool and has enough space for a
  6947. - // worst case merge situation. We want to associate the minimum
  6948. - // sized constant pool with the klass to save space.
  6949. - constantPoolHandle smaller_cp(THREAD,
  6950. - oopFactory::new_constantPool(scratch_cp_length,
  6951. - oopDesc::IsUnsafeConc,
  6952. - THREAD));
  6953. - // preserve orig_length() value in the smaller copy
  6954. - int orig_length = scratch_cp->orig_length();
  6955. - assert(orig_length != 0, "sanity check");
  6956. - smaller_cp->set_orig_length(orig_length);
  6957. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  6958. - scratch_cp = smaller_cp;
  6959. - smaller_cp()->set_is_conc_safe(true);
  6960. - }
  6961. -
  6962. - // attach new constant pool to klass
  6963. - scratch_cp->set_pool_holder(scratch_class());
  6964. -
  6965. - // attach klass to new constant pool
  6966. - scratch_class->set_constants(scratch_cp());
  6967. -
  6968. - int i; // for portability
  6969. -
  6970. - // update each field in klass to use new constant pool indices as needed
  6971. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  6972. - jshort cur_index = fs.name_index();
  6973. - jshort new_index = find_new_index(cur_index);
  6974. - if (new_index != 0) {
  6975. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6976. - ("field-name_index change: %d to %d", cur_index, new_index));
  6977. - fs.set_name_index(new_index);
  6978. - }
  6979. - cur_index = fs.signature_index();
  6980. - new_index = find_new_index(cur_index);
  6981. - if (new_index != 0) {
  6982. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6983. - ("field-signature_index change: %d to %d", cur_index, new_index));
  6984. - fs.set_signature_index(new_index);
  6985. - }
  6986. - cur_index = fs.initval_index();
  6987. - new_index = find_new_index(cur_index);
  6988. - if (new_index != 0) {
  6989. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6990. - ("field-initval_index change: %d to %d", cur_index, new_index));
  6991. - fs.set_initval_index(new_index);
  6992. - }
  6993. - cur_index = fs.generic_signature_index();
  6994. - new_index = find_new_index(cur_index);
  6995. - if (new_index != 0) {
  6996. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6997. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  6998. - fs.set_generic_signature_index(new_index);
  6999. - }
  7000. - } // end for each field
  7001. -
  7002. - // Update constant pool indices in the inner classes info to use
  7003. - // new constant indices as needed. The inner classes info is a
  7004. - // quadruple:
  7005. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  7006. - InnerClassesIterator iter(scratch_class);
  7007. - for (; !iter.done(); iter.next()) {
  7008. - int cur_index = iter.inner_class_info_index();
  7009. - if (cur_index == 0) {
  7010. - continue; // JVM spec. allows null inner class refs so skip it
  7011. - }
  7012. - int new_index = find_new_index(cur_index);
  7013. - if (new_index != 0) {
  7014. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7015. - ("inner_class_info change: %d to %d", cur_index, new_index));
  7016. - iter.set_inner_class_info_index(new_index);
  7017. - }
  7018. - cur_index = iter.outer_class_info_index();
  7019. - new_index = find_new_index(cur_index);
  7020. - if (new_index != 0) {
  7021. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7022. - ("outer_class_info change: %d to %d", cur_index, new_index));
  7023. - iter.set_outer_class_info_index(new_index);
  7024. - }
  7025. - cur_index = iter.inner_name_index();
  7026. - new_index = find_new_index(cur_index);
  7027. - if (new_index != 0) {
  7028. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7029. - ("inner_name change: %d to %d", cur_index, new_index));
  7030. - iter.set_inner_name_index(new_index);
  7031. - }
  7032. - } // end for each inner class
  7033. -
  7034. - // Attach each method in klass to the new constant pool and update
  7035. - // to use new constant pool indices as needed:
  7036. - objArrayHandle methods(THREAD, scratch_class->methods());
  7037. - for (i = methods->length() - 1; i >= 0; i--) {
  7038. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7039. - method->set_constants(scratch_cp());
  7040. -
  7041. - int new_index = find_new_index(method->name_index());
  7042. - if (new_index != 0) {
  7043. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7044. - ("method-name_index change: %d to %d", method->name_index(),
  7045. - new_index));
  7046. - method->set_name_index(new_index);
  7047. - }
  7048. - new_index = find_new_index(method->signature_index());
  7049. - if (new_index != 0) {
  7050. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7051. - ("method-signature_index change: %d to %d",
  7052. - method->signature_index(), new_index));
  7053. - method->set_signature_index(new_index);
  7054. - }
  7055. - new_index = find_new_index(method->generic_signature_index());
  7056. - if (new_index != 0) {
  7057. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7058. - ("method-generic_signature_index change: %d to %d",
  7059. - method->generic_signature_index(), new_index));
  7060. - method->set_generic_signature_index(new_index);
  7061. - }
  7062. -
  7063. - // Update constant pool indices in the method's checked exception
  7064. - // table to use new constant indices as needed.
  7065. - int cext_length = method->checked_exceptions_length();
  7066. - if (cext_length > 0) {
  7067. - CheckedExceptionElement * cext_table =
  7068. - method->checked_exceptions_start();
  7069. - for (int j = 0; j < cext_length; j++) {
  7070. - int cur_index = cext_table[j].class_cp_index;
  7071. - int new_index = find_new_index(cur_index);
  7072. - if (new_index != 0) {
  7073. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7074. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  7075. - cext_table[j].class_cp_index = (u2)new_index;
  7076. - }
  7077. - } // end for each checked exception table entry
  7078. - } // end if there are checked exception table entries
  7079. -
  7080. - // Update each catch type index in the method's exception table
  7081. - // to use new constant pool indices as needed. The exception table
  7082. - // holds quadruple entries of the form:
  7083. - // (beg_bci, end_bci, handler_bci, klass_index)
  7084. -
  7085. - ExceptionTable ex_table(method());
  7086. - int ext_length = ex_table.length();
  7087. -
  7088. - for (int j = 0; j < ext_length; j ++) {
  7089. - int cur_index = ex_table.catch_type_index(j);
  7090. - int new_index = find_new_index(cur_index);
  7091. - if (new_index != 0) {
  7092. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7093. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  7094. - ex_table.set_catch_type_index(j, new_index);
  7095. - }
  7096. - } // end for each exception table entry
  7097. -
  7098. - // Update constant pool indices in the method's local variable
  7099. - // table to use new constant indices as needed. The local variable
  7100. - // table hold sextuple entries of the form:
  7101. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  7102. - int lvt_length = method->localvariable_table_length();
  7103. - if (lvt_length > 0) {
  7104. - LocalVariableTableElement * lv_table =
  7105. - method->localvariable_table_start();
  7106. - for (int j = 0; j < lvt_length; j++) {
  7107. - int cur_index = lv_table[j].name_cp_index;
  7108. - int new_index = find_new_index(cur_index);
  7109. - if (new_index != 0) {
  7110. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7111. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  7112. - lv_table[j].name_cp_index = (u2)new_index;
  7113. - }
  7114. - cur_index = lv_table[j].descriptor_cp_index;
  7115. - new_index = find_new_index(cur_index);
  7116. - if (new_index != 0) {
  7117. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7118. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  7119. - new_index));
  7120. - lv_table[j].descriptor_cp_index = (u2)new_index;
  7121. - }
  7122. - cur_index = lv_table[j].signature_cp_index;
  7123. - new_index = find_new_index(cur_index);
  7124. - if (new_index != 0) {
  7125. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7126. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  7127. - lv_table[j].signature_cp_index = (u2)new_index;
  7128. - }
  7129. - } // end for each local variable table entry
  7130. - } // end if there are local variable table entries
  7131. + //unlock_threads();
  7132. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  7133. - } // end for each method
  7134. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7135. -} // end set_new_constant_pool()
  7136. + ResourceMark mark;
  7137. + VM_GC_Operation::doit_epilogue();
  7138. + TRACE_RC1("GC Operation epilogue finished! ");
  7139. -// Unevolving classes may point to methods of the_class directly
  7140. -// from their constant pool caches, itables, and/or vtables. We
  7141. -// use the SystemDictionary::classes_do() facility and this helper
  7142. -// to fix up these pointers.
  7143. -//
  7144. -// Note: We currently don't support updating the vtable in
  7145. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7146. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  7147. - oop initiating_loader, TRAPS) {
  7148. - Klass *k = k_oop->klass_part();
  7149. - if (k->oop_is_instance()) {
  7150. - HandleMark hm(THREAD);
  7151. - instanceKlass *ik = (instanceKlass *) k;
  7152. + // Free the array of scratch classes
  7153. + delete _new_classes;
  7154. + _new_classes = NULL;
  7155. - // HotSpot specific optimization! HotSpot does not currently
  7156. - // support delegation from the bootstrap class loader to a
  7157. - // user-defined class loader. This means that if the bootstrap
  7158. - // class loader is the initiating class loader, then it will also
  7159. - // be the defining class loader. This also means that classes
  7160. - // loaded by the bootstrap class loader cannot refer to classes
  7161. - // loaded by a user-defined class loader. Note: a user-defined
  7162. - // class loader can delegate to the bootstrap class loader.
  7163. - //
  7164. - // If the current class being redefined has a user-defined class
  7165. - // loader as its defining class loader, then we can skip all
  7166. - // classes loaded by the bootstrap class loader.
  7167. - bool is_user_defined =
  7168. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  7169. - if (is_user_defined && ik->class_loader() == NULL) {
  7170. - return;
  7171. - }
  7172. + // Free the array of affected classes
  7173. + delete _affected_klasses;
  7174. + _affected_klasses = NULL;
  7175. - // This is a very busy routine. We don't want too much tracing
  7176. - // printed out.
  7177. - bool trace_name_printed = false;
  7178. -
  7179. - // Very noisy: only enable this call if you are trying to determine
  7180. - // that a specific class gets found by this routine.
  7181. - // RC_TRACE macro has an embedded ResourceMark
  7182. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  7183. - // ("adjust check: name=%s", ik->external_name()));
  7184. - // trace_name_printed = true;
  7185. -
  7186. - // Fix the vtable embedded in the_class and subclasses of the_class,
  7187. - // if one exists. We discard scratch_class and we don't keep an
  7188. - // instanceKlass around to hold obsolete methods so we don't have
  7189. - // any other instanceKlass embedded vtables to update. The vtable
  7190. - // holds the methodOops for virtual (but not final) methods.
  7191. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  7192. - // ik->vtable() creates a wrapper object; rm cleans it up
  7193. - ResourceMark rm(THREAD);
  7194. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  7195. - _matching_new_methods,
  7196. - _matching_methods_length,
  7197. - &trace_name_printed);
  7198. - }
  7199. -
  7200. - // If the current class has an itable and we are either redefining an
  7201. - // interface or if the current class is a subclass of the_class, then
  7202. - // we potentially have to fix the itable. If we are redefining an
  7203. - // interface, then we have to call adjust_method_entries() for
  7204. - // every instanceKlass that has an itable since there isn't a
  7205. - // subclass relationship between an interface and an instanceKlass.
  7206. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  7207. - || ik->is_subclass_of(_the_class_oop))) {
  7208. - // ik->itable() creates a wrapper object; rm cleans it up
  7209. - ResourceMark rm(THREAD);
  7210. - ik->itable()->adjust_method_entries(_matching_old_methods,
  7211. - _matching_new_methods,
  7212. - _matching_methods_length,
  7213. - &trace_name_printed);
  7214. - }
  7215. -
  7216. - // The constant pools in other classes (other_cp) can refer to
  7217. - // methods in the_class. We have to update method information in
  7218. - // other_cp's cache. If other_cp has a previous version, then we
  7219. - // have to repeat the process for each previous version. The
  7220. - // constant pool cache holds the methodOops for non-virtual
  7221. - // methods and for virtual, final methods.
  7222. - //
  7223. - // Special case: if the current class is the_class, then new_cp
  7224. - // has already been attached to the_class and old_cp has already
  7225. - // been added as a previous version. The new_cp doesn't have any
  7226. - // cached references to old methods so it doesn't need to be
  7227. - // updated. We can simply start with the previous version(s) in
  7228. - // that case.
  7229. - constantPoolHandle other_cp;
  7230. - constantPoolCacheOop cp_cache;
  7231. -
  7232. - if (k_oop != _the_class_oop) {
  7233. - // this klass' constant pool cache may need adjustment
  7234. - other_cp = constantPoolHandle(ik->constants());
  7235. - cp_cache = other_cp->cache();
  7236. - if (cp_cache != NULL) {
  7237. - cp_cache->adjust_method_entries(_matching_old_methods,
  7238. - _matching_new_methods,
  7239. - _matching_methods_length,
  7240. - &trace_name_printed);
  7241. - }
  7242. - }
  7243. - {
  7244. - ResourceMark rm(THREAD);
  7245. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  7246. - // contain a GrowableArray of handles. We have to clean up the
  7247. - // GrowableArray _after_ the PreviousVersionWalker destructor
  7248. - // has destroyed the handles.
  7249. - {
  7250. - // the previous versions' constant pool caches may need adjustment
  7251. - PreviousVersionWalker pvw(ik);
  7252. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  7253. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  7254. - other_cp = pv_info->prev_constant_pool_handle();
  7255. - cp_cache = other_cp->cache();
  7256. - if (cp_cache != NULL) {
  7257. - cp_cache->adjust_method_entries(_matching_old_methods,
  7258. - _matching_new_methods,
  7259. - _matching_methods_length,
  7260. - &trace_name_printed);
  7261. - }
  7262. - }
  7263. - } // pvw is cleaned up
  7264. - } // rm is cleaned up
  7265. - }
  7266. -}
  7267. + TRACE_RC1("Redefinition finished!");
  7268. -void VM_RedefineClasses::update_jmethod_ids() {
  7269. - for (int j = 0; j < _matching_methods_length; ++j) {
  7270. - methodOop old_method = _matching_old_methods[j];
  7271. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  7272. - if (jmid != NULL) {
  7273. - // There is a jmethodID, change it to point to the new method
  7274. - methodHandle new_method_h(_matching_new_methods[j]);
  7275. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7276. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  7277. - "should be replaced");
  7278. - }
  7279. - }
  7280. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  7281. }
  7282. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  7283. - BitMap *emcp_methods, int * emcp_method_count_p) {
  7284. - *emcp_method_count_p = 0;
  7285. - int obsolete_count = 0;
  7286. - int old_index = 0;
  7287. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7288. - methodOop old_method = _matching_old_methods[j];
  7289. - methodOop new_method = _matching_new_methods[j];
  7290. - methodOop old_array_method;
  7291. -
  7292. - // Maintain an old_index into the _old_methods array by skipping
  7293. - // deleted methods
  7294. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7295. - != old_method) {
  7296. - ++old_index;
  7297. - }
  7298. -
  7299. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7300. - // The EMCP definition from JSR-163 requires the bytecodes to be
  7301. - // the same with the exception of constant pool indices which may
  7302. - // differ. However, the constants referred to by those indices
  7303. - // must be the same.
  7304. - //
  7305. - // We use methods_EMCP() for comparison since constant pool
  7306. - // merging can remove duplicate constant pool entries that were
  7307. - // present in the old method and removed from the rewritten new
  7308. - // method. A faster binary comparison function would consider the
  7309. - // old and new methods to be different when they are actually
  7310. - // EMCP.
  7311. - //
  7312. - // The old and new methods are EMCP and you would think that we
  7313. - // could get rid of one of them here and now and save some space.
  7314. - // However, the concept of EMCP only considers the bytecodes and
  7315. - // the constant pool entries in the comparison. Other things,
  7316. - // e.g., the line number table (LNT) or the local variable table
  7317. - // (LVT) don't count in the comparison. So the new (and EMCP)
  7318. - // method can have a new LNT that we need so we can't just
  7319. - // overwrite the new method with the old method.
  7320. - //
  7321. - // When this routine is called, we have already attached the new
  7322. - // methods to the_class so the old methods are effectively
  7323. - // overwritten. However, if an old method is still executing,
  7324. - // then the old method cannot be collected until sometime after
  7325. - // the old method call has returned. So the overwriting of old
  7326. - // methods by new methods will save us space except for those
  7327. - // (hopefully few) old methods that are still executing.
  7328. - //
  7329. - // A method refers to a constMethodOop and this presents another
  7330. - // possible avenue to space savings. The constMethodOop in the
  7331. - // new method contains possibly new attributes (LNT, LVT, etc).
  7332. - // At first glance, it seems possible to save space by replacing
  7333. - // the constMethodOop in the old method with the constMethodOop
  7334. - // from the new method. The old and new methods would share the
  7335. - // same constMethodOop and we would save the space occupied by
  7336. - // the old constMethodOop. However, the constMethodOop contains
  7337. - // a back reference to the containing method. Sharing the
  7338. - // constMethodOop between two methods could lead to confusion in
  7339. - // the code that uses the back reference. This would lead to
  7340. - // brittle code that could be broken in non-obvious ways now or
  7341. - // in the future.
  7342. - //
  7343. - // Another possibility is to copy the constMethodOop from the new
  7344. - // method to the old method and then overwrite the new method with
  7345. - // the old method. Since the constMethodOop contains the bytecodes
  7346. - // for the method embedded in the oop, this option would change
  7347. - // the bytecodes out from under any threads executing the old
  7348. - // method and make the thread's bcp invalid. Since EMCP requires
  7349. - // that the bytecodes be the same modulo constant pool indices, it
  7350. - // is straight forward to compute the correct new bcp in the new
  7351. - // constMethodOop from the old bcp in the old constMethodOop. The
  7352. - // time consuming part would be searching all the frames in all
  7353. - // of the threads to find all of the calls to the old method.
  7354. - //
  7355. - // It looks like we will have to live with the limited savings
  7356. - // that we get from effectively overwriting the old methods
  7357. - // when the new methods are attached to the_class.
  7358. -
  7359. - // track which methods are EMCP for add_previous_version() call
  7360. - emcp_methods->set_bit(old_index);
  7361. - (*emcp_method_count_p)++;
  7362. -
  7363. - // An EMCP method is _not_ obsolete. An obsolete method has a
  7364. - // different jmethodID than the current method. An EMCP method
  7365. - // has the same jmethodID as the current method. Having the
  7366. - // same jmethodID for all EMCP versions of a method allows for
  7367. - // a consistent view of the EMCP methods regardless of which
  7368. - // EMCP method you happen to have in hand. For example, a
  7369. - // breakpoint set in one EMCP method will work for all EMCP
  7370. - // versions of the method including the current one.
  7371. - } else {
  7372. - // mark obsolete methods as such
  7373. - old_method->set_is_obsolete();
  7374. - obsolete_count++;
  7375. -
  7376. - // obsolete methods need a unique idnum
  7377. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  7378. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  7379. -// u2 old_num = old_method->method_idnum();
  7380. - old_method->set_method_idnum(num);
  7381. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  7382. - }
  7383. - // With tracing we try not to "yack" too much. The position of
  7384. - // this trace assumes there are fewer obsolete methods than
  7385. - // EMCP methods.
  7386. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  7387. - old_method->name()->as_C_string(),
  7388. - old_method->signature()->as_C_string()));
  7389. - }
  7390. - old_method->set_is_old();
  7391. - }
  7392. - for (int i = 0; i < _deleted_methods_length; ++i) {
  7393. - methodOop old_method = _deleted_methods[i];
  7394. -
  7395. - assert(old_method->vtable_index() < 0,
  7396. - "cannot delete methods with vtable entries");;
  7397. -
  7398. - // Mark all deleted methods as old and obsolete
  7399. - old_method->set_is_old();
  7400. - old_method->set_is_obsolete();
  7401. - ++obsolete_count;
  7402. - // With tracing we try not to "yack" too much. The position of
  7403. - // this trace assumes there are fewer obsolete methods than
  7404. - // EMCP methods.
  7405. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  7406. - old_method->name()->as_C_string(),
  7407. - old_method->signature()->as_C_string()));
  7408. - }
  7409. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  7410. - "sanity check");
  7411. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  7412. - obsolete_count));
  7413. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  7414. + // classes for primitives cannot be redefined
  7415. + if (java_lang_Class::is_primitive(klass_mirror)) {
  7416. + return false;
  7417. + }
  7418. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  7419. + // classes for arrays cannot be redefined
  7420. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  7421. + return false;
  7422. + }
  7423. + return true;
  7424. }
  7425. -// This internal class transfers the native function registration from old methods
  7426. -// to new methods. It is designed to handle both the simple case of unchanged
  7427. -// native methods and the complex cases of native method prefixes being added and/or
  7428. -// removed.
  7429. -// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  7430. -//
  7431. -// This class is used after the new methods have been installed in "the_class".
  7432. -//
  7433. -// So, for example, the following must be handled. Where 'm' is a method and
  7434. -// a number followed by an underscore is a prefix.
  7435. -//
  7436. -// Old Name New Name
  7437. -// Simple transfer to new method m -> m
  7438. -// Add prefix m -> 1_m
  7439. -// Remove prefix 1_m -> m
  7440. -// Simultaneous add of prefixes m -> 3_2_1_m
  7441. -// Simultaneous removal of prefixes 3_2_1_m -> m
  7442. -// Simultaneous add and remove 1_m -> 2_m
  7443. -// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  7444. -//
  7445. -class TransferNativeFunctionRegistration {
  7446. - private:
  7447. - instanceKlassHandle the_class;
  7448. - int prefix_count;
  7449. - char** prefixes;
  7450. -
  7451. - // Recursively search the binary tree of possibly prefixed method names.
  7452. - // Iteration could be used if all agents were well behaved. Full tree walk is
  7453. - // more resilent to agents not cleaning up intermediate methods.
  7454. - // Branch at each depth in the binary tree is:
  7455. - // (1) without the prefix.
  7456. - // (2) with the prefix.
  7457. - // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  7458. - methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  7459. - Symbol* signature) {
  7460. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  7461. - if (name_symbol != NULL) {
  7462. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  7463. - if (method != NULL) {
  7464. - // Even if prefixed, intermediate methods must exist.
  7465. - if (method->is_native()) {
  7466. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  7467. - return method;
  7468. - }
  7469. - if (depth < prefix_count) {
  7470. - // Try applying further prefixes (other than this one).
  7471. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  7472. - if (method != NULL) {
  7473. - return method; // found
  7474. - }
  7475. -
  7476. - // Try adding this prefix to the method name and see if it matches
  7477. - // another method name.
  7478. - char* prefix = prefixes[depth];
  7479. - size_t prefix_len = strlen(prefix);
  7480. - size_t trial_len = name_len + prefix_len;
  7481. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  7482. - strcpy(trial_name_str, prefix);
  7483. - strcat(trial_name_str, name_str);
  7484. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  7485. - signature);
  7486. - if (method != NULL) {
  7487. - // If found along this branch, it was prefixed, mark as such
  7488. - method->set_is_prefixed_native();
  7489. - return method; // found
  7490. - }
  7491. - }
  7492. - }
  7493. - }
  7494. - return NULL; // This whole branch bore nothing
  7495. +#ifdef ASSERT
  7496. +
  7497. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7498. + klassOop k_oop = k_oop_latest;
  7499. + while (k_oop != NULL) {
  7500. +
  7501. + instanceKlassHandle k_handle(THREAD, k_oop);
  7502. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  7503. + k_oop = k_oop->klass_part()->old_version();
  7504. }
  7505. +}
  7506. - // Return the method name with old prefixes stripped away.
  7507. - char* method_name_without_prefixes(methodOop method) {
  7508. - Symbol* name = method->name();
  7509. - char* name_str = name->as_utf8();
  7510. +#endif
  7511. - // Old prefixing may be defunct, strip prefixes, if any.
  7512. - for (int i = prefix_count-1; i >= 0; i--) {
  7513. - char* prefix = prefixes[i];
  7514. - size_t prefix_len = strlen(prefix);
  7515. - if (strncmp(prefix, name_str, prefix_len) == 0) {
  7516. - name_str += prefix_len;
  7517. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  7518. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  7519. +// do that, they assume that cache entry is resolved already.
  7520. +void VM_RedefineClasses::unpatch_bytecode(methodOop method) {
  7521. + RawBytecodeStream bcs(method);
  7522. + Bytecodes::Code code;
  7523. + Bytecodes::Code java_code;
  7524. + while (!bcs.is_last_bytecode()) {
  7525. + code = bcs.raw_next();
  7526. + address bcp = bcs.bcp();
  7527. +
  7528. + if (code == Bytecodes::_breakpoint) {
  7529. + int bci = method->bci_from(bcp);
  7530. + code = method->orig_bytecode_at(bci);
  7531. + java_code = Bytecodes::java_code(code);
  7532. + if (code != java_code &&
  7533. + (java_code == Bytecodes::_getfield ||
  7534. + java_code == Bytecodes::_putfield ||
  7535. + java_code == Bytecodes::_aload_0)) {
  7536. + // Let breakpoint table handling unpatch bytecode
  7537. + method->set_orig_bytecode_at(bci, java_code);
  7538. + }
  7539. + } else {
  7540. + java_code = Bytecodes::java_code(code);
  7541. + if (code != java_code &&
  7542. + (java_code == Bytecodes::_getfield ||
  7543. + java_code == Bytecodes::_putfield ||
  7544. + java_code == Bytecodes::_aload_0)) {
  7545. + *bcp = java_code;
  7546. }
  7547. }
  7548. - return name_str;
  7549. - }
  7550. - // Strip any prefixes off the old native method, then try to find a
  7551. - // (possibly prefixed) new native that matches it.
  7552. - methodOop strip_and_search_for_new_native(methodOop method) {
  7553. - ResourceMark rm;
  7554. - char* name_str = method_name_without_prefixes(method);
  7555. - return search_prefix_name_space(0, name_str, strlen(name_str),
  7556. - method->signature());
  7557. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  7558. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  7559. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  7560. + assert(code2 == Bytecodes::_fast_igetfield ||
  7561. + code2 == Bytecodes::_fast_agetfield ||
  7562. + code2 == Bytecodes::_fast_fgetfield, "");
  7563. + *(bcp + 1) = Bytecodes::java_code(code2);
  7564. + }
  7565. }
  7566. +}
  7567. - public:
  7568. +// Unevolving classes may point to old methods directly
  7569. +// from their constant pool caches, itables, and/or vtables. We
  7570. +// use the SystemDictionary::classes_do() facility and this helper
  7571. +// to fix up these pointers. Additional field offsets and vtable indices
  7572. +// in the constant pool cache entries are fixed.
  7573. +//
  7574. +// Note: We currently don't support updating the vtable in
  7575. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7576. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7577. + klassOop k_oop = k_oop_latest;
  7578. + while (k_oop != NULL) {
  7579. + Klass *k = k_oop->klass_part();
  7580. + if (k->oop_is_instance()) {
  7581. + HandleMark hm(THREAD);
  7582. + instanceKlass *ik = (instanceKlass *) k;
  7583. - // Construct a native method transfer processor for this class.
  7584. - TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  7585. - assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  7586. + constantPoolHandle other_cp;
  7587. + constantPoolCacheOop cp_cache;
  7588. - the_class = _the_class;
  7589. - prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  7590. - }
  7591. + other_cp = constantPoolHandle(ik->constants());
  7592. - // Attempt to transfer any of the old or deleted methods that are native
  7593. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  7594. - for (int j = 0; j < methods_length; j++) {
  7595. - methodOop old_method = old_methods[j];
  7596. + for (int i=0; i<other_cp->length(); i++) {
  7597. + if (other_cp->tag_at(i).is_klass()) {
  7598. + klassOop klass = other_cp->klass_at(i, THREAD);
  7599. + if (klass->klass_part()->new_version() != NULL) {
  7600. - if (old_method->is_native() && old_method->has_native_function()) {
  7601. - methodOop new_method = strip_and_search_for_new_native(old_method);
  7602. - if (new_method != NULL) {
  7603. - // Actually set the native function in the new method.
  7604. - // Redefine does not send events (except CFLH), certainly not this
  7605. - // behind the scenes re-registration.
  7606. - new_method->set_native_function(old_method->native_function(),
  7607. - !methodOopDesc::native_bind_event_is_interesting);
  7608. + // (tw) TODO: check why/if this is necessary
  7609. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  7610. + }
  7611. + klass = other_cp->klass_at(i, THREAD);
  7612. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  7613. }
  7614. }
  7615. +
  7616. + cp_cache = other_cp->cache();
  7617. +
  7618. + if (cp_cache != NULL) {
  7619. + cp_cache->adjust_entries();
  7620. + }
  7621. +
  7622. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
  7623. + if (RewriteBytecodes) {
  7624. + ik->methods_do(unpatch_bytecode);
  7625. + }
  7626. }
  7627. + k_oop = k_oop->klass_part()->old_version();
  7628. }
  7629. -};
  7630. +}
  7631. -// Don't lose the association between a native method and its JNI function.
  7632. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  7633. - TransferNativeFunctionRegistration transfer(the_class);
  7634. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  7635. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  7636. +void VM_RedefineClasses::update_jmethod_ids() {
  7637. + for (int j = 0; j < _matching_methods_length; ++j) {
  7638. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7639. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  7640. +
  7641. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  7642. + if (old_method->new_version() != NULL && jmid == NULL) {
  7643. + // (tw) Have to create jmethodID in this case
  7644. + jmid = old_method->jmethod_id();
  7645. + }
  7646. +
  7647. + if (jmid != NULL) {
  7648. + // There is a jmethodID, change it to point to the new method
  7649. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  7650. + if (old_method->new_version() == NULL) {
  7651. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  7652. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  7653. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  7654. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  7655. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7656. + } else {
  7657. + jmethodID mid = new_method_h->jmethod_id();
  7658. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  7659. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  7660. + }
  7661. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7662. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  7663. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  7664. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  7665. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  7666. +
  7667. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7668. + }
  7669. + }
  7670. }
  7671. +
  7672. // Deoptimize all compiled code that depends on this class.
  7673. //
  7674. // If the can_redefine_classes capability is obtained in the onload
  7675. @@ -2964,7 +1835,10 @@ void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  7676. // All dependencies have been recorded from startup or this is a second or
  7677. // subsequent use of RedefineClasses
  7678. - if (JvmtiExport::all_dependencies_are_recorded()) {
  7679. +
  7680. + // For now deopt all
  7681. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  7682. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  7683. Universe::flush_evol_dependents_on(k_h);
  7684. } else {
  7685. CodeCache::mark_all_nmethods_for_deoptimization();
  7686. @@ -2987,10 +1861,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7687. methodOop old_method;
  7688. methodOop new_method;
  7689. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7690. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7691. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  7692. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7693. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7694. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7695. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  7696. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7697. _matching_methods_length = 0;
  7698. _deleted_methods_length = 0;
  7699. @@ -3005,36 +1879,36 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7700. }
  7701. // New method at the end
  7702. new_method = (methodOop) _new_methods->obj_at(nj);
  7703. - _added_methods[_added_methods_length++] = new_method;
  7704. + _added_methods[_added_methods_length++] = nj;
  7705. ++nj;
  7706. } else if (nj >= _new_methods->length()) {
  7707. // Old method, at the end, is deleted
  7708. old_method = (methodOop) _old_methods->obj_at(oj);
  7709. - _deleted_methods[_deleted_methods_length++] = old_method;
  7710. + _deleted_methods[_deleted_methods_length++] = oj;
  7711. ++oj;
  7712. } else {
  7713. old_method = (methodOop) _old_methods->obj_at(oj);
  7714. new_method = (methodOop) _new_methods->obj_at(nj);
  7715. if (old_method->name() == new_method->name()) {
  7716. if (old_method->signature() == new_method->signature()) {
  7717. - _matching_old_methods[_matching_methods_length ] = old_method;
  7718. - _matching_new_methods[_matching_methods_length++] = new_method;
  7719. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  7720. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  7721. ++nj;
  7722. ++oj;
  7723. } else {
  7724. // added overloaded have already been moved to the end,
  7725. // so this is a deleted overloaded method
  7726. - _deleted_methods[_deleted_methods_length++] = old_method;
  7727. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7728. ++oj;
  7729. }
  7730. } else { // names don't match
  7731. if (old_method->name()->fast_compare(new_method->name()) > 0) {
  7732. // new method
  7733. - _added_methods[_added_methods_length++] = new_method;
  7734. + _added_methods[_added_methods_length++] = nj;//new_method;
  7735. ++nj;
  7736. } else {
  7737. // deleted method
  7738. - _deleted_methods[_deleted_methods_length++] = old_method;
  7739. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7740. ++oj;
  7741. }
  7742. }
  7743. @@ -3042,6 +1916,7 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7744. }
  7745. assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  7746. assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  7747. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  7748. }
  7749. @@ -3049,287 +1924,176 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7750. // Install the redefinition of a class:
  7751. // - house keeping (flushing breakpoints and caches, deoptimizing
  7752. // dependent compiled code)
  7753. -// - replacing parts in the_class with parts from scratch_class
  7754. -// - adding a weak reference to track the obsolete but interesting
  7755. -// parts of the_class
  7756. // - adjusting constant pool caches and vtables in other classes
  7757. -// that refer to methods in the_class. These adjustments use the
  7758. -// SystemDictionary::classes_do() facility which only allows
  7759. -// a helper method to be specified. The interesting parameters
  7760. -// that we would like to pass to the helper method are saved in
  7761. -// static global fields in the VM operation.
  7762. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  7763. - instanceKlassHandle scratch_class, TRAPS) {
  7764. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  7765. +
  7766. + ResourceMark rm(THREAD);
  7767. - RC_TIMER_START(_timer_rsc_phase1);
  7768. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7769. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7770. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  7771. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  7772. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  7773. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  7774. +#ifndef JVMTI_KERNEL
  7775. // Remove all breakpoints in methods of this class
  7776. JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  7777. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  7778. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  7779. +#endif // !JVMTI_KERNEL
  7780. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  7781. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  7782. // We are redefining java.lang.reflect.Method. Method.invoke() is
  7783. // cached and users of the cache care about each active version of
  7784. // the method so we have to track this previous version.
  7785. // Do this before methods get switched
  7786. Universe::reflect_invoke_cache()->add_previous_version(
  7787. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7788. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7789. }
  7790. - // Deoptimize all compiled code that depends on this class
  7791. - flush_dependent_code(the_class, THREAD);
  7792. -
  7793. - _old_methods = the_class->methods();
  7794. - _new_methods = scratch_class->methods();
  7795. - _the_class_oop = the_class_oop;
  7796. + _old_methods = the_old_class->methods();
  7797. + _new_methods = the_new_class->methods();
  7798. compute_added_deleted_matching_methods();
  7799. - update_jmethod_ids();
  7800. -
  7801. - // Attach new constant pool to the original klass. The original
  7802. - // klass still refers to the old constant pool (for now).
  7803. - scratch_class->constants()->set_pool_holder(the_class());
  7804. -
  7805. -#if 0
  7806. - // In theory, with constant pool merging in place we should be able
  7807. - // to save space by using the new, merged constant pool in place of
  7808. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  7809. - // the klass version we are replacing now and any constant pool(s) in
  7810. - // previous versions of klass. Nice theory, doesn't work in practice.
  7811. - // When this code is enabled, even simple programs throw NullPointer
  7812. - // exceptions. I'm guessing that this is caused by some constant pool
  7813. - // cache difference between the new, merged constant pool and the
  7814. - // constant pool that was just being used by the klass. I'm keeping
  7815. - // this code around to archive the idea, but the code has to remain
  7816. - // disabled for now.
  7817. -
  7818. - // Attach each old method to the new constant pool. This can be
  7819. - // done here since we are past the bytecode verification and
  7820. - // constant pool optimization phases.
  7821. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  7822. - methodOop method = (methodOop)_old_methods->obj_at(i);
  7823. - method->set_constants(scratch_class->constants());
  7824. - }
  7825. -
  7826. - {
  7827. - // walk all previous versions of the klass
  7828. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  7829. - PreviousVersionWalker pvw(ik);
  7830. - instanceKlassHandle ikh;
  7831. - do {
  7832. - ikh = pvw.next_previous_version();
  7833. - if (!ikh.is_null()) {
  7834. - ik = ikh();
  7835. -
  7836. - // attach previous version of klass to the new constant pool
  7837. - ik->set_constants(scratch_class->constants());
  7838. -
  7839. - // Attach each method in the previous version of klass to the
  7840. - // new constant pool
  7841. - objArrayOop prev_methods = ik->methods();
  7842. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  7843. - methodOop method = (methodOop)prev_methods->obj_at(i);
  7844. - method->set_constants(scratch_class->constants());
  7845. - }
  7846. - }
  7847. - } while (!ikh.is_null());
  7848. - }
  7849. -#endif
  7850. -
  7851. - // Replace methods and constantpool
  7852. - the_class->set_methods(_new_methods);
  7853. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  7854. - // and to be able to undo operation easily.
  7855. -
  7856. - constantPoolOop old_constants = the_class->constants();
  7857. - the_class->set_constants(scratch_class->constants());
  7858. - scratch_class->set_constants(old_constants); // See the previous comment.
  7859. -#if 0
  7860. - // We are swapping the guts of "the new class" with the guts of "the
  7861. - // class". Since the old constant pool has just been attached to "the
  7862. - // new class", it seems logical to set the pool holder in the old
  7863. - // constant pool also. However, doing this will change the observable
  7864. - // class hierarchy for any old methods that are still executing. A
  7865. - // method can query the identity of its "holder" and this query uses
  7866. - // the method's constant pool link to find the holder. The change in
  7867. - // holding class from "the class" to "the new class" can confuse
  7868. - // things.
  7869. - //
  7870. - // Setting the old constant pool's holder will also cause
  7871. - // verification done during vtable initialization below to fail.
  7872. - // During vtable initialization, the vtable's class is verified to be
  7873. - // a subtype of the method's holder. The vtable's class is "the
  7874. - // class" and the method's holder is gotten from the constant pool
  7875. - // link in the method itself. For "the class"'s directly implemented
  7876. - // methods, the method holder is "the class" itself (as gotten from
  7877. - // the new constant pool). The check works fine in this case. The
  7878. - // check also works fine for methods inherited from super classes.
  7879. - //
  7880. - // Miranda methods are a little more complicated. A miranda method is
  7881. - // provided by an interface when the class implementing the interface
  7882. - // does not provide its own method. These interfaces are implemented
  7883. - // internally as an instanceKlass. These special instanceKlasses
  7884. - // share the constant pool of the class that "implements" the
  7885. - // interface. By sharing the constant pool, the method holder of a
  7886. - // miranda method is the class that "implements" the interface. In a
  7887. - // non-redefine situation, the subtype check works fine. However, if
  7888. - // the old constant pool's pool holder is modified, then the check
  7889. - // fails because there is no class hierarchy relationship between the
  7890. - // vtable's class and "the new class".
  7891. -
  7892. - old_constants->set_pool_holder(scratch_class());
  7893. -#endif
  7894. // track which methods are EMCP for add_previous_version() call below
  7895. - BitMap emcp_methods(_old_methods->length());
  7896. +
  7897. + // (tw) TODO: Check if we need the concept of EMCP?
  7898. + BitMap emcp_methods(_old_methods->length());
  7899. int emcp_method_count = 0;
  7900. emcp_methods.clear(); // clears 0..(length() - 1)
  7901. +
  7902. + // We need to mark methods as old!!
  7903. check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  7904. - transfer_old_native_function_registrations(the_class);
  7905. -
  7906. - // The class file bytes from before any retransformable agents mucked
  7907. - // with them was cached on the scratch class, move to the_class.
  7908. - // Note: we still want to do this if nothing needed caching since it
  7909. - // should get cleared in the_class too.
  7910. - if (the_class->get_cached_class_file_bytes() == 0) {
  7911. - // the_class doesn't have a cache yet so copy it
  7912. - the_class->set_cached_class_file(
  7913. - scratch_class->get_cached_class_file_bytes(),
  7914. - scratch_class->get_cached_class_file_len());
  7915. - }
  7916. -#ifndef PRODUCT
  7917. - else {
  7918. - assert(the_class->get_cached_class_file_bytes() ==
  7919. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  7920. - assert(the_class->get_cached_class_file_len() ==
  7921. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  7922. - }
  7923. -#endif
  7924. + update_jmethod_ids();
  7925. - // Replace inner_classes
  7926. - typeArrayOop old_inner_classes = the_class->inner_classes();
  7927. - the_class->set_inner_classes(scratch_class->inner_classes());
  7928. - scratch_class->set_inner_classes(old_inner_classes);
  7929. + // TODO:
  7930. + transfer_old_native_function_registrations(the_old_class);
  7931. - // Initialize the vtable and interface table after
  7932. - // methods have been rewritten
  7933. - {
  7934. - ResourceMark rm(THREAD);
  7935. - // no exception should happen here since we explicitly
  7936. - // do not check loader constraints.
  7937. - // compare_and_normalize_class_versions has already checked:
  7938. - // - classloaders unchanged, signatures unchanged
  7939. - // - all instanceKlasses for redefined classes reused & contents updated
  7940. - the_class->vtable()->initialize_vtable(false, THREAD);
  7941. - the_class->itable()->initialize_itable(false, THREAD);
  7942. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  7943. - }
  7944. -
  7945. - // Leave arrays of jmethodIDs and itable index cache unchanged
  7946. -
  7947. - // Copy the "source file name" attribute from new class version
  7948. - the_class->set_source_file_name(scratch_class->source_file_name());
  7949. -
  7950. - // Copy the "source debug extension" attribute from new class version
  7951. - the_class->set_source_debug_extension(
  7952. - scratch_class->source_debug_extension(),
  7953. - scratch_class->source_debug_extension() == NULL ? 0 :
  7954. - (int)strlen(scratch_class->source_debug_extension()));
  7955. -
  7956. - // Use of javac -g could be different in the old and the new
  7957. - if (scratch_class->access_flags().has_localvariable_table() !=
  7958. - the_class->access_flags().has_localvariable_table()) {
  7959. -
  7960. - AccessFlags flags = the_class->access_flags();
  7961. - if (scratch_class->access_flags().has_localvariable_table()) {
  7962. - flags.set_has_localvariable_table();
  7963. - } else {
  7964. - flags.clear_has_localvariable_table();
  7965. - }
  7966. - the_class->set_access_flags(flags);
  7967. - }
  7968. -
  7969. - // Replace class annotation fields values
  7970. - typeArrayOop old_class_annotations = the_class->class_annotations();
  7971. - the_class->set_class_annotations(scratch_class->class_annotations());
  7972. - scratch_class->set_class_annotations(old_class_annotations);
  7973. -
  7974. - // Replace fields annotation fields values
  7975. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  7976. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  7977. - scratch_class->set_fields_annotations(old_fields_annotations);
  7978. -
  7979. - // Replace methods annotation fields values
  7980. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  7981. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  7982. - scratch_class->set_methods_annotations(old_methods_annotations);
  7983. -
  7984. - // Replace methods parameter annotation fields values
  7985. - objArrayOop old_methods_parameter_annotations =
  7986. - the_class->methods_parameter_annotations();
  7987. - the_class->set_methods_parameter_annotations(
  7988. - scratch_class->methods_parameter_annotations());
  7989. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  7990. -
  7991. - // Replace methods default annotation fields values
  7992. - objArrayOop old_methods_default_annotations =
  7993. - the_class->methods_default_annotations();
  7994. - the_class->set_methods_default_annotations(
  7995. - scratch_class->methods_default_annotations());
  7996. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  7997. -
  7998. - // Replace minor version number of class file
  7999. - u2 old_minor_version = the_class->minor_version();
  8000. - the_class->set_minor_version(scratch_class->minor_version());
  8001. - scratch_class->set_minor_version(old_minor_version);
  8002. -
  8003. - // Replace major version number of class file
  8004. - u2 old_major_version = the_class->major_version();
  8005. - the_class->set_major_version(scratch_class->major_version());
  8006. - scratch_class->set_major_version(old_major_version);
  8007. -
  8008. - // Replace CP indexes for class and name+type of enclosing method
  8009. - u2 old_class_idx = the_class->enclosing_method_class_index();
  8010. - u2 old_method_idx = the_class->enclosing_method_method_index();
  8011. - the_class->set_enclosing_method_indices(
  8012. - scratch_class->enclosing_method_class_index(),
  8013. - scratch_class->enclosing_method_method_index());
  8014. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  8015. -
  8016. - // keep track of previous versions of this class
  8017. - the_class->add_previous_version(scratch_class, &emcp_methods,
  8018. - emcp_method_count);
  8019. -
  8020. - RC_TIMER_STOP(_timer_rsc_phase1);
  8021. - RC_TIMER_START(_timer_rsc_phase2);
  8022. - // Adjust constantpool caches and vtables for all classes
  8023. - // that reference methods of the evolved class.
  8024. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  8025. - if (the_class->oop_map_cache() != NULL) {
  8026. - // Flush references to any obsolete methods from the oop map cache
  8027. - // so that obsolete methods are not pinned.
  8028. - the_class->oop_map_cache()->flush_obsolete_entries();
  8029. +#ifdef ASSERT
  8030. +
  8031. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8032. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  8033. +
  8034. + //JNIHandles::verify();
  8035. +
  8036. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8037. +
  8038. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  8039. + assert(the_new_class->old_version() != NULL, "Must not be null");
  8040. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  8041. +
  8042. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  8043. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  8044. }
  8045. + _old_methods->verify();
  8046. + _new_methods->verify();
  8047. +
  8048. + the_new_class->vtable()->verify(tty);
  8049. + the_old_class->vtable()->verify(tty);
  8050. +
  8051. +#endif
  8052. +
  8053. // increment the classRedefinedCount field in the_class and in any
  8054. // direct and indirect subclasses of the_class
  8055. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  8056. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  8057. +
  8058. +}
  8059. +
  8060. +
  8061. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  8062. + TRACE_RC3("Checking matching methods for EMCP");
  8063. + *emcp_method_count_p = 0;
  8064. + int obsolete_count = 0;
  8065. + int old_index = 0;
  8066. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8067. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  8068. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  8069. + methodOop old_array_method;
  8070. +
  8071. + // Maintain an old_index into the _old_methods array by skipping
  8072. + // deleted methods
  8073. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8074. + != old_method) {
  8075. + ++old_index;
  8076. + }
  8077. - // RC_TRACE macro has an embedded ResourceMark
  8078. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  8079. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  8080. - the_class->external_name(),
  8081. - java_lang_Class::classRedefinedCount(the_class_mirror),
  8082. - os::available_memory() >> 10));
  8083. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8084. + // The EMCP definition from JSR-163 requires the bytecodes to be
  8085. + // the same with the exception of constant pool indices which may
  8086. + // differ. However, the constants referred to by those indices
  8087. + // must be the same.
  8088. + //
  8089. + // We use methods_EMCP() for comparison since constant pool
  8090. + // merging can remove duplicate constant pool entries that were
  8091. + // present in the old method and removed from the rewritten new
  8092. + // method. A faster binary comparison function would consider the
  8093. + // old and new methods to be different when they are actually
  8094. + // EMCP.
  8095. +
  8096. + // track which methods are EMCP for add_previous_version() call
  8097. + emcp_methods->set_bit(old_index);
  8098. + (*emcp_method_count_p)++;
  8099. +
  8100. + // An EMCP method is _not_ obsolete. An obsolete method has a
  8101. + // different jmethodID than the current method. An EMCP method
  8102. + // has the same jmethodID as the current method. Having the
  8103. + // same jmethodID for all EMCP versions of a method allows for
  8104. + // a consistent view of the EMCP methods regardless of which
  8105. + // EMCP method you happen to have in hand. For example, a
  8106. + // breakpoint set in one EMCP method will work for all EMCP
  8107. + // versions of the method including the current one.
  8108. +
  8109. + old_method->set_new_version(new_method);
  8110. + new_method->set_old_version(old_method);
  8111. +
  8112. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  8113. +
  8114. + // Transfer breakpoints
  8115. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  8116. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  8117. + TRACE_RC2("Checking breakpoint");
  8118. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  8119. + if (bp->match(old_method)) {
  8120. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  8121. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  8122. + new_method->set_breakpoint(bp->bci());
  8123. + }
  8124. + }
  8125. + } else {
  8126. + // mark obsolete methods as such
  8127. + old_method->set_is_obsolete();
  8128. + obsolete_count++;
  8129. +
  8130. + // With tracing we try not to "yack" too much. The position of
  8131. + // this trace assumes there are fewer obsolete methods than
  8132. + // EMCP methods.
  8133. + TRACE_RC3("mark %s(%s) as obsolete",
  8134. + old_method->name()->as_C_string(),
  8135. + old_method->signature()->as_C_string());
  8136. + }
  8137. + old_method->set_is_old();
  8138. + }
  8139. + for (int i = 0; i < _deleted_methods_length; ++i) {
  8140. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  8141. - RC_TIMER_STOP(_timer_rsc_phase2);
  8142. -} // end redefine_single_class()
  8143. + //assert(old_method->vtable_index() < 0,
  8144. + // "cannot delete methods with vtable entries");;
  8145. + // Mark all deleted methods as old and obsolete
  8146. + old_method->set_is_old();
  8147. + old_method->set_is_obsolete();
  8148. + ++obsolete_count;
  8149. + // With tracing we try not to "yack" too much. The position of
  8150. + // this trace assumes there are fewer obsolete methods than
  8151. + // EMCP methods.
  8152. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  8153. + old_method->name()->as_C_string(),
  8154. + old_method->signature()->as_C_string());
  8155. + }
  8156. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  8157. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  8158. +}
  8159. // Increment the classRedefinedCount field in the specific instanceKlass
  8160. // and in all direct and indirect subclasses.
  8161. @@ -3338,134 +2102,267 @@ void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  8162. klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  8163. int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  8164. java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  8165. -
  8166. - if (class_oop != _the_class_oop) {
  8167. - // _the_class_oop count is printed at end of redefine_single_class()
  8168. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  8169. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  8170. - }
  8171. -
  8172. - for (Klass *subk = ik->subklass(); subk != NULL;
  8173. - subk = subk->next_sibling()) {
  8174. - if (subk->oop_is_instance()) {
  8175. - // Only update instanceKlasses
  8176. - instanceKlass *subik = (instanceKlass*)subk;
  8177. - // recursively do subclasses of the current subclass
  8178. - increment_class_counter(subik, THREAD);
  8179. - }
  8180. - }
  8181. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  8182. }
  8183. -void VM_RedefineClasses::check_class(klassOop k_oop,
  8184. - oop initiating_loader, TRAPS) {
  8185. +#ifndef PRODUCT
  8186. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  8187. Klass *k = k_oop->klass_part();
  8188. if (k->oop_is_instance()) {
  8189. HandleMark hm(THREAD);
  8190. instanceKlass *ik = (instanceKlass *) k;
  8191. - bool no_old_methods = true; // be optimistic
  8192. - ResourceMark rm(THREAD);
  8193. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  8194. +
  8195. + if (ik->vtable_length() > 0) {
  8196. + ResourceMark rm(THREAD);
  8197. + if (!ik->vtable()->check_no_old_or_obsolete_entries()) {
  8198. + TRACE_RC1("size of class: %d\n", k_oop->size());
  8199. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  8200. + assert(false, "OLD method found");
  8201. + }
  8202. +
  8203. + ik->vtable()->verify(tty, true);
  8204. + }
  8205. + }
  8206. +}
  8207. +
  8208. +#endif
  8209. - // a vtable should never contain old or obsolete methods
  8210. - if (ik->vtable_length() > 0 &&
  8211. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  8212. - if (RC_TRACE_ENABLED(0x00004000)) {
  8213. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8214. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  8215. - " -- OLD or OBSOLETE method found -- class: %s",
  8216. - ik->signature_name()));
  8217. - ik->vtable()->dump_vtable();
  8218. +static bool match_right(void* value, Pair<klassOop, klassOop> elem) {
  8219. + return elem.right() == value;
  8220. +}
  8221. +
  8222. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS)
  8223. +{
  8224. + GrowableArray< Pair<klassOop, klassOop> > links;
  8225. +
  8226. + for (int i=0; i<class_count; i++) {
  8227. +
  8228. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  8229. + instanceKlassHandle the_class(THREAD, java_lang_Class::as_klassOop(mirror));
  8230. + Handle the_class_loader(THREAD, the_class->class_loader());
  8231. + Handle protection_domain(THREAD, the_class->protection_domain());
  8232. +
  8233. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  8234. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  8235. + ClassFileParser cfp(&st);
  8236. +
  8237. + GrowableArray<Symbol*> symbolArr;
  8238. + TempNewSymbol parsed_name;
  8239. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  8240. + cfp.parseClassFile(the_class->name(), the_class_loader, protection_domain, the_class, KlassHandle(), NULL, &symbolArr, parsed_name, false, THREAD);
  8241. +
  8242. + for (int j=0; j<symbolArr.length(); j++) {
  8243. + Symbol* sym = symbolArr.at(j);
  8244. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  8245. + klassOop super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
  8246. + if (super_klass != NULL) {
  8247. + instanceKlassHandle the_super_class(THREAD, super_klass);
  8248. + if (_affected_klasses->contains(the_super_class)) {
  8249. + TRACE_RC2("Found class to link");
  8250. + links.append(Pair<klassOop, klassOop>(super_klass, the_class()));
  8251. + }
  8252. }
  8253. - no_old_methods = false;
  8254. - }
  8255. -
  8256. - // an itable should never contain old or obsolete methods
  8257. - if (ik->itable_length() > 0 &&
  8258. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  8259. - if (RC_TRACE_ENABLED(0x00004000)) {
  8260. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8261. - ("klassItable::check_no_old_or_obsolete_entries failure"
  8262. - " -- OLD or OBSOLETE method found -- class: %s",
  8263. - ik->signature_name()));
  8264. - ik->itable()->dump_itable();
  8265. + }
  8266. +
  8267. + assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
  8268. + the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
  8269. + }
  8270. +
  8271. +
  8272. + TRACE_RC1("Identified links between classes! ");
  8273. +
  8274. + for (int i=0; i < _affected_klasses->length(); i++) {
  8275. + instanceKlassHandle klass = _affected_klasses->at(i);
  8276. +
  8277. + if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
  8278. + klass->clear_redefinition_flag(Klass::MarkedAsAffected);
  8279. + klassOop superKlass = klass->super();
  8280. + if (_affected_klasses->contains(superKlass)) {
  8281. + links.append(Pair<klassOop, klassOop>(superKlass, klass()));
  8282. }
  8283. - no_old_methods = false;
  8284. - }
  8285. -
  8286. - // the constant pool cache should never contain old or obsolete methods
  8287. - if (ik->constants() != NULL &&
  8288. - ik->constants()->cache() != NULL &&
  8289. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  8290. - if (RC_TRACE_ENABLED(0x00004000)) {
  8291. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8292. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  8293. - " -- OLD or OBSOLETE method found -- class: %s",
  8294. - ik->signature_name()));
  8295. - ik->constants()->cache()->dump_cache();
  8296. +
  8297. + objArrayOop superInterfaces = klass->local_interfaces();
  8298. + for (int j=0; j<superInterfaces->length(); j++) {
  8299. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  8300. + if (_affected_klasses->contains(interfaceKlass)) {
  8301. + links.append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  8302. + }
  8303. }
  8304. - no_old_methods = false;
  8305. + }
  8306. + }
  8307. +
  8308. + IF_TRACE_RC2 {
  8309. + TRACE_RC2("Identified links: ");
  8310. + for (int i=0; i<links.length(); i++) {
  8311. + TRACE_RC2("%s to %s", links.at(i).left()->klass_part()->name()->as_C_string(),
  8312. + links.at(i).right()->klass_part()->name()->as_C_string());
  8313. + }
  8314. + }
  8315. +
  8316. + for (int i = 0; i < _affected_klasses->length(); i++) {
  8317. + int j;
  8318. + for (j = i; j < _affected_klasses->length(); j++) {
  8319. + // Search for node with no incoming edges
  8320. + klassOop oop = _affected_klasses->at(j)();
  8321. + int k = links.find(oop, match_right);
  8322. + if (k == -1) break;
  8323. + }
  8324. + if (j == _affected_klasses->length()) {
  8325. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  8326. }
  8327. - if (!no_old_methods) {
  8328. - if (RC_TRACE_ENABLED(0x00004000)) {
  8329. - dump_methods();
  8330. + // Remove all links from this node
  8331. + klassOop oop = _affected_klasses->at(j)();
  8332. + int k = 0;
  8333. + while (k < links.length()) {
  8334. + if (links.adr_at(k)->left() == oop) {
  8335. + links.delete_at(k);
  8336. } else {
  8337. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  8338. - "to see more info about the following guarantee() failure.");
  8339. + k++;
  8340. }
  8341. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  8342. }
  8343. +
  8344. + // Swap node
  8345. + instanceKlassHandle tmp = _affected_klasses->at(j);
  8346. + _affected_klasses->at_put(j, _affected_klasses->at(i));
  8347. + _affected_klasses->at_put(i, tmp);
  8348. }
  8349. +
  8350. + return JVMTI_ERROR_NONE;
  8351. }
  8352. -void VM_RedefineClasses::dump_methods() {
  8353. - int j;
  8354. - RC_TRACE(0x00004000, ("_old_methods --"));
  8355. - for (j = 0; j < _old_methods->length(); ++j) {
  8356. - methodOop m = (methodOop) _old_methods->obj_at(j);
  8357. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8358. - m->access_flags().print_on(tty);
  8359. - tty->print(" -- ");
  8360. - m->print_name(tty);
  8361. - tty->cr();
  8362. - }
  8363. - RC_TRACE(0x00004000, ("_new_methods --"));
  8364. - for (j = 0; j < _new_methods->length(); ++j) {
  8365. - methodOop m = (methodOop) _new_methods->obj_at(j);
  8366. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8367. - m->access_flags().print_on(tty);
  8368. - tty->print(" -- ");
  8369. - m->print_name(tty);
  8370. - tty->cr();
  8371. - }
  8372. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  8373. - for (j = 0; j < _matching_methods_length; ++j) {
  8374. - methodOop m = _matching_old_methods[j];
  8375. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8376. - m->access_flags().print_on(tty);
  8377. - tty->print(" -- ");
  8378. - m->print_name(tty);
  8379. - tty->cr();
  8380. - m = _matching_new_methods[j];
  8381. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  8382. - m->access_flags().print_on(tty);
  8383. - tty->cr();
  8384. - }
  8385. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  8386. - for (j = 0; j < _deleted_methods_length; ++j) {
  8387. - methodOop m = _deleted_methods[j];
  8388. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8389. - m->access_flags().print_on(tty);
  8390. - tty->print(" -- ");
  8391. - m->print_name(tty);
  8392. - tty->cr();
  8393. - }
  8394. - RC_TRACE(0x00004000, ("_added_methods --"));
  8395. - for (j = 0; j < _added_methods_length; ++j) {
  8396. - methodOop m = _added_methods[j];
  8397. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8398. - m->access_flags().print_on(tty);
  8399. - tty->print(" -- ");
  8400. - m->print_name(tty);
  8401. - tty->cr();
  8402. +// This internal class transfers the native function registration from old methods
  8403. +// to new methods. It is designed to handle both the simple case of unchanged
  8404. +// native methods and the complex cases of native method prefixes being added and/or
  8405. +// removed.
  8406. +// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  8407. +//
  8408. +// This class is used after the new methods have been installed in "the_class".
  8409. +//
  8410. +// So, for example, the following must be handled. Where 'm' is a method and
  8411. +// a number followed by an underscore is a prefix.
  8412. +//
  8413. +// Old Name New Name
  8414. +// Simple transfer to new method m -> m
  8415. +// Add prefix m -> 1_m
  8416. +// Remove prefix 1_m -> m
  8417. +// Simultaneous add of prefixes m -> 3_2_1_m
  8418. +// Simultaneous removal of prefixes 3_2_1_m -> m
  8419. +// Simultaneous add and remove 1_m -> 2_m
  8420. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8421. +//
  8422. +class TransferNativeFunctionRegistration {
  8423. +private:
  8424. + instanceKlassHandle the_class;
  8425. + int prefix_count;
  8426. + char** prefixes;
  8427. +
  8428. + // Recursively search the binary tree of possibly prefixed method names.
  8429. + // Iteration could be used if all agents were well behaved. Full tree walk is
  8430. + // more resilent to agents not cleaning up intermediate methods.
  8431. + // Branch at each depth in the binary tree is:
  8432. + // (1) without the prefix.
  8433. + // (2) with the prefix.
  8434. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  8435. + methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  8436. + Symbol* signature) {
  8437. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8438. + if (name_symbol != NULL) {
  8439. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  8440. + if (method != NULL) {
  8441. + // Even if prefixed, intermediate methods must exist.
  8442. + if (method->is_native()) {
  8443. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8444. + return method;
  8445. + }
  8446. + if (depth < prefix_count) {
  8447. + // Try applying further prefixes (other than this one).
  8448. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8449. + if (method != NULL) {
  8450. + return method; // found
  8451. + }
  8452. +
  8453. + // Try adding this prefix to the method name and see if it matches
  8454. + // another method name.
  8455. + char* prefix = prefixes[depth];
  8456. + size_t prefix_len = strlen(prefix);
  8457. + size_t trial_len = name_len + prefix_len;
  8458. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8459. + strcpy(trial_name_str, prefix);
  8460. + strcat(trial_name_str, name_str);
  8461. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8462. + signature);
  8463. + if (method != NULL) {
  8464. + // If found along this branch, it was prefixed, mark as such
  8465. + method->set_is_prefixed_native();
  8466. + return method; // found
  8467. + }
  8468. + }
  8469. + }
  8470. + }
  8471. + return NULL; // This whole branch bore nothing
  8472. + }
  8473. +
  8474. + // Return the method name with old prefixes stripped away.
  8475. + char* method_name_without_prefixes(methodOop method) {
  8476. + Symbol* name = method->name();
  8477. + char* name_str = name->as_utf8();
  8478. +
  8479. + // Old prefixing may be defunct, strip prefixes, if any.
  8480. + for (int i = prefix_count-1; i >= 0; i--) {
  8481. + char* prefix = prefixes[i];
  8482. + size_t prefix_len = strlen(prefix);
  8483. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  8484. + name_str += prefix_len;
  8485. + }
  8486. + }
  8487. + return name_str;
  8488. + }
  8489. +
  8490. + // Strip any prefixes off the old native method, then try to find a
  8491. + // (possibly prefixed) new native that matches it.
  8492. + methodOop strip_and_search_for_new_native(methodOop method) {
  8493. + ResourceMark rm;
  8494. + char* name_str = method_name_without_prefixes(method);
  8495. + return search_prefix_name_space(0, name_str, strlen(name_str),
  8496. + method->signature());
  8497. + }
  8498. +
  8499. +public:
  8500. +
  8501. + // Construct a native method transfer processor for this class.
  8502. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  8503. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  8504. +
  8505. + the_class = _the_class;
  8506. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  8507. + }
  8508. +
  8509. + // Attempt to transfer any of the old or deleted methods that are native
  8510. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  8511. + for (int j = 0; j < methods_length; j++) {
  8512. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  8513. +
  8514. + if (old_method->is_native() && old_method->has_native_function()) {
  8515. + methodOop new_method = strip_and_search_for_new_native(old_method);
  8516. + if (new_method != NULL) {
  8517. + // Actually set the native function in the new method.
  8518. + // Redefine does not send events (except CFLH), certainly not this
  8519. + // behind the scenes re-registration.
  8520. + new_method->set_native_function(old_method->native_function(),
  8521. + !methodOopDesc::native_bind_event_is_interesting);
  8522. +
  8523. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  8524. + }
  8525. + }
  8526. + }
  8527. }
  8528. +};
  8529. +
  8530. +// Don't lose the association between a native method and its JNI function.
  8531. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  8532. + TransferNativeFunctionRegistration transfer(old_klass);
  8533. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  8534. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  8535. }
  8536. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8537. index 671f2ae..8333cee 100644
  8538. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8539. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8540. @@ -1,5 +1,5 @@
  8541. /*
  8542. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  8543. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  8544. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8545. *
  8546. * This code is free software; you can redistribute it and/or modify it
  8547. @@ -30,332 +30,29 @@
  8548. #include "memory/resourceArea.hpp"
  8549. #include "oops/objArrayKlass.hpp"
  8550. #include "oops/objArrayOop.hpp"
  8551. +#include "oops/fieldStreams.hpp"
  8552. #include "prims/jvmtiRedefineClassesTrace.hpp"
  8553. -#include "runtime/vm_operations.hpp"
  8554. -
  8555. -// Introduction:
  8556. -//
  8557. -// The RedefineClasses() API is used to change the definition of one or
  8558. -// more classes. While the API supports redefining more than one class
  8559. -// in a single call, in general, the API is discussed in the context of
  8560. -// changing the definition of a single current class to a single new
  8561. -// class. For clarity, the current class is will always be called
  8562. -// "the_class" and the new class will always be called "scratch_class".
  8563. -//
  8564. -// The name "the_class" is used because there is only one structure
  8565. -// that represents a specific class; redefinition does not replace the
  8566. -// structure, but instead replaces parts of the structure. The name
  8567. -// "scratch_class" is used because the structure that represents the
  8568. -// new definition of a specific class is simply used to carry around
  8569. -// the parts of the new definition until they are used to replace the
  8570. -// appropriate parts in the_class. Once redefinition of a class is
  8571. -// complete, scratch_class is thrown away.
  8572. -//
  8573. -//
  8574. -// Implementation Overview:
  8575. -//
  8576. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  8577. -// does the real work. The work is split in varying degrees between
  8578. -// doit_prologue(), doit() and doit_epilogue().
  8579. -//
  8580. -// 1) doit_prologue() is called by the JavaThread on the way to a
  8581. -// safepoint. It does parameter verification and loads scratch_class
  8582. -// which involves:
  8583. -// - parsing the incoming class definition using the_class' class
  8584. -// loader and security context
  8585. -// - linking scratch_class
  8586. -// - merging constant pools and rewriting bytecodes as needed
  8587. -// for the merged constant pool
  8588. -// - verifying the bytecodes in scratch_class
  8589. -// - setting up the constant pool cache and rewriting bytecodes
  8590. -// as needed to use the cache
  8591. -// - finally, scratch_class is compared to the_class to verify
  8592. -// that it is a valid replacement class
  8593. -// - if everything is good, then scratch_class is saved in an
  8594. -// instance field in the VM operation for the doit() call
  8595. -//
  8596. -// Note: A JavaThread must do the above work.
  8597. -//
  8598. -// 2) doit() is called by the VMThread during a safepoint. It installs
  8599. -// the new class definition(s) which involves:
  8600. -// - retrieving the scratch_class from the instance field in the
  8601. -// VM operation
  8602. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8603. -// dependent compiled code)
  8604. -// - replacing parts in the_class with parts from scratch_class
  8605. -// - adding weak reference(s) to track the obsolete but interesting
  8606. -// parts of the_class
  8607. -// - adjusting constant pool caches and vtables in other classes
  8608. -// that refer to methods in the_class. These adjustments use the
  8609. -// SystemDictionary::classes_do() facility which only allows
  8610. -// a helper method to be specified. The interesting parameters
  8611. -// that we would like to pass to the helper method are saved in
  8612. -// static global fields in the VM operation.
  8613. -// - telling the SystemDictionary to notice our changes
  8614. -//
  8615. -// Note: the above work must be done by the VMThread to be safe.
  8616. -//
  8617. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  8618. -// is finished and the safepoint is done. It simply cleans up
  8619. -// memory allocated in doit_prologue() and used in doit().
  8620. -//
  8621. -//
  8622. -// Constant Pool Details:
  8623. -//
  8624. -// When the_class is redefined, we cannot just replace the constant
  8625. -// pool in the_class with the constant pool from scratch_class because
  8626. -// that could confuse obsolete methods that may still be running.
  8627. -// Instead, the constant pool from the_class, old_cp, is merged with
  8628. -// the constant pool from scratch_class, scratch_cp. The resulting
  8629. -// constant pool, merge_cp, replaces old_cp in the_class.
  8630. -//
  8631. -// The key part of any merging algorithm is the entry comparison
  8632. -// function so we have to know the types of entries in a constant pool
  8633. -// in order to merge two of them together. Constant pools can contain
  8634. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  8635. -// is not presently used so we only have to worry about the other 11
  8636. -// entry types. For the purposes of constant pool merging, it is
  8637. -// helpful to know that the 11 entry types fall into 3 different
  8638. -// subtypes: "direct", "indirect" and "double-indirect".
  8639. -//
  8640. -// Direct CP entries contain data and do not contain references to
  8641. -// other CP entries. The following are direct CP entries:
  8642. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  8643. -//
  8644. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  8645. -// and no other data. The following are indirect CP entries:
  8646. -// JVM_CONSTANT_{Class,NameAndType,String}
  8647. -//
  8648. -// Double-indirect CP entries contain two references to indirect CP
  8649. -// entries and no other data. The following are double-indirect CP
  8650. -// entries:
  8651. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  8652. -//
  8653. -// When comparing entries between two constant pools, the entry types
  8654. -// are compared first and if they match, then further comparisons are
  8655. -// made depending on the entry subtype. Comparing direct CP entries is
  8656. -// simply a matter of comparing the data associated with each entry.
  8657. -// Comparing both indirect and double-indirect CP entries requires
  8658. -// recursion.
  8659. -//
  8660. -// Fortunately, the recursive combinations are limited because indirect
  8661. -// CP entries can only refer to direct CP entries and double-indirect
  8662. -// CP entries can only refer to indirect CP entries. The following is
  8663. -// an example illustration of the deepest set of indirections needed to
  8664. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  8665. -//
  8666. -// JVM_CONSTANT_Fieldref {
  8667. -// class_index => JVM_CONSTANT_Class {
  8668. -// name_index => JVM_CONSTANT_Utf8 {
  8669. -// <data-1>
  8670. -// }
  8671. -// }
  8672. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  8673. -// name_index => JVM_CONSTANT_Utf8 {
  8674. -// <data-2>
  8675. -// }
  8676. -// descriptor_index => JVM_CONSTANT_Utf8 {
  8677. -// <data-3>
  8678. -// }
  8679. -// }
  8680. -// }
  8681. -//
  8682. -// The above illustration is not a data structure definition for any
  8683. -// computer language. The curly braces ('{' and '}') are meant to
  8684. -// delimit the context of the "fields" in the CP entry types shown.
  8685. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  8686. -// "=>", e.g., the class_index is used to indirectly reference a
  8687. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  8688. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  8689. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  8690. -// have to do a total of 5 indirections just to get to the CP entries
  8691. -// that contain the interesting pieces of data and then we have to
  8692. -// fetch the three pieces of data. This means we have to do a total of
  8693. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  8694. -// entries.
  8695. -//
  8696. -// Here is the indirection, data and dereference count for each entry
  8697. -// type:
  8698. -//
  8699. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  8700. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  8701. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  8702. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  8703. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  8704. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  8705. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  8706. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  8707. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  8708. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  8709. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  8710. -//
  8711. -// So different subtypes of CP entries require different amounts of
  8712. -// work for a proper comparison.
  8713. -//
  8714. -// Now that we've talked about the different entry types and how to
  8715. -// compare them we need to get back to merging. This is not a merge in
  8716. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  8717. -// constant pools, we copy all the entries from old_cp to merge_cp,
  8718. -// preserving entry order. Next we append all the unique entries from
  8719. -// scratch_cp to merge_cp and we track the index changes from the
  8720. -// location in scratch_cp to the possibly new location in merge_cp.
  8721. -// When we are done, any obsolete code that is still running that
  8722. -// uses old_cp should not be able to observe any difference if it
  8723. -// were to use merge_cp. As for the new code in scratch_class, it is
  8724. -// modified to use the appropriate index values in merge_cp before it
  8725. -// is used to replace the code in the_class.
  8726. -//
  8727. -// There is one small complication in copying the entries from old_cp
  8728. -// to merge_cp. Two of the CP entry types are special in that they are
  8729. -// lazily resolved. Before explaining the copying complication, we need
  8730. -// to digress into CP entry resolution.
  8731. -//
  8732. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  8733. -// the class file, but are not stored in memory as such until they are
  8734. -// resolved. The entries are not resolved unless they are used because
  8735. -// resolution is expensive. During class file parsing the entries are
  8736. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  8737. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  8738. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  8739. -// have been parsed, but the index values in the entries have not been
  8740. -// validated. After the entire constant pool has been parsed, the index
  8741. -// values can be validated and then the entries are converted into
  8742. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  8743. -// entries. During this conversion process, the UTF8 values that are
  8744. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  8745. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  8746. -// entries are modified to refer to the Symbol*s. This optimization
  8747. -// eliminates one level of indirection for those two CP entry types and
  8748. -// gets the entries ready for verification. During class file parsing
  8749. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  8750. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  8751. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  8752. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  8753. -// entries.
  8754. -//
  8755. -// Now we can get back to the copying complication. When we copy
  8756. -// entries from old_cp to merge_cp, we have to revert any
  8757. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  8758. -// or verification will fail.
  8759. -//
  8760. -// It is important to explicitly state that the merging algorithm
  8761. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  8762. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  8763. -// entries in the merge_cp. This is done both to make verification
  8764. -// happy and to avoid adding more brittleness between RedefineClasses
  8765. -// and the constant pool cache. By allowing the constant pool cache
  8766. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  8767. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  8768. -// about those algorithms in RedefineClasses.
  8769. -//
  8770. -// Appending unique entries from scratch_cp to merge_cp is straight
  8771. -// forward for direct CP entries and most indirect CP entries. For the
  8772. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  8773. -// indirect CP entry types, the presence of more than one piece of
  8774. -// interesting data makes appending the entries more complicated.
  8775. -//
  8776. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  8777. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  8778. -// If the index in scratch_cp is different than the destination index
  8779. -// in merge_cp, then the change in index value is tracked.
  8780. -//
  8781. -// Note: the above discussion for the direct CP entries also applies
  8782. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  8783. -//
  8784. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  8785. -// one data element at the end of the recursion, we know that we have
  8786. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  8787. -// unique then it is appended to merge_cp before the current entry.
  8788. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  8789. -// is updated to refer to the duplicate entry in merge_cp before it is
  8790. -// appended to merge_cp. Again, any changes in index values are tracked
  8791. -// as needed.
  8792. -//
  8793. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  8794. -// types is theoretical. Since those entry types have already been
  8795. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  8796. -// they are handled as direct CP entries.
  8797. -//
  8798. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  8799. -// data elements at the end of the recursions, we know that we have
  8800. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  8801. -// entries are appended to merge_cp before the current entry. For any
  8802. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  8803. -// updated to refer to the duplicate entry in merge_cp before it is
  8804. -// appended to merge_cp. Again, any changes in index values are tracked
  8805. -// as needed.
  8806. -//
  8807. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  8808. -// types, since there are two indirect CP entries and three data
  8809. -// elements at the end of the recursions, we know that we have between
  8810. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  8811. -// above for an example of all six entries. The uniqueness algorithm
  8812. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  8813. -// covered above. Any unique entries are appended to merge_cp before
  8814. -// the current entry. For any entries that are not unique, the current
  8815. -// entry is updated to refer to the duplicate entry in merge_cp before
  8816. -// it is appended to merge_cp. Again, any changes in index values are
  8817. -// tracked as needed.
  8818. -//
  8819. -//
  8820. -// Other Details:
  8821. -//
  8822. -// Details for other parts of RedefineClasses need to be written.
  8823. -// This is a placeholder section.
  8824. -//
  8825. -//
  8826. -// Open Issues (in no particular order):
  8827. -//
  8828. -// - How do we serialize the RedefineClasses() API without deadlocking?
  8829. -//
  8830. -// - SystemDictionary::parse_stream() was called with a NULL protection
  8831. -// domain since the initial version. This has been changed to pass
  8832. -// the_class->protection_domain(). This change has been tested with
  8833. -// all NSK tests and nothing broke, but what will adding it now break
  8834. -// in ways that we don't test?
  8835. -//
  8836. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  8837. -// (indirect) use of the Relocator class that the max instruction
  8838. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  8839. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  8840. -// what it does to the bytecodes. More investigation is needed.
  8841. -//
  8842. -// - java.lang.Object methods can be called on arrays. This is
  8843. -// implemented via the arrayKlassOop vtable which we don't
  8844. -// update. For example, if we redefine java.lang.Object.toString(),
  8845. -// then the new version of the method will not be called for array
  8846. -// objects.
  8847. -//
  8848. -// - How do we know if redefine_single_class() and the guts of
  8849. -// instanceKlass are out of sync? I don't think this can be
  8850. -// automated, but we should probably order the work in
  8851. -// redefine_single_class() to match the order of field
  8852. -// definitions in instanceKlass. We also need to add some
  8853. -// comments about keeping things in sync.
  8854. -//
  8855. -// - set_new_constant_pool() is huge and we should consider refactoring
  8856. -// it into smaller chunks of work.
  8857. -//
  8858. -// - The exception table update code in set_new_constant_pool() defines
  8859. -// const values that are also defined in a local context elsewhere.
  8860. -// The same literal values are also used in elsewhere. We need to
  8861. -// coordinate a cleanup of these constants with Runtime.
  8862. -//
  8863. -
  8864. -class VM_RedefineClasses: public VM_Operation {
  8865. +#include "gc_implementation/shared/vmGCOperations.hpp"
  8866. +
  8867. +// New version that allows arbitrary changes to already loaded classes.
  8868. +class VM_RedefineClasses: public VM_GC_Operation {
  8869. private:
  8870. +
  8871. // These static fields are needed by SystemDictionary::classes_do()
  8872. // facility and the adjust_cpool_cache_and_vtable() helper:
  8873. static objArrayOop _old_methods;
  8874. static objArrayOop _new_methods;
  8875. - static methodOop* _matching_old_methods;
  8876. - static methodOop* _matching_new_methods;
  8877. - static methodOop* _deleted_methods;
  8878. - static methodOop* _added_methods;
  8879. + static int* _matching_old_methods;
  8880. + static int* _matching_new_methods;
  8881. + static int* _deleted_methods;
  8882. + static int* _added_methods;
  8883. static int _matching_methods_length;
  8884. static int _deleted_methods_length;
  8885. static int _added_methods_length;
  8886. - static klassOop _the_class_oop;
  8887. +
  8888. + static int _revision_number;
  8889. +
  8890. + static GrowableArray<instanceKlassHandle>* _affected_klasses;
  8891. // The instance fields are used to pass information from
  8892. // doit_prologue() to doit() and doit_epilogue().
  8893. @@ -366,40 +63,28 @@ class VM_RedefineClasses: public VM_Operation {
  8894. // RetransformClasses. Indicate which.
  8895. JvmtiClassLoadKind _class_load_kind;
  8896. - // _index_map_count is just an optimization for knowing if
  8897. - // _index_map_p contains any entries.
  8898. - int _index_map_count;
  8899. - intArray * _index_map_p;
  8900. - // ptr to _class_count scratch_classes
  8901. - instanceKlassHandle * _scratch_classes;
  8902. - jvmtiError _res;
  8903. + GrowableArray<instanceKlassHandle>* _new_classes;
  8904. + jvmtiError _result;
  8905. + int _max_redefinition_flags;
  8906. // Performance measurement support. These timers do not cover all
  8907. // the work done for JVM/TI RedefineClasses() but they do cover
  8908. // the heavy lifting.
  8909. - elapsedTimer _timer_rsc_phase1;
  8910. - elapsedTimer _timer_rsc_phase2;
  8911. - elapsedTimer _timer_vm_op_prologue;
  8912. -
  8913. - // These routines are roughly in call order unless otherwise noted.
  8914. -
  8915. - // Load the caller's new class definition(s) into _scratch_classes.
  8916. - // Constant pool merging work is done here as needed. Also calls
  8917. - // compare_and_normalize_class_versions() to verify the class
  8918. - // definition(s).
  8919. + elapsedTimer _timer_total;
  8920. + elapsedTimer _timer_prologue;
  8921. + elapsedTimer _timer_class_linking;
  8922. + elapsedTimer _timer_class_loading;
  8923. + elapsedTimer _timer_prepare_redefinition;
  8924. + elapsedTimer _timer_wait_for_locks;
  8925. + elapsedTimer _timer_heap_iteration;
  8926. + elapsedTimer _timer_redefinition;
  8927. + elapsedTimer _timer_vm_op_epilogue;
  8928. +
  8929. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  8930. + jvmtiError find_sorted_affected_classes( );
  8931. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  8932. jvmtiError load_new_class_versions(TRAPS);
  8933. - // Verify that the caller provided class definition(s) that meet
  8934. - // the restrictions of RedefineClasses. Normalize the order of
  8935. - // overloaded methods as needed.
  8936. - jvmtiError compare_and_normalize_class_versions(
  8937. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  8938. -
  8939. - // Swap annotations[i] with annotations[j]
  8940. - // Used by compare_and_normalize_class_versions() when normalizing
  8941. - // overloaded methods or changing idnum as when adding or deleting methods.
  8942. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  8943. -
  8944. // Figure out which new methods match old methods in name and signature,
  8945. // which methods have been added, and which are no longer present
  8946. void compute_added_deleted_matching_methods();
  8947. @@ -407,95 +92,71 @@ class VM_RedefineClasses: public VM_Operation {
  8948. // Change jmethodIDs to point to the new methods
  8949. void update_jmethod_ids();
  8950. - // In addition to marking methods as obsolete, this routine
  8951. - // records which methods are EMCP (Equivalent Module Constant
  8952. - // Pool) in the emcp_methods BitMap and returns the number of
  8953. - // EMCP methods via emcp_method_count_p. This information is
  8954. - // used when information about the previous version of the_class
  8955. - // is squirreled away.
  8956. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  8957. - int * emcp_method_count_p);
  8958. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  8959. + void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  8960. +
  8961. + static void add_affected_klasses( klassOop obj );
  8962. - // Unevolving classes may point to methods of the_class directly
  8963. - // from their constant pool caches, itables, and/or vtables. We
  8964. - // use the SystemDictionary::classes_do() facility and this helper
  8965. - // to fix up these pointers.
  8966. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  8967. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
  8968. // Install the redefinition of a class
  8969. - void redefine_single_class(jclass the_jclass,
  8970. - instanceKlassHandle scratch_class, TRAPS);
  8971. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  8972. // Increment the classRedefinedCount field in the specific instanceKlass
  8973. // and in all direct and indirect subclasses.
  8974. void increment_class_counter(instanceKlass *ik, TRAPS);
  8975. - // Support for constant pool merging (these routines are in alpha
  8976. - // order):
  8977. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  8978. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  8979. - int find_new_index(int old_index);
  8980. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  8981. - constantPoolHandle cp2, int index2);
  8982. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  8983. - constantPoolHandle cp2, int index2);
  8984. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  8985. - bool merge_constant_pools(constantPoolHandle old_cp,
  8986. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  8987. - int *merge_cp_length_p, TRAPS);
  8988. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  8989. - instanceKlassHandle scratch_class, TRAPS);
  8990. - u2 rewrite_cp_ref_in_annotation_data(
  8991. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  8992. - const char * trace_mesg, TRAPS);
  8993. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  8994. - bool rewrite_cp_refs_in_annotation_struct(
  8995. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  8996. - bool rewrite_cp_refs_in_annotations_typeArray(
  8997. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  8998. - bool rewrite_cp_refs_in_class_annotations(
  8999. - instanceKlassHandle scratch_class, TRAPS);
  9000. - bool rewrite_cp_refs_in_element_value(
  9001. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9002. - bool rewrite_cp_refs_in_fields_annotations(
  9003. - instanceKlassHandle scratch_class, TRAPS);
  9004. - void rewrite_cp_refs_in_method(methodHandle method,
  9005. - methodHandle * new_method_p, TRAPS);
  9006. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  9007. - bool rewrite_cp_refs_in_methods_annotations(
  9008. - instanceKlassHandle scratch_class, TRAPS);
  9009. - bool rewrite_cp_refs_in_methods_default_annotations(
  9010. - instanceKlassHandle scratch_class, TRAPS);
  9011. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  9012. - instanceKlassHandle scratch_class, TRAPS);
  9013. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  9014. - void rewrite_cp_refs_in_verification_type_info(
  9015. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  9016. - u1 frame_size, TRAPS);
  9017. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  9018. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  9019. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  9020. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  9021. - static void dump_methods();
  9022. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  9023. +
  9024. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  9025. +
  9026. + static void unpatch_bytecode(methodOop method);
  9027. +
  9028. +#ifdef ASSERT
  9029. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  9030. +#endif
  9031. +
  9032. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  9033. + void calculate_instance_update_information(klassOop new_version);
  9034. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  9035. + static void mark_as_scavengable(nmethod* nm);
  9036. +
  9037. + bool check_arguments();
  9038. + jvmtiError check_arguments_error();
  9039. public:
  9040. - VM_RedefineClasses(jint class_count,
  9041. - const jvmtiClassDefinition *class_defs,
  9042. - JvmtiClassLoadKind class_load_kind);
  9043. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  9044. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  9045. + virtual ~VM_RedefineClasses();
  9046. +
  9047. bool doit_prologue();
  9048. void doit();
  9049. void doit_epilogue();
  9050. + void rollback();
  9051. - bool allow_nested_vm_operations() const { return true; }
  9052. - jvmtiError check_error() { return _res; }
  9053. + jvmtiError check_exception() const;
  9054. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  9055. + bool skip_operation() const { return false; }
  9056. + bool allow_nested_vm_operations() const { return true; }
  9057. + jvmtiError check_error() { return _result; }
  9058. // Modifiable test must be shared between IsModifiableClass query
  9059. // and redefine implementation
  9060. static bool is_modifiable_class(oop klass_mirror);
  9061. +
  9062. + // Utility methods for transfering field access flags
  9063. +
  9064. + static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
  9065. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  9066. +
  9067. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9068. +
  9069. + void lock_threads();
  9070. + void unlock_threads();
  9071. +
  9072. + static void swap_marks(oop first, oop second);
  9073. +
  9074. };
  9075. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  9076. diff --git a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9077. index 878d300..9dbe748 100644
  9078. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9079. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9080. @@ -1,5 +1,5 @@
  9081. /*
  9082. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  9083. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  9084. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9085. *
  9086. * This code is free software; you can redistribute it and/or modify it
  9087. @@ -22,114 +22,26 @@
  9088. *
  9089. */
  9090. -#ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9091. -#define SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9092. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  9093. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  9094. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  9095. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  9096. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  9097. -// RedefineClasses tracing support via the TraceRedefineClasses
  9098. -// option. A bit is assigned to each group of trace messages.
  9099. -// Groups of messages are individually selectable. We have to use
  9100. -// decimal values on the command line since the command option
  9101. -// parsing logic doesn't like non-decimal numerics. The HEX values
  9102. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  9103. -// the old cumulative behavior, pick the level after the one in
  9104. -// which you are interested and subtract one, e.g., 33554431 will
  9105. -// print every tracing message.
  9106. -//
  9107. -// 0x00000000 | 0 - default; no tracing messages
  9108. -// 0x00000001 | 1 - name each target class before loading, after
  9109. -// loading and after redefinition is completed
  9110. -// 0x00000002 | 2 - print info if parsing, linking or
  9111. -// verification throws an exception
  9112. -// 0x00000004 | 4 - print timer info for the VM operation
  9113. -// 0x00000008 | 8 - print subclass counter updates
  9114. -// 0x00000010 | 16 - unused
  9115. -// 0x00000020 | 32 - unused
  9116. -// 0x00000040 | 64 - unused
  9117. -// 0x00000080 | 128 - unused
  9118. -// 0x00000100 | 256 - previous class weak reference addition
  9119. -// 0x00000200 | 512 - previous class weak reference mgmt during
  9120. -// class unloading checks (GC)
  9121. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  9122. -// add previous ops (GC)
  9123. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  9124. -// 0x00001000 | 4096 - detect calls to obsolete methods
  9125. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  9126. -// 0x00004000 | 16384 - detect old/obsolete methods in metadata
  9127. -// 0x00008000 | 32768 - old/new method matching/add/delete
  9128. -// 0x00010000 | 65536 - impl details: CP size info
  9129. -// 0x00020000 | 131072 - impl details: CP merge pass info
  9130. -// 0x00040000 | 262144 - impl details: CP index maps
  9131. -// 0x00080000 | 524288 - impl details: modified CP index values
  9132. -// 0x00100000 | 1048576 - impl details: vtable updates
  9133. -// 0x00200000 | 2097152 - impl details: itable updates
  9134. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  9135. -// 0x00800000 | 8388608 - impl details: methodComparator info
  9136. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  9137. -// 0x02000000 | 33554432 - impl details: annotation updates
  9138. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  9139. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  9140. -// 0x10000000 | 268435456 - unused
  9141. -// 0x20000000 | 536870912 - unused
  9142. -// 0x40000000 | 1073741824 - unused
  9143. -// 0x80000000 | 2147483648 - unused
  9144. -//
  9145. -// Note: The ResourceMark is to cleanup resource allocated args.
  9146. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  9147. -#define RC_TRACE(level, args) \
  9148. - if ((TraceRedefineClasses & level) != 0) { \
  9149. - ResourceMark rm; \
  9150. - tty->print("RedefineClasses-0x%x: ", level); \
  9151. - tty->print_cr args; \
  9152. - } while (0)
  9153. -
  9154. -#define RC_TRACE_NO_CR(level, args) \
  9155. - if ((TraceRedefineClasses & level) != 0) { \
  9156. - ResourceMark rm; \
  9157. - tty->print("RedefineClasses-0x%x: ", level); \
  9158. - tty->print args; \
  9159. - } while (0)
  9160. -
  9161. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  9162. - if ((TraceRedefineClasses & level) != 0) { \
  9163. - ResourceMark rm(thread); \
  9164. - tty->print("RedefineClasses-0x%x: ", level); \
  9165. - tty->print_cr args; \
  9166. - } while (0)
  9167. -
  9168. -#define RC_TRACE_MESG(args) \
  9169. - { \
  9170. - ResourceMark rm; \
  9171. - tty->print("RedefineClasses: "); \
  9172. - tty->print_cr args; \
  9173. - } while (0)
  9174. -
  9175. -// Macro for checking if TraceRedefineClasses has a specific bit
  9176. -// enabled. Returns true if the bit specified by level is set.
  9177. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  9178. -
  9179. -// Macro for checking if TraceRedefineClasses has one or more bits
  9180. -// set in a range of bit values. Returns true if one or more bits
  9181. -// is set in the range from low..high inclusive. Assumes that low
  9182. -// and high are single bit values.
  9183. -//
  9184. -// ((high << 1) - 1)
  9185. -// Yields a mask that removes bits greater than the high bit value.
  9186. -// This algorithm doesn't work with highest bit.
  9187. -// ~(low - 1)
  9188. -// Yields a mask that removes bits lower than the low bit value.
  9189. -#define RC_TRACE_IN_RANGE(low, high) \
  9190. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  9191. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  9192. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  9193. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  9194. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  9195. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  9196. // Timer support macros. Only do timer operations if timer tracing
  9197. // is enabled. The "while (0)" is so we can use semi-colon at end of
  9198. // the macro.
  9199. #define RC_TIMER_START(t) \
  9200. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9201. + if (TimeRedefineClasses) { \
  9202. t.start(); \
  9203. } while (0)
  9204. #define RC_TIMER_STOP(t) \
  9205. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9206. + if (TimeRedefineClasses) { \
  9207. t.stop(); \
  9208. } while (0)
  9209. -
  9210. -#endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9211. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  9212. index 60eaf97..785dc24 100644
  9213. --- a/src/share/vm/prims/methodComparator.cpp
  9214. +++ b/src/share/vm/prims/methodComparator.cpp
  9215. @@ -42,10 +42,9 @@ bool MethodComparator::methods_EMCP(methodOop old_method, methodOop new_method)
  9216. if (old_method->code_size() != new_method->code_size())
  9217. return false;
  9218. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  9219. - // RC_TRACE macro has an embedded ResourceMark
  9220. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  9221. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  9222. old_method->name()->as_C_string(),
  9223. - check_stack_and_locals_size(old_method, new_method)));
  9224. + check_stack_and_locals_size(old_method, new_method));
  9225. return false;
  9226. }
  9227. @@ -114,10 +113,9 @@ bool MethodComparator::methods_switchable(methodOop old_method, methodOop new_me
  9228. // Now we can test all forward jumps
  9229. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  9230. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  9231. - RC_TRACE(0x00800000,
  9232. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9233. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9234. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  9235. - fwd_jmps.at(i*2+1)));
  9236. + fwd_jmps.at(i*2+1));
  9237. return false;
  9238. }
  9239. }
  9240. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  9241. index 22d450b..bac1ae6 100644
  9242. --- a/src/share/vm/runtime/arguments.cpp
  9243. +++ b/src/share/vm/runtime/arguments.cpp
  9244. @@ -54,8 +54,8 @@
  9245. #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  9246. #endif
  9247. -// Note: This is a special bug reporting site for the JVM
  9248. -#define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  9249. +// (tw) The DCE VM has its own JIRA bug tracking system.
  9250. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  9251. #define DEFAULT_JAVA_LAUNCHER "generic"
  9252. char** Arguments::_jvm_flags_array = NULL;
  9253. @@ -1792,6 +1792,16 @@ bool Arguments::check_gc_consistency() {
  9254. status = false;
  9255. }
  9256. + // (tw) Must use serial GC. This limitation applies because the instance size changing GC modifications
  9257. + // are only built into the mark and compact algorithm.
  9258. + if (!UseSerialGC && i >= 1) {
  9259. + //jio_fprintf(defaultStream::error_stream(),
  9260. + // "Must use the serial GC in the Dynamic Code Evolution VM\n");
  9261. + //status = false;
  9262. + } else {
  9263. + UseSerialGC = true;
  9264. + }
  9265. +
  9266. return status;
  9267. }
  9268. @@ -3208,7 +3218,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
  9269. // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  9270. set_aggressive_opts_flags();
  9271. -
  9272. +#ifndef COMPILER2
  9273. // Turn off biased locking for locking debug mode flags,
  9274. // which are subtlely different from each other but neither works with
  9275. // biased locking.
  9276. @@ -3225,6 +3235,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
  9277. }
  9278. UseBiasedLocking = false;
  9279. }
  9280. +#endif
  9281. #ifdef CC_INTERP
  9282. // Clear flags not supported by the C++ interpreter
  9283. diff --git a/src/share/vm/runtime/fieldDescriptor.cpp b/src/share/vm/runtime/fieldDescriptor.cpp
  9284. index 3d5213f..9cc701b 100644
  9285. --- a/src/share/vm/runtime/fieldDescriptor.cpp
  9286. +++ b/src/share/vm/runtime/fieldDescriptor.cpp
  9287. @@ -92,7 +92,8 @@ void fieldDescriptor::initialize(klassOop k, int index) {
  9288. instanceKlass* ik = instanceKlass::cast(k);
  9289. _cp = ik->constants();
  9290. FieldInfo* f = ik->field(index);
  9291. - assert(!f->is_internal(), "regular Java fields only");
  9292. + // (tw) do we need this?
  9293. +// assert(!f->is_internal(), "regular Java fields only");
  9294. _access_flags = accessFlags_from(f->access_flags());
  9295. guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
  9296. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  9297. index 8df7220..341b399 100644
  9298. --- a/src/share/vm/runtime/globals.hpp
  9299. +++ b/src/share/vm/runtime/globals.hpp
  9300. @@ -1230,6 +1230,11 @@ class CommandLineFlags {
  9301. product(intx, TraceRedefineClasses, 0, \
  9302. "Trace level for JVMTI RedefineClasses") \
  9303. \
  9304. + product(bool, TimeRedefineClasses, false, \
  9305. + "Measure timing for JVMTI RedefineClasses") \
  9306. + \
  9307. + product(bool, AllowAdvancedClassRedefinition, true, \
  9308. + "Allow advanced class redefinition beyond swapping method bodies")\
  9309. develop(bool, StressMethodComparator, false, \
  9310. "run the MethodComparator on all loaded methods") \
  9311. \
  9312. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  9313. index 2875ee0..61fd8fe 100644
  9314. --- a/src/share/vm/runtime/interfaceSupport.hpp
  9315. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  9316. @@ -296,7 +296,7 @@ class ThreadToNativeFromVM : public ThreadStateTransition {
  9317. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  9318. // We are leaving the VM at this point and going directly to native code.
  9319. // Block, if we are in the middle of a safepoint synchronization.
  9320. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9321. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9322. thread->frame_anchor()->make_walkable(thread);
  9323. trans_and_fence(_thread_in_vm, _thread_in_native);
  9324. // Check for pending. async. exceptions or suspends.
  9325. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  9326. index edbba98..4a27925 100644
  9327. --- a/src/share/vm/runtime/javaCalls.cpp
  9328. +++ b/src/share/vm/runtime/javaCalls.cpp
  9329. @@ -60,7 +60,7 @@ JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, Ja
  9330. bool clear_pending_exception = true;
  9331. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  9332. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9333. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9334. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  9335. _result = result;
  9336. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  9337. index 3cbcaca..30839d7 100644
  9338. --- a/src/share/vm/runtime/jniHandles.cpp
  9339. +++ b/src/share/vm/runtime/jniHandles.cpp
  9340. @@ -112,6 +112,10 @@ jobject JNIHandles::make_weak_global(Handle obj) {
  9341. }
  9342. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  9343. + if (mh->newest_version() != mh()) {
  9344. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  9345. + return (jmethodID) make_weak_global(mh_new);
  9346. + }
  9347. return (jmethodID) make_weak_global(mh);
  9348. }
  9349. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  9350. index 2095237..c541434 100644
  9351. --- a/src/share/vm/runtime/mutex.cpp
  9352. +++ b/src/share/vm/runtime/mutex.cpp
  9353. @@ -1227,7 +1227,7 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
  9354. // in increasing rank order (modulo any native ranks)
  9355. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9356. if (tmp->next() != NULL) {
  9357. - assert(tmp->rank() == Mutex::native ||
  9358. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9359. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9360. }
  9361. }
  9362. @@ -1247,7 +1247,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
  9363. // in increasing rank order (modulo any native ranks)
  9364. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9365. if (tmp->next() != NULL) {
  9366. - assert(tmp->rank() == Mutex::native ||
  9367. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9368. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9369. }
  9370. }
  9371. @@ -1310,6 +1310,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
  9372. // already hold Terminator_lock - may happen because of periodic safepoints
  9373. if (this->rank() != Mutex::native &&
  9374. this->rank() != Mutex::suspend_resume &&
  9375. + this->rank() != Mutex::redefine_classes &&
  9376. locks != NULL && locks->rank() <= this->rank() &&
  9377. !SafepointSynchronize::is_at_safepoint() &&
  9378. this != Interrupt_lock &&
  9379. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  9380. index 7d2cd82..11eb32e 100644
  9381. --- a/src/share/vm/runtime/mutex.hpp
  9382. +++ b/src/share/vm/runtime/mutex.hpp
  9383. @@ -109,7 +109,8 @@ class Monitor : public CHeapObj<mtInternal> {
  9384. barrier = safepoint + 1,
  9385. nonleaf = barrier + 1,
  9386. max_nonleaf = nonleaf + 900,
  9387. - native = max_nonleaf + 1
  9388. + native = max_nonleaf + 1,
  9389. + redefine_classes = native + 1
  9390. };
  9391. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  9392. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  9393. index a6b2106..3a3110b 100644
  9394. --- a/src/share/vm/runtime/mutexLocker.cpp
  9395. +++ b/src/share/vm/runtime/mutexLocker.cpp
  9396. @@ -49,6 +49,7 @@
  9397. // Consider using GCC's __read_mostly.
  9398. Mutex* Patching_lock = NULL;
  9399. +Mutex* RedefineClasses_lock = NULL;
  9400. Monitor* SystemDictionary_lock = NULL;
  9401. Mutex* PackageTable_lock = NULL;
  9402. Mutex* CompiledIC_lock = NULL;
  9403. @@ -278,6 +279,7 @@ void mutex_init() {
  9404. def(MethodCompileQueue_lock , Monitor, nonleaf+4, true );
  9405. def(Debug2_lock , Mutex , nonleaf+4, true );
  9406. def(Debug3_lock , Mutex , nonleaf+4, true );
  9407. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  9408. def(CompileThread_lock , Monitor, nonleaf+5, false );
  9409. def(JfrMsg_lock , Monitor, leaf, true);
  9410. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  9411. index 40008bb..60c7cce 100644
  9412. --- a/src/share/vm/runtime/mutexLocker.hpp
  9413. +++ b/src/share/vm/runtime/mutexLocker.hpp
  9414. @@ -43,6 +43,7 @@
  9415. // Mutexes used in the VM.
  9416. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  9417. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  9418. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  9419. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  9420. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  9421. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  9422. index cd009ed..a53ad09 100644
  9423. --- a/src/share/vm/runtime/reflection.cpp
  9424. +++ b/src/share/vm/runtime/reflection.cpp
  9425. @@ -468,7 +468,8 @@ bool Reflection::verify_class_access(klassOop current_class, klassOop new_class,
  9426. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9427. if ( JDK_Version::is_gte_jdk14x_version()
  9428. && UseNewReflection
  9429. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9430. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9431. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9432. return true;
  9433. }
  9434. @@ -519,6 +520,12 @@ bool Reflection::verify_field_access(klassOop current_class,
  9435. AccessFlags access,
  9436. bool classloader_only,
  9437. bool protected_restriction) {
  9438. +
  9439. + // (tw) Decide accessibility based on active version
  9440. + if (current_class != NULL) {
  9441. + current_class = current_class->klass_part()->active_version();
  9442. + }
  9443. +
  9444. // Verify that current_class can access a field of field_class, where that
  9445. // field's access bits are "access". We assume that we've already verified
  9446. // that current_class can access field_class.
  9447. @@ -560,7 +567,8 @@ bool Reflection::verify_field_access(klassOop current_class,
  9448. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9449. if ( JDK_Version::is_gte_jdk14x_version()
  9450. && UseNewReflection
  9451. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9452. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9453. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9454. return true;
  9455. }
  9456. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  9457. index 709d783..689b9a2 100644
  9458. --- a/src/share/vm/runtime/sharedRuntime.cpp
  9459. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  9460. @@ -603,21 +603,13 @@ void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Symbol* n
  9461. //
  9462. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  9463. JavaThread* thread, methodOopDesc* method))
  9464. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  9465. + assert(TraceRedefineClasses >= 4, "wrong call");
  9466. if (method->is_obsolete()) {
  9467. // We are calling an obsolete method, but this is not necessarily
  9468. // an error. Our method could have been redefined just after we
  9469. // fetched the methodOop from the constant pool.
  9470. -
  9471. - // RC_TRACE macro has an embedded ResourceMark
  9472. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  9473. - ("calling obsolete method '%s'",
  9474. - method->name_and_sig_as_C_string()));
  9475. - if (RC_TRACE_ENABLED(0x00002000)) {
  9476. - // this option is provided to debug calls to obsolete methods
  9477. - guarantee(false, "faulting at call to an obsolete method.");
  9478. - }
  9479. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  9480. }
  9481. return 0;
  9482. JRT_END
  9483. @@ -1137,7 +1129,20 @@ methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
  9484. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  9485. int retry_count = 0;
  9486. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  9487. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  9488. + callee_method->method_holder()->klass_part()->super() != NULL) {
  9489. +
  9490. + // (tw) If we are executing an old method, this is OK!
  9491. + {
  9492. + ResourceMark rm(thread);
  9493. + RegisterMap cbl_map(thread, false);
  9494. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  9495. +
  9496. + CodeBlob* caller_cb = caller_frame.cb();
  9497. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  9498. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  9499. + if (caller_nm->method()->is_old()) break;
  9500. + }
  9501. +
  9502. // If has a pending exception then there is no need to re-try to
  9503. // resolve this method.
  9504. // If the method has been redefined, we need to try again.
  9505. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  9506. index ae28b65..bb0681e 100644
  9507. --- a/src/share/vm/runtime/thread.cpp
  9508. +++ b/src/share/vm/runtime/thread.cpp
  9509. @@ -216,6 +216,8 @@ Thread::Thread() {
  9510. set_self_raw_id(0);
  9511. set_lgrp_id(-1);
  9512. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  9513. +
  9514. // allocated data structures
  9515. set_osthread(NULL);
  9516. set_resource_area(new (mtThread)ResourceArea());
  9517. @@ -249,6 +251,7 @@ Thread::Thread() {
  9518. omFreeProvision = 32 ;
  9519. omInUseList = NULL ;
  9520. omInUseCount = 0 ;
  9521. + _pretend_new_universe = false;
  9522. #ifdef ASSERT
  9523. _visited_for_critical_count = false;
  9524. @@ -884,6 +887,15 @@ bool Thread::owns_locks_but_compiled_lock() const {
  9525. return false;
  9526. }
  9527. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  9528. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  9529. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  9530. + return true;
  9531. + }
  9532. + }
  9533. + return false;
  9534. +}
  9535. +
  9536. #endif
  9537. @@ -1637,7 +1649,7 @@ void JavaThread::run() {
  9538. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  9539. assert(JavaThread::current() == this, "sanity check");
  9540. - assert(!Thread::current()->owns_locks(), "sanity check");
  9541. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  9542. DTRACE_THREAD_PROBE(start, this);
  9543. @@ -3193,7 +3205,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  9544. // Create a CompilerThread
  9545. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9546. -: JavaThread(&compiler_thread_entry) {
  9547. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  9548. _env = NULL;
  9549. _log = NULL;
  9550. _task = NULL;
  9551. @@ -3201,6 +3213,7 @@ CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9552. _counters = counters;
  9553. _buffer_blob = NULL;
  9554. _scanned_nmethod = NULL;
  9555. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  9556. #ifndef PRODUCT
  9557. _ideal_graph_printer = NULL;
  9558. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  9559. index 774bd27..4620820 100644
  9560. --- a/src/share/vm/runtime/thread.hpp
  9561. +++ b/src/share/vm/runtime/thread.hpp
  9562. @@ -202,12 +202,15 @@ class Thread: public ThreadShadow {
  9563. public:
  9564. void enter_signal_handler() { _num_nested_signal++; }
  9565. void leave_signal_handler() { _num_nested_signal--; }
  9566. - bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9567. + bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9568. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  9569. private:
  9570. // Debug tracing
  9571. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  9572. + Mutex* _redefine_classes_mutex;
  9573. +
  9574. // Active_handles points to a block of handles
  9575. JNIHandleBlock* _active_handles;
  9576. @@ -530,10 +533,15 @@ public:
  9577. uintptr_t _self_raw_id; // used by get_thread (mutable)
  9578. int _lgrp_id;
  9579. +
  9580. + bool _pretend_new_universe;
  9581. +
  9582. public:
  9583. // Stack overflow support
  9584. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  9585. + 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; } }
  9586. + bool pretend_new_universe() { return _pretend_new_universe; }
  9587. void set_stack_base(address base) { _stack_base = base; }
  9588. size_t stack_size() const { return _stack_size; }
  9589. void set_stack_size(size_t size) { _stack_size = size; }
  9590. @@ -570,6 +578,7 @@ public:
  9591. void print_owned_locks() const { print_owned_locks_on(tty); }
  9592. Monitor* owned_locks() const { return _owned_locks; }
  9593. bool owns_locks() const { return owned_locks() != NULL; }
  9594. + bool owns_locks_but_redefine_classes_lock() const;
  9595. bool owns_locks_but_compiled_lock() const;
  9596. // Deadlock detection
  9597. @@ -1793,6 +1802,8 @@ class CompilerThread : public JavaThread {
  9598. CompileTask* _task;
  9599. CompileQueue* _queue;
  9600. BufferBlob* _buffer_blob;
  9601. + bool _should_bailout;
  9602. + Mutex* _compilation_mutex;
  9603. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  9604. @@ -1802,12 +1813,16 @@ class CompilerThread : public JavaThread {
  9605. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  9606. + bool should_bailout() const { return _should_bailout; }
  9607. + void set_should_bailout(bool b) { _should_bailout = false; }
  9608. +
  9609. bool is_Compiler_thread() const { return true; }
  9610. // Hide this compiler thread from external view.
  9611. bool is_hidden_from_external_view() const { return true; }
  9612. CompileQueue* queue() { return _queue; }
  9613. CompilerCounters* counters() { return _counters; }
  9614. + Mutex *compilation_mutex() { return _compilation_mutex; }
  9615. // Get/set the thread's compilation environment.
  9616. ciEnv* env() { return _env; }
  9617. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  9618. index 7643670..0d3cd70 100644
  9619. --- a/src/share/vm/runtime/vmThread.cpp
  9620. +++ b/src/share/vm/runtime/vmThread.cpp
  9621. @@ -691,6 +691,9 @@ void VMThread::execute(VM_Operation* op) {
  9622. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  9623. Thread::oops_do(f, cf);
  9624. _vm_queue->oops_do(f);
  9625. + if (_cur_vm_operation != NULL) {
  9626. + _cur_vm_operation->oops_do(f);
  9627. + }
  9628. }
  9629. //------------------------------------------------------------------------------------------------------------------
  9630. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  9631. index 03f254d..18e324b 100644
  9632. --- a/src/share/vm/utilities/exceptions.cpp
  9633. +++ b/src/share/vm/utilities/exceptions.cpp
  9634. @@ -254,6 +254,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  9635. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  9636. assert(!thread->has_pending_exception(), "already has exception");
  9637. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  9638. + Thread::current()->set_pretend_new_universe(false);
  9639. Handle h_exception;
  9640. // Resolve exception klass
  9641. @@ -285,6 +287,7 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  9642. h_exception = Handle(thread, thread->pending_exception());
  9643. thread->clear_pending_exception();
  9644. }
  9645. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  9646. return h_exception;
  9647. }
  9648. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  9649. index 2a6d6b8..4b6927f 100644
  9650. --- a/src/share/vm/utilities/growableArray.hpp
  9651. +++ b/src/share/vm/utilities/growableArray.hpp
  9652. @@ -145,6 +145,33 @@ class GenericGrowableArray : public ResourceObj {
  9653. assert(on_stack(), "fast ResourceObj path only");
  9654. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  9655. }
  9656. +
  9657. +};
  9658. +
  9659. +template<class E, class F> class Pair : public StackObj
  9660. +{
  9661. +private:
  9662. + E _left;
  9663. + F _right;
  9664. +
  9665. +public:
  9666. +
  9667. + Pair() {
  9668. +
  9669. + }
  9670. +
  9671. + Pair(E left, F right) {
  9672. + this->_left = left;
  9673. + this->_right = right;
  9674. + }
  9675. +
  9676. + E left() {
  9677. + return _left;
  9678. + }
  9679. +
  9680. + F right() {
  9681. + return _right;
  9682. + }
  9683. };
  9684. template<class E> class GrowableArray : public GenericGrowableArray {