Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

full-jdk7u11-b21.patch 492KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076
  1. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  2. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  3. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  4. @@ -2109,6 +2109,22 @@
  5. // resolve first time through
  6. address entry;
  7. switch (bytecode()) {
  8. + case Bytecodes::_fast_agetfield : // fall through
  9. + case Bytecodes::_fast_bgetfield : // fall through
  10. + case Bytecodes::_fast_cgetfield : // fall through
  11. + case Bytecodes::_fast_dgetfield : // fall through
  12. + case Bytecodes::_fast_fgetfield : // fall through
  13. + case Bytecodes::_fast_igetfield : // fall through
  14. + case Bytecodes::_fast_lgetfield : // fall through
  15. + case Bytecodes::_fast_sgetfield : // fall through
  16. + case Bytecodes::_fast_aputfield : // fall through
  17. + case Bytecodes::_fast_bputfield : // fall through
  18. + case Bytecodes::_fast_cputfield : // fall through
  19. + case Bytecodes::_fast_dputfield : // fall through
  20. + case Bytecodes::_fast_fputfield : // fall through
  21. + case Bytecodes::_fast_iputfield : // fall through
  22. + case Bytecodes::_fast_lputfield : // fall through
  23. + case Bytecodes::_fast_sputfield : // fall through
  24. case Bytecodes::_getstatic : // fall through
  25. case Bytecodes::_putstatic : // fall through
  26. case Bytecodes::_getfield : // fall through
  27. @@ -2203,6 +2219,7 @@
  28. // Correct values of the cache and index registers are preserved.
  29. void TemplateTable::jvmti_post_field_access(Register cache,
  30. Register index,
  31. + int byte_no,
  32. bool is_static,
  33. bool has_tos) {
  34. if (JvmtiExport::can_post_field_access()) {
  35. @@ -2229,7 +2246,11 @@
  36. // cache: cache entry pointer
  37. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  38. rax, cache);
  39. - __ get_cache_and_index_at_bcp(cache, index, 1);
  40. +
  41. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  42. + __ restore_bcp();
  43. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  44. +
  45. __ bind(L1);
  46. }
  47. }
  48. @@ -2250,7 +2271,7 @@
  49. const Register flags = rax;
  50. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  51. - jvmti_post_field_access(cache, index, is_static, false);
  52. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  53. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  54. if (!is_static) pop_and_check_object(obj);
  55. @@ -2385,7 +2406,7 @@
  56. // The registers cache and index expected to be set before call.
  57. // The function may destroy various registers, just not the cache and index registers.
  58. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  59. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  60. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  61. @@ -2443,7 +2464,11 @@
  62. // rcx: jvalue object on the stack
  63. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  64. rbx, rax, rcx);
  65. - __ get_cache_and_index_at_bcp(cache, index, 1);
  66. +
  67. + // (tw) Redefinition might have occured => reresolve the cp entry.
  68. + __ restore_bcp();
  69. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  70. +
  71. __ bind(L1);
  72. }
  73. }
  74. @@ -2459,7 +2484,7 @@
  75. const Register flags = rax;
  76. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  77. - jvmti_post_field_mod(cache, index, is_static);
  78. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  79. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  80. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  81. @@ -2697,6 +2722,11 @@
  82. // rax,: cache entry pointer
  83. // rcx: jvalue object on the stack
  84. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  85. +
  86. + // (tw) Redefinition might have occured => reresolve the cp entry.
  87. + __ restore_bcp();
  88. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  89. +
  90. if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); // restore high value
  91. __ pop(rax); // restore lower value
  92. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  93. @@ -2817,6 +2847,11 @@
  94. // rcx: cache entry pointer
  95. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  96. __ pop_ptr(rax); // restore object pointer
  97. +
  98. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  99. + __ restore_bcp();
  100. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  101. +
  102. __ bind(L1);
  103. }
  104. @@ -2987,6 +3022,26 @@
  105. __ bind(notFinal);
  106. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  107. + Label notOld;
  108. + __ movl(rax, flags);
  109. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  110. + __ jcc(Assembler::zero, notOld);
  111. +
  112. + // Need a null check here!
  113. + __ null_check(recv);
  114. +
  115. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  116. + // DCEVM: TODO: Check if we can improve performance by inlining.
  117. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  118. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  119. +
  120. + // profile this call
  121. + __ profile_final_call(rax);
  122. + __ jump_from_interpreted(method, rdx);
  123. +
  124. + __ bind(notOld);
  125. +
  126. // get receiver klass
  127. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  128. // Keep recv in rcx for callee expects it there
  129. @@ -3068,6 +3123,31 @@
  130. invokevirtual_helper(rbx, rcx, rdx);
  131. __ bind(notMethod);
  132. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  133. + //__ movl(rax, rdx);
  134. + Label notOld;
  135. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  136. + __ jcc(Assembler::zero, notOld);
  137. +
  138. + // Get receiver klass into rdx - also a null check
  139. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  140. + __ verify_oop(rdx);
  141. +
  142. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  143. + // DCEVM: TODO: Check if we can improve performance by inlining.
  144. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  145. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  146. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  147. +
  148. + // DCEVM: TODO: Check if resolved method could be null.
  149. +
  150. + // profile this call
  151. + __ profile_virtual_call(rdx, rsi, rdi);
  152. +
  153. + __ jump_from_interpreted(rbx, rdx);
  154. +
  155. + __ bind(notOld);
  156. +
  157. // Get receiver klass into rdx - also a null check
  158. __ restore_locals(); // restore rdi
  159. __ load_klass(rdx, rcx);
  160. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  161. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  162. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  163. @@ -2145,6 +2145,22 @@
  164. // resolve first time through
  165. address entry;
  166. switch (bytecode()) {
  167. + case Bytecodes::_fast_agetfield : // fall through
  168. + case Bytecodes::_fast_bgetfield : // fall through
  169. + case Bytecodes::_fast_cgetfield : // fall through
  170. + case Bytecodes::_fast_dgetfield : // fall through
  171. + case Bytecodes::_fast_fgetfield : // fall through
  172. + case Bytecodes::_fast_igetfield : // fall through
  173. + case Bytecodes::_fast_lgetfield : // fall through
  174. + case Bytecodes::_fast_sgetfield : // fall through
  175. + case Bytecodes::_fast_aputfield : // fall through
  176. + case Bytecodes::_fast_bputfield : // fall through
  177. + case Bytecodes::_fast_cputfield : // fall through
  178. + case Bytecodes::_fast_dputfield : // fall through
  179. + case Bytecodes::_fast_fputfield : // fall through
  180. + case Bytecodes::_fast_iputfield : // fall through
  181. + case Bytecodes::_fast_lputfield : // fall through
  182. + case Bytecodes::_fast_sputfield : // fall through
  183. case Bytecodes::_getstatic:
  184. case Bytecodes::_putstatic:
  185. case Bytecodes::_getfield:
  186. @@ -2251,7 +2267,7 @@
  187. // The registers cache and index expected to be set before call.
  188. // Correct values of the cache and index registers are preserved.
  189. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  190. - bool is_static, bool has_tos) {
  191. + int byte_no, bool is_static, bool has_tos) {
  192. // do the JVMTI work here to avoid disturbing the register state below
  193. // We use c_rarg registers here because we want to use the register used in
  194. // the call to the VM
  195. @@ -2282,7 +2298,11 @@
  196. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  197. InterpreterRuntime::post_field_access),
  198. c_rarg1, c_rarg2, c_rarg3);
  199. - __ get_cache_and_index_at_bcp(cache, index, 1);
  200. +
  201. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  202. + __ restore_bcp();
  203. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  204. +
  205. __ bind(L1);
  206. }
  207. }
  208. @@ -2304,7 +2324,7 @@
  209. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  210. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  211. - jvmti_post_field_access(cache, index, is_static, false);
  212. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  213. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  214. if (!is_static) {
  215. @@ -2438,7 +2458,7 @@
  216. // The registers cache and index expected to be set before call.
  217. // The function may destroy various registers, just not the cache and index registers.
  218. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  219. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  220. transition(vtos, vtos);
  221. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  222. @@ -2491,7 +2511,11 @@
  223. CAST_FROM_FN_PTR(address,
  224. InterpreterRuntime::post_field_modification),
  225. c_rarg1, c_rarg2, c_rarg3);
  226. - __ get_cache_and_index_at_bcp(cache, index, 1);
  227. +
  228. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  229. + __ restore_bcp();
  230. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  231. +
  232. __ bind(L1);
  233. }
  234. }
  235. @@ -2507,7 +2531,7 @@
  236. const Register bc = c_rarg3;
  237. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  238. - jvmti_post_field_mod(cache, index, is_static);
  239. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  240. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  241. // [jk] not needed currently
  242. @@ -2715,6 +2739,11 @@
  243. CAST_FROM_FN_PTR(address,
  244. InterpreterRuntime::post_field_modification),
  245. rbx, c_rarg2, c_rarg3);
  246. +
  247. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  248. + __ restore_bcp();
  249. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  250. +
  251. __ pop(rax); // restore lower value
  252. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  253. __ bind(L2);
  254. @@ -2815,6 +2844,11 @@
  255. InterpreterRuntime::post_field_access),
  256. c_rarg1, c_rarg2);
  257. __ pop_ptr(rax); // restore object pointer
  258. +
  259. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  260. + __ restore_bcp();
  261. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  262. +
  263. __ bind(L1);
  264. }
  265. @@ -3030,6 +3064,26 @@
  266. __ bind(notFinal);
  267. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  268. + Label notOld;
  269. + __ movl(rax, flags);
  270. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  271. + __ jcc(Assembler::zero, notOld);
  272. +
  273. + // Need a null check here!
  274. + __ null_check(recv);
  275. +
  276. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  277. + // DCEVM: TODO: Check if we can improve performance by inlining.
  278. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  279. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  280. +
  281. + // profile this call
  282. + __ profile_final_call(rax);
  283. + __ jump_from_interpreted(method, rdx);
  284. +
  285. + __ bind(notOld);
  286. +
  287. // get receiver klass
  288. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  289. __ load_klass(rax, recv);
  290. @@ -3113,6 +3167,35 @@
  291. invokevirtual_helper(rbx, rcx, rdx);
  292. __ bind(notMethod);
  293. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  294. + Label notOld;
  295. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  296. + __ jcc(Assembler::zero, notOld);
  297. +
  298. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  299. + // DCEVM: TODO: Check if we can improve performance by inlining.
  300. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  301. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  302. + // DCEVM: FIXME: What exactly should we store here?
  303. + __ push(rcx); // destroyed by Linux arguments passing conventions
  304. + __ movptr(r14, rcx);
  305. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  306. + __ pop(rcx);
  307. +
  308. + // Get receiver klass into rdx - also a null check
  309. + __ restore_locals(); // restore r14
  310. + __ load_klass(rdx, rcx);
  311. + __ verify_oop(rdx);
  312. +
  313. + // DCEVM: TODO: Check if resolved method could be null.
  314. +
  315. + // profile this call
  316. + __ profile_virtual_call(rdx, r13, r14);
  317. +
  318. + __ jump_from_interpreted(rbx, rdx);
  319. +
  320. + __ bind(notOld);
  321. +
  322. // Get receiver klass into rdx - also a null check
  323. __ restore_locals(); // restore r14
  324. __ load_klass(rdx, rcx);
  325. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  326. --- a/src/share/vm/c1/c1_Compilation.hpp
  327. +++ b/src/share/vm/c1/c1_Compilation.hpp
  328. @@ -239,8 +239,8 @@
  329. #define BAILOUT(msg) { bailout(msg); return; }
  330. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  331. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  332. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  333. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  334. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  335. class InstructionMark: public StackObj {
  336. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  337. --- a/src/share/vm/ci/ciEnv.cpp
  338. +++ b/src/share/vm/ci/ciEnv.cpp
  339. @@ -1181,3 +1181,11 @@
  340. // If memory is low, we stop compiling methods.
  341. record_method_not_compilable("out of memory");
  342. }
  343. +
  344. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  345. +void ciEnv::cleanup_after_redefinition() {
  346. +
  347. + if (_factory != NULL) {
  348. + _factory->cleanup_after_redefinition();
  349. + }
  350. +}
  351. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  352. --- a/src/share/vm/ci/ciEnv.hpp
  353. +++ b/src/share/vm/ci/ciEnv.hpp
  354. @@ -419,6 +419,8 @@
  355. void record_failure(const char* reason);
  356. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  357. void record_out_of_memory_failure();
  358. +
  359. + void cleanup_after_redefinition();
  360. };
  361. #endif // SHARE_VM_CI_CIENV_HPP
  362. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  363. --- a/src/share/vm/ci/ciObjectFactory.cpp
  364. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  365. @@ -294,6 +294,11 @@
  366. // into the table. We need to recompute our index.
  367. index = find(keyHandle(), _ci_objects);
  368. }
  369. +
  370. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  371. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  372. + return _ci_objects->at(index);
  373. + }
  374. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  375. insert(index, new_object, _ci_objects);
  376. return new_object;
  377. @@ -758,3 +763,50 @@
  378. _unloaded_instances->length(),
  379. _unloaded_klasses->length());
  380. }
  381. +
  382. +// DCEVM: Resoring the ciObject arrays after class redefinition
  383. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  384. +
  385. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  386. + oop last = NULL;
  387. + for (int j = 0; j< objects->length(); j++) {
  388. + oop o = objects->at(j)->get_oop();
  389. + if (last >= o) {
  390. + int cur_last_index = j - 1;
  391. + oop cur_last = last;
  392. + while (cur_last >= o) {
  393. +
  394. + // Swap the two objects to guarantee ordering
  395. + ciObject *tmp = objects->at(cur_last_index);
  396. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  397. + objects->at_put(cur_last_index + 1, tmp);
  398. +
  399. + // Decrement index to move one step to the left
  400. + cur_last_index--;
  401. + if (cur_last_index < 0) {
  402. + break;
  403. + }
  404. + cur_last = objects->at(cur_last_index)->get_oop();
  405. + }
  406. + } else {
  407. + assert(last < o, "out of order");
  408. + last = o;
  409. + }
  410. + }
  411. +
  412. +#ifdef ASSERT
  413. + if (CIObjectFactoryVerify) {
  414. + oop last = NULL;
  415. + for (int j = 0; j< objects->length(); j++) {
  416. + oop o = objects->at(j)->get_oop();
  417. + assert(last < o, "out of order");
  418. + last = o;
  419. + }
  420. + }
  421. +#endif // ASSERT
  422. +}
  423. +
  424. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  425. +void ciObjectFactory::cleanup_after_redefinition() {
  426. + sort_ci_objects(_ci_objects);
  427. +}
  428. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  429. --- a/src/share/vm/ci/ciObjectFactory.hpp
  430. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  431. @@ -38,6 +38,7 @@
  432. class ciObjectFactory : public ResourceObj {
  433. friend class VMStructs;
  434. friend class ciEnv;
  435. + friend class CompileBroker;
  436. private:
  437. static volatile bool _initialized;
  438. @@ -137,6 +138,11 @@
  439. void print_contents();
  440. void print();
  441. +
  442. +private:
  443. +
  444. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  445. + void cleanup_after_redefinition();
  446. };
  447. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  448. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  449. --- a/src/share/vm/classfile/classFileParser.cpp
  450. +++ b/src/share/vm/classfile/classFileParser.cpp
  451. @@ -787,6 +787,7 @@
  452. Handle class_loader,
  453. Handle protection_domain,
  454. Symbol* class_name,
  455. + KlassHandle old_klass,
  456. TRAPS) {
  457. ClassFileStream* cfs = stream();
  458. assert(length > 0, "only called for length>0");
  459. @@ -805,6 +806,9 @@
  460. interface_index, CHECK_(nullHandle));
  461. if (cp->tag_at(interface_index).is_klass()) {
  462. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  463. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  464. + interf = KlassHandle(THREAD, interf->newest_version());
  465. + }
  466. } else {
  467. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  468. @@ -817,6 +821,9 @@
  469. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  470. unresolved_klass, class_loader, protection_domain,
  471. false, CHECK_(nullHandle));
  472. + if (!old_klass.is_null()) {
  473. + k = k->klass_part()->newest_version();
  474. + }
  475. interf = KlassHandle(THREAD, k);
  476. if (LinkWellKnownClasses) // my super type is well known to me
  477. @@ -1705,6 +1712,8 @@
  478. int runtime_invisible_parameter_annotations_length = 0;
  479. u1* annotation_default = NULL;
  480. int annotation_default_length = 0;
  481. + u2 code_section_table_length;
  482. + typeArrayHandle code_section_table;
  483. // Parse code and exceptions attribute
  484. u2 method_attributes_count = cfs->get_u2_fast();
  485. @@ -1874,6 +1883,24 @@
  486. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  487. stackmap_data = typeArrayHandle(THREAD, sm);
  488. parsed_stackmap_attribute = true;
  489. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  490. + int length = code_attribute_length;
  491. + int value_count = length / sizeof(u2);
  492. + int line_count = length / 3;
  493. + if (TraceRedefineClasses >= 3) {
  494. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  495. + }
  496. + code_section_table_length = value_count;
  497. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  498. + code_section_table->set_length(value_count);
  499. +
  500. + for (int i = 0; i < value_count; ++i) {
  501. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  502. + code_section_table->short_at_put(i, value);
  503. + if (TraceRedefineClasses >= 4) {
  504. + tty->print_cr("Code section table at %d: %d", i, value);
  505. + }
  506. + }
  507. } else {
  508. // Skip unknown attributes
  509. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  510. @@ -1994,6 +2021,18 @@
  511. }
  512. #endif
  513. + // DCEVM: TODO: Get a different solution for the problem of method forward
  514. + // points and variable sized interpreter frames.
  515. + if (UseMethodForwardPoints) {
  516. + if (max_stack > MethodForwardPointsMaxStack) {
  517. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  518. + }
  519. + if (max_locals > MethodForwardPointsMaxLocals) {
  520. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  521. + }
  522. + max_stack = MethodForwardPointsMaxStack;
  523. + max_locals = MethodForwardPointsMaxLocals;
  524. + }
  525. // Fill in code attribute information
  526. m->set_max_stack(max_stack);
  527. m->set_max_locals(max_locals);
  528. @@ -2008,6 +2047,8 @@
  529. */
  530. m->set_exception_table(exception_handlers());
  531. + m->constMethod()->set_code_section_table(code_section_table());
  532. +
  533. // Copy byte codes
  534. m->set_code(code_start);
  535. @@ -2543,6 +2584,24 @@
  536. "Invalid Deprecated classfile attribute length %u in class file %s",
  537. attribute_length, CHECK);
  538. }
  539. + // DCEVM: Check for deleted field attribute
  540. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  541. +
  542. + char field_redefinition_policy = cfs->get_u1_fast();
  543. + k->set_field_redefinition_policy(field_redefinition_policy);
  544. +
  545. + // DCEVM: Check for deleted static field attribute
  546. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  547. +
  548. + char static_field_redefinition_policy = cfs->get_u1_fast();
  549. + k->set_static_field_redefinition_policy(static_field_redefinition_policy);
  550. +
  551. + // DCEVM: Check for deleted method attribute
  552. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  553. +
  554. + char method_redefinition_policy = cfs->get_u1_fast();
  555. + k->set_method_redefinition_policy(method_redefinition_policy);
  556. +
  557. } else if (_major_version >= JAVA_1_5_VERSION) {
  558. if (tag == vmSymbols::tag_signature()) {
  559. if (attribute_length != 2) {
  560. @@ -2634,9 +2693,126 @@
  561. }
  562. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  563. +// them in a growable array.
  564. +void ClassFileParser::findSuperSymbols(Symbol* name,
  565. + Handle class_loader,
  566. + Handle protection_domain,
  567. + KlassHandle old_klass,
  568. + GrowableArray<Symbol*> &handles,
  569. + TRAPS) {
  570. +
  571. + _cp_patches = NULL;
  572. + // So that JVMTI can cache class file in the state before retransformable agents
  573. + // have modified it
  574. + unsigned char *cached_class_file_bytes = NULL;
  575. +
  576. + ClassFileStream* cfs = stream();
  577. +
  578. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  579. +
  580. + instanceKlassHandle nullHandle;
  581. +
  582. + // Save the class file name for easier error message printing.
  583. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  584. +
  585. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  586. + // Magic value
  587. + u4 magic = cfs->get_u4_fast();
  588. + if (magic != JAVA_CLASSFILE_MAGIC) {
  589. + // Invalid class file!
  590. + return;
  591. + }
  592. +
  593. + // Version numbers
  594. + u2 minor_version = cfs->get_u2_fast();
  595. + u2 major_version = cfs->get_u2_fast();
  596. +
  597. + // Check version numbers - we check this even with verifier off
  598. + if (!is_supported_version(major_version, minor_version)) {
  599. +
  600. + // Unsupported version!
  601. + return;
  602. + }
  603. +
  604. + _major_version = major_version;
  605. + _minor_version = minor_version;
  606. +
  607. +
  608. + // Check if verification needs to be relaxed for this class file
  609. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  610. + _relax_verify = Verifier::relax_verify_for(class_loader());
  611. + _need_verify = false;
  612. +
  613. + // Constant pool
  614. + constantPoolHandle cp = parse_constant_pool(CHECK);
  615. + int cp_size = cp->length();
  616. +
  617. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  618. +
  619. + // Access flags
  620. + AccessFlags access_flags;
  621. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  622. +
  623. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  624. + // Set abstract bit for old class files for backward compatibility
  625. + flags |= JVM_ACC_ABSTRACT;
  626. + }
  627. + access_flags.set_flags(flags);
  628. +
  629. + // This class and superclass
  630. + instanceKlassHandle super_klass;
  631. + u2 this_class_index = cfs->get_u2_fast();
  632. + check_property(
  633. + valid_cp_range(this_class_index, cp_size) &&
  634. + cp->tag_at(this_class_index).is_unresolved_klass(),
  635. + "Invalid this class index %u in constant pool in class file %s",
  636. + this_class_index, CHECK);
  637. +
  638. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  639. + assert(class_name != NULL, "class_name can't be null");
  640. +
  641. + // Update _class_name which could be null previously to be class_name
  642. + _class_name = class_name;
  643. +
  644. + // DCEVM: DO NOT release all handles when parsing is done
  645. + {// HandleMark hm(THREAD);
  646. +
  647. + // Checks if name in class file matches requested name
  648. + if (name != NULL && class_name != name) {
  649. + return;
  650. + }
  651. +
  652. + u2 super_class_index = cfs->get_u2_fast();
  653. +
  654. + if (super_class_index != 0) {
  655. + Symbol* super_class = cp->klass_name_at(super_class_index);
  656. + handles.append(super_class);
  657. + } else {
  658. + // DCEVM: This redefinition must be for the Object class.
  659. + }
  660. +
  661. + // Interfaces
  662. + u2 itfs_len = cfs->get_u2_fast();
  663. + objArrayHandle local_interfaces;
  664. + if (itfs_len == 0) {
  665. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  666. + } else {
  667. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  668. + }
  669. +
  670. + for (int i=0; i<local_interfaces->length(); i++) {
  671. + oop o = local_interfaces->obj_at(i);
  672. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  673. + handles.append(interface_handle);
  674. + }
  675. + }
  676. +}
  677. +
  678. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  679. Handle class_loader,
  680. Handle protection_domain,
  681. + KlassHandle old_klass,
  682. KlassHandle host_klass,
  683. GrowableArray<Handle>* cp_patches,
  684. TempNewSymbol& parsed_name,
  685. @@ -2688,10 +2864,13 @@
  686. unsigned char* ptr = cfs->buffer();
  687. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  688. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  689. + Thread::current()->set_pretend_new_universe(false);
  690. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  691. &ptr, &end_ptr,
  692. &cached_class_file_bytes,
  693. &cached_class_file_length);
  694. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  695. if (ptr != cfs->buffer()) {
  696. // JVMTI agent has modified class file data.
  697. @@ -2847,7 +3026,11 @@
  698. // However, make sure it is not an array type.
  699. bool is_array = false;
  700. if (cp->tag_at(super_class_index).is_klass()) {
  701. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  702. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  703. + if (!old_klass.is_null()) {
  704. + resolved_klass = resolved_klass->klass_part()->newest_version();
  705. + }
  706. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  707. if (_need_verify)
  708. is_array = super_klass->oop_is_array();
  709. } else if (_need_verify) {
  710. @@ -2865,7 +3048,7 @@
  711. if (itfs_len == 0) {
  712. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  713. } else {
  714. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  715. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  716. }
  717. u2 java_fields_count = 0;
  718. @@ -2912,7 +3095,9 @@
  719. protection_domain,
  720. true,
  721. CHECK_(nullHandle));
  722. -
  723. + if (!old_klass.is_null()) {
  724. + k = k->klass_part()->newest_version();
  725. + }
  726. KlassHandle kh (THREAD, k);
  727. super_klass = instanceKlassHandle(THREAD, kh());
  728. if (LinkWellKnownClasses) // my super class is well known to me
  729. @@ -3303,6 +3488,19 @@
  730. rt = REF_NONE;
  731. } else {
  732. rt = super_klass->reference_type();
  733. +
  734. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  735. + if (name == vmSymbols::java_lang_ref_Reference()) {
  736. + rt = REF_OTHER;
  737. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  738. + rt = REF_SOFT;
  739. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  740. + rt = REF_WEAK;
  741. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  742. + rt = REF_FINAL;
  743. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  744. + rt = REF_PHANTOM;
  745. + }
  746. }
  747. // We can now create the basic klassOop for this klass
  748. @@ -3402,7 +3600,7 @@
  749. // Do final class setup
  750. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  751. - set_precomputed_flags(this_klass);
  752. + set_precomputed_flags(this_klass, old_klass);
  753. // reinitialize modifiers, using the InnerClasses attribute
  754. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  755. @@ -3425,6 +3623,10 @@
  756. // Allocate mirror and initialize static fields
  757. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  758. + if (rt == REF_OTHER) {
  759. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  760. + }
  761. +
  762. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  763. false /* not shared class */);
  764. @@ -3567,7 +3769,7 @@
  765. }
  766. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  767. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  768. klassOop super = k->super();
  769. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  770. @@ -3575,7 +3777,9 @@
  771. if (!_has_empty_finalizer) {
  772. if (_has_finalizer ||
  773. (super != NULL && super->klass_part()->has_finalizer())) {
  774. - k->set_has_finalizer();
  775. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  776. + k->set_has_finalizer();
  777. + }
  778. }
  779. }
  780. @@ -3591,7 +3795,7 @@
  781. // Check if this klass supports the java.lang.Cloneable interface
  782. if (SystemDictionary::Cloneable_klass_loaded()) {
  783. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  784. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  785. k->set_is_cloneable();
  786. }
  787. }
  788. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  789. --- a/src/share/vm/classfile/classFileParser.hpp
  790. +++ b/src/share/vm/classfile/classFileParser.hpp
  791. @@ -78,6 +78,7 @@
  792. Handle class_loader,
  793. Handle protection_domain,
  794. Symbol* class_name,
  795. + KlassHandle old_klass,
  796. TRAPS);
  797. // Field parsing
  798. @@ -151,7 +152,7 @@
  799. unsigned int nonstatic_oop_map_count,
  800. int* nonstatic_oop_offsets,
  801. unsigned int* nonstatic_oop_counts);
  802. - void set_precomputed_flags(instanceKlassHandle k);
  803. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  804. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  805. objArrayHandle local_ifs, TRAPS);
  806. @@ -263,21 +264,33 @@
  807. instanceKlassHandle parseClassFile(Symbol* name,
  808. Handle class_loader,
  809. Handle protection_domain,
  810. + KlassHandle old_klass,
  811. TempNewSymbol& parsed_name,
  812. bool verify,
  813. TRAPS) {
  814. KlassHandle no_host_klass;
  815. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  816. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  817. }
  818. instanceKlassHandle parseClassFile(Symbol* name,
  819. Handle class_loader,
  820. Handle protection_domain,
  821. + KlassHandle old_klass,
  822. KlassHandle host_klass,
  823. GrowableArray<Handle>* cp_patches,
  824. TempNewSymbol& parsed_name,
  825. bool verify,
  826. TRAPS);
  827. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  828. +
  829. + // DCEVM: Creates symbol handles for the super class and the interfaces
  830. + void findSuperSymbols(Symbol* name,
  831. + Handle class_loader,
  832. + Handle protection_domain,
  833. + KlassHandle old_klass,
  834. + GrowableArray<Symbol*> &handles,
  835. + TRAPS);
  836. +
  837. // Verifier checks
  838. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  839. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  840. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  841. --- a/src/share/vm/classfile/classLoader.cpp
  842. +++ b/src/share/vm/classfile/classLoader.cpp
  843. @@ -915,6 +915,7 @@
  844. instanceKlassHandle result = parser.parseClassFile(h_name,
  845. class_loader,
  846. protection_domain,
  847. + KlassHandle(),
  848. parsed_name,
  849. false,
  850. CHECK_(h));
  851. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  852. --- a/src/share/vm/classfile/dictionary.cpp
  853. +++ b/src/share/vm/classfile/dictionary.cpp
  854. @@ -326,6 +326,21 @@
  855. }
  856. }
  857. +
  858. +// DCEVM: Just the classes from defining class loaders
  859. +void Dictionary::classes_do(ObjectClosure *closure) {
  860. + for (int index = 0; index < table_size(); index++) {
  861. + for (DictionaryEntry* probe = bucket(index);
  862. + probe != NULL;
  863. + probe = probe->next()) {
  864. + klassOop k = probe->klass();
  865. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  866. + closure->do_object(k);
  867. + }
  868. + }
  869. + }
  870. +}
  871. +
  872. // Added for initialize_itable_for_klass to handle exceptions
  873. // Just the classes from defining class loaders
  874. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  875. @@ -433,6 +448,33 @@
  876. add_entry(index, entry);
  877. }
  878. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  879. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  880. +
  881. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  882. + bool found = false;
  883. + for (int index = 0; index < table_size(); index++) {
  884. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  885. + if (entry->klass() == old_class()) {
  886. + entry->set_literal(k());
  887. + found = true;
  888. + }
  889. + }
  890. + }
  891. +
  892. + return found;
  893. +}
  894. +
  895. +// DCEVM: Undo previous updates to the system dictionary
  896. +void Dictionary::rollback_redefinition() {
  897. + for (int index = 0; index < table_size(); index++) {
  898. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  899. + if (entry->klass()->klass_part()->is_redefining()) {
  900. + entry->set_literal(entry->klass()->klass_part()->old_version());
  901. + }
  902. + }
  903. + }
  904. +}
  905. // This routine does not lock the system dictionary.
  906. //
  907. @@ -459,12 +501,22 @@
  908. return NULL;
  909. }
  910. +// DCEVM: return old version if we are not in the new universe?
  911. +klassOop Dictionary::intercept_for_version(klassOop k) {
  912. + if (k == NULL) return k;
  913. +
  914. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  915. + return k->klass_part()->old_version();
  916. + }
  917. +
  918. + return k;
  919. +}
  920. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  921. Handle loader, Handle protection_domain, TRAPS) {
  922. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  923. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  924. - return entry->klass();
  925. + return intercept_for_version(entry->klass());
  926. } else {
  927. return NULL;
  928. }
  929. @@ -477,7 +529,7 @@
  930. assert (index == index_for(name, loader), "incorrect index?");
  931. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  932. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  933. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  934. }
  935. @@ -489,7 +541,7 @@
  936. assert (index == index_for(name, Handle()), "incorrect index?");
  937. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  938. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  939. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  940. }
  941. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  942. --- a/src/share/vm/classfile/dictionary.hpp
  943. +++ b/src/share/vm/classfile/dictionary.hpp
  944. @@ -73,6 +73,10 @@
  945. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  946. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  947. +
  948. + void rollback_redefinition();
  949. +
  950. klassOop find_class(int index, unsigned int hash,
  951. Symbol* name, Handle loader);
  952. @@ -89,6 +93,7 @@
  953. void classes_do(void f(klassOop, TRAPS), TRAPS);
  954. void classes_do(void f(klassOop, oop));
  955. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  956. + void classes_do(ObjectClosure *closure);
  957. void methods_do(void f(methodOop));
  958. @@ -105,6 +110,7 @@
  959. bool do_unloading(BoolObjectClosure* is_alive);
  960. // Protection domains
  961. + static klassOop intercept_for_version(klassOop k);
  962. klassOop find(int index, unsigned int hash, Symbol* name,
  963. Handle loader, Handle protection_domain, TRAPS);
  964. bool is_valid_protection_domain(int index, unsigned int hash,
  965. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  966. --- a/src/share/vm/classfile/javaClasses.cpp
  967. +++ b/src/share/vm/classfile/javaClasses.cpp
  968. @@ -1783,7 +1783,7 @@
  969. klassOop klass = SystemDictionary::reflect_Method_klass();
  970. // This class is eagerly initialized during VM initialization, since we keep a refence
  971. // to one of the methods
  972. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  973. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  974. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  975. }
  976. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  977. --- a/src/share/vm/classfile/javaClasses.hpp
  978. +++ b/src/share/vm/classfile/javaClasses.hpp
  979. @@ -213,7 +213,6 @@
  980. class java_lang_Class : AllStatic {
  981. friend class VMStructs;
  982. -
  983. private:
  984. // The fake offsets are added by the class loader when java.lang.Class is loaded
  985. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  986. --- a/src/share/vm/classfile/loaderConstraints.cpp
  987. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  988. @@ -449,7 +449,7 @@
  989. if (k != NULL) {
  990. // We found the class in the system dictionary, so we should
  991. // make sure that the klassOop matches what we already have.
  992. - guarantee(k == probe->klass(), "klass should be in dictionary");
  993. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  994. } else {
  995. // If we don't find the class in the system dictionary, it
  996. // has to be in the placeholders table.
  997. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  998. --- a/src/share/vm/classfile/loaderConstraints.hpp
  999. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1000. @@ -106,7 +106,7 @@
  1001. klassOop klass() { return literal(); }
  1002. klassOop* klass_addr() { return literal_addr(); }
  1003. - void set_klass(klassOop k) { set_literal(k); }
  1004. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1005. LoaderConstraintEntry* next() {
  1006. return (LoaderConstraintEntry*)HashtableEntry<klassOop>::next();
  1007. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1008. --- a/src/share/vm/classfile/systemDictionary.cpp
  1009. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1010. @@ -151,6 +151,7 @@
  1011. // can return a null klass
  1012. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1013. }
  1014. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1015. return klass;
  1016. }
  1017. @@ -193,7 +194,8 @@
  1018. // Forwards to resolve_instance_class_or_null
  1019. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1020. - assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
  1021. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1022. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL, "Can not load classes with the Compiler thread");
  1023. if (FieldType::is_array(class_name)) {
  1024. return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
  1025. } else if (FieldType::is_obj(class_name)) {
  1026. @@ -997,6 +999,7 @@
  1027. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1028. class_loader,
  1029. protection_domain,
  1030. + KlassHandle(),
  1031. host_klass,
  1032. cp_patches,
  1033. parsed_name,
  1034. @@ -1056,8 +1059,15 @@
  1035. Handle protection_domain,
  1036. ClassFileStream* st,
  1037. bool verify,
  1038. + KlassHandle old_class,
  1039. TRAPS) {
  1040. + bool redefine_classes_locked = false;
  1041. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1042. + Thread::current()->redefine_classes_mutex()->lock();
  1043. + redefine_classes_locked = true;
  1044. + }
  1045. +
  1046. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1047. // or all classloaders with UnsyncloadClass do not acquire lock here
  1048. bool DoObjectLock = true;
  1049. @@ -1085,9 +1095,14 @@
  1050. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1051. class_loader,
  1052. protection_domain,
  1053. + old_class,
  1054. parsed_name,
  1055. verify,
  1056. THREAD);
  1057. + if (!old_class.is_null() && !k.is_null()) {
  1058. + k->set_redefining(true);
  1059. + k->set_old_version(old_class());
  1060. + }
  1061. const char* pkg = "java/";
  1062. if (!HAS_PENDING_EXCEPTION &&
  1063. @@ -1122,13 +1137,18 @@
  1064. // Add class just loaded
  1065. // If a class loader supports parallel classloading handle parallel define requests
  1066. // find_or_define_instance_class may return a different instanceKlass
  1067. - if (is_parallelCapable(class_loader)) {
  1068. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1069. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1070. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1071. } else {
  1072. - define_instance_class(k, THREAD);
  1073. + define_instance_class(k, old_class, THREAD);
  1074. }
  1075. }
  1076. + if (redefine_classes_locked) {
  1077. + Thread::current()->redefine_classes_mutex()->unlock();
  1078. + }
  1079. +
  1080. // If parsing the class file or define_instance_class failed, we
  1081. // need to remove the placeholder added on our behalf. But we
  1082. // must make sure parsed_name is valid first (it won't be if we had
  1083. @@ -1157,7 +1177,7 @@
  1084. MutexLocker mu(SystemDictionary_lock, THREAD);
  1085. klassOop check = find_class(parsed_name, class_loader);
  1086. - assert(check == k(), "should be present in the dictionary");
  1087. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1088. klassOop check2 = find_class(h_name, h_loader);
  1089. assert(check == check2, "name inconsistancy in SystemDictionary");
  1090. @@ -1453,7 +1473,11 @@
  1091. }
  1092. }
  1093. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1094. +void SystemDictionary::rollback_redefinition() {
  1095. + dictionary()->rollback_redefinition();
  1096. +}
  1097. +
  1098. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1099. Handle class_loader_h(THREAD, k->class_loader());
  1100. @@ -1480,13 +1504,23 @@
  1101. Symbol* name_h = k->name();
  1102. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1103. int d_index = dictionary()->hash_to_index(d_hash);
  1104. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1105. +
  1106. + // DCEVM: Update version of the klassOop in the system dictionary
  1107. + // TODO: Check for thread safety!
  1108. + if (!old_class.is_null()) {
  1109. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1110. + assert (ok, "must have found old class and updated!");
  1111. + }
  1112. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1113. +
  1114. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1115. // Register class just loaded with class loader (placed in Vector)
  1116. // Note we do this before updating the dictionary, as this can
  1117. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1118. // class in the dictionary and will not update the class hierarchy).
  1119. - if (k->class_loader() != NULL) {
  1120. + // (tw) Only register if not redefining a class.
  1121. + if (k->class_loader() != NULL && old_class.is_null()) {
  1122. methodHandle m(THREAD, Universe::loader_addClass_method());
  1123. JavaValue result(T_VOID);
  1124. JavaCallArguments args(class_loader_h);
  1125. @@ -1512,8 +1546,9 @@
  1126. }
  1127. k->eager_initialize(THREAD);
  1128. + // (tw) Only notify jvmti if not redefining a class.
  1129. // notify jvmti
  1130. - if (JvmtiExport::should_post_class_load()) {
  1131. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1132. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1133. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1134. @@ -1586,7 +1621,7 @@
  1135. }
  1136. }
  1137. - define_instance_class(k, THREAD);
  1138. + define_instance_class(k, KlassHandle(), THREAD);
  1139. Handle linkage_exception = Handle(); // null handle
  1140. @@ -1716,6 +1751,14 @@
  1141. Universe::flush_dependents_on(k);
  1142. }
  1143. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1144. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1145. + assert(k.not_null(), "just checking");
  1146. +
  1147. + k->remove_from_sibling_list();
  1148. +
  1149. + // TODO: Remove from interfaces.
  1150. +}
  1151. // ----------------------------------------------------------------------------
  1152. // GC support
  1153. @@ -1804,7 +1847,8 @@
  1154. }
  1155. -void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1156. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1157. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1158. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1159. f->do_oop((oop*) &_well_known_klasses[k]);
  1160. }
  1161. @@ -1818,6 +1862,23 @@
  1162. }
  1163. }
  1164. + // TODO: Check if we need to call FilterFieldsMap
  1165. +}
  1166. +
  1167. +void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1168. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1169. + f->do_oop((oop*) &_well_known_klasses[k]);
  1170. + }
  1171. +
  1172. + {
  1173. + for (int i = 0; i < T_VOID+1; i++) {
  1174. + if (_box_klasses[i] != NULL) {
  1175. + assert(i >= T_BOOLEAN, "checking");
  1176. + f->do_oop((oop*) &_box_klasses[i]);
  1177. + }
  1178. + }
  1179. + }
  1180. +
  1181. // The basic type mirrors would have already been processed in
  1182. // Universe::oops_do(), via a call to shared_oops_do(), so should
  1183. // not be processed again.
  1184. @@ -1836,6 +1897,11 @@
  1185. dictionary()->classes_do(f);
  1186. }
  1187. +// (tw) Iterate over all classes in the dictionary.
  1188. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1189. + dictionary()->classes_do(closure);
  1190. +}
  1191. +
  1192. // Added for initialize_itable_for_klass
  1193. // Just the classes from defining class loaders
  1194. // Don't iterate over placeholders
  1195. @@ -1989,7 +2055,9 @@
  1196. // Preload ref klasses and set reference types
  1197. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1198. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1199. +
  1200. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1201. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1202. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1203. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1204. @@ -2081,7 +2149,11 @@
  1205. // also holds array classes
  1206. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1207. - if ((defining == true) || (k() != check)) {
  1208. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1209. + ResourceMark rm(Thread::current());
  1210. + tty->print_cr("(%d / %d) (%s/%s)", k->revision_number(), check->klass_part()->revision_number(), k->name()->as_C_string(), check->klass_part()->name()->as_C_string());
  1211. + k()->print();
  1212. + check->print();
  1213. linkage_error = "loader (instance of %s): attempted duplicate class "
  1214. "definition for name: \"%s\"";
  1215. } else {
  1216. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1217. --- a/src/share/vm/classfile/systemDictionary.hpp
  1218. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1219. @@ -276,7 +276,7 @@
  1220. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1221. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1222. Handle protection_domain,
  1223. - ClassFileStream* st, bool verify, TRAPS);
  1224. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1225. // Lookup an already loaded class. If not found NULL is returned.
  1226. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1227. @@ -320,6 +320,8 @@
  1228. // Iterate over all klasses in dictionary
  1229. // Just the classes from defining class loaders
  1230. static void classes_do(void f(klassOop));
  1231. + static void classes_do(ObjectClosure *closure);
  1232. + static void preloaded_classes_do(OopClosure *closure);
  1233. // Added for initialize_itable_for_klass to handle exceptions
  1234. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1235. // All classes, and their class loaders
  1236. @@ -427,6 +429,8 @@
  1237. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1238. }
  1239. + static void rollback_redefinition();
  1240. +
  1241. public:
  1242. #define WK_KLASS_DECLARE(name, symbol, option) \
  1243. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1244. @@ -608,7 +612,7 @@
  1245. // after waiting, but before reentering SystemDictionary_lock
  1246. // to preserve lock order semantics.
  1247. static void double_lock_wait(Handle lockObject, TRAPS);
  1248. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1249. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1250. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1251. Handle class_loader,
  1252. instanceKlassHandle k, TRAPS);
  1253. @@ -627,6 +631,11 @@
  1254. // Setup link to hierarchy
  1255. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1256. +public:
  1257. +
  1258. + // Remove link to hierarchy
  1259. + static void remove_from_hierarchy(instanceKlassHandle k);
  1260. +
  1261. private:
  1262. // We pass in the hashtable index so we can calculate it outside of
  1263. // the SystemDictionary_lock.
  1264. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1265. --- a/src/share/vm/classfile/verifier.cpp
  1266. +++ b/src/share/vm/classfile/verifier.cpp
  1267. @@ -103,7 +103,7 @@
  1268. return !need_verify;
  1269. }
  1270. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1271. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1272. HandleMark hm;
  1273. ResourceMark rm(THREAD);
  1274. @@ -127,17 +127,19 @@
  1275. split_verifier.verify_class(THREAD);
  1276. exception_name = split_verifier.result();
  1277. if (klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1278. - FailOverToOldVerifier && !HAS_PENDING_EXCEPTION &&
  1279. + FailOverToOldVerifier && may_use_old_verifier && !HAS_PENDING_EXCEPTION &&
  1280. (exception_name == vmSymbols::java_lang_VerifyError() ||
  1281. exception_name == vmSymbols::java_lang_ClassFormatError())) {
  1282. if (TraceClassInitialization) {
  1283. tty->print_cr(
  1284. "Fail over class verification to old verifier for: %s", klassName);
  1285. }
  1286. + assert(may_use_old_verifier, "");
  1287. exception_name = inference_verify(
  1288. klass, message_buffer, message_buffer_len, THREAD);
  1289. }
  1290. } else {
  1291. + assert(may_use_old_verifier, "");
  1292. exception_name = inference_verify(
  1293. klass, message_buffer, message_buffer_len, THREAD);
  1294. }
  1295. @@ -152,6 +154,9 @@
  1296. }
  1297. tty->print_cr("End class verification for: %s", klassName);
  1298. }
  1299. + } else if (TraceClassInitialization) {
  1300. + // (tw) Output not verified classes
  1301. + tty->print_cr("Class %s was not verified", klassName);
  1302. }
  1303. if (HAS_PENDING_EXCEPTION) {
  1304. @@ -203,7 +208,7 @@
  1305. // NOTE: this is called too early in the bootstrapping process to be
  1306. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1307. (refl_magic_klass == NULL ||
  1308. - !klass->is_subtype_of(refl_magic_klass) ||
  1309. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1310. VerifyReflectionBytecodes)
  1311. );
  1312. }
  1313. @@ -272,7 +277,7 @@
  1314. ClassVerifier::ClassVerifier(
  1315. instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS)
  1316. : _thread(THREAD), _exception_type(NULL), _message(msg),
  1317. - _message_buffer_len(msg_len), _klass(klass) {
  1318. + _message_buffer_len(msg_len), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1319. _this_type = VerificationType::reference_type(klass->name());
  1320. // Create list to hold symbols in reference area.
  1321. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1322. @@ -296,7 +301,7 @@
  1323. _klass->external_name());
  1324. }
  1325. - objArrayHandle methods(THREAD, _klass->methods());
  1326. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1327. int num_methods = methods->length();
  1328. for (int index = 0; index < num_methods; index++) {
  1329. @@ -2081,7 +2086,10 @@
  1330. VerificationType stack_object_type =
  1331. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1332. if (current_type() != stack_object_type) {
  1333. - assert(cp->cache() == NULL, "not rewritten yet");
  1334. +
  1335. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1336. + //assert(cp->cache() == NULL, "not rewritten yet");
  1337. +
  1338. Symbol* ref_class_name =
  1339. cp->klass_name_at(cp->klass_ref_index_at(index));
  1340. // See the comments in verify_field_instructions() for
  1341. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1342. --- a/src/share/vm/classfile/verifier.hpp
  1343. +++ b/src/share/vm/classfile/verifier.hpp
  1344. @@ -47,7 +47,7 @@
  1345. * Otherwise, no exception is thrown and the return indicates the
  1346. * error.
  1347. */
  1348. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1349. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1350. // Return false if the class is loaded by the bootstrap loader,
  1351. // or if defineClass was called requesting skipping verification
  1352. @@ -97,7 +97,10 @@
  1353. size_t _message_buffer_len;
  1354. GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
  1355. +public:
  1356. void verify_method(methodHandle method, TRAPS);
  1357. +
  1358. +private:
  1359. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1360. void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
  1361. void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
  1362. @@ -168,6 +171,7 @@
  1363. VerificationType object_type() const;
  1364. + instanceKlassHandle _klass_to_verify;
  1365. instanceKlassHandle _klass; // the class being verified
  1366. methodHandle _method; // current method being verified
  1367. VerificationType _this_type; // the verification type of the current class
  1368. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1369. --- a/src/share/vm/classfile/vmSymbols.hpp
  1370. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1371. @@ -131,6 +131,10 @@
  1372. template(tag_annotation_default, "AnnotationDefault") \
  1373. template(tag_enclosing_method, "EnclosingMethod") \
  1374. template(tag_bootstrap_methods, "BootstrapMethods") \
  1375. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1376. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1377. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1378. + template(tag_code_sections, "CodeSections") \
  1379. \
  1380. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1381. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1382. @@ -376,6 +380,10 @@
  1383. template(oop_size_name, "oop_size") \
  1384. template(static_oop_field_count_name, "static_oop_field_count") \
  1385. \
  1386. + /* mutator in case of class redefinition */ \
  1387. + template(static_transformer_name, "$staticTransformer") \
  1388. + template(transformer_name, "$transformer") \
  1389. + \
  1390. /* non-intrinsic name/signature pairs: */ \
  1391. template(register_method_name, "register") \
  1392. do_alias(register_method_signature, object_void_signature) \
  1393. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1394. --- a/src/share/vm/compiler/compileBroker.cpp
  1395. +++ b/src/share/vm/compiler/compileBroker.cpp
  1396. @@ -1166,6 +1166,14 @@
  1397. int comp_level,
  1398. methodHandle hot_method, int hot_count,
  1399. const char* comment, Thread* THREAD) {
  1400. + JavaThread* thread = JavaThread::current();
  1401. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1402. + return NULL; // FIXME: DCEVM: should we do something else?
  1403. + }
  1404. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1405. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1406. + }
  1407. +
  1408. // make sure arguments make sense
  1409. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1410. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1411. @@ -1245,6 +1253,7 @@
  1412. }
  1413. // RedefineClasses() has replaced this method; just return
  1414. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1415. if (method->is_old()) {
  1416. return NULL;
  1417. }
  1418. @@ -1576,6 +1585,8 @@
  1419. // Never compile a method if breakpoints are present in it
  1420. if (method()->number_of_breakpoints() == 0) {
  1421. + thread->compilation_mutex()->lock();
  1422. + thread->set_should_bailout(false);
  1423. // Compile the method.
  1424. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1425. #ifdef COMPILER1
  1426. @@ -1599,6 +1610,7 @@
  1427. // After compilation is disabled, remove remaining methods from queue
  1428. method->clear_queued_for_compilation();
  1429. }
  1430. + thread->compilation_mutex()->unlock();
  1431. }
  1432. }
  1433. }
  1434. @@ -2127,3 +2139,15 @@
  1435. st->cr();
  1436. #endif
  1437. }
  1438. +
  1439. +// (tw) Clean up compiler interface after a class redefinition step
  1440. +void CompileBroker::cleanup_after_redefinition() {
  1441. + int num_threads = _method_threads->length();
  1442. +
  1443. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1444. + for (int i=0; i<num_threads; i++) {
  1445. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1446. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1447. + }
  1448. + }
  1449. +}
  1450. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1451. --- a/src/share/vm/compiler/compileBroker.hpp
  1452. +++ b/src/share/vm/compiler/compileBroker.hpp
  1453. @@ -407,6 +407,8 @@
  1454. static void print_last_compile();
  1455. static void print_compiler_threads_on(outputStream* st);
  1456. +
  1457. + static void cleanup_after_redefinition();
  1458. };
  1459. #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP
  1460. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1461. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1462. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1463. @@ -157,6 +157,13 @@
  1464. }
  1465. }
  1466. +
  1467. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1468. + CompactPoint* cp, HeapWord* compact_top) {
  1469. + ShouldNotReachHere();
  1470. + return NULL;
  1471. +}
  1472. +
  1473. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1474. // update the block offset table. Removed initialize_threshold call because
  1475. // CFLS does not use a block offset array for contiguous spaces.
  1476. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1477. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1478. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1479. @@ -149,6 +149,7 @@
  1480. // Support for compacting cms
  1481. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1482. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1483. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1484. // Initialization helpers.
  1485. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1486. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1487. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1488. @@ -30,6 +30,8 @@
  1489. #include "oops/objArrayKlass.inline.hpp"
  1490. #include "oops/oop.inline.hpp"
  1491. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1492. +
  1493. Stack<oop> MarkSweep::_marking_stack;
  1494. Stack<DataLayout*> MarkSweep::_revisit_mdo_stack;
  1495. Stack<Klass*> MarkSweep::_revisit_klass_stack;
  1496. @@ -350,3 +352,86 @@
  1497. }
  1498. #endif
  1499. +
  1500. +// (tw) Copy the rescued objects to their destination address after compaction.
  1501. +void MarkSweep::copy_rescued_objects_back() {
  1502. +
  1503. + if (_rescued_oops != NULL) {
  1504. +
  1505. + for (int i=0; i<_rescued_oops->length(); i++) {
  1506. + oop rescued_obj = _rescued_oops->at(i);
  1507. +
  1508. + int size = rescued_obj->size();
  1509. + oop new_obj = rescued_obj->forwardee();
  1510. +
  1511. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1512. + MarkSweep::update_fields(rescued_obj, new_obj);
  1513. + } else {
  1514. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1515. + }
  1516. +
  1517. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1518. +
  1519. + new_obj->init_mark();
  1520. + assert(new_obj->is_oop(), "must be a valid oop");
  1521. + }
  1522. + _rescued_oops->clear();
  1523. + _rescued_oops = NULL;
  1524. + }
  1525. +}
  1526. +
  1527. +// (tw) Update instances of a class whose fields changed.
  1528. +void MarkSweep::update_fields(oop q, oop new_location) {
  1529. +
  1530. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1531. +
  1532. + klassOop old_klass_oop = q->klass();
  1533. + klassOop new_klass_oop = q->blueprint()->new_version();
  1534. +
  1535. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1536. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1537. +
  1538. + int size = q->size_given_klass(old_klass);
  1539. + int new_size = q->size_given_klass(new_klass);
  1540. +
  1541. + oop tmp_obj = q;
  1542. +
  1543. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1544. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1545. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1546. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1547. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1548. + }
  1549. + }
  1550. +
  1551. + int *cur = new_klass_oop->klass_part()->update_information();
  1552. +
  1553. + tmp_obj->set_klass_no_check(new_klass_oop);
  1554. +
  1555. + if (cur == NULL) {
  1556. + assert(size == new_size, "just checking");
  1557. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1558. + } else {
  1559. + int destOffset = 0;
  1560. + while (*cur != 0) {
  1561. + if (*cur > 0) {
  1562. + int size = *cur;
  1563. + cur++;
  1564. + int offset = *cur;
  1565. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1566. + destOffset += size;
  1567. + cur++;
  1568. + } else {
  1569. + assert(*cur < 0, "");
  1570. + int skip = -*cur;
  1571. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1572. + destOffset += skip;
  1573. + cur++;
  1574. + }
  1575. + }
  1576. + }
  1577. +
  1578. + if (tmp_obj != q) {
  1579. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1580. + }
  1581. +}
  1582. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1583. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1584. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1585. @@ -115,8 +115,12 @@
  1586. friend class AdjustPointerClosure;
  1587. friend class KeepAliveClosure;
  1588. friend class VM_MarkSweep;
  1589. + friend class GenMarkSweep;
  1590. friend void marksweep_init();
  1591. +public:
  1592. + static GrowableArray<oop>* _rescued_oops;
  1593. +
  1594. //
  1595. // Vars
  1596. //
  1597. @@ -200,6 +204,8 @@
  1598. template <class T> static inline void mark_and_push(T* p);
  1599. static inline void push_objarray(oop obj, size_t index);
  1600. + static void copy_rescued_objects_back();
  1601. + static void update_fields(oop q, oop new_location);
  1602. static void follow_stack(); // Empty marking stack.
  1603. static void preserve_mark(oop p, markOop mark);
  1604. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1605. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1606. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1607. @@ -403,7 +403,7 @@
  1608. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1609. assert(h_exception->is_oop(), "just checking");
  1610. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1611. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1612. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1613. if (ExitVMOnVerifyError) vm_exit(-1);
  1614. ShouldNotReachHere();
  1615. }
  1616. @@ -674,6 +674,82 @@
  1617. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1618. IRT_END
  1619. +// (tw) Correctly resolve method when running old code.
  1620. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1621. + {
  1622. + MonitorLockerEx ml(RedefinitionSync_lock);
  1623. + while (Threads::wait_at_instrumentation_entry()) {
  1624. + ml.wait();
  1625. + }
  1626. + }
  1627. + frame f = last_frame(thread);
  1628. + methodOop m = f.interpreter_frame_method();
  1629. + methodOop forward_method = m->forward_method();
  1630. + if (forward_method != NULL) {
  1631. + int bci = f.interpreter_frame_bci();
  1632. +
  1633. + if (TraceRedefineClasses >= 3) {
  1634. + tty->print_cr("Executing NOP in method %s at bci %d %d", m->name()->as_C_string(), bci, m->is_in_code_section(bci + 1));
  1635. + }
  1636. +
  1637. + int next_bci = bci - 1;
  1638. + // First try bci before NOP.
  1639. + if (!m->is_in_code_section(next_bci)) {
  1640. + // Try bci after NOP.
  1641. + next_bci = bci + 1;
  1642. + if (!m->is_in_code_section(next_bci)) return;
  1643. + }
  1644. +
  1645. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1646. + if (TraceRedefineClasses >= 2) {
  1647. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1648. + }
  1649. + RegisterMap reg_map(thread);
  1650. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1651. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1652. + iframe->set_method(forward_method, new_bci - 1);
  1653. + }
  1654. +IRT_END
  1655. +
  1656. +// (tw) Correctly resolve method when running old code.
  1657. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1658. + // extract receiver from the outgoing argument list if necessary
  1659. + Handle receiver(thread, receiverOop);
  1660. +
  1661. + // TODO: Check for invokeinterface!
  1662. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1663. +
  1664. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1665. + klassOop klass = receiverOop->klass();
  1666. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1667. + klass = klass->klass_part()->old_version();
  1668. + }
  1669. +
  1670. + // TODO: Check for correctness if different vtable indices in different versions?
  1671. +
  1672. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1673. + thread->set_vm_result(method);
  1674. +IRT_END
  1675. +
  1676. +// Correctly resolve interface method when running old code.
  1677. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1678. +
  1679. + // extract receiver from the outgoing argument list if necessary
  1680. + Handle receiver(thread, receiverOop);
  1681. +
  1682. + // TODO: Check for invokeinterface!
  1683. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1684. +
  1685. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1686. + klassOop klass = receiverOop->klass();
  1687. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1688. + klass = klass->klass_part()->old_version();
  1689. + }
  1690. +
  1691. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1692. + thread->set_vm_result(method);
  1693. +IRT_END
  1694. +
  1695. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
  1696. // extract receiver from the outgoing argument list if necessary
  1697. Handle receiver(thread, NULL);
  1698. @@ -702,6 +778,10 @@
  1699. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1700. int retry_count = 0;
  1701. while (info.resolved_method()->is_old()) {
  1702. + // (tw) If we are executing an old method, this is OK!
  1703. + if (method(thread)->is_old()) {
  1704. + break;
  1705. + }
  1706. // It is very unlikely that method is redefined more than 100 times
  1707. // in the middle of resolve. If it is looping here more than 100 times
  1708. // means then there could be a bug here.
  1709. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1710. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1711. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1712. @@ -137,6 +137,9 @@
  1713. static void post_method_entry(JavaThread *thread);
  1714. static void post_method_exit (JavaThread *thread);
  1715. static int interpreter_contains(address pc);
  1716. + static void forward_method(JavaThread *thread);
  1717. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1718. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1719. // Native signature handlers
  1720. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1721. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1722. --- a/src/share/vm/interpreter/linkResolver.cpp
  1723. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1724. @@ -145,8 +145,8 @@
  1725. // Klass resolution
  1726. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1727. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1728. - sel_klass->as_klassOop(),
  1729. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1730. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1731. true)) {
  1732. ResourceMark rm(THREAD);
  1733. Exceptions::fthrow(
  1734. @@ -258,7 +258,7 @@
  1735. // We'll check for the method name first, as that's most likely
  1736. // to be false (so we'll short-circuit out of these tests).
  1737. if (sel_method->name() == vmSymbols::clone_name() &&
  1738. - sel_klass() == SystemDictionary::Object_klass() &&
  1739. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1740. resolved_klass->oop_is_array()) {
  1741. // We need to change "protected" to "public".
  1742. assert(flags.is_protected(), "clone not protected?");
  1743. @@ -334,6 +334,149 @@
  1744. }
  1745. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1746. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1747. +
  1748. + // Interface method lookup?
  1749. + if (is_interface) {
  1750. +
  1751. + // lookup method in this interface or its super, java.lang.Object
  1752. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1753. +
  1754. + if (resolved_method.is_null()) {
  1755. + // lookup method in all the super-interfaces
  1756. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1757. + }
  1758. +
  1759. + // Other methods
  1760. + } else {
  1761. +
  1762. + // 2. lookup method in resolved klass and its super klasses
  1763. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1764. +
  1765. + if (resolved_method.is_null()) { // not found in the class hierarchy
  1766. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1767. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1768. +
  1769. + if (resolved_method.is_null()) {
  1770. + // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  1771. + lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  1772. + }
  1773. + }
  1774. + }
  1775. +}
  1776. +
  1777. +void LinkResolver::lookup_correct_field(fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static) {
  1778. +
  1779. + // First attempt unversioned
  1780. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1781. +
  1782. +
  1783. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1784. +
  1785. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  1786. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1787. + if (is_static) {
  1788. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1789. + }
  1790. +
  1791. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1792. +
  1793. + if (redefinition_policy != Klass::DynamicCheck) {
  1794. +
  1795. + if (redefinition_policy == Klass::AccessOldMembers) {
  1796. + // Forget looked up fields
  1797. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1798. + }
  1799. +
  1800. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1801. +
  1802. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1803. +
  1804. + // Select correct version for resolved klass.
  1805. + find_correct_resolved_klass(resolved_klass, current_klass);
  1806. +
  1807. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1808. +
  1809. + // FIXME: idubrov
  1810. + //if (sel_klass.is_null()) {
  1811. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1812. + //} else {
  1813. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1814. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1815. + //}
  1816. + }
  1817. + }
  1818. + }
  1819. +}
  1820. +
  1821. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1822. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1823. +
  1824. + // First attempt unversioned
  1825. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1826. +
  1827. + // (tw) Are we in an old method that wants to see a different view on the world?
  1828. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1829. +
  1830. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  1831. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1832. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1833. +
  1834. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1835. +
  1836. + // We do not throw the exception
  1837. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1838. + // Forget any new member lookup
  1839. + resolved_method = methodHandle(THREAD, NULL);
  1840. + }
  1841. +
  1842. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1843. +
  1844. + if (resolved_method.is_null()) {
  1845. +
  1846. + // Select correct version for resolved klass.
  1847. + find_correct_resolved_klass(resolved_klass, current_klass);
  1848. +
  1849. + // Now do the lookup in a second attempt with a different resolved klass.
  1850. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1851. +
  1852. + // FIXME: idubrov
  1853. + //IF_TRACE_RC2 {
  1854. + // ResourceMark rm(THREAD);
  1855. + // if (resolved_method.is_null()) {
  1856. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1857. + // } else {
  1858. + // assert(resolved_method->is_old(), "must be old method!");
  1859. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1860. + // }
  1861. + //}
  1862. + }
  1863. + }
  1864. + }
  1865. +
  1866. + if (resolved_method.is_null()) {
  1867. + // no method found
  1868. + ResourceMark rm(THREAD);
  1869. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1870. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1871. + method_name,
  1872. + method_signature));
  1873. + }
  1874. +}
  1875. +
  1876. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1877. + int current_klass_revision = current_klass->revision_number();
  1878. + int resolved_klass_revision = resolved_klass->revision_number();
  1879. + // FIXME: idubrov
  1880. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1881. +
  1882. + while (resolved_klass->revision_number() > current_klass_revision) {
  1883. + assert(resolved_klass->old_version(), "must have old version");
  1884. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1885. + }
  1886. +}
  1887. +
  1888. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1889. Symbol* method_name, Symbol* method_signature,
  1890. KlassHandle current_klass, bool check_access, TRAPS) {
  1891. @@ -346,27 +489,8 @@
  1892. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1893. }
  1894. - // 2. lookup method in resolved klass and its super klasses
  1895. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1896. -
  1897. - if (resolved_method.is_null()) { // not found in the class hierarchy
  1898. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1899. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1900. -
  1901. - if (resolved_method.is_null()) {
  1902. - // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  1903. - lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  1904. - }
  1905. -
  1906. - if (resolved_method.is_null()) {
  1907. - // 4. method lookup failed
  1908. - ResourceMark rm(THREAD);
  1909. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1910. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1911. - method_name,
  1912. - method_signature));
  1913. - }
  1914. - }
  1915. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1916. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1917. // 5. check if method is concrete
  1918. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1919. @@ -434,20 +558,7 @@
  1920. }
  1921. // lookup method in this interface or its super, java.lang.Object
  1922. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1923. -
  1924. - if (resolved_method.is_null()) {
  1925. - // lookup method in all the super-interfaces
  1926. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1927. - if (resolved_method.is_null()) {
  1928. - // no method found
  1929. - ResourceMark rm(THREAD);
  1930. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1931. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1932. - method_name,
  1933. - method_signature));
  1934. - }
  1935. - }
  1936. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1937. if (check_access) {
  1938. HandleMark hm(THREAD);
  1939. @@ -534,9 +645,14 @@
  1940. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1941. }
  1942. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  1943. +
  1944. // Resolve instance field
  1945. fieldDescriptor fd; // find_field initializes fd if found
  1946. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  1947. +
  1948. + KlassHandle sel_klass;
  1949. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  1950. +
  1951. // check if field exists; i.e., if a klass containing the field def has been selected
  1952. if (sel_klass.is_null()){
  1953. ResourceMark rm(THREAD);
  1954. @@ -544,7 +660,6 @@
  1955. }
  1956. // check access
  1957. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  1958. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  1959. // check for errors
  1960. @@ -556,7 +671,7 @@
  1961. }
  1962. // Final fields can only be accessed from its own class.
  1963. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1964. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1965. THROW(vmSymbols::java_lang_IllegalAccessError());
  1966. }
  1967. @@ -761,7 +876,7 @@
  1968. bool check_access, bool check_null_and_abstract, TRAPS) {
  1969. methodHandle resolved_method;
  1970. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1971. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1972. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1973. }
  1974. // throws linktime exceptions
  1975. @@ -791,6 +906,7 @@
  1976. KlassHandle resolved_klass,
  1977. Handle recv,
  1978. KlassHandle recv_klass,
  1979. + KlassHandle current_klass,
  1980. bool check_null_and_abstract,
  1981. TRAPS) {
  1982. @@ -839,7 +955,40 @@
  1983. // recv_klass might be an arrayKlassOop but all vtables start at
  1984. // the same place. The cast is to avoid virtual call and assertion.
  1985. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1986. +
  1987. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  1988. + // have anything in common, as the receiver type could've been hotswapped.
  1989. + // Does not always work (method could be resolved with correct dynamic type and later
  1990. + // be called at the same place with a wrong dynamic type).
  1991. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  1992. +
  1993. + // The vTable must be based on the view of the world of the resolved method
  1994. + klassOop method_holder = resolved_method->method_holder();
  1995. +
  1996. + if (method_holder->klass_part()->new_version() != NULL) {
  1997. + // We are executing in old code
  1998. + // FIXME: idubrov
  1999. + //TRACE_RC2("Calling a method in old code");
  2000. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2001. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2002. + }
  2003. + }
  2004. +
  2005. + if (inst->is_subtype_of(method_holder)) {
  2006. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2007. + } else {
  2008. +
  2009. + tty->print_cr("Failure:");
  2010. + inst->as_klassOop()->print();
  2011. + inst->super()->print();
  2012. + juint off = inst->super_check_offset();
  2013. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2014. + sup->print();
  2015. + method_holder->print();
  2016. +
  2017. + bool b = inst->is_subtype_of(method_holder);
  2018. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), "(tw) A virtual method was called, but the type of the receiver is not related with the type of the class of the called method!");
  2019. + }
  2020. }
  2021. }
  2022. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2023. --- a/src/share/vm/interpreter/linkResolver.hpp
  2024. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2025. @@ -106,7 +106,11 @@
  2026. // It does all necessary link-time checks & throws exceptions if necessary.
  2027. class LinkResolver: AllStatic {
  2028. - private:
  2029. +private:
  2030. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2031. + static void lookup_correct_field (fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static);
  2032. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2033. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2034. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2035. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2036. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2037. @@ -129,7 +133,7 @@
  2038. 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);
  2039. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2040. - 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);
  2041. + 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);
  2042. 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);
  2043. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2044. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2045. --- a/src/share/vm/interpreter/templateTable.hpp
  2046. +++ b/src/share/vm/interpreter/templateTable.hpp
  2047. @@ -328,8 +328,8 @@
  2048. static void shouldnotreachhere();
  2049. // jvmti support
  2050. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2051. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2052. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2053. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2054. static void jvmti_post_fast_field_mod();
  2055. // debugging of TemplateGenerator
  2056. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2057. --- a/src/share/vm/memory/genMarkSweep.cpp
  2058. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2059. @@ -409,6 +409,7 @@
  2060. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2061. // here (perm_gen first rather than last), so we tell the validate code
  2062. // to use a higher index (saved from phase2) when verifying perm_gen.
  2063. + assert(_rescued_oops == NULL, "must be empty before processing");
  2064. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2065. Generation* pg = gch->perm_gen();
  2066. @@ -421,10 +422,14 @@
  2067. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2068. + MarkSweep::copy_rescued_objects_back();
  2069. +
  2070. GenCompactClosure blk;
  2071. gch->generation_iterate(&blk, true);
  2072. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2073. + MarkSweep::copy_rescued_objects_back();
  2074. +
  2075. pg->post_compact(); // Shared spaces verification.
  2076. }
  2077. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2078. --- a/src/share/vm/memory/permGen.cpp
  2079. +++ b/src/share/vm/memory/permGen.cpp
  2080. @@ -57,7 +57,12 @@
  2081. for (;;) {
  2082. {
  2083. - MutexLocker ml(Heap_lock);
  2084. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2085. + Monitor *lock = Heap_lock;
  2086. + if (SafepointSynchronize::is_at_safepoint()) {
  2087. + lock = NULL;
  2088. + }
  2089. + MutexLockerEx ml(lock);
  2090. if ((obj = gen->allocate(size, false)) != NULL) {
  2091. return obj;
  2092. }
  2093. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2094. --- a/src/share/vm/memory/space.cpp
  2095. +++ b/src/share/vm/memory/space.cpp
  2096. @@ -378,6 +378,31 @@
  2097. _compaction_top = bottom();
  2098. }
  2099. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2100. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2101. +CompactPoint* cp, HeapWord* compact_top) {
  2102. + // First check if we should switch compaction space
  2103. + assert(this == cp->space, "'this' should be current compaction space.");
  2104. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2105. + while (size > compaction_max_size) {
  2106. + // switch to next compaction space
  2107. + cp->space->set_compaction_top(compact_top);
  2108. + cp->space = cp->space->next_compaction_space();
  2109. + if (cp->space == NULL) {
  2110. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2111. + assert(cp->gen != NULL, "compaction must succeed");
  2112. + cp->space = cp->gen->first_compaction_space();
  2113. + assert(cp->space != NULL, "generation must have a first compaction space");
  2114. + }
  2115. + compact_top = cp->space->bottom();
  2116. + cp->space->set_compaction_top(compact_top);
  2117. + cp->threshold = cp->space->initialize_threshold();
  2118. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2119. + }
  2120. +
  2121. + return compact_top;
  2122. +}
  2123. +
  2124. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2125. CompactPoint* cp, HeapWord* compact_top) {
  2126. // q is alive
  2127. @@ -401,7 +426,7 @@
  2128. }
  2129. // store the forwarding pointer into the mark word
  2130. - if ((HeapWord*)q != compact_top) {
  2131. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2132. q->forward_to(oop(compact_top));
  2133. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2134. } else {
  2135. @@ -449,7 +474,208 @@
  2136. // Faster object search.
  2137. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2138. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2139. + if (!Universe::is_redefining_gc_run()) {
  2140. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2141. + return;
  2142. + }
  2143. +
  2144. + /* Compute the new addresses for the live objects and store it in the mark
  2145. + * Used by universe::mark_sweep_phase2()
  2146. + */
  2147. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2148. +
  2149. + /* We're sure to be here before any objects are compacted into this
  2150. + * space, so this is a good time to initialize this:
  2151. + */
  2152. + set_compaction_top(bottom());
  2153. +
  2154. + if (cp->space == NULL) {
  2155. + assert(cp->gen != NULL, "need a generation");
  2156. + assert(cp->threshold == NULL, "just checking");
  2157. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2158. + cp->space = cp->gen->first_compaction_space();
  2159. + compact_top = cp->space->bottom();
  2160. + cp->space->set_compaction_top(compact_top);
  2161. + cp->threshold = cp->space->initialize_threshold();
  2162. + } else {
  2163. + compact_top = cp->space->compaction_top();
  2164. + }
  2165. +
  2166. + /* We allow some amount of garbage towards the bottom of the space, so
  2167. + * we don't start compacting before there is a significant gain to be made.
  2168. + * Occasionally, we want to ensure a full compaction, which is determined
  2169. + * by the MarkSweepAlwaysCompactCount parameter.
  2170. + */
  2171. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2172. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2173. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2174. +
  2175. + size_t allowed_deadspace = 0;
  2176. + if (skip_dead) {
  2177. + int ratio = (int)allowed_dead_ratio();
  2178. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2179. + }
  2180. +
  2181. + HeapWord* q = bottom();
  2182. + HeapWord* t = end();
  2183. +
  2184. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2185. + live object. */
  2186. + HeapWord* first_dead = end();/* The first dead object. */
  2187. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2188. + first header of preceding free area. */
  2189. + _first_dead = first_dead;
  2190. +
  2191. + const intx interval = PrefetchScanIntervalInBytes;
  2192. +
  2193. + while (q < t) {
  2194. + assert(!block_is_obj(q) ||
  2195. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2196. + oop(q)->mark()->has_bias_pattern(),
  2197. + "these are the only valid states during a mark sweep");
  2198. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2199. + /* prefetch beyond q */
  2200. + Prefetch::write(q, interval);
  2201. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2202. + size_t size = block_size(q);
  2203. +
  2204. + // DCEVM: begin
  2205. + //////////////////////////////////////////////////////////////////////////
  2206. + size_t forward_size = size;
  2207. +
  2208. + // Compute the forward sizes and leave out objects whose position could
  2209. + // possibly overlap other objects.
  2210. +
  2211. + // DCEVM: There is a new version of the class of q => different size
  2212. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2213. +
  2214. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2215. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2216. + forward_size = new_size;
  2217. + }
  2218. +
  2219. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2220. +
  2221. + bool rescueing = false;
  2222. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2223. + if (MarkSweep::_rescued_oops == NULL) {
  2224. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2225. + }
  2226. + // FIXME: idubrov
  2227. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2228. + MarkSweep::_rescued_oops->append(oop(q));
  2229. + } else {
  2230. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2231. + }
  2232. +
  2233. + if ((size != forward_size || rescueing) && q < first_dead) {
  2234. + // (tw) This object moves => first_dead must be set to here!
  2235. + first_dead = q;
  2236. + }
  2237. + //////////////////////////////////////////////////////////////////////////
  2238. + q += size;
  2239. + end_of_live = q;
  2240. + } else {
  2241. + /* run over all the contiguous dead objects */
  2242. + HeapWord* end = q;
  2243. + do {
  2244. + /* prefetch beyond end */
  2245. + Prefetch::write(end, interval);
  2246. + end += block_size(end);
  2247. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2248. +
  2249. + /* see if we might want to pretend this object is alive so that
  2250. + * we don't have to compact quite as often.
  2251. + */
  2252. + if (allowed_deadspace > 0 && q == compact_top) {
  2253. + size_t sz = pointer_delta(end, q);
  2254. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2255. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2256. + q = end;
  2257. + end_of_live = end;
  2258. + continue;
  2259. + }
  2260. + }
  2261. +
  2262. + /* otherwise, it really is a free region. */
  2263. +
  2264. + /* for the previous LiveRange, record the end of the live objects. */
  2265. + if (liveRange) {
  2266. + liveRange->set_end(q);
  2267. + }
  2268. +
  2269. + /* record the current LiveRange object.
  2270. + * liveRange->start() is overlaid on the mark word.
  2271. + */
  2272. + liveRange = (LiveRange*)q;
  2273. + liveRange->set_start(end);
  2274. + liveRange->set_end(end);
  2275. +
  2276. + /* see if this is the first dead region. */
  2277. + if (q < first_dead) {
  2278. + first_dead = q;
  2279. + }
  2280. +
  2281. + /* move on to the next object */
  2282. + q = end;
  2283. + }
  2284. + }
  2285. +
  2286. + //////////////////////////////////////////////////////////////////////////
  2287. + // Compute the forwarding addresses for the objects that need to be
  2288. + // rescued.
  2289. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2290. + if (MarkSweep::_rescued_oops != NULL) {
  2291. + // FIXME: idubrov
  2292. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2293. +
  2294. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2295. + oop q = MarkSweep::_rescued_oops->at(i);
  2296. +
  2297. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2298. + size_t size = block_size((HeapWord*)q);
  2299. +
  2300. + size_t forward_size = size;
  2301. +
  2302. + // (tw) There is a new version of the class of q => different size
  2303. + if (oop(q)->blueprint()->new_version() != NULL) {
  2304. +
  2305. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2306. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2307. + forward_size = new_size;
  2308. + }
  2309. +
  2310. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2311. + assert(compact_top <= t, "must not write over end of space!");
  2312. + }
  2313. + MarkSweep::_rescued_oops->clear();
  2314. + MarkSweep::_rescued_oops = NULL;
  2315. + }
  2316. + //////////////////////////////////////////////////////////////////////////
  2317. +
  2318. + assert(q == t, "just checking");
  2319. + if (liveRange != NULL) {
  2320. + liveRange->set_end(q);
  2321. + }
  2322. + _end_of_live = end_of_live;
  2323. + if (end_of_live < first_dead) {
  2324. + first_dead = end_of_live;
  2325. + }
  2326. + _first_dead = first_dead;
  2327. +
  2328. +// FIXME: idubrov
  2329. +// if (_first_dead > top()) {
  2330. +// _first_dead = top();
  2331. +// }
  2332. +//
  2333. +// if (_end_of_live > top()) {
  2334. +// _end_of_live = top();
  2335. +// }
  2336. + assert(_first_dead <= top(), "Must be smaller equal");
  2337. + assert(_end_of_live <= top(), "Must be smaller equal");
  2338. +
  2339. + /* save the compaction_top of the compaction space. */
  2340. + cp->space->set_compaction_top(compact_top);
  2341. }
  2342. void Space::adjust_pointers() {
  2343. @@ -490,17 +716,313 @@
  2344. assert(q == t, "just checking");
  2345. }
  2346. +
  2347. +#ifdef ASSERT
  2348. +
  2349. +int CompactibleSpace::space_index(oop obj) {
  2350. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2351. +
  2352. + if (heap->is_in_permanent(obj)) {
  2353. + return -1;
  2354. + }
  2355. +
  2356. + int index = 0;
  2357. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2358. + Generation* gen = heap->get_gen(i);
  2359. + CompactibleSpace* space = gen->first_compaction_space();
  2360. + while (space != NULL) {
  2361. + if (space->is_in_reserved(obj)) {
  2362. + return index;
  2363. + }
  2364. + space = space->next_compaction_space();
  2365. + index++;
  2366. + }
  2367. + }
  2368. +
  2369. + tty->print_cr("could not compute space_index for %08xh", obj);
  2370. + index = 0;
  2371. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2372. + Generation* gen = heap->get_gen(i);
  2373. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2374. +
  2375. + CompactibleSpace* space = gen->first_compaction_space();
  2376. + while (space != NULL) {
  2377. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2378. + space = space->next_compaction_space();
  2379. + index++;
  2380. + }
  2381. + }
  2382. +
  2383. + ShouldNotReachHere();
  2384. + return 0;
  2385. +}
  2386. +#endif
  2387. +
  2388. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2389. +
  2390. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2391. +
  2392. + if (old_obj->is_perm()) {
  2393. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2394. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2395. + return true;
  2396. + }
  2397. + }
  2398. +
  2399. + int size = old_obj->size();
  2400. + int original_size = size;
  2401. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2402. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2403. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2404. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2405. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2406. + }
  2407. +
  2408. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2409. +
  2410. + if (is_in_reserved(new_obj)) {
  2411. + // Old and new address are in same space, so just compare the address.
  2412. + // Must rescue if object moves towards the top of the space.
  2413. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2414. + return normalComparison;
  2415. +
  2416. + } else {
  2417. +
  2418. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2419. +
  2420. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2421. + if (tenured_gen->is_in_reserved(new_obj)) {
  2422. + // Must never rescue when moving from the new into the old generation.
  2423. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2424. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2425. + return false;
  2426. +
  2427. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2428. + // Must always rescue when moving from the old into the new generation.
  2429. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2430. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2431. + return true;
  2432. +
  2433. + } else {
  2434. + // In the new generation, eden is located before the from space, so a
  2435. + // simple pointer comparison is sufficient.
  2436. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2437. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2438. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2439. + return normalComparison;
  2440. + }
  2441. + }
  2442. +}
  2443. +
  2444. +oop CompactibleSpace::rescue(oop old_obj) {
  2445. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2446. +
  2447. + int size = old_obj->size();
  2448. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2449. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2450. +
  2451. + if (MarkSweep::_rescued_oops == NULL) {
  2452. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2453. + }
  2454. +
  2455. + MarkSweep::_rescued_oops->append(rescued_obj);
  2456. + return rescued_obj;
  2457. +}
  2458. +
  2459. void CompactibleSpace::adjust_pointers() {
  2460. // Check first is there is any work to do.
  2461. if (used() == 0) {
  2462. return; // Nothing to do.
  2463. }
  2464. + /* adjust all the interior pointers to point at the new locations of objects
  2465. + * Used by MarkSweep::mark_sweep_phase3() */
  2466. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2467. + HeapWord* q = bottom();
  2468. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2469. +
  2470. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2471. +
  2472. + debug_only(HeapWord* prev_q = NULL);
  2473. + debug_only(HeapWord* prev_prev_q = NULL);
  2474. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2475. + if (q < t && _first_dead > q &&
  2476. + !oop(q)->is_gc_marked()) {
  2477. + /* we have a chunk of the space which hasn't moved and we've
  2478. + * reinitialized the mark word during the previous pass, so we can't
  2479. + * use is_gc_marked for the traversal. */
  2480. + HeapWord* end = _first_dead;
  2481. +
  2482. + while (q < end) {
  2483. + /* I originally tried to conjoin "block_start(q) == q" to the
  2484. + * assertion below, but that doesn't work, because you can't
  2485. + * accurately traverse previous objects to get to the current one
  2486. + * after their pointers (including pointers into permGen) have been
  2487. + * updated, until the actual compaction is done. dld, 4/00 */
  2488. + assert(block_is_obj(q),
  2489. + "should be at block boundaries, and should be looking at objs");
  2490. +
  2491. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2492. +
  2493. + /* point all the oops to the new location */
  2494. + size_t size = oop(q)->adjust_pointers();
  2495. + size = adjust_obj_size(size);
  2496. +
  2497. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2498. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2499. +
  2500. + debug_only(prev_prev_prev_q = prev_prev_q);
  2501. + debug_only(prev_prev_q = prev_q);
  2502. + debug_only(prev_q = q);
  2503. + q += size;
  2504. + }
  2505. +
  2506. + // (tw) first_dead can be live object!
  2507. + q = _first_dead;
  2508. +
  2509. +// if (_first_dead == t) {
  2510. +// q = t;
  2511. +// } else {
  2512. +// /* $$$ This is funky. Using this to read the previously written
  2513. +// * LiveRange. See also use below. */
  2514. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2515. +// }
  2516. + }
  2517. +
  2518. + const intx interval = PrefetchScanIntervalInBytes;
  2519. +
  2520. + debug_only(prev_q = NULL);
  2521. + debug_only(prev_prev_q = NULL);
  2522. + debug_only(prev_prev_prev_q = NULL);
  2523. + while (q < t) {
  2524. + /* prefetch beyond q */
  2525. + Prefetch::write(q, interval);
  2526. + if (oop(q)->is_gc_marked()) {
  2527. + /* q is alive */
  2528. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2529. + /* point all the oops to the new location */
  2530. + size_t size = oop(q)->adjust_pointers();
  2531. + size = adjust_obj_size(size);
  2532. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2533. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2534. + debug_only(prev_prev_prev_q = prev_prev_q);
  2535. + debug_only(prev_prev_q = prev_q);
  2536. + debug_only(prev_q = q);
  2537. + q += size;
  2538. + } else {
  2539. + /* q is not a live object, so its mark should point at the next
  2540. + * live object */
  2541. + debug_only(prev_prev_prev_q = prev_prev_q);
  2542. + debug_only(prev_prev_q = prev_q);
  2543. + debug_only(prev_q = q);
  2544. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2545. + assert(q > prev_q, "we should be moving forward through memory");
  2546. + }
  2547. + }
  2548. +
  2549. + assert(q == t, "just checking");
  2550. }
  2551. void CompactibleSpace::compact() {
  2552. - SCAN_AND_COMPACT(obj_size);
  2553. +
  2554. + if(!Universe::is_redefining_gc_run()) {
  2555. + SCAN_AND_COMPACT(obj_size);
  2556. + return;
  2557. + }
  2558. +
  2559. + /* Copy all live objects to their new location
  2560. + * Used by MarkSweep::mark_sweep_phase4() */
  2561. +
  2562. + HeapWord* q = bottom();
  2563. + HeapWord* const t = _end_of_live;
  2564. + debug_only(HeapWord* prev_q = NULL);
  2565. +
  2566. + if (q < t && _first_dead > q &&
  2567. + !oop(q)->is_gc_marked()) {
  2568. + debug_only(
  2569. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2570. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2571. + * the traversal. */
  2572. + HeapWord* const end = _first_dead;
  2573. +
  2574. + while (q < end) {
  2575. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2576. + assert(!oop(q)->is_gc_marked(),
  2577. + "should be unmarked (special dense prefix handling)");
  2578. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2579. + debug_only(prev_q = q);
  2580. + q += size;
  2581. + }
  2582. + ) /* debug_only */
  2583. + // (tw) first_dead can be live object!
  2584. + q = _first_dead;
  2585. +
  2586. + //if (_first_dead == t) {
  2587. + // q = t;
  2588. + //} else {
  2589. + ///* $$$ Funky */
  2590. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2591. + //}
  2592. + }
  2593. +
  2594. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2595. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2596. + while (q < t) {
  2597. + if (!oop(q)->is_gc_marked()) {
  2598. + /* mark is pointer to next marked oop */
  2599. + debug_only(prev_q = q);
  2600. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2601. + assert(q > prev_q, "we should be moving forward through memory");
  2602. + } else {
  2603. + /* prefetch beyond q */
  2604. + Prefetch::read(q, scan_interval);
  2605. +
  2606. + /* size and destination */
  2607. + size_t size = obj_size(q);
  2608. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2609. +
  2610. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2611. + oop dest_obj = rescue(oop(q));
  2612. + debug_only(Copy::fill_to_words(q, size, 0));
  2613. + } else {
  2614. +
  2615. + /* prefetch beyond compaction_top */
  2616. + Prefetch::write(compaction_top, copy_interval);
  2617. +
  2618. + /* copy object and reinit its mark */
  2619. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2620. + compaction_top));
  2621. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2622. +
  2623. + if (oop(q)->blueprint()->new_version() != NULL) {
  2624. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2625. + } else {
  2626. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2627. + }
  2628. + oop(compaction_top)->init_mark();
  2629. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2630. + }
  2631. +
  2632. + debug_only(prev_q = q);
  2633. + q += size;
  2634. + }
  2635. + }
  2636. +
  2637. + /* Let's remember if we were empty before we did the compaction. */
  2638. + bool was_empty = used_region().is_empty();
  2639. + /* Reset space after compaction is complete */
  2640. + reset_after_compaction();
  2641. + /* We do this clear, below, since it has overloaded meanings for some */
  2642. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2643. + /* compacted into will have had their offset table thresholds updated */
  2644. + /* continuously, but those that weren't need to have their thresholds */
  2645. + /* re-initialized. Also mangles unused area for debugging. */
  2646. + if (used_region().is_empty()) {
  2647. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2648. + } else {
  2649. + if (ZapUnusedHeapArea) mangle_unused_area();
  2650. + }
  2651. +
  2652. + //SCAN_AND_COMPACT(obj_size);
  2653. }
  2654. void Space::print_short() const { print_short_on(tty); }
  2655. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2656. --- a/src/share/vm/memory/space.hpp
  2657. +++ b/src/share/vm/memory/space.hpp
  2658. @@ -445,6 +445,9 @@
  2659. // indicates when the next such action should be taken.
  2660. virtual void prepare_for_compaction(CompactPoint* cp);
  2661. // MarkSweep support phase3
  2662. + DEBUG_ONLY(int space_index(oop obj));
  2663. + bool must_rescue(oop old_obj, oop new_obj);
  2664. + oop rescue(oop old_obj);
  2665. virtual void adjust_pointers();
  2666. // MarkSweep support phase4
  2667. virtual void compact();
  2668. @@ -475,6 +478,10 @@
  2669. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2670. HeapWord* compact_top);
  2671. + // (tw)
  2672. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2673. + HeapWord* compact_top);
  2674. +
  2675. // Return a size with adjusments as required of the space.
  2676. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2677. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2678. --- a/src/share/vm/memory/universe.cpp
  2679. +++ b/src/share/vm/memory/universe.cpp
  2680. @@ -100,6 +100,8 @@
  2681. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2682. #endif
  2683. +bool Universe::_is_redefining_gc_run = false;
  2684. +
  2685. // Known objects
  2686. klassOop Universe::_boolArrayKlassObj = NULL;
  2687. klassOop Universe::_byteArrayKlassObj = NULL;
  2688. @@ -203,6 +205,38 @@
  2689. f(systemObjArrayKlassObj());
  2690. }
  2691. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2692. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2693. +
  2694. + class AlwaysTrueClosure: public BoolObjectClosure {
  2695. + public:
  2696. + void do_object(oop p) { ShouldNotReachHere(); }
  2697. + bool do_object_b(oop p) { return true; }
  2698. + };
  2699. + AlwaysTrueClosure always_true;
  2700. +
  2701. + // General strong roots
  2702. + Universe::oops_do(oopClosure);
  2703. + JNIHandles::oops_do(oopClosure);
  2704. + Threads::oops_do(oopClosure, NULL);
  2705. + ObjectSynchronizer::oops_do(oopClosure);
  2706. + FlatProfiler::oops_do(oopClosure);
  2707. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2708. + JvmtiExport::oops_do(oopClosure);
  2709. + // SO_AllClasses
  2710. + SystemDictionary::oops_do(oopClosure);
  2711. +
  2712. + // Now adjust pointers in remaining weak roots. (All of which should
  2713. + // have been cleared if they pointed to non-surviving objects.)
  2714. + // Global (weak) JNI handles
  2715. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2716. +
  2717. + CodeCache::oops_do(oopClosure);
  2718. + StringTable::oops_do(oopClosure);
  2719. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2720. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2721. +}
  2722. +
  2723. void Universe::oops_do(OopClosure* f, bool do_all) {
  2724. f->do_oop((oop*) &_int_mirror);
  2725. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2726. --- a/src/share/vm/memory/universe.hpp
  2727. +++ b/src/share/vm/memory/universe.hpp
  2728. @@ -127,6 +127,8 @@
  2729. friend class SystemDictionary;
  2730. friend class VMStructs;
  2731. friend class CompactingPermGenGen;
  2732. + friend class Space;
  2733. + friend class ContiguousSpace;
  2734. friend class VM_PopulateDumpSharedSpace;
  2735. friend jint universe_init();
  2736. @@ -257,7 +259,18 @@
  2737. static void compute_verify_oop_data();
  2738. + static bool _is_redefining_gc_run;
  2739. +
  2740. public:
  2741. +
  2742. + static bool is_redefining_gc_run() {
  2743. + return _is_redefining_gc_run;
  2744. + }
  2745. +
  2746. + static void set_redefining_gc_run(bool b) {
  2747. + _is_redefining_gc_run = b;
  2748. + }
  2749. +
  2750. // Known classes in the VM
  2751. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2752. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2753. @@ -396,6 +409,8 @@
  2754. // Iteration
  2755. + static void root_oops_do(OopClosure *f);
  2756. +
  2757. // Apply "f" to the addresses of all the direct heap pointers maintained
  2758. // as static fields of "Universe".
  2759. static void oops_do(OopClosure* f, bool do_all = false);
  2760. @@ -412,6 +427,7 @@
  2761. // Debugging
  2762. static bool verify_in_progress() { return _verify_in_progress; }
  2763. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2764. static void verify(bool allow_dirty = true, bool silent = false,
  2765. VerifyOption option = VerifyOption_Default );
  2766. static int verify_count() { return _verify_count; }
  2767. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2768. --- a/src/share/vm/oops/arrayKlass.cpp
  2769. +++ b/src/share/vm/oops/arrayKlass.cpp
  2770. @@ -129,9 +129,9 @@
  2771. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2772. // An array is a subtype of Serializable, Clonable, and Object
  2773. - return k == SystemDictionary::Object_klass()
  2774. - || k == SystemDictionary::Cloneable_klass()
  2775. - || k == SystemDictionary::Serializable_klass();
  2776. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2777. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2778. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2779. }
  2780. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2781. --- a/src/share/vm/oops/constMethodKlass.cpp
  2782. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2783. @@ -101,6 +101,7 @@
  2784. MarkSweep::mark_and_push(cm->adr_method());
  2785. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2786. MarkSweep::mark_and_push(cm->adr_exception_table());
  2787. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2788. // Performance tweak: We skip iterating over the klass pointer since we
  2789. // know that Universe::constMethodKlassObj never moves.
  2790. }
  2791. @@ -113,6 +114,7 @@
  2792. PSParallelCompact::mark_and_push(cm, cm_oop->adr_method());
  2793. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2794. PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table());
  2795. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2796. // Performance tweak: We skip iterating over the klass pointer since we
  2797. // know that Universe::constMethodKlassObj never moves.
  2798. }
  2799. @@ -124,6 +126,7 @@
  2800. blk->do_oop(cm->adr_method());
  2801. blk->do_oop(cm->adr_stackmap_data());
  2802. blk->do_oop(cm->adr_exception_table());
  2803. + blk->do_oop(cm->adr_code_section_table());
  2804. // Get size before changing pointers.
  2805. // Don't call size() or oop_size() since that is a virtual call.
  2806. int size = cm->object_size();
  2807. @@ -141,6 +144,8 @@
  2808. if (mr.contains(adr)) blk->do_oop(adr);
  2809. adr = cm->adr_exception_table();
  2810. if (mr.contains(adr)) blk->do_oop(adr);
  2811. + adr = cm->adr_code_section_table();
  2812. + if (mr.contains(adr)) blk->do_oop(adr);
  2813. // Get size before changing pointers.
  2814. // Don't call size() or oop_size() since that is a virtual call.
  2815. int size = cm->object_size();
  2816. @@ -156,6 +161,7 @@
  2817. MarkSweep::adjust_pointer(cm->adr_method());
  2818. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2819. MarkSweep::adjust_pointer(cm->adr_exception_table());
  2820. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2821. // Get size before changing pointers.
  2822. // Don't call size() or oop_size() since that is a virtual call.
  2823. int size = cm->object_size();
  2824. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2825. --- a/src/share/vm/oops/constMethodOop.hpp
  2826. +++ b/src/share/vm/oops/constMethodOop.hpp
  2827. @@ -114,7 +114,7 @@
  2828. public:
  2829. oop* oop_block_beg() const { return adr_method(); }
  2830. - oop* oop_block_end() const { return adr_exception_table() + 1; }
  2831. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2832. private:
  2833. //
  2834. @@ -132,6 +132,10 @@
  2835. // table is pointing to Universe::the_empty_int_array
  2836. typeArrayOop _exception_table;
  2837. +
  2838. + // (tw) Table mapping code sections for method forward points.
  2839. + typeArrayOop _code_section_table;
  2840. +
  2841. //
  2842. // End of the oop block.
  2843. //
  2844. @@ -184,6 +188,28 @@
  2845. void set_exception_table(typeArrayOop e) { oop_store_without_check((oop*) &_exception_table, (oop) e); }
  2846. bool has_exception_handler() const { return exception_table() != NULL && exception_table()->length() > 0; }
  2847. + // code section table
  2848. + typeArrayOop code_section_table() const { return _code_section_table; }
  2849. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2850. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2851. + static const int ValuesPerCodeSectionEntry = 3;
  2852. + int code_section_entries() const {
  2853. + if (!has_code_section_table()) return 0;
  2854. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2855. + }
  2856. +
  2857. + int code_section_new_index_at(int index) const {
  2858. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2859. + }
  2860. +
  2861. + int code_section_original_index_at(int index) const {
  2862. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2863. + }
  2864. +
  2865. + int code_section_length_at(int index) const {
  2866. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2867. + }
  2868. +
  2869. void init_fingerprint() {
  2870. const uint64_t initval = CONST64(0x8000000000000000);
  2871. _fingerprint = initval;
  2872. @@ -285,6 +311,7 @@
  2873. oop* adr_method() const { return (oop*)&_method; }
  2874. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2875. oop* adr_exception_table() const { return (oop*)&_exception_table; }
  2876. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2877. bool is_conc_safe() { return _is_conc_safe; }
  2878. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2879. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2880. --- a/src/share/vm/oops/cpCacheOop.cpp
  2881. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2882. @@ -36,9 +36,15 @@
  2883. // Implememtation of ConstantPoolCacheEntry
  2884. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2885. + _flags = other->_flags; // flags
  2886. +}
  2887. +
  2888. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2889. assert(0 < index && index < 0x10000, "sanity check");
  2890. _indices = index;
  2891. + _f1 = NULL;
  2892. + _f2 = 0;
  2893. assert(constant_pool_index() == index, "");
  2894. }
  2895. @@ -50,7 +56,7 @@
  2896. int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
  2897. bool is_vfinal, bool is_volatile,
  2898. - bool is_method_interface, bool is_method) {
  2899. + bool is_method_interface, bool is_method, bool is_old_method) {
  2900. int f = state;
  2901. assert( state < number_of_states, "Invalid state in as_flags");
  2902. @@ -65,7 +71,9 @@
  2903. if (is_method_interface) f |= 1;
  2904. f <<= 1;
  2905. if (is_method) f |= 1;
  2906. - f <<= ConstantPoolCacheEntry::hotSwapBit;
  2907. + f <<= 1;
  2908. + if (is_old_method) f |= 1;
  2909. + f <<= ConstantPoolCacheEntry::oldMethodBit;
  2910. // Preserve existing flag bit values
  2911. #ifdef ASSERT
  2912. int old_state = ((_flags >> tosBits) & 0x0F);
  2913. @@ -137,7 +145,7 @@
  2914. set_f2(field_offset);
  2915. assert(field_index <= field_index_mask,
  2916. "field index does not fit in low flag bits");
  2917. - set_flags(as_flags(field_type, is_final, false, is_volatile, false, false) |
  2918. + set_flags(as_flags(field_type, is_final, false, is_volatile, false, false, false) |
  2919. (field_index & field_index_mask));
  2920. set_bytecode_1(get_code);
  2921. set_bytecode_2(put_code);
  2922. @@ -153,7 +161,8 @@
  2923. int vtable_index) {
  2924. assert(!is_secondary_entry(), "");
  2925. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2926. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2927. + // (tw) No longer valid assert
  2928. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2929. bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
  2930. int byte_no = -1;
  2931. @@ -167,6 +176,9 @@
  2932. } else {
  2933. assert(vtable_index >= 0, "valid index");
  2934. set_f2(vtable_index);
  2935. +
  2936. + // (tw) save method holder in f1 for virtual calls
  2937. + set_f1(method());
  2938. }
  2939. byte_no = 2;
  2940. break;
  2941. @@ -212,7 +224,7 @@
  2942. needs_vfinal_flag,
  2943. false,
  2944. change_to_virtual,
  2945. - true)|
  2946. + true, method->is_old())|
  2947. method()->size_of_parameters());
  2948. // Note: byte_no also appears in TemplateTable::resolve.
  2949. @@ -252,7 +264,7 @@
  2950. assert(instanceKlass::cast(interf)->is_interface(), "must be an interface");
  2951. set_f1(interf);
  2952. set_f2(index);
  2953. - set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true) | method()->size_of_parameters());
  2954. + set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true, method->is_old()) | method()->size_of_parameters());
  2955. set_bytecode_1(Bytecodes::_invokeinterface);
  2956. }
  2957. @@ -282,7 +294,7 @@
  2958. param_size -= 1; // do not count MH.this; it is not stacked for invokedynamic
  2959. bool is_final = true;
  2960. assert(signature_invoker->is_final_method(), "is_final");
  2961. - int flags = as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true) | param_size;
  2962. + int flags = as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true, false) | param_size;
  2963. assert(_flags == 0 || _flags == flags, "flags should be the same");
  2964. set_flags(flags);
  2965. // do not do set_bytecode on a secondary CP cache entry
  2966. @@ -416,26 +428,13 @@
  2967. // If this constantPoolCacheEntry refers to old_method then update it
  2968. // to refer to new_method.
  2969. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  2970. - methodOop new_method, bool * trace_name_printed) {
  2971. + methodOop new_method) {
  2972. if (is_vfinal()) {
  2973. +
  2974. // virtual and final so f2() contains method ptr instead of vtable index
  2975. - if (f2() == (intptr_t)old_method) {
  2976. - // match old_method so need an update
  2977. - _f2 = (intptr_t)new_method;
  2978. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  2979. - if (!(*trace_name_printed)) {
  2980. - // RC_TRACE_MESG macro has an embedded ResourceMark
  2981. - RC_TRACE_MESG(("adjust: name=%s",
  2982. - Klass::cast(old_method->method_holder())->external_name()));
  2983. - *trace_name_printed = true;
  2984. - }
  2985. - // RC_TRACE macro has an embedded ResourceMark
  2986. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  2987. - new_method->name()->as_C_string(),
  2988. - new_method->signature()->as_C_string()));
  2989. - }
  2990. -
  2991. + if((methodOop)f2() != NULL && ((methodOop)f2())->method_holder()->klass_part()->new_version()) {
  2992. + initialize_entry(constant_pool_index());
  2993. return true;
  2994. }
  2995. @@ -443,65 +442,28 @@
  2996. return false;
  2997. }
  2998. - if ((oop)_f1 == NULL) {
  2999. - // NULL f1() means this is a virtual entry so bail out
  3000. - // We are assuming that the vtable index does not need change.
  3001. + // (tw) check how to update interface methods!
  3002. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3003. +
  3004. + if(((methodOop)f1())->method_holder()->klass_part()->new_version()) {
  3005. + initialize_entry(constant_pool_index());
  3006. + return true;
  3007. + }
  3008. +
  3009. return false;
  3010. }
  3011. if ((oop)_f1 == old_method) {
  3012. _f1 = new_method;
  3013. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3014. - if (!(*trace_name_printed)) {
  3015. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3016. - RC_TRACE_MESG(("adjust: name=%s",
  3017. - Klass::cast(old_method->method_holder())->external_name()));
  3018. - *trace_name_printed = true;
  3019. - }
  3020. - // RC_TRACE macro has an embedded ResourceMark
  3021. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3022. - new_method->name()->as_C_string(),
  3023. - new_method->signature()->as_C_string()));
  3024. - }
  3025. -
  3026. + return true;
  3027. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && ((methodOop)f1())->method_holder()->klass_part()->new_version())) {
  3028. + initialize_entry(constant_pool_index());
  3029. return true;
  3030. }
  3031. return false;
  3032. }
  3033. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3034. - if (!is_method_entry()) {
  3035. - // not a method entry so not interesting by default
  3036. - return false;
  3037. - }
  3038. -
  3039. - methodOop m = NULL;
  3040. - if (is_vfinal()) {
  3041. - // virtual and final so _f2 contains method ptr instead of vtable index
  3042. - m = (methodOop)_f2;
  3043. - } else if ((oop)_f1 == NULL) {
  3044. - // NULL _f1 means this is a virtual entry so also not interesting
  3045. - return false;
  3046. - } else {
  3047. - if (!((oop)_f1)->is_method()) {
  3048. - // _f1 can also contain a klassOop for an interface
  3049. - return false;
  3050. - }
  3051. - m = (methodOop)_f1;
  3052. - }
  3053. -
  3054. - assert(m != NULL && m->is_method(), "sanity check");
  3055. - if (m == NULL || !m->is_method() || m->method_holder() != k) {
  3056. - // robustness for above sanity checks or method is not in
  3057. - // the interesting class
  3058. - return false;
  3059. - }
  3060. -
  3061. - // the method is in the interesting class so the entry is interesting
  3062. - return true;
  3063. -}
  3064. -
  3065. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3066. // print separator
  3067. if (index == 0) tty->print_cr(" -------------");
  3068. @@ -542,38 +504,18 @@
  3069. // RedefineClasses() API support:
  3070. // If any entry of this constantPoolCache points to any of
  3071. // old_methods, replace it with the corresponding new_method.
  3072. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3073. - int methods_length, bool * trace_name_printed) {
  3074. -
  3075. - if (methods_length == 0) {
  3076. - // nothing to do if there are no methods
  3077. - return;
  3078. - }
  3079. -
  3080. - // get shorthand for the interesting class
  3081. - klassOop old_holder = old_methods[0]->method_holder();
  3082. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3083. + int methods_length) {
  3084. for (int i = 0; i < length(); i++) {
  3085. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3086. - // skip uninteresting methods
  3087. - continue;
  3088. - }
  3089. + if (entry_at(i)->is_field_entry()) {
  3090. - // The constantPoolCache contains entries for several different
  3091. - // things, but we only care about methods. In fact, we only care
  3092. - // about methods in the same class as the one that contains the
  3093. - // old_methods. At this point, we have an interesting entry.
  3094. -
  3095. - for (int j = 0; j < methods_length; j++) {
  3096. - methodOop old_method = old_methods[j];
  3097. - methodOop new_method = new_methods[j];
  3098. -
  3099. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3100. - trace_name_printed)) {
  3101. - // current old_method matched this entry and we updated it so
  3102. - // break out and get to the next interesting entry if there one
  3103. - break;
  3104. - }
  3105. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3106. + // point to changed fields
  3107. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3108. +
  3109. + } else if(entry_at(i)->is_method_entry()) {
  3110. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3111. }
  3112. }
  3113. }
  3114. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3115. --- a/src/share/vm/oops/cpCacheOop.hpp
  3116. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3117. @@ -135,19 +135,24 @@
  3118. void set_bytecode_2(Bytecodes::Code code);
  3119. void set_f1(oop f1) {
  3120. oop existing_f1 = _f1; // read once
  3121. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3122. + // (tw) need to relax assertion for redefinition
  3123. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3124. oop_store(&_f1, f1);
  3125. }
  3126. void set_f1_if_null_atomic(oop f1);
  3127. - void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; }
  3128. + void set_f2(intx f2) {
  3129. + // (tw) need to relax assertion for redefinition
  3130. + // assert(_f2 == 0 || _f2 == f2, "illegal field change");
  3131. + _f2 = f2; }
  3132. int as_flags(TosState state, bool is_final, bool is_vfinal, bool is_volatile,
  3133. - bool is_method_interface, bool is_method);
  3134. + bool is_method_interface, bool is_method, bool is_old_method);
  3135. void set_flags(intx flags) { _flags = flags; }
  3136. public:
  3137. // specific bit values in flag field
  3138. // Note: the interpreter knows this layout!
  3139. enum FlagBitValues {
  3140. + oldMethodBit = 22,
  3141. hotSwapBit = 23,
  3142. methodInterface = 24,
  3143. volatileField = 25,
  3144. @@ -167,6 +172,8 @@
  3145. void initialize_entry(int original_index); // initialize primary entry
  3146. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3147. + void copy_from(ConstantPoolCacheEntry *other);
  3148. +
  3149. void set_field( // sets entry to resolved field state
  3150. Bytecodes::Code get_code, // the bytecode used for reading the field
  3151. Bytecodes::Code put_code, // the bytecode used for writing the field
  3152. @@ -296,9 +303,7 @@
  3153. // trace_name_printed is set to true if the current call has
  3154. // printed the klass name so that other routines in the adjust_*
  3155. // group don't print the klass name.
  3156. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3157. - bool * trace_name_printed);
  3158. - bool is_interesting_method_entry(klassOop k);
  3159. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3160. bool is_field_entry() const { return (_flags & (1 << hotSwapBit)) == 0; }
  3161. bool is_method_entry() const { return (_flags & (1 << hotSwapBit)) != 0; }
  3162. @@ -397,14 +402,9 @@
  3163. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3164. }
  3165. - // RedefineClasses() API support:
  3166. - // If any entry of this constantPoolCache points to any of
  3167. - // old_methods, replace it with the corresponding new_method.
  3168. - // trace_name_printed is set to true if the current call has
  3169. - // printed the klass name so that other routines in the adjust_*
  3170. - // group don't print the klass name.
  3171. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3172. - int methods_length, bool * trace_name_printed);
  3173. + // (tw) Update method and field references
  3174. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3175. + int methods_length);
  3176. };
  3177. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3178. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3179. --- a/src/share/vm/oops/instanceKlass.cpp
  3180. +++ b/src/share/vm/oops/instanceKlass.cpp
  3181. @@ -248,12 +248,118 @@
  3182. }
  3183. +void instanceKlass::initialize_redefined_class() {
  3184. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3185. + name()->as_C_string()));
  3186. +
  3187. + assert(!is_initialized(), "");
  3188. + assert(this->old_version() != NULL, "");
  3189. + assert(is_linked(), "must be linked before");
  3190. +
  3191. +
  3192. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3193. + class UpdateStaticFieldClosure : public FieldClosure {
  3194. +
  3195. + private:
  3196. + instanceKlassHandle this_oop;
  3197. +
  3198. + public:
  3199. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3200. + this->this_oop = this_oop;
  3201. + }
  3202. +
  3203. + virtual void do_field(fieldDescriptor* fd) {
  3204. + fieldDescriptor result;
  3205. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3206. +
  3207. + if (found && result.is_static()) {
  3208. + int old_offset = result.offset();
  3209. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3210. +
  3211. + oop new_location = this_oop()->java_mirror();
  3212. + oop old_location = this_oop->old_version()->java_mirror();
  3213. + int offset = fd->offset();
  3214. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3215. + fd->name()->as_C_string(), old_offset, offset));
  3216. +
  3217. + oop cur_oop;
  3218. +
  3219. + switch(result.field_type()) {
  3220. +
  3221. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3222. +
  3223. + case T_BOOLEAN:
  3224. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3225. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3226. + break;
  3227. +
  3228. + case T_CHAR:
  3229. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3230. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3231. + break;
  3232. +
  3233. + case T_FLOAT:
  3234. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3235. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3236. + break;
  3237. +
  3238. + case T_DOUBLE:
  3239. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3240. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3241. + break;
  3242. +
  3243. + case T_BYTE:
  3244. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3245. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3246. + break;
  3247. +
  3248. + case T_SHORT:
  3249. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3250. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3251. + break;
  3252. +
  3253. + case T_INT:
  3254. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3255. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3256. + break;
  3257. +
  3258. + case T_LONG:
  3259. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3260. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3261. + break;
  3262. +
  3263. + case T_OBJECT:
  3264. + case T_ARRAY:
  3265. + cur_oop = old_location->obj_field(old_offset);
  3266. + new_location->obj_field_put_raw(offset, cur_oop);
  3267. + old_location->obj_field_put_raw(old_offset, NULL);
  3268. + break;
  3269. +
  3270. + default:
  3271. + ShouldNotReachHere();
  3272. + }
  3273. + } else {
  3274. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3275. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3276. + // field not found
  3277. + // (tw) TODO: Probably this call is not necessary here!
  3278. + // FIXME: idubrov
  3279. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3280. + }
  3281. + }
  3282. + };
  3283. +
  3284. + UpdateStaticFieldClosure cl(this_oop);
  3285. + this->do_local_static_fields(&cl);
  3286. +}
  3287. +
  3288. +
  3289. bool instanceKlass::verify_code(
  3290. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3291. // 1) Verify the bytecodes
  3292. Verifier::Mode mode =
  3293. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3294. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3295. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3296. }
  3297. @@ -360,7 +466,13 @@
  3298. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3299. jt->get_thread_stat()->perf_timers_addr(),
  3300. PerfClassTraceTime::CLASS_VERIFY);
  3301. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3302. + if (this_oop->is_redefining()) {
  3303. + Thread::current()->set_pretend_new_universe(true);
  3304. + }
  3305. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3306. + if (this_oop->is_redefining()) {
  3307. + Thread::current()->set_pretend_new_universe(false);
  3308. + }
  3309. if (!verify_ok) {
  3310. return false;
  3311. }
  3312. @@ -398,7 +510,8 @@
  3313. }
  3314. #endif
  3315. this_oop->set_init_state(linked);
  3316. - if (JvmtiExport::should_post_class_prepare()) {
  3317. + // (tw) Must check for old version in order to prevent infinite loops.
  3318. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3319. Thread *thread = THREAD;
  3320. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3321. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3322. @@ -665,6 +778,18 @@
  3323. return false;
  3324. }
  3325. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3326. + k = k->klass_part()->newest_version();
  3327. + if (this->newest_version() == k) return true;
  3328. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3329. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3330. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3331. + return true;
  3332. + }
  3333. + }
  3334. + return false;
  3335. +}
  3336. +
  3337. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3338. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3339. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3340. @@ -793,7 +918,25 @@
  3341. }
  3342. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3343. +
  3344. + ResourceMark rm(THREAD);
  3345. methodHandle h_method(THREAD, this_oop->class_initializer());
  3346. +
  3347. + if (this_oop->revision_number() != -1){
  3348. + methodOop m = NULL;
  3349. + if (AllowAdvancedClassRedefinition) {
  3350. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3351. + }
  3352. + methodHandle method(m);
  3353. + if (method() != NULL && method()->is_static()) {
  3354. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3355. + h_method = method;
  3356. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3357. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3358. + return;
  3359. + }
  3360. + }
  3361. +
  3362. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3363. if (TraceClassInitialization) {
  3364. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3365. @@ -942,6 +1085,137 @@
  3366. }
  3367. }
  3368. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3369. + int *arr = NEW_C_HEAP_ARRAY(int, values.length());
  3370. + for (int i=0; i<values.length(); i++) {
  3371. + arr[i] = values.at(i);
  3372. + }
  3373. + set_update_information(arr);
  3374. +}
  3375. +
  3376. +void instanceKlass::clear_update_information() {
  3377. + FREE_C_HEAP_ARRAY(int, update_information());
  3378. + set_update_information(NULL);
  3379. +}
  3380. +
  3381. +typedef Pair<int, klassOop> typeInfoPair;
  3382. +
  3383. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3384. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length());
  3385. + for (int i=0; i<values.length(); i++) {
  3386. + arr[i] = values.at(i);
  3387. + }
  3388. + set_type_check_information(arr);
  3389. +}
  3390. +
  3391. +void instanceKlass::clear_type_check_information() {
  3392. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information());
  3393. + set_type_check_information(NULL);
  3394. +}
  3395. +
  3396. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3397. +
  3398. + assert (old_version() != NULL, "must have old version!");
  3399. +
  3400. + klassOop old_klass_oop = old_version();
  3401. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3402. + instanceKlass *new_klass = this;
  3403. +
  3404. + fieldDescriptor fd;
  3405. + fieldDescriptor old_fd;
  3406. +
  3407. + instanceKlass *cur_new_klass = new_klass;
  3408. + klassOop cur_new_klass_oop = this->as_klassOop();
  3409. +
  3410. + if (_fields_not_changed) {
  3411. +
  3412. + class MyFieldClosure : public FieldClosure {
  3413. +
  3414. + FieldEvolutionClosure *_cl;
  3415. + public:
  3416. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3417. + virtual void do_field(fieldDescriptor* fd) {
  3418. + _cl->do_changed_field(fd, fd);
  3419. + }
  3420. + };
  3421. +
  3422. + MyFieldClosure mfc(cl);
  3423. + do_nonstatic_fields(&mfc);
  3424. + } else {
  3425. +
  3426. + _fields_not_changed = true;
  3427. + GrowableArray<fieldDescriptor> fds;
  3428. + while (true) {
  3429. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3430. + fd.initialize(cur_new_klass_oop, fs.index());
  3431. + if (fd.is_static()) {
  3432. + continue;
  3433. + }
  3434. + fds.append(fd);
  3435. + }
  3436. +
  3437. + if (cur_new_klass->super() != NULL) {
  3438. + cur_new_klass_oop = cur_new_klass->super();
  3439. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3440. + } else {
  3441. + break;
  3442. + }
  3443. + }
  3444. +
  3445. + GrowableArray<fieldDescriptor> sortedFds;
  3446. + while (fds.length() > 0) {
  3447. + int minOffset = 0x7fffffff;
  3448. + int minIndex = -1;
  3449. + for (int i=0; i<fds.length(); i++) {
  3450. + int curOffset = fds.adr_at(i)->offset();
  3451. + if (curOffset < minOffset) {
  3452. + minOffset = curOffset;
  3453. + minIndex = i;
  3454. + }
  3455. + }
  3456. +
  3457. + sortedFds.append(fds.at(minIndex));
  3458. + fds.remove_at(minIndex);
  3459. + }
  3460. +
  3461. +
  3462. + for (int i=0; i<sortedFds.length(); i++) {
  3463. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3464. +
  3465. + char found = 0;
  3466. + instanceKlass *cur_old_klass = old_klass;
  3467. + klassOop cur_old_klass_oop = old_klass_oop;
  3468. + while (true) {
  3469. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3470. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3471. + if (old_fd.is_static()) {
  3472. + continue;
  3473. + }
  3474. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3475. + found = 1;
  3476. + break;
  3477. + }
  3478. + }
  3479. + if (!found && cur_old_klass->super()) {
  3480. + cur_old_klass_oop = cur_old_klass->super();
  3481. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3482. + } else {
  3483. + break;
  3484. + }
  3485. + }
  3486. +
  3487. + if (found) {
  3488. + if (old_fd.offset() != fd.offset()) {
  3489. + _fields_not_changed = false;
  3490. + }
  3491. + cl->do_changed_field(&old_fd, &fd);
  3492. + } else {
  3493. + _fields_not_changed = false;
  3494. + cl->do_new_field(&fd);
  3495. + }
  3496. + }
  3497. + }
  3498. +}
  3499. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3500. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3501. @@ -1331,6 +1605,20 @@
  3502. return id;
  3503. }
  3504. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3505. + size_t idnum = (size_t)method->method_idnum();
  3506. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3507. + size_t length; // length assigned as debugging crumb
  3508. + jmethodID id = NULL;
  3509. + if (jmeths != NULL && // If there is a cache
  3510. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3511. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3512. + return true;
  3513. + }
  3514. +
  3515. + return false;
  3516. +}
  3517. +
  3518. // Cache an itable index
  3519. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3520. @@ -1490,6 +1778,13 @@
  3521. last = b;
  3522. b = b->next();
  3523. }
  3524. +
  3525. + // (tw) Hack as dependencies get wrong version of klassOop
  3526. + if(this->old_version() != NULL) {
  3527. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3528. + return;
  3529. + }
  3530. +
  3531. #ifdef ASSERT
  3532. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3533. nm->print();
  3534. @@ -2337,6 +2632,9 @@
  3535. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3536. st->print(BULLET"fake entry for mirror: ");
  3537. mirrored_klass->print_value_on(st);
  3538. + if (mirrored_klass != NULL) {
  3539. + st->print_cr("revision: %d (oldest=%d, newest=%d)", mirrored_klass->klass_part()->revision_number(), mirrored_klass->klass_part()->oldest_version()->klass_part()->revision_number(), mirrored_klass->klass_part()->newest_version()->klass_part()->revision_number());
  3540. + }
  3541. st->cr();
  3542. st->print(BULLET"fake entry resolved_constructor: ");
  3543. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3544. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3545. --- a/src/share/vm/oops/instanceKlass.hpp
  3546. +++ b/src/share/vm/oops/instanceKlass.hpp
  3547. @@ -99,6 +99,22 @@
  3548. virtual void do_field(fieldDescriptor* fd) = 0;
  3549. };
  3550. +// (tw) Iterates over the fields of the old and new class
  3551. +class FieldEvolutionClosure : public StackObj {
  3552. +public:
  3553. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3554. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3555. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3556. +};
  3557. +
  3558. +// (tw) Iterates over the methods of the old and new class
  3559. +class MethodEvolutionClosure : public StackObj {
  3560. +public:
  3561. + virtual void do_new_method(methodOop oop) = 0;
  3562. + virtual void do_old_method(methodOop oop) = 0;
  3563. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3564. +};
  3565. +
  3566. #ifndef PRODUCT
  3567. // Print fields.
  3568. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3569. @@ -264,6 +280,11 @@
  3570. // _idnum_allocated_count.
  3571. u1 _init_state; // state of class
  3572. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3573. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3574. + // information is cached.
  3575. + bool _fields_not_changed;
  3576. +
  3577. u1 _reference_type; // reference type
  3578. // embedded Java vtable follows here
  3579. @@ -397,6 +418,7 @@
  3580. // initialization (virtuals from Klass)
  3581. bool should_be_initialized() const; // means that initialize should be called
  3582. void initialize(TRAPS);
  3583. + void initialize_redefined_class();
  3584. void link_class(TRAPS);
  3585. bool link_class_or_fail(TRAPS); // returns false on failure
  3586. void unlink_class();
  3587. @@ -549,6 +571,7 @@
  3588. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3589. size_t *length_p, jmethodID* id_p);
  3590. jmethodID jmethod_id_or_null(methodOop method);
  3591. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3592. // cached itable index support
  3593. void set_cached_itable_index(size_t idnum, int index);
  3594. @@ -630,6 +653,7 @@
  3595. // subclass/subinterface checks
  3596. bool implements_interface(klassOop k) const;
  3597. + bool implements_interface_any_version(klassOop k) const;
  3598. // Access to implementors of an interface. We only store the count
  3599. // of implementors, and in case, there are only a few
  3600. @@ -659,6 +683,12 @@
  3601. void do_local_static_fields(FieldClosure* cl);
  3602. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3603. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3604. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3605. + void store_update_information(GrowableArray<int> &values);
  3606. + void clear_update_information();
  3607. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3608. + void clear_type_check_information();
  3609. +
  3610. void methods_do(void f(methodOop method));
  3611. void array_klasses_do(void f(klassOop k));
  3612. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3613. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3614. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3615. @@ -451,6 +451,28 @@
  3616. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3617. klassKlass::oop_print_on(obj, st);
  3618. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3619. +
  3620. + st->print(BULLET"revision: %d", ik->revision_number());
  3621. +
  3622. + if (ik->new_version() != NULL) {
  3623. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3624. + }
  3625. +
  3626. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3627. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3628. + }
  3629. +
  3630. + if (ik->old_version() != NULL) {
  3631. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3632. + }
  3633. +
  3634. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3635. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3636. + }
  3637. +
  3638. + st->cr();
  3639. +
  3640. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3641. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3642. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3643. @@ -636,7 +658,7 @@
  3644. }
  3645. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3646. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3647. - guarantee(sib->super() == super, "siblings should have same superklass");
  3648. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3649. sib = sib->next_sibling();
  3650. }
  3651. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3652. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3653. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3654. @@ -455,10 +455,13 @@
  3655. instanceKlass* ik = instanceKlass::cast(k);
  3656. // Check that we have the right class
  3657. - debug_only(static bool first_time = true);
  3658. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3659. - "Invalid update of maps");
  3660. - debug_only(first_time = false);
  3661. +
  3662. + // (tw) Asserts no longer valid for class redefinition
  3663. + // debug_only(static bool first_time = true);
  3664. +
  3665. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3666. + // "Invalid update of maps");
  3667. + //debug_only(first_time = false);
  3668. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3669. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3670. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3671. --- a/src/share/vm/oops/klass.cpp
  3672. +++ b/src/share/vm/oops/klass.cpp
  3673. @@ -54,6 +54,26 @@
  3674. return false;
  3675. }
  3676. +void Klass::update_supers_to_newest_version() {
  3677. +
  3678. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3679. +
  3680. + for (uint i=0; i<primary_super_limit(); i++) {
  3681. + klassOop cur = _primary_supers[i];
  3682. + if (cur != NULL) {
  3683. + _primary_supers[i] = cur->klass_part()->newest_version();
  3684. + }
  3685. + }
  3686. +
  3687. + // Scan the array-of-objects
  3688. + int cnt = secondary_supers()->length();
  3689. + for (int i = 0; i < cnt; i++) {
  3690. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3691. + if (cur != NULL) {
  3692. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3693. + }
  3694. + }
  3695. +}
  3696. bool Klass::search_secondary_supers(klassOop k) const {
  3697. // Put some extra logic here out-of-line, before the search proper.
  3698. // This cuts down the size of the inline method.
  3699. @@ -160,6 +180,16 @@
  3700. kl->set_alloc_size(0);
  3701. TRACE_SET_KLASS_TRACE_ID(kl, 0);
  3702. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3703. + kl->set_redefining(false);
  3704. + kl->set_new_version(NULL);
  3705. + kl->set_old_version(NULL);
  3706. + kl->set_redefinition_index(-1);
  3707. + kl->set_revision_number(-1);
  3708. + kl->set_field_redefinition_policy(DynamicCheck);
  3709. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3710. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3711. +
  3712. kl->set_prototype_header(markOopDesc::prototype());
  3713. kl->set_biased_lock_revocation_count(0);
  3714. kl->set_last_biased_lock_bulk_revocation_time(0);
  3715. @@ -232,7 +262,7 @@
  3716. set_super(NULL);
  3717. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3718. assert(super_depth() == 0, "Object must already be initialized properly");
  3719. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3720. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3721. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3722. "initialize this only once to a non-trivial value");
  3723. set_super(k);
  3724. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3725. --- a/src/share/vm/oops/klass.hpp
  3726. +++ b/src/share/vm/oops/klass.hpp
  3727. @@ -170,6 +170,7 @@
  3728. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3729. };
  3730. +template<class L, class R> class Pair;
  3731. class Klass : public Klass_vtbl {
  3732. friend class VMStructs;
  3733. @@ -222,6 +223,39 @@
  3734. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3735. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3736. + // (tw) Different class redefinition flags of code evolution.
  3737. + enum RedefinitionFlags {
  3738. +
  3739. + // This class is not redefined at all!
  3740. + NoRedefinition,
  3741. +
  3742. + // There are changes to the class meta data.
  3743. + ModifyClass = 1,
  3744. +
  3745. + // The size of the class meta data changes.
  3746. + ModifyClassSize = ModifyClass << 1,
  3747. +
  3748. + // There are change to the instance format.
  3749. + ModifyInstances = ModifyClassSize << 1,
  3750. +
  3751. + // The size of instances changes.
  3752. + ModifyInstanceSize = ModifyInstances << 1,
  3753. +
  3754. + // A super type of this class is removed.
  3755. + RemoveSuperType = ModifyInstanceSize << 1,
  3756. +
  3757. + // This class (or one of its super classes) has an instance transformer method.
  3758. + HasInstanceTransformer = RemoveSuperType << 1,
  3759. + };
  3760. +
  3761. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3762. + enum RedefinitionPolicy {
  3763. + StaticCheck,
  3764. + DynamicCheck,
  3765. + AccessDeletedMembers,
  3766. + AccessOldMembers
  3767. + };
  3768. +
  3769. protected:
  3770. //
  3771. // The oop block. All oop fields must be declared here and only oop fields
  3772. @@ -241,6 +275,10 @@
  3773. oop _java_mirror;
  3774. // Superclass
  3775. klassOop _super;
  3776. + // Old class
  3777. + klassOop _old_version;
  3778. + // New class
  3779. + klassOop _new_version;
  3780. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3781. klassOop _subklass;
  3782. // Sibling link (or NULL); links all subklasses of a klass
  3783. @@ -253,6 +291,19 @@
  3784. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3785. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3786. + // (tw) Non-oop fields for enhanced class redefinition
  3787. + jint _revision_number; // The revision number for redefined classes
  3788. + jint _redefinition_index; // Index of this class when performing the redefinition
  3789. + bool _subtype_changed;
  3790. + int _redefinition_flags; // Level of class redefinition
  3791. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3792. + int * _update_information; // Update information
  3793. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3794. + char _method_redefinition_policy;
  3795. + char _field_redefinition_policy;
  3796. + char _static_field_redefinition_policy;
  3797. + bool _is_redefining;
  3798. +
  3799. #ifndef PRODUCT
  3800. int _verify_count; // to avoid redundant verifies
  3801. #endif
  3802. @@ -301,6 +352,99 @@
  3803. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3804. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3805. + // BEGIN class redefinition utilities
  3806. +
  3807. + // double links between new and old version of a class
  3808. + klassOop old_version() const { return _old_version; }
  3809. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3810. + klassOop new_version() const { return _new_version; }
  3811. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3812. +
  3813. + // A subtype of this class is no longer a subtype
  3814. + bool has_subtype_changed() const { return _subtype_changed; }
  3815. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3816. + _subtype_changed = b; }
  3817. + // state of being redefined
  3818. + int redefinition_index() const { return _redefinition_index; }
  3819. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3820. + void set_redefining(bool b) { _is_redefining = b; }
  3821. + bool is_redefining() const { return _is_redefining; }
  3822. + int redefinition_flags() const { return _redefinition_flags; }
  3823. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3824. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3825. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3826. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3827. +
  3828. + // update information
  3829. + int *update_information() const { return _update_information; }
  3830. + void set_update_information(int *info) { _update_information = info; }
  3831. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3832. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3833. +
  3834. + bool is_same_or_older_version(klassOop klass) const {
  3835. + if (Klass::cast(klass) == this) { return true; }
  3836. + else if (_old_version == NULL) { return false; }
  3837. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3838. + }
  3839. +
  3840. + // Revision number for redefined classes, -1 for originally loaded classes
  3841. + jint revision_number() const {
  3842. + return _revision_number;
  3843. + }
  3844. +
  3845. + bool was_redefined() const {
  3846. + return _revision_number != -1;
  3847. + }
  3848. +
  3849. + void set_revision_number(jint number) {
  3850. + _revision_number = number;
  3851. + }
  3852. +
  3853. + char method_redefinition_policy() {
  3854. + return _method_redefinition_policy;
  3855. + }
  3856. +
  3857. + void set_method_redefinition_policy(char v) {
  3858. + _method_redefinition_policy = v;
  3859. + }
  3860. +
  3861. + char field_redefinition_policy() {
  3862. + return _field_redefinition_policy;
  3863. + }
  3864. +
  3865. + void set_field_redefinition_policy(char v) {
  3866. + _field_redefinition_policy = v;
  3867. + }
  3868. +
  3869. + char static_field_redefinition_policy() {
  3870. + return _static_field_redefinition_policy;
  3871. + }
  3872. +
  3873. + void set_static_field_redefinition_policy(char v) {
  3874. + _static_field_redefinition_policy = v;
  3875. + }
  3876. +
  3877. + klassOop oldest_version() const {
  3878. + if (_old_version == NULL) { return this->as_klassOop(); }
  3879. + else { return _old_version->klass_part()->oldest_version(); };
  3880. + }
  3881. +
  3882. + klassOop newest_version() const {
  3883. + if (_new_version == NULL) { return this->as_klassOop(); }
  3884. + else { return _new_version->klass_part()->newest_version(); };
  3885. + }
  3886. +
  3887. + klassOop active_version() const {
  3888. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3889. + else { return _new_version->klass_part()->active_version(); };
  3890. + }
  3891. +
  3892. + bool is_newest_version() const {
  3893. + return _new_version == NULL;
  3894. + }
  3895. +
  3896. + // END class redefinition utilities
  3897. +
  3898. objArrayOop secondary_supers() const { return _secondary_supers; }
  3899. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3900. @@ -361,6 +505,8 @@
  3901. void set_next_sibling(klassOop s);
  3902. oop* adr_super() const { return (oop*)&_super; }
  3903. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3904. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3905. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3906. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3907. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3908. @@ -490,6 +636,7 @@
  3909. return search_secondary_supers(k);
  3910. }
  3911. }
  3912. + void update_supers_to_newest_version();
  3913. bool search_secondary_supers(klassOop k) const;
  3914. // Find LCA in class hierarchy
  3915. @@ -818,6 +965,8 @@
  3916. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  3917. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  3918. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  3919. #endif // SHARE_VM_OOPS_KLASS_HPP
  3920. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3921. --- a/src/share/vm/oops/klassKlass.cpp
  3922. +++ b/src/share/vm/oops/klassKlass.cpp
  3923. @@ -68,6 +68,8 @@
  3924. Klass* k = Klass::cast(klassOop(obj));
  3925. // If we are alive it is valid to keep our superclass and subtype caches alive
  3926. MarkSweep::mark_and_push(k->adr_super());
  3927. + MarkSweep::mark_and_push(k->adr_old_version());
  3928. + MarkSweep::mark_and_push(k->adr_new_version());
  3929. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3930. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3931. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3932. @@ -87,6 +89,8 @@
  3933. Klass* k = Klass::cast(klassOop(obj));
  3934. // If we are alive it is valid to keep our superclass and subtype caches alive
  3935. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3936. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3937. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3938. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3939. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3940. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3941. @@ -106,6 +110,8 @@
  3942. int size = oop_size(obj);
  3943. Klass* k = Klass::cast(klassOop(obj));
  3944. blk->do_oop(k->adr_super());
  3945. + blk->do_oop(k->adr_old_version());
  3946. + blk->do_oop(k->adr_new_version());
  3947. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3948. blk->do_oop(k->adr_primary_supers()+i);
  3949. blk->do_oop(k->adr_secondary_super_cache());
  3950. @@ -134,6 +140,10 @@
  3951. oop* adr;
  3952. adr = k->adr_super();
  3953. if (mr.contains(adr)) blk->do_oop(adr);
  3954. + adr = k->adr_old_version();
  3955. + if (mr.contains(adr)) blk->do_oop(adr);
  3956. + adr = k->adr_new_version();
  3957. + if (mr.contains(adr)) blk->do_oop(adr);
  3958. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3959. adr = k->adr_primary_supers()+i;
  3960. if (mr.contains(adr)) blk->do_oop(adr);
  3961. @@ -147,6 +157,8 @@
  3962. // The following are "weak links" in the perm gen and are
  3963. // treated specially in a later phase of a perm gen collection.
  3964. assert(oop(k)->is_perm(), "should be in perm");
  3965. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  3966. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  3967. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  3968. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  3969. if (blk->should_remember_klasses()
  3970. @@ -167,6 +179,8 @@
  3971. Klass* k = Klass::cast(klassOop(obj));
  3972. MarkSweep::adjust_pointer(k->adr_super());
  3973. + MarkSweep::adjust_pointer(k->adr_new_version());
  3974. + MarkSweep::adjust_pointer(k->adr_old_version());
  3975. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3976. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3977. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3978. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  3979. --- a/src/share/vm/oops/klassOop.hpp
  3980. +++ b/src/share/vm/oops/klassOop.hpp
  3981. @@ -41,8 +41,10 @@
  3982. // returns the Klass part containing dispatching behavior
  3983. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  3984. - // Convenience wrapper
  3985. + // Convenience wrappers
  3986. inline oop java_mirror() const;
  3987. + inline klassOop old_version() const;
  3988. + inline klassOop new_version() const;
  3989. private:
  3990. // These have no implementation since klassOop should never be accessed in this fashion
  3991. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  3992. --- a/src/share/vm/oops/klassVtable.cpp
  3993. +++ b/src/share/vm/oops/klassVtable.cpp
  3994. @@ -97,7 +97,8 @@
  3995. vtable_length = Universe::base_vtable_size();
  3996. }
  3997. - if (super == NULL && !Universe::is_bootstrapping() &&
  3998. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  3999. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4000. vtable_length != Universe::base_vtable_size()) {
  4001. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4002. // only way this should happen is from
  4003. @@ -107,9 +108,9 @@
  4004. vtable_length = Universe::base_vtable_size();
  4005. }
  4006. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4007. - "bad vtable size for class Object");
  4008. + "bad vtable size for class Object");*/
  4009. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4010. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4011. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4012. }
  4013. int klassVtable::index_of(methodOop m, int len) const {
  4014. @@ -1186,6 +1187,7 @@
  4015. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4016. vtableEntry* vte = &vt->table()[index];
  4017. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4018. if (vte->method()->name() != table()[index].method()->name() ||
  4019. vte->method()->signature() != table()[index].method()->signature()) {
  4020. fatal("mismatched name/signature of vtable entries");
  4021. @@ -1205,6 +1207,8 @@
  4022. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4023. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4024. + // (tw) TODO: Check: Does not hold?
  4025. + if (method() != NULL) {
  4026. assert(method() != NULL, "must have set method");
  4027. method()->verify();
  4028. // we sub_type, because it could be a miranda method
  4029. @@ -1212,7 +1216,13 @@
  4030. #ifndef PRODUCT
  4031. print();
  4032. #endif
  4033. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4034. + klassOop first_klass = vt->klass()();
  4035. + klassOop second_klass = method()->method_holder();
  4036. + // (tw) the following fatal does not work for old versions of classes
  4037. + if (first_klass->klass_part()->is_newest_version()) {
  4038. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4039. + }
  4040. + }
  4041. }
  4042. }
  4043. @@ -1220,7 +1230,7 @@
  4044. void vtableEntry::print() {
  4045. ResourceMark rm;
  4046. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4047. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4048. if (Verbose) {
  4049. tty->print("m %#lx ", (address)method());
  4050. }
  4051. @@ -1292,7 +1302,7 @@
  4052. for (int i = 0; i < length(); i++) {
  4053. methodOop m = unchecked_method_at(i);
  4054. if (m != NULL) {
  4055. - if (m->is_old()) {
  4056. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4057. return false;
  4058. }
  4059. }
  4060. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4061. --- a/src/share/vm/oops/methodKlass.cpp
  4062. +++ b/src/share/vm/oops/methodKlass.cpp
  4063. @@ -93,6 +93,10 @@
  4064. m->set_adapter_entry(NULL);
  4065. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4066. + m->set_forward_method(NULL);
  4067. + m->set_new_version(NULL);
  4068. + m->set_old_version(NULL);
  4069. +
  4070. if (access_flags.is_native()) {
  4071. m->clear_native_function();
  4072. m->set_signature_handler(NULL);
  4073. @@ -127,6 +131,9 @@
  4074. // Performance tweak: We skip iterating over the klass pointer since we
  4075. // know that Universe::methodKlassObj never moves.
  4076. MarkSweep::mark_and_push(m->adr_constMethod());
  4077. + MarkSweep::mark_and_push(m->adr_forward_method());
  4078. + MarkSweep::mark_and_push(m->adr_new_version());
  4079. + MarkSweep::mark_and_push(m->adr_old_version());
  4080. MarkSweep::mark_and_push(m->adr_constants());
  4081. if (m->method_data() != NULL) {
  4082. MarkSweep::mark_and_push(m->adr_method_data());
  4083. @@ -141,6 +148,9 @@
  4084. // Performance tweak: We skip iterating over the klass pointer since we
  4085. // know that Universe::methodKlassObj never moves.
  4086. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4087. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4088. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4089. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4090. PSParallelCompact::mark_and_push(cm, m->adr_constants());
  4091. #ifdef COMPILER2
  4092. if (m->method_data() != NULL) {
  4093. @@ -159,6 +169,9 @@
  4094. // Performance tweak: We skip iterating over the klass pointer since we
  4095. // know that Universe::methodKlassObj never moves
  4096. blk->do_oop(m->adr_constMethod());
  4097. + blk->do_oop(m->adr_forward_method());
  4098. + blk->do_oop(m->adr_new_version());
  4099. + blk->do_oop(m->adr_old_version());
  4100. blk->do_oop(m->adr_constants());
  4101. if (m->method_data() != NULL) {
  4102. blk->do_oop(m->adr_method_data());
  4103. @@ -178,6 +191,12 @@
  4104. oop* adr;
  4105. adr = m->adr_constMethod();
  4106. if (mr.contains(adr)) blk->do_oop(adr);
  4107. + adr = m->adr_new_version();
  4108. + if (mr.contains(adr)) blk->do_oop(adr);
  4109. + adr = m->adr_forward_method();
  4110. + if (mr.contains(adr)) blk->do_oop(adr);
  4111. + adr = m->adr_old_version();
  4112. + if (mr.contains(adr)) blk->do_oop(adr);
  4113. adr = m->adr_constants();
  4114. if (mr.contains(adr)) blk->do_oop(adr);
  4115. if (m->method_data() != NULL) {
  4116. @@ -197,6 +216,9 @@
  4117. // Performance tweak: We skip iterating over the klass pointer since we
  4118. // know that Universe::methodKlassObj never moves.
  4119. MarkSweep::adjust_pointer(m->adr_constMethod());
  4120. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4121. + MarkSweep::adjust_pointer(m->adr_new_version());
  4122. + MarkSweep::adjust_pointer(m->adr_old_version());
  4123. MarkSweep::adjust_pointer(m->adr_constants());
  4124. if (m->method_data() != NULL) {
  4125. MarkSweep::adjust_pointer(m->adr_method_data());
  4126. @@ -213,6 +235,9 @@
  4127. assert(obj->is_method(), "should be method");
  4128. methodOop m = methodOop(obj);
  4129. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4130. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4131. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4132. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4133. PSParallelCompact::adjust_pointer(m->adr_constants());
  4134. #ifdef COMPILER2
  4135. if (m->method_data() != NULL) {
  4136. @@ -234,7 +259,18 @@
  4137. methodOop m = methodOop(obj);
  4138. // get the effect of PrintOopAddress, always, for methods:
  4139. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4140. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4141. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4142. +
  4143. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4144. + st->print(" (old)");
  4145. + }
  4146. + st->cr();
  4147. +
  4148. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4149. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4150. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4151. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4152. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4153. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4154. m->constants()->print_value_on(st); st->cr();
  4155. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4156. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4157. --- a/src/share/vm/oops/methodOop.cpp
  4158. +++ b/src/share/vm/oops/methodOop.cpp
  4159. @@ -328,6 +328,70 @@
  4160. }
  4161. +bool methodOopDesc::is_in_code_section(int bci) {
  4162. + // There is no table => every bci is in the code section table.
  4163. + if (!constMethod()->has_code_section_table()) return true;
  4164. +
  4165. + constMethodOop m = constMethod();
  4166. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4167. + u2 new_index = m->code_section_new_index_at(i);
  4168. + u2 length = m->code_section_length_at(i);
  4169. + if (bci >= new_index && bci < new_index + length) {
  4170. + // We are in a specified code section.
  4171. + return true;
  4172. + }
  4173. + }
  4174. +
  4175. + return false;
  4176. +}
  4177. +
  4178. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4179. + int original_bci = -1;
  4180. + if (constMethod()->has_code_section_table()) {
  4181. + assert(is_in_code_section(bci), "can only forward in section");
  4182. + // First calculate back to original bci.
  4183. + constMethodOop m = constMethod();
  4184. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4185. + u2 new_index = m->code_section_new_index_at(i);
  4186. + u2 original_index = m->code_section_original_index_at(i);
  4187. + u2 length = m->code_section_length_at(i);
  4188. + if (bci >= new_index && bci < new_index + length) {
  4189. + // We are in a specified code section.
  4190. + original_bci = bci - new_index + original_index;
  4191. + break;
  4192. + }
  4193. + }
  4194. + assert (original_bci != -1, "must have been in code section");
  4195. + } else {
  4196. + // No code sections specified => we are in an original method.
  4197. + original_bci = bci;
  4198. + }
  4199. +
  4200. + // We know the original bci => match to new method.
  4201. + int new_bci = -1;
  4202. + if (new_method->constMethod()->has_code_section_table()) {
  4203. + // Map to new bci.
  4204. + constMethodOop m = new_method->constMethod();
  4205. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4206. + u2 new_index = m->code_section_new_index_at(i);
  4207. + u2 original_index = m->code_section_original_index_at(i);
  4208. + u2 length = m->code_section_length_at(i);
  4209. + if (original_bci >= original_index && original_bci < original_index + length) {
  4210. + new_bci = original_bci - original_index + new_index;
  4211. + break;
  4212. + }
  4213. + }
  4214. + assert (new_bci != -1, "must have found new code section");
  4215. +
  4216. + } else {
  4217. + // We are in an original method.
  4218. + new_bci = original_bci;
  4219. + }
  4220. +
  4221. + return new_bci;
  4222. +}
  4223. +
  4224. +
  4225. int methodOopDesc::extra_stack_words() {
  4226. // not an inline function, to avoid a header dependency on Interpreter
  4227. return extra_stack_entries() * Interpreter::stackElementSize;
  4228. @@ -1079,6 +1143,9 @@
  4229. // Reset correct method/const method, method size, and parameter info
  4230. newcm->set_method(newm());
  4231. newm->set_constMethod(newcm);
  4232. + newm->set_forward_method(newm->forward_method());
  4233. + newm->set_new_version(newm->new_version());
  4234. + newm->set_old_version(newm->old_version());
  4235. assert(newcm->method() == newm(), "check");
  4236. newm->constMethod()->set_code_size(new_code_length);
  4237. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4238. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4239. --- a/src/share/vm/oops/methodOop.hpp
  4240. +++ b/src/share/vm/oops/methodOop.hpp
  4241. @@ -116,6 +116,11 @@
  4242. AccessFlags _access_flags; // Access flags
  4243. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4244. // note: can have vtables with >2**16 elements (because of inheritance)
  4245. + // (tw) Newer version of method available?
  4246. + methodOop _forward_method;
  4247. + methodOop _new_version;
  4248. + methodOop _old_version;
  4249. +
  4250. #ifdef CC_INTERP
  4251. int _result_index; // C++ interpreter needs for converting results to/from stack
  4252. #endif
  4253. @@ -174,6 +179,32 @@
  4254. int name_index() const { return constMethod()->name_index(); }
  4255. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4256. + methodOop forward_method() const {return _forward_method; }
  4257. + void set_forward_method(methodOop m) { _forward_method = m; }
  4258. + bool has_forward_method() const { return forward_method() != NULL; }
  4259. + methodOop new_version() const {return _new_version; }
  4260. + void set_new_version(methodOop m) { _new_version = m; }
  4261. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4262. +
  4263. + methodOop old_version() const {return _old_version; };
  4264. + void set_old_version(methodOop m) {
  4265. + if (m == NULL) {
  4266. + _old_version = NULL;
  4267. + return;
  4268. + }
  4269. +
  4270. + assert(_old_version == NULL, "may only be set once");
  4271. + assert(this->code_size() == m->code_size(), "must have same code length");
  4272. + _old_version = m;
  4273. + }
  4274. +
  4275. + methodOop oldest_version() const {
  4276. + if(_old_version == NULL) return (methodOop)this;
  4277. + else {
  4278. + return old_version()->oldest_version();
  4279. + }
  4280. + }
  4281. +
  4282. // signature
  4283. Symbol* signature() const { return _constants->symbol_at(signature_index()); }
  4284. int signature_index() const { return constMethod()->signature_index(); }
  4285. @@ -670,6 +701,10 @@
  4286. // Inline cache support
  4287. void cleanup_inline_caches();
  4288. + // (tw) Method forwarding support.
  4289. + bool is_in_code_section(int bci);
  4290. + int calculate_forward_bci(int bci, methodOop new_method);
  4291. +
  4292. // Find if klass for method is loaded
  4293. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4294. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4295. @@ -723,6 +758,9 @@
  4296. // Garbage collection support
  4297. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4298. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4299. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4300. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4301. oop* adr_constants() const { return (oop*)&_constants; }
  4302. oop* adr_method_data() const { return (oop*)&_method_data; }
  4303. };
  4304. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4305. --- a/src/share/vm/oops/oop.hpp
  4306. +++ b/src/share/vm/oops/oop.hpp
  4307. @@ -94,6 +94,7 @@
  4308. narrowOop* compressed_klass_addr();
  4309. void set_klass(klassOop k);
  4310. + void set_klass_no_check(klassOop k);
  4311. // For klass field compression
  4312. int klass_gap() const;
  4313. @@ -134,6 +135,7 @@
  4314. bool is_array() const;
  4315. bool is_objArray() const;
  4316. bool is_klass() const;
  4317. + bool is_instanceKlass() const;
  4318. bool is_thread() const;
  4319. bool is_method() const;
  4320. bool is_constMethod() const;
  4321. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4322. --- a/src/share/vm/oops/oop.inline.hpp
  4323. +++ b/src/share/vm/oops/oop.inline.hpp
  4324. @@ -115,6 +115,14 @@
  4325. }
  4326. }
  4327. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4328. + if (UseCompressedOops) {
  4329. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4330. + } else {
  4331. + oop_store_without_check(klass_addr(), (oop) k);
  4332. + }
  4333. +}
  4334. +
  4335. inline int oopDesc::klass_gap() const {
  4336. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4337. }
  4338. @@ -148,6 +156,7 @@
  4339. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4340. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4341. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4342. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4343. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4344. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4345. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4346. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4347. --- a/src/share/vm/prims/jni.cpp
  4348. +++ b/src/share/vm/prims/jni.cpp
  4349. @@ -405,7 +405,7 @@
  4350. }
  4351. }
  4352. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4353. - Handle(), &st, true,
  4354. + Handle(), &st, true, KlassHandle(),
  4355. CHECK_NULL);
  4356. if (TraceClassResolution && k != NULL) {
  4357. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4358. --- a/src/share/vm/prims/jvm.cpp
  4359. +++ b/src/share/vm/prims/jvm.cpp
  4360. @@ -866,7 +866,7 @@
  4361. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4362. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4363. protection_domain, &st,
  4364. - verify != 0,
  4365. + verify != 0, KlassHandle(),
  4366. CHECK_NULL);
  4367. if (TraceClassResolution && k != NULL) {
  4368. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4369. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4370. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4371. @@ -290,7 +290,10 @@
  4372. class_definitions[index].klass = jcls;
  4373. }
  4374. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4375. - VMThread::execute(&op);
  4376. + {
  4377. + MutexLocker sd_mutex(RedefineClasses_lock);
  4378. + VMThread::execute(&op);
  4379. + }
  4380. return (op.check_error());
  4381. } /* end RetransformClasses */
  4382. @@ -299,9 +302,12 @@
  4383. // class_definitions - pre-checked for NULL
  4384. jvmtiError
  4385. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4386. -//TODO: add locking
  4387. +
  4388. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4389. - VMThread::execute(&op);
  4390. + {
  4391. + MutexLocker sd_mutex(RedefineClasses_lock);
  4392. + VMThread::execute(&op);
  4393. + }
  4394. return (op.check_error());
  4395. } /* end RedefineClasses */
  4396. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4397. --- a/src/share/vm/prims/jvmtiExport.cpp
  4398. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4399. @@ -2307,7 +2307,7 @@
  4400. // iterate over any code blob descriptors collected and post a
  4401. // DYNAMIC_CODE_GENERATED event to the profiler.
  4402. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4403. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4404. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4405. // iterate over any code blob descriptors that we collected
  4406. if (_code_blobs != NULL) {
  4407. for (int i=0; i<_code_blobs->length(); i++) {
  4408. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4409. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4410. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4411. @@ -286,6 +286,8 @@
  4412. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4413. ((methodOopDesc*)_method->*meth_act)(_bci);
  4414. + // DCEVM: TODO: Check how we can implement this differently here!
  4415. +
  4416. // add/remove breakpoint to/from versions of the method that
  4417. // are EMCP. Directly or transitively obsolete methods are
  4418. // not saved in the PreviousVersionInfo.
  4419. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4420. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4421. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4422. @@ -30,491 +30,637 @@
  4423. #include "interpreter/rewriter.hpp"
  4424. #include "memory/gcLocker.hpp"
  4425. #include "memory/universe.inline.hpp"
  4426. +#include "memory/cardTableRS.hpp"
  4427. +#include "oops/klassVtable.hpp"
  4428. #include "oops/fieldStreams.hpp"
  4429. -#include "oops/klassVtable.hpp"
  4430. #include "prims/jvmtiImpl.hpp"
  4431. #include "prims/jvmtiRedefineClasses.hpp"
  4432. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4433. #include "prims/methodComparator.hpp"
  4434. #include "runtime/deoptimization.hpp"
  4435. #include "runtime/relocator.hpp"
  4436. #include "utilities/bitMap.inline.hpp"
  4437. +#include "compiler/compileBroker.hpp"
  4438. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4439. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4440. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4441. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4442. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4443. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4444. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4445. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4446. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4447. +int* VM_RedefineClasses::_added_methods = NULL;
  4448. int VM_RedefineClasses::_matching_methods_length = 0;
  4449. int VM_RedefineClasses::_deleted_methods_length = 0;
  4450. int VM_RedefineClasses::_added_methods_length = 0;
  4451. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4452. -
  4453. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4454. - const jvmtiClassDefinition *class_defs,
  4455. - JvmtiClassLoadKind class_load_kind) {
  4456. +// Holds the revision number of the current class redefinition
  4457. +int VM_RedefineClasses::_revision_number = -1;
  4458. +
  4459. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4460. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4461. + RC_TIMER_START(_timer_total);
  4462. _class_count = class_count;
  4463. _class_defs = class_defs;
  4464. _class_load_kind = class_load_kind;
  4465. - _res = JVMTI_ERROR_NONE;
  4466. + _updated_oops = NULL;
  4467. + _result = JVMTI_ERROR_NONE;
  4468. }
  4469. +VM_RedefineClasses::~VM_RedefineClasses() {
  4470. + {
  4471. + MonitorLockerEx ml(RedefinitionSync_lock);
  4472. + Threads::set_wait_at_instrumentation_entry(false);
  4473. + ml.notify_all();
  4474. + }
  4475. +
  4476. + unlock_threads();
  4477. + RC_TIMER_STOP(_timer_total);
  4478. +
  4479. + if (TimeRedefineClasses) {
  4480. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4481. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4482. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4483. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4484. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4485. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4486. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4487. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4488. + tty->print_cr("------------------------------------------------------------------");
  4489. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4490. + }
  4491. +}
  4492. +
  4493. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4494. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4495. +
  4496. + // Create array with all classes for which the redefine command was given
  4497. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4498. + for (int i=0; i<_class_count; i++) {
  4499. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4500. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4501. + klasses_to_redefine.append(klass_handle);
  4502. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4503. + }
  4504. +
  4505. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4506. + GrowableArray<instanceKlassHandle> affected_classes;
  4507. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4508. +
  4509. + // Trace affected classes
  4510. + if (RC_TRACE_ENABLED(0x00000001)) {
  4511. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4512. + affected_classes.length()));
  4513. + for (int i=0; i<affected_classes.length(); i++) {
  4514. + RC_TRACE(0x00000001, ("%s",
  4515. + affected_classes.at(i)->name()->as_C_string()));
  4516. + }
  4517. + }
  4518. +
  4519. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4520. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4521. + all_affected_klasses->appendAll(&affected_classes);
  4522. +
  4523. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4524. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4525. + if (RC_TRACE_ENABLED(0x00000001)) {
  4526. + RC_TRACE(0x00000001, ("Redefine order: "));
  4527. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4528. + RC_TRACE(0x00000001, ("%s",
  4529. + all_affected_klasses->at(i)->name()->as_C_string()));
  4530. + }
  4531. + }
  4532. +
  4533. + return result;
  4534. +}
  4535. +
  4536. +// Searches for the class bytes of the given class and returns them as a byte array.
  4537. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4538. +
  4539. + *not_changed = false;
  4540. +
  4541. + // Search for the index in the redefinition array that corresponds to the current class
  4542. + int j;
  4543. + for (j=0; j<_class_count; j++) {
  4544. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4545. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4546. + if (the_class_oop == the_class()) {
  4547. + break;
  4548. + }
  4549. + }
  4550. +
  4551. + if (j == _class_count) {
  4552. +
  4553. + *not_changed = true;
  4554. +
  4555. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4556. + // so the user did not specify a different bytecode for that class.
  4557. +
  4558. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4559. + // not cached, we need to reconstitute the class file from VM representation
  4560. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4561. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4562. +
  4563. + JvmtiClassFileReconstituter reconstituter(the_class);
  4564. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4565. + return reconstituter.get_error();
  4566. + }
  4567. +
  4568. + *class_byte_count = (jint)reconstituter.class_file_size();
  4569. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4570. +
  4571. + } else {
  4572. +
  4573. + // it is cached, get it from the cache
  4574. + *class_byte_count = the_class->get_cached_class_file_len();
  4575. + *class_bytes = the_class->get_cached_class_file_bytes();
  4576. + }
  4577. +
  4578. + } else {
  4579. +
  4580. + // Redefine with bytecodes at index j
  4581. + *class_bytes = _class_defs[j].class_bytes;
  4582. + *class_byte_count = _class_defs[j].class_byte_count;
  4583. + }
  4584. +
  4585. + return JVMTI_ERROR_NONE;
  4586. +}
  4587. +
  4588. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4589. bool VM_RedefineClasses::doit_prologue() {
  4590. - if (_class_count == 0) {
  4591. - _res = JVMTI_ERROR_NONE;
  4592. +
  4593. + _revision_number++;
  4594. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4595. +
  4596. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4597. + RC_TIMER_START(_timer_prologue);
  4598. +
  4599. + if (!check_arguments()) {
  4600. + RC_TIMER_STOP(_timer_prologue);
  4601. return false;
  4602. }
  4603. - if (_class_defs == NULL) {
  4604. - _res = JVMTI_ERROR_NULL_POINTER;
  4605. +
  4606. + // We first load new class versions in the prologue, because somewhere down the
  4607. + // call chain it is required that the current thread is a Java thread.
  4608. + _new_classes = new (ResourceObj::C_HEAP) GrowableArray<instanceKlassHandle>(5, true);
  4609. + _result = load_new_class_versions(Thread::current());
  4610. +
  4611. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4612. + if (_result != JVMTI_ERROR_NONE) {
  4613. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4614. + delete _new_classes;
  4615. + _new_classes = NULL;
  4616. + RC_TIMER_STOP(_timer_prologue);
  4617. return false;
  4618. }
  4619. +
  4620. + RC_TRACE(0x00000001, ("nearly finished"));
  4621. + VM_GC_Operation::doit_prologue();
  4622. + RC_TIMER_STOP(_timer_prologue);
  4623. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4624. + return true;
  4625. +}
  4626. +
  4627. +// Checks basic properties of the arguments of the redefinition command.
  4628. +bool VM_RedefineClasses::check_arguments() {
  4629. +
  4630. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4631. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4632. for (int i = 0; i < _class_count; i++) {
  4633. - if (_class_defs[i].klass == NULL) {
  4634. - _res = JVMTI_ERROR_INVALID_CLASS;
  4635. - return false;
  4636. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4637. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4638. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4639. + }
  4640. +
  4641. + return true;
  4642. +}
  4643. +
  4644. +jvmtiError VM_RedefineClasses::check_exception() const {
  4645. + Thread* THREAD = Thread::current();
  4646. + if (HAS_PENDING_EXCEPTION) {
  4647. +
  4648. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4649. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4650. + ex_name->as_C_string()));
  4651. + if (TraceRedefineClasses >= 1) {
  4652. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4653. + tty->print_cr("");
  4654. }
  4655. - if (_class_defs[i].class_byte_count == 0) {
  4656. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4657. - return false;
  4658. - }
  4659. - if (_class_defs[i].class_bytes == NULL) {
  4660. - _res = JVMTI_ERROR_NULL_POINTER;
  4661. - return false;
  4662. + CLEAR_PENDING_EXCEPTION;
  4663. +
  4664. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4665. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4666. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4667. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4668. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4669. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4670. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4671. + // The message will be "XXX (wrong name: YYY)"
  4672. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4673. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4674. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4675. + } else {
  4676. + // Just in case more exceptions can be thrown..
  4677. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4678. }
  4679. }
  4680. - // Start timer after all the sanity checks; not quite accurate, but
  4681. - // better than adding a bunch of stop() calls.
  4682. - RC_TIMER_START(_timer_vm_op_prologue);
  4683. -
  4684. - // We first load new class versions in the prologue, because somewhere down the
  4685. - // call chain it is required that the current thread is a Java thread.
  4686. - _res = load_new_class_versions(Thread::current());
  4687. - if (_res != JVMTI_ERROR_NONE) {
  4688. - // Free os::malloc allocated memory in load_new_class_version.
  4689. - os::free(_scratch_classes);
  4690. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4691. - return false;
  4692. + return JVMTI_ERROR_NONE;
  4693. +}
  4694. +
  4695. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4696. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4697. +
  4698. + ResourceMark rm(THREAD);
  4699. +
  4700. + RC_TRACE(0x00000001, ("==================================================================="));
  4701. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  4702. + _class_count));
  4703. +
  4704. + // Retrieve an array of all classes that need to be redefined
  4705. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4706. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4707. + if (err != JVMTI_ERROR_NONE) {
  4708. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  4709. + (int)err));
  4710. + return err;
  4711. }
  4712. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4713. - return true;
  4714. -}
  4715. -
  4716. -void VM_RedefineClasses::doit() {
  4717. - Thread *thread = Thread::current();
  4718. -
  4719. - if (UseSharedSpaces) {
  4720. - // Sharing is enabled so we remap the shared readonly space to
  4721. - // shared readwrite, private just in case we need to redefine
  4722. - // a shared class. We do the remap during the doit() phase of
  4723. - // the safepoint to be safer.
  4724. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4725. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4726. - ("failed to remap shared readonly space to readwrite, private"));
  4727. - _res = JVMTI_ERROR_INTERNAL;
  4728. - return;
  4729. +
  4730. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4731. +
  4732. + _max_redefinition_flags = Klass::NoRedefinition;
  4733. + jvmtiError result = JVMTI_ERROR_NONE;
  4734. +
  4735. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4736. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  4737. + i+1, all_affected_klasses.length()));
  4738. +
  4739. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4740. + RC_TRACE(0x00000002, ("name=%s",
  4741. + the_class->name()->as_C_string()));
  4742. +
  4743. + the_class->link_class(THREAD);
  4744. + result = check_exception();
  4745. + if (result != JVMTI_ERROR_NONE) break;
  4746. +
  4747. + // Find new class bytes
  4748. + const unsigned char* class_bytes;
  4749. + jint class_byte_count;
  4750. + jvmtiError error;
  4751. + jboolean not_changed;
  4752. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4753. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  4754. + (int)error));
  4755. + result = error;
  4756. + break;
  4757. + }
  4758. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4759. +
  4760. +
  4761. + // Set redefined class handle in JvmtiThreadState class.
  4762. + // This redefined class is sent to agent event handler for class file
  4763. + // load hook event.
  4764. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4765. +
  4766. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  4767. +
  4768. + RC_TIMER_STOP(_timer_prologue);
  4769. + RC_TIMER_START(_timer_class_loading);
  4770. +
  4771. +
  4772. + // Parse the stream.
  4773. + Handle the_class_loader(THREAD, the_class->class_loader());
  4774. + Handle protection_domain(THREAD, the_class->protection_domain());
  4775. + Symbol* the_class_sym = the_class->name();
  4776. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4777. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  4778. + the_class_loader,
  4779. + protection_domain,
  4780. + &st,
  4781. + true,
  4782. + the_class,
  4783. + THREAD));
  4784. +
  4785. + not_changed = false;
  4786. +
  4787. + RC_TIMER_STOP(_timer_class_loading);
  4788. + RC_TIMER_START(_timer_prologue);
  4789. +
  4790. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  4791. + // Clear class_being_redefined just to be sure.
  4792. + state->clear_class_being_redefined();
  4793. +
  4794. + result = check_exception();
  4795. + if (result != JVMTI_ERROR_NONE) break;
  4796. +
  4797. +#ifdef ASSERT
  4798. +
  4799. + assert(new_class() != NULL, "Class could not be loaded!");
  4800. + assert(new_class() != the_class(), "must be different");
  4801. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4802. +
  4803. +
  4804. + objArrayOop k_interfaces = new_class->local_interfaces();
  4805. + for (int j=0; j<k_interfaces->length(); j++) {
  4806. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4807. + }
  4808. +
  4809. + if (!THREAD->is_Compiler_thread()) {
  4810. +
  4811. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  4812. + the_class->name()->as_C_string(),
  4813. + (address)(the_class->class_loader()),
  4814. + (address)(the_class->protection_domain())));
  4815. + // If we are on the compiler thread, we must not try to resolve a class.
  4816. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4817. +
  4818. + if (systemLookup != NULL) {
  4819. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4820. +
  4821. +
  4822. + Klass *subklass = new_class()->klass_part()->subklass();
  4823. + while (subklass != NULL) {
  4824. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4825. + subklass = subklass->next_sibling();
  4826. + }
  4827. + } else {
  4828. + // This can happen for reflection generated classes.. ?
  4829. + CLEAR_PENDING_EXCEPTION;
  4830. + }
  4831. + }
  4832. +
  4833. +#endif
  4834. +
  4835. + if (RC_TRACE_ENABLED(0x00000001)) {
  4836. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4837. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  4838. + new_class->name()->as_C_string(),
  4839. + new_class->layout_helper(),
  4840. + the_class->layout_helper()));
  4841. + }
  4842. + }
  4843. +
  4844. + // Set the new version of the class
  4845. + new_class->set_revision_number(_revision_number);
  4846. + new_class->set_redefinition_index(i);
  4847. + the_class->set_new_version(new_class());
  4848. + _new_classes->append(new_class);
  4849. +
  4850. + assert(new_class->new_version() == NULL, "");
  4851. +
  4852. + int redefinition_flags = Klass::NoRedefinition;
  4853. +
  4854. + if (not_changed) {
  4855. + redefinition_flags = Klass::NoRedefinition;
  4856. + } else if (AllowAdvancedClassRedefinition) {
  4857. + redefinition_flags = calculate_redefinition_flags(new_class);
  4858. + } else {
  4859. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4860. + if (allowed != JVMTI_ERROR_NONE) {
  4861. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  4862. + result = allowed;
  4863. + break;
  4864. + }
  4865. + redefinition_flags = Klass::ModifyClass;
  4866. + }
  4867. +
  4868. + if (new_class->super() != NULL) {
  4869. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4870. + }
  4871. +
  4872. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4873. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4874. + }
  4875. +
  4876. + new_class->set_redefinition_flags(redefinition_flags);
  4877. +
  4878. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4879. +
  4880. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4881. + // TODO: Check if watch access flags of static fields are updated correctly.
  4882. + calculate_instance_update_information(_new_classes->at(i)());
  4883. + } else {
  4884. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4885. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4886. +
  4887. + fieldDescriptor fd_new;
  4888. + fieldDescriptor fd_old;
  4889. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  4890. + fd_new.initialize(new_class(), fs.index());
  4891. + fd_old.initialize(new_class->old_version(), fs.index());
  4892. + transfer_special_access_flags(&fd_old, &fd_new);
  4893. + }
  4894. + }
  4895. +
  4896. + if (RC_TRACE_ENABLED(0x00000008)) {
  4897. + if (new_class->super() != NULL) {
  4898. + RC_TRACE(0x00000008, ("Super class is %s",
  4899. + new_class->super()->klass_part()->name()->as_C_string()));
  4900. + }
  4901. + }
  4902. +
  4903. +#ifdef ASSERT
  4904. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4905. +
  4906. + the_class->vtable()->verify(tty);
  4907. + new_class->vtable()->verify(tty);
  4908. +#endif
  4909. +
  4910. + RC_TRACE(0x00000002, ("Verification done!"));
  4911. +
  4912. + if (i == all_affected_klasses.length() - 1) {
  4913. +
  4914. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4915. +
  4916. + RC_TIMER_STOP(_timer_prologue);
  4917. + lock_threads();
  4918. + RC_TIMER_START(_timer_prologue);
  4919. +
  4920. + for (int j=0; j<all_affected_klasses.length(); j++) {
  4921. +
  4922. + klassOop initial_klass = all_affected_klasses.at(j)();
  4923. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4924. + Klass *cur_klass = initial_subklass;
  4925. + while(cur_klass != NULL) {
  4926. +
  4927. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  4928. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4929. + if (!all_affected_klasses.contains(handle)) {
  4930. +
  4931. + int k = i + 1;
  4932. + for (; k<all_affected_klasses.length(); k++) {
  4933. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4934. + break;
  4935. + }
  4936. + }
  4937. + all_affected_klasses.insert_before(k, handle);
  4938. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  4939. + cur_klass->name()->as_C_string()));
  4940. + }
  4941. + }
  4942. +
  4943. + cur_klass = cur_klass->next_sibling();
  4944. + }
  4945. + }
  4946. +
  4947. + int new_count = all_affected_klasses.length() - 1 - i;
  4948. + if (new_count != 0) {
  4949. +
  4950. + unlock_threads();
  4951. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  4952. + new_count));
  4953. + }
  4954. }
  4955. }
  4956. - for (int i = 0; i < _class_count; i++) {
  4957. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4958. + if (result != JVMTI_ERROR_NONE) {
  4959. + rollback();
  4960. + return result;
  4961. }
  4962. - // Disable any dependent concurrent compilations
  4963. - SystemDictionary::notice_modification();
  4964. -
  4965. - // Set flag indicating that some invariants are no longer true.
  4966. - // See jvmtiExport.hpp for detailed explanation.
  4967. - JvmtiExport::set_has_redefined_a_class();
  4968. +
  4969. + RC_TIMER_STOP(_timer_prologue);
  4970. + RC_TIMER_START(_timer_class_linking);
  4971. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4972. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4973. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4974. + instanceKlassHandle new_class(the_class->new_version());
  4975. +
  4976. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  4977. + i,
  4978. + all_affected_klasses.length(),
  4979. + the_class->name()->as_C_string()));
  4980. + new_class->link_class(THREAD);
  4981. +
  4982. + result = check_exception();
  4983. + if (result != JVMTI_ERROR_NONE) break;
  4984. + }
  4985. + RC_TIMER_STOP(_timer_class_linking);
  4986. + RC_TIMER_START(_timer_prologue);
  4987. +
  4988. + if (result != JVMTI_ERROR_NONE) {
  4989. + rollback();
  4990. + return result;
  4991. + }
  4992. +
  4993. + RC_TRACE(0x00000002, ("All classes loaded!"));
  4994. #ifdef ASSERT
  4995. - SystemDictionary::classes_do(check_class, thread);
  4996. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4997. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4998. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4999. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5000. + assert(new_version->new_version() == NULL, "Must be newest version");
  5001. +
  5002. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5003. + new_version()->print();
  5004. + new_version->super()->print();
  5005. + }
  5006. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5007. + }
  5008. +
  5009. + SystemDictionary::classes_do(check_class, THREAD);
  5010. +
  5011. #endif
  5012. +
  5013. + RC_TRACE(0x00000001, ("Finished verification!"));
  5014. + return JVMTI_ERROR_NONE;
  5015. }
  5016. -void VM_RedefineClasses::doit_epilogue() {
  5017. - // Free os::malloc allocated memory.
  5018. - // The memory allocated in redefine will be free'ed in next VM operation.
  5019. - os::free(_scratch_classes);
  5020. -
  5021. - if (RC_TRACE_ENABLED(0x00000004)) {
  5022. - // Used to have separate timers for "doit" and "all", but the timer
  5023. - // overhead skewed the measurements.
  5024. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  5025. - _timer_rsc_phase2.milliseconds();
  5026. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  5027. -
  5028. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  5029. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  5030. - _timer_vm_op_prologue.milliseconds(), doit_time));
  5031. - RC_TRACE(0x00000004,
  5032. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  5033. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  5034. +void VM_RedefineClasses::lock_threads() {
  5035. +
  5036. + RC_TIMER_START(_timer_wait_for_locks);
  5037. +
  5038. +
  5039. + JavaThread *javaThread = Threads::first();
  5040. + while (javaThread != NULL) {
  5041. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5042. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5043. + compilerThread->set_should_bailout(true);
  5044. + }
  5045. + javaThread = javaThread->next();
  5046. }
  5047. +
  5048. + int cnt = 0;
  5049. + javaThread = Threads::first();
  5050. + while (javaThread != NULL) {
  5051. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5052. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5053. + compilerThread->compilation_mutex()->lock();
  5054. + cnt++;
  5055. + }
  5056. + javaThread = javaThread->next();
  5057. + }
  5058. +
  5059. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5060. +
  5061. + cnt = 0;
  5062. + javaThread = Threads::first();
  5063. + while (javaThread != NULL) {
  5064. + if (javaThread != Thread::current()) {
  5065. + javaThread->redefine_classes_mutex()->lock();
  5066. + }
  5067. + javaThread = javaThread->next();
  5068. + }
  5069. +
  5070. +
  5071. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5072. +
  5073. + RC_TIMER_STOP(_timer_wait_for_locks);
  5074. }
  5075. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  5076. - // classes for primitives cannot be redefined
  5077. - if (java_lang_Class::is_primitive(klass_mirror)) {
  5078. - return false;
  5079. +void VM_RedefineClasses::unlock_threads() {
  5080. +
  5081. + int cnt = 0;
  5082. + JavaThread *javaThread = Threads::first();
  5083. + Thread *thread = Thread::current();
  5084. + while (javaThread != NULL) {
  5085. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5086. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5087. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5088. + compilerThread->compilation_mutex()->unlock();
  5089. + cnt++;
  5090. + }
  5091. + }
  5092. + javaThread = javaThread->next();
  5093. }
  5094. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  5095. - // classes for arrays cannot be redefined
  5096. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  5097. - return false;
  5098. +
  5099. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5100. +
  5101. + cnt = 0;
  5102. + javaThread = Threads::first();
  5103. + while (javaThread != NULL) {
  5104. + if (javaThread != Thread::current()) {
  5105. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5106. + javaThread->redefine_classes_mutex()->unlock();
  5107. + }
  5108. + }
  5109. + javaThread = javaThread->next();
  5110. }
  5111. - return true;
  5112. +
  5113. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5114. }
  5115. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  5116. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  5117. -// direct CP entries, there is just the current entry to append. For
  5118. -// indirect and double-indirect CP entries, there are zero or more
  5119. -// referenced CP entries along with the current entry to append.
  5120. -// Indirect and double-indirect CP entries are handled by recursive
  5121. -// calls to append_entry() as needed. The referenced CP entries are
  5122. -// always appended to *merge_cp_p before the referee CP entry. These
  5123. -// referenced CP entries may already exist in *merge_cp_p in which case
  5124. -// there is nothing extra to append and only the current entry is
  5125. -// appended.
  5126. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  5127. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  5128. - TRAPS) {
  5129. -
  5130. - // append is different depending on entry tag type
  5131. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5132. -
  5133. - // The old verifier is implemented outside the VM. It loads classes,
  5134. - // but does not resolve constant pool entries directly so we never
  5135. - // see Class entries here with the old verifier. Similarly the old
  5136. - // verifier does not like Class entries in the input constant pool.
  5137. - // The split-verifier is implemented in the VM so it can optionally
  5138. - // and directly resolve constant pool entries to load classes. The
  5139. - // split-verifier can accept either Class entries or UnresolvedClass
  5140. - // entries in the input constant pool. We revert the appended copy
  5141. - // back to UnresolvedClass so that either verifier will be happy
  5142. - // with the constant pool entry.
  5143. - case JVM_CONSTANT_Class:
  5144. - {
  5145. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5146. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  5147. - scratch_cp->klass_name_at(scratch_i));
  5148. -
  5149. - if (scratch_i != *merge_cp_length_p) {
  5150. - // The new entry in *merge_cp_p is at a different index than
  5151. - // the new entry in scratch_cp so we need to map the index values.
  5152. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5153. - }
  5154. - (*merge_cp_length_p)++;
  5155. - } break;
  5156. -
  5157. - // these are direct CP entries so they can be directly appended,
  5158. - // but double and long take two constant pool entries
  5159. - case JVM_CONSTANT_Double: // fall through
  5160. - case JVM_CONSTANT_Long:
  5161. - {
  5162. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5163. - THREAD);
  5164. -
  5165. - if (scratch_i != *merge_cp_length_p) {
  5166. - // The new entry in *merge_cp_p is at a different index than
  5167. - // the new entry in scratch_cp so we need to map the index values.
  5168. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5169. - }
  5170. - (*merge_cp_length_p) += 2;
  5171. - } break;
  5172. -
  5173. - // these are direct CP entries so they can be directly appended
  5174. - case JVM_CONSTANT_Float: // fall through
  5175. - case JVM_CONSTANT_Integer: // fall through
  5176. - case JVM_CONSTANT_Utf8: // fall through
  5177. -
  5178. - // This was an indirect CP entry, but it has been changed into
  5179. - // an interned string so this entry can be directly appended.
  5180. - case JVM_CONSTANT_String: // fall through
  5181. -
  5182. - // These were indirect CP entries, but they have been changed into
  5183. - // Symbol*s so these entries can be directly appended.
  5184. - case JVM_CONSTANT_UnresolvedClass: // fall through
  5185. - case JVM_CONSTANT_UnresolvedString:
  5186. - {
  5187. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5188. - THREAD);
  5189. -
  5190. - if (scratch_i != *merge_cp_length_p) {
  5191. - // The new entry in *merge_cp_p is at a different index than
  5192. - // the new entry in scratch_cp so we need to map the index values.
  5193. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5194. - }
  5195. - (*merge_cp_length_p)++;
  5196. - } break;
  5197. -
  5198. - // this is an indirect CP entry so it needs special handling
  5199. - case JVM_CONSTANT_NameAndType:
  5200. - {
  5201. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  5202. - int new_name_ref_i = 0;
  5203. - bool match = (name_ref_i < *merge_cp_length_p) &&
  5204. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  5205. - THREAD);
  5206. - if (!match) {
  5207. - // forward reference in *merge_cp_p or not a direct match
  5208. -
  5209. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  5210. - THREAD);
  5211. - if (found_i != 0) {
  5212. - guarantee(found_i != name_ref_i,
  5213. - "compare_entry_to() and find_matching_entry() do not agree");
  5214. -
  5215. - // Found a matching entry somewhere else in *merge_cp_p so
  5216. - // just need a mapping entry.
  5217. - new_name_ref_i = found_i;
  5218. - map_index(scratch_cp, name_ref_i, found_i);
  5219. - } else {
  5220. - // no match found so we have to append this entry to *merge_cp_p
  5221. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  5222. - THREAD);
  5223. - // The above call to append_entry() can only append one entry
  5224. - // so the post call query of *merge_cp_length_p is only for
  5225. - // the sake of consistency.
  5226. - new_name_ref_i = *merge_cp_length_p - 1;
  5227. - }
  5228. - }
  5229. -
  5230. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5231. - int new_signature_ref_i = 0;
  5232. - match = (signature_ref_i < *merge_cp_length_p) &&
  5233. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  5234. - signature_ref_i, THREAD);
  5235. - if (!match) {
  5236. - // forward reference in *merge_cp_p or not a direct match
  5237. -
  5238. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  5239. - *merge_cp_p, THREAD);
  5240. - if (found_i != 0) {
  5241. - guarantee(found_i != signature_ref_i,
  5242. - "compare_entry_to() and find_matching_entry() do not agree");
  5243. -
  5244. - // Found a matching entry somewhere else in *merge_cp_p so
  5245. - // just need a mapping entry.
  5246. - new_signature_ref_i = found_i;
  5247. - map_index(scratch_cp, signature_ref_i, found_i);
  5248. - } else {
  5249. - // no match found so we have to append this entry to *merge_cp_p
  5250. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  5251. - merge_cp_length_p, THREAD);
  5252. - // The above call to append_entry() can only append one entry
  5253. - // so the post call query of *merge_cp_length_p is only for
  5254. - // the sake of consistency.
  5255. - new_signature_ref_i = *merge_cp_length_p - 1;
  5256. - }
  5257. - }
  5258. -
  5259. - // If the referenced entries already exist in *merge_cp_p, then
  5260. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5261. - // In that case, all we are appending is the current entry.
  5262. - if (new_name_ref_i == 0) {
  5263. - new_name_ref_i = name_ref_i;
  5264. - } else {
  5265. - RC_TRACE(0x00080000,
  5266. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5267. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5268. - }
  5269. - if (new_signature_ref_i == 0) {
  5270. - new_signature_ref_i = signature_ref_i;
  5271. - } else {
  5272. - RC_TRACE(0x00080000,
  5273. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5274. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5275. - }
  5276. -
  5277. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5278. - new_name_ref_i, new_signature_ref_i);
  5279. - if (scratch_i != *merge_cp_length_p) {
  5280. - // The new entry in *merge_cp_p is at a different index than
  5281. - // the new entry in scratch_cp so we need to map the index values.
  5282. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5283. - }
  5284. - (*merge_cp_length_p)++;
  5285. - } break;
  5286. -
  5287. - // this is a double-indirect CP entry so it needs special handling
  5288. - case JVM_CONSTANT_Fieldref: // fall through
  5289. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5290. - case JVM_CONSTANT_Methodref:
  5291. - {
  5292. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5293. - int new_klass_ref_i = 0;
  5294. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  5295. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  5296. - THREAD);
  5297. - if (!match) {
  5298. - // forward reference in *merge_cp_p or not a direct match
  5299. -
  5300. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  5301. - THREAD);
  5302. - if (found_i != 0) {
  5303. - guarantee(found_i != klass_ref_i,
  5304. - "compare_entry_to() and find_matching_entry() do not agree");
  5305. -
  5306. - // Found a matching entry somewhere else in *merge_cp_p so
  5307. - // just need a mapping entry.
  5308. - new_klass_ref_i = found_i;
  5309. - map_index(scratch_cp, klass_ref_i, found_i);
  5310. - } else {
  5311. - // no match found so we have to append this entry to *merge_cp_p
  5312. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  5313. - THREAD);
  5314. - // The above call to append_entry() can only append one entry
  5315. - // so the post call query of *merge_cp_length_p is only for
  5316. - // the sake of consistency. Without the optimization where we
  5317. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  5318. - // could be appended.
  5319. - new_klass_ref_i = *merge_cp_length_p - 1;
  5320. - }
  5321. - }
  5322. -
  5323. - int name_and_type_ref_i =
  5324. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5325. - int new_name_and_type_ref_i = 0;
  5326. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  5327. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  5328. - name_and_type_ref_i, THREAD);
  5329. - if (!match) {
  5330. - // forward reference in *merge_cp_p or not a direct match
  5331. -
  5332. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  5333. - *merge_cp_p, THREAD);
  5334. - if (found_i != 0) {
  5335. - guarantee(found_i != name_and_type_ref_i,
  5336. - "compare_entry_to() and find_matching_entry() do not agree");
  5337. -
  5338. - // Found a matching entry somewhere else in *merge_cp_p so
  5339. - // just need a mapping entry.
  5340. - new_name_and_type_ref_i = found_i;
  5341. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  5342. - } else {
  5343. - // no match found so we have to append this entry to *merge_cp_p
  5344. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  5345. - merge_cp_length_p, THREAD);
  5346. - // The above call to append_entry() can append more than
  5347. - // one entry so the post call query of *merge_cp_length_p
  5348. - // is required in order to get the right index for the
  5349. - // JVM_CONSTANT_NameAndType entry.
  5350. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  5351. - }
  5352. - }
  5353. -
  5354. - // If the referenced entries already exist in *merge_cp_p, then
  5355. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  5356. - // 0. In that case, all we are appending is the current entry.
  5357. - if (new_klass_ref_i == 0) {
  5358. - new_klass_ref_i = klass_ref_i;
  5359. - }
  5360. - if (new_name_and_type_ref_i == 0) {
  5361. - new_name_and_type_ref_i = name_and_type_ref_i;
  5362. - }
  5363. -
  5364. - const char *entry_name;
  5365. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5366. - case JVM_CONSTANT_Fieldref:
  5367. - entry_name = "Fieldref";
  5368. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5369. - new_name_and_type_ref_i);
  5370. - break;
  5371. - case JVM_CONSTANT_InterfaceMethodref:
  5372. - entry_name = "IFMethodref";
  5373. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5374. - new_klass_ref_i, new_name_and_type_ref_i);
  5375. - break;
  5376. - case JVM_CONSTANT_Methodref:
  5377. - entry_name = "Methodref";
  5378. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5379. - new_name_and_type_ref_i);
  5380. - break;
  5381. - default:
  5382. - guarantee(false, "bad switch");
  5383. - break;
  5384. - }
  5385. -
  5386. - if (klass_ref_i != new_klass_ref_i) {
  5387. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5388. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5389. - }
  5390. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5391. - RC_TRACE(0x00080000,
  5392. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5393. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5394. - new_name_and_type_ref_i));
  5395. - }
  5396. -
  5397. - if (scratch_i != *merge_cp_length_p) {
  5398. - // The new entry in *merge_cp_p is at a different index than
  5399. - // the new entry in scratch_cp so we need to map the index values.
  5400. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5401. - }
  5402. - (*merge_cp_length_p)++;
  5403. - } break;
  5404. -
  5405. - // At this stage, Class or UnresolvedClass could be here, but not
  5406. - // ClassIndex
  5407. - case JVM_CONSTANT_ClassIndex: // fall through
  5408. -
  5409. - // Invalid is used as the tag for the second constant pool entry
  5410. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5411. - // not be seen by itself.
  5412. - case JVM_CONSTANT_Invalid: // fall through
  5413. -
  5414. - // At this stage, String or UnresolvedString could be here, but not
  5415. - // StringIndex
  5416. - case JVM_CONSTANT_StringIndex: // fall through
  5417. -
  5418. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5419. - // here
  5420. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5421. -
  5422. - default:
  5423. - {
  5424. - // leave a breadcrumb
  5425. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5426. - ShouldNotReachHere();
  5427. - } break;
  5428. - } // end switch tag value
  5429. -} // end append_entry()
  5430. -
  5431. -
  5432. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5433. - typeArrayOop save;
  5434. -
  5435. - save = scratch_class->get_method_annotations_of(i);
  5436. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5437. - scratch_class->set_method_annotations_of(j, save);
  5438. -
  5439. - save = scratch_class->get_method_parameter_annotations_of(i);
  5440. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5441. - scratch_class->set_method_parameter_annotations_of(j, save);
  5442. -
  5443. - save = scratch_class->get_method_default_annotations_of(i);
  5444. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5445. - scratch_class->set_method_default_annotations_of(j, save);
  5446. -}
  5447. -
  5448. -
  5449. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5450. - instanceKlassHandle the_class,
  5451. - instanceKlassHandle scratch_class) {
  5452. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5453. +
  5454. +
  5455. +
  5456. + // Compatibility mode => check for unsupported modification
  5457. +
  5458. +
  5459. + assert(scratch_class->old_version() != NULL, "must have old version");
  5460. + instanceKlassHandle the_class(scratch_class->old_version());
  5461. +
  5462. int i;
  5463. // Check superclasses, or rather their names, since superclasses themselves can be
  5464. // requested to replace.
  5465. // Check for NULL superclass first since this might be java.lang.Object
  5466. if (the_class->super() != scratch_class->super() &&
  5467. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5468. - Klass::cast(the_class->super())->name() !=
  5469. - Klass::cast(scratch_class->super())->name())) {
  5470. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5471. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5472. + Klass::cast(the_class->super())->name() !=
  5473. + Klass::cast(scratch_class->super())->name())) {
  5474. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5475. }
  5476. // Check if the number, names and order of directly implemented interfaces are the same.
  5477. @@ -532,8 +678,8 @@
  5478. }
  5479. for (i = 0; i < n_intfs; i++) {
  5480. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5481. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5482. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5483. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5484. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5485. }
  5486. }
  5487. @@ -682,12 +828,8 @@
  5488. idnum_owner->set_method_idnum(new_num);
  5489. }
  5490. k_new_method->set_method_idnum(old_num);
  5491. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5492. }
  5493. }
  5494. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5495. - k_new_method->name_and_sig_as_C_string(), ni,
  5496. - k_old_method->name_and_sig_as_C_string(), oi));
  5497. // advance to next pair of methods
  5498. ++oi;
  5499. ++ni;
  5500. @@ -696,11 +838,11 @@
  5501. // method added, see if it is OK
  5502. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5503. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5504. - // hack: private should be treated as final, but alas
  5505. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5506. - ) {
  5507. - // new methods must be private
  5508. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5509. + // hack: private should be treated as final, but alas
  5510. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5511. + ) {
  5512. + // new methods must be private
  5513. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5514. }
  5515. {
  5516. u2 num = the_class->next_method_idnum();
  5517. @@ -715,24 +857,19 @@
  5518. idnum_owner->set_method_idnum(new_num);
  5519. }
  5520. k_new_method->set_method_idnum(num);
  5521. - swap_all_method_annotations(new_num, num, scratch_class);
  5522. }
  5523. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5524. - k_new_method->name_and_sig_as_C_string(), ni));
  5525. ++ni; // advance to next new method
  5526. break;
  5527. case deleted:
  5528. // method deleted, see if it is OK
  5529. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5530. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5531. - // hack: private should be treated as final, but alas
  5532. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5533. - ) {
  5534. - // deleted methods must be private
  5535. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5536. + // hack: private should be treated as final, but alas
  5537. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5538. + ) {
  5539. + // deleted methods must be private
  5540. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5541. }
  5542. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5543. - k_old_method->name_and_sig_as_C_string(), oi));
  5544. ++oi; // advance to next old method
  5545. break;
  5546. default:
  5547. @@ -743,2084 +880,2272 @@
  5548. return JVMTI_ERROR_NONE;
  5549. }
  5550. -
  5551. -// Find new constant pool index value for old constant pool index value
  5552. -// by seaching the index map. Returns zero (0) if there is no mapped
  5553. -// value for the old constant pool index.
  5554. -int VM_RedefineClasses::find_new_index(int old_index) {
  5555. - if (_index_map_count == 0) {
  5556. - // map is empty so nothing can be found
  5557. - return 0;
  5558. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5559. +
  5560. + int result = Klass::NoRedefinition;
  5561. +
  5562. +
  5563. +
  5564. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5565. + new_class->name()->as_C_string()));
  5566. +
  5567. + assert(new_class->old_version() != NULL, "must have old version");
  5568. + instanceKlassHandle the_class(new_class->old_version());
  5569. +
  5570. + // Check whether class is in the error init state.
  5571. + if (the_class->is_in_error_state()) {
  5572. + // TBD #5057930: special error code is needed in 1.6
  5573. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5574. }
  5575. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5576. - // The old_index is out of range so it is not mapped. This should
  5577. - // not happen in regular constant pool merging use, but it can
  5578. - // happen if a corrupt annotation is processed.
  5579. - return 0;
  5580. + int i;
  5581. +
  5582. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5583. + // Check superclasses
  5584. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5585. + if (the_class->super() != new_class->super()) {
  5586. + // Super class changed
  5587. +
  5588. + klassOop cur_klass = the_class->super();
  5589. + while (cur_klass != NULL) {
  5590. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5591. + RC_TRACE(0x00000002, ("Removed super class %s",
  5592. + cur_klass->klass_part()->name()->as_C_string()));
  5593. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5594. +
  5595. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5596. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5597. + cur_klass->klass_part()->name()->as_C_string()));
  5598. + cur_klass->klass_part()->set_subtype_changed(true);
  5599. + }
  5600. + }
  5601. +
  5602. + cur_klass = cur_klass->klass_part()->super();
  5603. + }
  5604. +
  5605. + cur_klass = new_class->super();
  5606. + while (cur_klass != NULL) {
  5607. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5608. + RC_TRACE(0x00000002, ("Added super class %s",
  5609. + cur_klass->klass_part()->name()->as_C_string()));
  5610. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5611. + }
  5612. + cur_klass = cur_klass->klass_part()->super();
  5613. + }
  5614. }
  5615. - int value = _index_map_p->at(old_index);
  5616. - if (value == -1) {
  5617. - // the old_index is not mapped
  5618. - return 0;
  5619. - }
  5620. -
  5621. - return value;
  5622. -} // end find_new_index()
  5623. -
  5624. -
  5625. -// Returns true if the current mismatch is due to a resolved/unresolved
  5626. -// class pair. Otherwise, returns false.
  5627. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5628. - int index1, constantPoolHandle cp2, int index2) {
  5629. -
  5630. - jbyte t1 = cp1->tag_at(index1).value();
  5631. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5632. - return false; // wrong entry type; not our special case
  5633. - }
  5634. -
  5635. - jbyte t2 = cp2->tag_at(index2).value();
  5636. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5637. - return false; // wrong entry type; not our special case
  5638. - }
  5639. -
  5640. - if (t1 == t2) {
  5641. - return false; // not a mismatch; not our special case
  5642. - }
  5643. -
  5644. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5645. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5646. - if (strcmp(s1, s2) != 0) {
  5647. - return false; // strings don't match; not our special case
  5648. - }
  5649. -
  5650. - return true; // made it through the gauntlet; this is our special case
  5651. -} // end is_unresolved_class_mismatch()
  5652. -
  5653. -
  5654. -// Returns true if the current mismatch is due to a resolved/unresolved
  5655. -// string pair. Otherwise, returns false.
  5656. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5657. - int index1, constantPoolHandle cp2, int index2) {
  5658. -
  5659. - jbyte t1 = cp1->tag_at(index1).value();
  5660. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5661. - return false; // wrong entry type; not our special case
  5662. - }
  5663. -
  5664. - jbyte t2 = cp2->tag_at(index2).value();
  5665. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5666. - return false; // wrong entry type; not our special case
  5667. - }
  5668. -
  5669. - if (t1 == t2) {
  5670. - return false; // not a mismatch; not our special case
  5671. - }
  5672. -
  5673. - char *s1 = cp1->string_at_noresolve(index1);
  5674. - char *s2 = cp2->string_at_noresolve(index2);
  5675. - if (strcmp(s1, s2) != 0) {
  5676. - return false; // strings don't match; not our special case
  5677. - }
  5678. -
  5679. - return true; // made it through the gauntlet; this is our special case
  5680. -} // end is_unresolved_string_mismatch()
  5681. -
  5682. -
  5683. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5684. - // For consistency allocate memory using os::malloc wrapper.
  5685. - _scratch_classes = (instanceKlassHandle *)
  5686. - os::malloc(sizeof(instanceKlassHandle) * _class_count);
  5687. - if (_scratch_classes == NULL) {
  5688. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5689. - }
  5690. -
  5691. - ResourceMark rm(THREAD);
  5692. -
  5693. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5694. - // state can only be NULL if the current thread is exiting which
  5695. - // should not happen since we're trying to do a RedefineClasses
  5696. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5697. - for (int i = 0; i < _class_count; i++) {
  5698. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5699. - // classes for primitives cannot be redefined
  5700. - if (!is_modifiable_class(mirror)) {
  5701. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5702. - }
  5703. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5704. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5705. - Symbol* the_class_sym = the_class->name();
  5706. -
  5707. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5708. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5709. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5710. - the_class->external_name(), _class_load_kind,
  5711. - os::available_memory() >> 10));
  5712. -
  5713. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5714. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5715. -
  5716. - // Parse the stream.
  5717. - Handle the_class_loader(THREAD, the_class->class_loader());
  5718. - Handle protection_domain(THREAD, the_class->protection_domain());
  5719. - // Set redefined class handle in JvmtiThreadState class.
  5720. - // This redefined class is sent to agent event handler for class file
  5721. - // load hook event.
  5722. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5723. -
  5724. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5725. - the_class_loader,
  5726. - protection_domain,
  5727. - &st,
  5728. - THREAD);
  5729. - // Clear class_being_redefined just to be sure.
  5730. - state->clear_class_being_redefined();
  5731. -
  5732. - // TODO: if this is retransform, and nothing changed we can skip it
  5733. -
  5734. - instanceKlassHandle scratch_class (THREAD, k);
  5735. -
  5736. - if (HAS_PENDING_EXCEPTION) {
  5737. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5738. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5739. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5740. - ex_name->as_C_string()));
  5741. - CLEAR_PENDING_EXCEPTION;
  5742. -
  5743. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5744. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5745. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5746. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5747. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5748. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5749. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5750. - // The message will be "XXX (wrong name: YYY)"
  5751. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5752. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5753. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5754. - } else { // Just in case more exceptions can be thrown..
  5755. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5756. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5757. + // Check interfaces
  5758. +
  5759. + // Interfaces removed?
  5760. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5761. + for (i = 0; i<old_interfaces->length(); i++) {
  5762. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5763. + if (!new_class->implements_interface_any_version(old_interface())) {
  5764. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5765. + RC_TRACE(0x00000002, ("Removed interface %s",
  5766. + old_interface->name()->as_C_string()));
  5767. +
  5768. + if (!old_interface->has_subtype_changed()) {
  5769. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5770. + old_interface->name()->as_C_string()));
  5771. + old_interface->set_subtype_changed(true);
  5772. }
  5773. }
  5774. -
  5775. - // Ensure class is linked before redefine
  5776. - if (!the_class->is_linked()) {
  5777. - the_class->link_class(THREAD);
  5778. - if (HAS_PENDING_EXCEPTION) {
  5779. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5780. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5781. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5782. - ex_name->as_C_string()));
  5783. - CLEAR_PENDING_EXCEPTION;
  5784. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5785. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5786. + }
  5787. +
  5788. + // Interfaces added?
  5789. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5790. + for (i = 0; i<new_interfaces->length(); i++) {
  5791. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5792. + result = result | Klass::ModifyClass;
  5793. + RC_TRACE(0x00000002, ("Added interface %s",
  5794. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  5795. + }
  5796. + }
  5797. +
  5798. +
  5799. + // Check whether class modifiers are the same.
  5800. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5801. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5802. + if (old_flags != new_flags) {
  5803. + // TODO (tw): Can this have any effects?
  5804. + }
  5805. +
  5806. + // Check if the number, names, types and order of fields declared in these classes
  5807. + // are the same.
  5808. + JavaFieldStream old_fs(the_class);
  5809. + JavaFieldStream new_fs(new_class);
  5810. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5811. + // access
  5812. + old_flags = old_fs.access_flags().as_short();
  5813. + new_flags = new_fs.access_flags().as_short();
  5814. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5815. + // (tw) Can this have any effects?
  5816. + }
  5817. + // offset
  5818. + if (old_fs.offset() != new_fs.offset()) {
  5819. + result = result | Klass::ModifyInstances;
  5820. + }
  5821. + // name and signature
  5822. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5823. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5824. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5825. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5826. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5827. + result = result | Klass::ModifyInstances;
  5828. + }
  5829. + }
  5830. +
  5831. + if (!old_fs.done() || !new_fs.done()) {
  5832. + result = result | Klass::ModifyInstances;
  5833. + }
  5834. +
  5835. + // Do a parallel walk through the old and new methods. Detect
  5836. + // cases where they match (exist in both), have been added in
  5837. + // the new methods, or have been deleted (exist only in the
  5838. + // old methods). The class file parser places methods in order
  5839. + // by method name, but does not order overloaded methods by
  5840. + // signature. In order to determine what fate befell the methods,
  5841. + // this code places the overloaded new methods that have matching
  5842. + // old methods in the same order as the old methods and places
  5843. + // new overloaded methods at the end of overloaded methods of
  5844. + // that name. The code for this order normalization is adapted
  5845. + // from the algorithm used in instanceKlass::find_method().
  5846. + // Since we are swapping out of order entries as we find them,
  5847. + // we only have to search forward through the overloaded methods.
  5848. + // Methods which are added and have the same name as an existing
  5849. + // method (but different signature) will be put at the end of
  5850. + // the methods with that name, and the name mismatch code will
  5851. + // handle them.
  5852. + objArrayHandle k_old_methods(the_class->methods());
  5853. + objArrayHandle k_new_methods(new_class->methods());
  5854. + int n_old_methods = k_old_methods->length();
  5855. + int n_new_methods = k_new_methods->length();
  5856. +
  5857. + int ni = 0;
  5858. + int oi = 0;
  5859. + while (true) {
  5860. + methodOop k_old_method;
  5861. + methodOop k_new_method;
  5862. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  5863. +
  5864. + if (oi >= n_old_methods) {
  5865. + if (ni >= n_new_methods) {
  5866. + break; // we've looked at everything, done
  5867. + }
  5868. + // New method at the end
  5869. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5870. + method_was = added;
  5871. + } else if (ni >= n_new_methods) {
  5872. + // Old method, at the end, is deleted
  5873. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5874. + method_was = deleted;
  5875. + } else {
  5876. + // There are more methods in both the old and new lists
  5877. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5878. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5879. + if (k_old_method->name() != k_new_method->name()) {
  5880. + // Methods are sorted by method name, so a mismatch means added
  5881. + // or deleted
  5882. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  5883. + method_was = added;
  5884. } else {
  5885. - return JVMTI_ERROR_INTERNAL;
  5886. + method_was = deleted;
  5887. + }
  5888. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5889. + // Both the name and signature match
  5890. + method_was = matched;
  5891. + } else {
  5892. + // The name matches, but the signature doesn't, which means we have to
  5893. + // search forward through the new overloaded methods.
  5894. + int nj; // outside the loop for post-loop check
  5895. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5896. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5897. + if (k_old_method->name() != m->name()) {
  5898. + // reached another method name so no more overloaded methods
  5899. + method_was = deleted;
  5900. + break;
  5901. + }
  5902. + if (k_old_method->signature() == m->signature()) {
  5903. + // found a match so swap the methods
  5904. + k_new_methods->obj_at_put(ni, m);
  5905. + k_new_methods->obj_at_put(nj, k_new_method);
  5906. + k_new_method = m;
  5907. + method_was = matched;
  5908. + break;
  5909. + }
  5910. + }
  5911. +
  5912. + if (nj >= n_new_methods) {
  5913. + // reached the end without a match; so method was deleted
  5914. + method_was = deleted;
  5915. }
  5916. }
  5917. }
  5918. - // Do the validity checks in compare_and_normalize_class_versions()
  5919. - // before verifying the byte codes. By doing these checks first, we
  5920. - // limit the number of functions that require redirection from
  5921. - // the_class to scratch_class. In particular, we don't have to
  5922. - // modify JNI GetSuperclass() and thus won't change its performance.
  5923. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5924. - scratch_class);
  5925. - if (res != JVMTI_ERROR_NONE) {
  5926. - return res;
  5927. + switch (method_was) {
  5928. + case matched:
  5929. + // methods match, be sure modifiers do too
  5930. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5931. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5932. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  5933. + // (tw) Can this have any effects? Probably yes on vtables?
  5934. + result = result | Klass::ModifyClass;
  5935. }
  5936. -
  5937. - // verify what the caller passed us
  5938. {
  5939. - // The bug 6214132 caused the verification to fail.
  5940. - // Information about the_class and scratch_class is temporarily
  5941. - // recorded into jvmtiThreadState. This data is used to redirect
  5942. - // the_class to scratch_class in the JVM_* functions called by the
  5943. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5944. - // description.
  5945. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5946. - Verifier::verify(
  5947. - scratch_class, Verifier::ThrowException, true, THREAD);
  5948. - }
  5949. -
  5950. - if (HAS_PENDING_EXCEPTION) {
  5951. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5952. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5953. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5954. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5955. - CLEAR_PENDING_EXCEPTION;
  5956. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5957. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5958. - } else {
  5959. - // tell the caller the bytecodes are bad
  5960. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5961. + u2 new_num = k_new_method->method_idnum();
  5962. + u2 old_num = k_old_method->method_idnum();
  5963. + if (new_num != old_num) {
  5964. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  5965. + if (idnum_owner != NULL) {
  5966. + // There is already a method assigned this idnum -- switch them
  5967. + idnum_owner->set_method_idnum(new_num);
  5968. + }
  5969. + k_new_method->set_method_idnum(old_num);
  5970. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  5971. + new_num,
  5972. + old_num));
  5973. + // swap_all_method_annotations(old_num, new_num, new_class);
  5974. }
  5975. }
  5976. -
  5977. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5978. - if (res != JVMTI_ERROR_NONE) {
  5979. - return res;
  5980. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5981. + k_new_method->name_and_sig_as_C_string(), ni,
  5982. + k_old_method->name_and_sig_as_C_string(), oi));
  5983. + // advance to next pair of methods
  5984. + ++oi;
  5985. + ++ni;
  5986. + break;
  5987. + case added:
  5988. + // method added, see if it is OK
  5989. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5990. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5991. + // hack: private should be treated as final, but alas
  5992. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5993. + ) {
  5994. + // new methods must be private
  5995. + result = result | Klass::ModifyClass;
  5996. }
  5997. -
  5998. - if (VerifyMergedCPBytecodes) {
  5999. - // verify what we have done during constant pool merging
  6000. - {
  6001. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6002. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6003. + {
  6004. + u2 num = the_class->next_method_idnum();
  6005. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6006. + // cannot add any more methods
  6007. + result = result | Klass::ModifyClass;
  6008. }
  6009. -
  6010. - if (HAS_PENDING_EXCEPTION) {
  6011. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6012. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6013. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6014. - ("verify_byte_codes post merge-CP exception: '%s'",
  6015. - ex_name->as_C_string()));
  6016. - CLEAR_PENDING_EXCEPTION;
  6017. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6018. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6019. - } else {
  6020. - // tell the caller that constant pool merging screwed up
  6021. - return JVMTI_ERROR_INTERNAL;
  6022. + u2 new_num = k_new_method->method_idnum();
  6023. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6024. + if (idnum_owner != NULL) {
  6025. + // There is already a method assigned this idnum -- switch them
  6026. + idnum_owner->set_method_idnum(new_num);
  6027. + }
  6028. + k_new_method->set_method_idnum(num);
  6029. + //swap_all_method_annotations(new_num, num, new_class);
  6030. + }
  6031. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6032. + k_new_method->name_and_sig_as_C_string(), ni));
  6033. + ++ni; // advance to next new method
  6034. + break;
  6035. + case deleted:
  6036. + // method deleted, see if it is OK
  6037. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6038. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6039. + // hack: private should be treated as final, but alas
  6040. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6041. + ) {
  6042. + // deleted methods must be private
  6043. + result = result | Klass::ModifyClass;
  6044. + }
  6045. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6046. + k_old_method->name_and_sig_as_C_string(), oi));
  6047. + ++oi; // advance to next old method
  6048. + break;
  6049. + default:
  6050. + ShouldNotReachHere();
  6051. + }
  6052. + }
  6053. +
  6054. + if (new_class()->size() != new_class->old_version()->size()) {
  6055. + result |= Klass::ModifyClassSize;
  6056. + }
  6057. +
  6058. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6059. + result |= Klass::ModifyInstanceSize;
  6060. + }
  6061. +
  6062. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6063. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6064. + result |= Klass::HasInstanceTransformer;
  6065. + }
  6066. +
  6067. + // (tw) Check method bodies to be able to return NoChange?
  6068. + return result;
  6069. +}
  6070. +
  6071. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6072. +
  6073. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6074. +
  6075. + private:
  6076. +
  6077. + GrowableArray<int> info;
  6078. + int curPosition;
  6079. + bool copy_backwards;
  6080. +
  6081. + public:
  6082. +
  6083. + bool does_copy_backwards() {
  6084. + return copy_backwards;
  6085. + }
  6086. +
  6087. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6088. +
  6089. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6090. +
  6091. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6092. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6093. + }
  6094. +
  6095. + info.append(base_offset);
  6096. + info.append(0);
  6097. + curPosition = base_offset;
  6098. + copy_backwards = false;
  6099. + }
  6100. +
  6101. + GrowableArray<int> &finish() {
  6102. + info.append(0);
  6103. + return info;
  6104. + }
  6105. +
  6106. + virtual void do_new_field(fieldDescriptor* fd){
  6107. + int alignment = fd->offset() - curPosition;
  6108. + if (alignment > 0) {
  6109. + // This field was aligned, so we need to make sure that we fill the gap
  6110. + fill(alignment);
  6111. + }
  6112. +
  6113. + int size = size_of_type(fd->field_type());
  6114. + fill(size);
  6115. + }
  6116. +
  6117. + private:
  6118. +
  6119. + void fill(int size) {
  6120. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6121. + (*info.adr_at(info.length() - 1)) -= size;
  6122. + } else {
  6123. + info.append(-size);
  6124. + }
  6125. +
  6126. + curPosition += size;
  6127. + }
  6128. +
  6129. + int size_of_type(BasicType type) {
  6130. + int size = 0;
  6131. + switch(type) {
  6132. + case T_BOOLEAN:
  6133. + size = sizeof(jboolean);
  6134. + break;
  6135. +
  6136. + case T_CHAR:
  6137. + size = (sizeof(jchar));
  6138. + break;
  6139. +
  6140. + case T_FLOAT:
  6141. + size = (sizeof(jfloat));
  6142. + break;
  6143. +
  6144. + case T_DOUBLE:
  6145. + size = (sizeof(jdouble));
  6146. + break;
  6147. +
  6148. + case T_BYTE:
  6149. + size = (sizeof(jbyte));
  6150. + break;
  6151. +
  6152. + case T_SHORT:
  6153. + size = (sizeof(jshort));
  6154. + break;
  6155. +
  6156. + case T_INT:
  6157. + size = (sizeof(jint));
  6158. + break;
  6159. +
  6160. + case T_LONG:
  6161. + size = (sizeof(jlong));
  6162. + break;
  6163. +
  6164. + case T_OBJECT:
  6165. + case T_ARRAY:
  6166. + if (UseCompressedOops) {
  6167. + size = sizeof(narrowOop);
  6168. + } else {
  6169. + size = (sizeof(oop));
  6170. + }
  6171. + break;
  6172. +
  6173. + default:
  6174. + ShouldNotReachHere();
  6175. + }
  6176. +
  6177. + assert(size > 0, "");
  6178. + return size;
  6179. +
  6180. + }
  6181. +
  6182. + public:
  6183. +
  6184. + virtual void do_old_field(fieldDescriptor* fd){}
  6185. +
  6186. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6187. +
  6188. + int alignment = new_fd->offset() - curPosition;
  6189. + if (alignment > 0) {
  6190. + // This field was aligned, so we need to make sure that we fill the gap
  6191. + fill(alignment);
  6192. + }
  6193. +
  6194. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6195. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6196. +
  6197. + int offset = old_fd->offset();
  6198. + int size = size_of_type(old_fd->field_type());
  6199. +
  6200. + int prevEnd = -1;
  6201. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6202. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6203. + }
  6204. +
  6205. + if (prevEnd == offset) {
  6206. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6207. + } else {
  6208. + info.append(size);
  6209. + info.append(offset);
  6210. + }
  6211. +
  6212. + if (old_fd->offset() < new_fd->offset()) {
  6213. + copy_backwards = true;
  6214. + }
  6215. +
  6216. + transfer_special_access_flags(old_fd, new_fd);
  6217. +
  6218. + curPosition += size;
  6219. + }
  6220. + };
  6221. +
  6222. + UpdateFieldsEvolutionClosure cl(new_version);
  6223. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6224. +
  6225. + GrowableArray<int> result = cl.finish();
  6226. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6227. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6228. +
  6229. + if (RC_TRACE_ENABLED(0x00000002)) {
  6230. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6231. + new_version->klass_part()->name()->as_C_string()));
  6232. + if (cl.does_copy_backwards()) {
  6233. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6234. + }
  6235. + for (int i=0; i<result.length(); i++) {
  6236. + int curNum = result.at(i);
  6237. + if (curNum < 0) {
  6238. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6239. + } else if (curNum > 0) {
  6240. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6241. + i++;
  6242. + } else {
  6243. + RC_TRACE(0x00000002, ("\tEND"));
  6244. + }
  6245. + }
  6246. + }
  6247. +}
  6248. +
  6249. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6250. + assert(FieldType::is_obj(signature), "");
  6251. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6252. +}
  6253. +
  6254. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6255. + if (klass->klass_part()->is_redefining()) {
  6256. + klass = klass->klass_part()->old_version();
  6257. + }
  6258. +
  6259. + // We found an instance klass!
  6260. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6261. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6262. +
  6263. + class MyFieldClosure : public FieldClosure {
  6264. +
  6265. + public:
  6266. +
  6267. + GrowableArray< Pair<int, klassOop> > *_arr;
  6268. +
  6269. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6270. + _arr = arr;
  6271. + }
  6272. +
  6273. + virtual void do_field(fieldDescriptor* fd) {
  6274. + if (fd->field_type() == T_OBJECT) {
  6275. + Symbol* signature = fd->signature();
  6276. + if (FieldType::is_obj(signature)) {
  6277. + Symbol* name = signature_to_class_name(signature);
  6278. + klassOop field_klass;
  6279. + if (is_field_dangerous(name, fd, field_klass)) {
  6280. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6281. + fd->name()->as_C_string(),
  6282. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6283. + name->as_C_string()));
  6284. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6285. + }
  6286. + }
  6287. +
  6288. + // Array fields can never be a problem!
  6289. + }
  6290. + }
  6291. +
  6292. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6293. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6294. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6295. + if(field_klass != NULL) {
  6296. + if (field_klass->klass_part()->is_redefining()) {
  6297. + field_klass = field_klass->klass_part()->old_version();
  6298. + }
  6299. + if (field_klass->klass_part()->has_subtype_changed()) {
  6300. + return true;
  6301. + }
  6302. + }
  6303. + return false;
  6304. + }
  6305. + };
  6306. +
  6307. + MyFieldClosure fieldClosure(&type_check_information);
  6308. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6309. +
  6310. + if (type_check_information.length() > 0) {
  6311. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6312. + cur_instance_klass->store_type_check_information(type_check_information);
  6313. + }
  6314. +}
  6315. +
  6316. +bool VM_RedefineClasses::check_field_value_types() {
  6317. +
  6318. + Thread *THREAD = Thread::current();
  6319. + class CheckFieldTypesClosure : public ObjectClosure {
  6320. +
  6321. + private:
  6322. +
  6323. + bool _result;
  6324. +
  6325. + public:
  6326. +
  6327. + CheckFieldTypesClosure() {
  6328. + _result = true;
  6329. + }
  6330. +
  6331. + bool result() { return _result; }
  6332. +
  6333. + virtual void do_object(oop obj) {
  6334. +
  6335. + if (!_result) {
  6336. + return;
  6337. + }
  6338. +
  6339. + if (obj->is_objArray()) {
  6340. +
  6341. + objArrayOop array = objArrayOop(obj);
  6342. +
  6343. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6344. +
  6345. + if (element_klass->klass_part()->has_subtype_changed()) {
  6346. + int length = array->length();
  6347. + for (int i=0; i<length; i++) {
  6348. + oop element = array->obj_at(i);
  6349. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6350. + // Check subtype relationship to static type of array
  6351. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6352. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6353. + element_klass->klass_part()->name()->as_C_string(),
  6354. + i,
  6355. + element->blueprint()->name()->as_C_string()));
  6356. + _result = false;
  6357. + break;
  6358. + }
  6359. + }
  6360. + }
  6361. + }
  6362. +
  6363. + } else {
  6364. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6365. + if (cur != NULL) {
  6366. + // Type check information exists for this oop
  6367. + while ((*cur).left() != -1) {
  6368. + check_field(obj, (*cur).left(), (*cur).right());
  6369. + cur++;
  6370. + }
  6371. }
  6372. }
  6373. }
  6374. - Rewriter::rewrite(scratch_class, THREAD);
  6375. - if (!HAS_PENDING_EXCEPTION) {
  6376. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6377. - }
  6378. - if (HAS_PENDING_EXCEPTION) {
  6379. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6380. - CLEAR_PENDING_EXCEPTION;
  6381. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6382. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6383. - } else {
  6384. - return JVMTI_ERROR_INTERNAL;
  6385. - }
  6386. - }
  6387. -
  6388. - _scratch_classes[i] = scratch_class;
  6389. -
  6390. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6391. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6392. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6393. - the_class->external_name(), os::available_memory() >> 10));
  6394. - }
  6395. -
  6396. - return JVMTI_ERROR_NONE;
  6397. -}
  6398. -
  6399. -
  6400. -// Map old_index to new_index as needed. scratch_cp is only needed
  6401. -// for RC_TRACE() calls.
  6402. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6403. - int old_index, int new_index) {
  6404. - if (find_new_index(old_index) != 0) {
  6405. - // old_index is already mapped
  6406. - return;
  6407. - }
  6408. -
  6409. - if (old_index == new_index) {
  6410. - // no mapping is needed
  6411. - return;
  6412. - }
  6413. -
  6414. - _index_map_p->at_put(old_index, new_index);
  6415. - _index_map_count++;
  6416. -
  6417. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6418. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6419. -} // end map_index()
  6420. -
  6421. -
  6422. -// Merge old_cp and scratch_cp and return the results of the merge via
  6423. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6424. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6425. -// in *merge_cp_p. Also creates a map of indices from entries in
  6426. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6427. -// entries are only created for entries in scratch_cp that occupy a
  6428. -// different location in *merged_cp_p.
  6429. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6430. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6431. - int *merge_cp_length_p, TRAPS) {
  6432. -
  6433. - if (merge_cp_p == NULL) {
  6434. - assert(false, "caller must provide scatch constantPool");
  6435. - return false; // robustness
  6436. - }
  6437. - if (merge_cp_length_p == NULL) {
  6438. - assert(false, "caller must provide scatch CP length");
  6439. - return false; // robustness
  6440. - }
  6441. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6442. - // but the caller might be smart so make sure we have at least
  6443. - // the minimum.
  6444. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6445. - assert(false, "merge area too small");
  6446. - return false; // robustness
  6447. - }
  6448. -
  6449. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6450. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6451. - scratch_cp->length()));
  6452. -
  6453. - {
  6454. - // Pass 0:
  6455. - // The old_cp is copied to *merge_cp_p; this means that any code
  6456. - // using old_cp does not have to change. This work looks like a
  6457. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6458. - // handle one special case:
  6459. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6460. - // This will make verification happy.
  6461. -
  6462. - int old_i; // index into old_cp
  6463. -
  6464. - // index zero (0) is not used in constantPools
  6465. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6466. - // leave debugging crumb
  6467. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6468. - switch (old_tag) {
  6469. - case JVM_CONSTANT_Class:
  6470. - case JVM_CONSTANT_UnresolvedClass:
  6471. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6472. - // May be resolving while calling this so do the same for
  6473. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6474. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6475. - old_cp->klass_name_at(old_i));
  6476. - break;
  6477. -
  6478. - case JVM_CONSTANT_Double:
  6479. - case JVM_CONSTANT_Long:
  6480. - // just copy the entry to *merge_cp_p, but double and long take
  6481. - // two constant pool entries
  6482. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6483. - old_i++;
  6484. - break;
  6485. -
  6486. - default:
  6487. - // just copy the entry to *merge_cp_p
  6488. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6489. - break;
  6490. - }
  6491. - } // end for each old_cp entry
  6492. -
  6493. - // We don't need to sanity check that *merge_cp_length_p is within
  6494. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6495. - (*merge_cp_length_p) = old_i;
  6496. - }
  6497. -
  6498. - // merge_cp_len should be the same as old_cp->length() at this point
  6499. - // so this trace message is really a "warm-and-breathing" message.
  6500. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6501. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6502. -
  6503. - int scratch_i; // index into scratch_cp
  6504. - {
  6505. - // Pass 1a:
  6506. - // Compare scratch_cp entries to the old_cp entries that we have
  6507. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6508. - // exact duplicates (matching entry at same index) so we only
  6509. - // compare entries in the common indice range.
  6510. - int increment = 1;
  6511. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6512. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6513. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6514. - case JVM_CONSTANT_Double:
  6515. - case JVM_CONSTANT_Long:
  6516. - // double and long take two constant pool entries
  6517. - increment = 2;
  6518. - break;
  6519. -
  6520. - default:
  6521. - increment = 1;
  6522. - break;
  6523. - }
  6524. -
  6525. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6526. - scratch_i, CHECK_0);
  6527. - if (match) {
  6528. - // found a match at the same index so nothing more to do
  6529. - continue;
  6530. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6531. - *merge_cp_p, scratch_i)) {
  6532. - // The mismatch in compare_entry_to() above is because of a
  6533. - // resolved versus unresolved class entry at the same index
  6534. - // with the same string value. Since Pass 0 reverted any
  6535. - // class entries to unresolved class entries in *merge_cp_p,
  6536. - // we go with the unresolved class entry.
  6537. - continue;
  6538. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6539. - *merge_cp_p, scratch_i)) {
  6540. - // The mismatch in compare_entry_to() above is because of a
  6541. - // resolved versus unresolved string entry at the same index
  6542. - // with the same string value. We can live with whichever
  6543. - // happens to be at scratch_i in *merge_cp_p.
  6544. - continue;
  6545. - }
  6546. -
  6547. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6548. - CHECK_0);
  6549. - if (found_i != 0) {
  6550. - guarantee(found_i != scratch_i,
  6551. - "compare_entry_to() and find_matching_entry() do not agree");
  6552. -
  6553. - // Found a matching entry somewhere else in *merge_cp_p so
  6554. - // just need a mapping entry.
  6555. - map_index(scratch_cp, scratch_i, found_i);
  6556. - continue;
  6557. - }
  6558. -
  6559. - // The find_matching_entry() call above could fail to find a match
  6560. - // due to a resolved versus unresolved class or string entry situation
  6561. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6562. - // However, we would have to call is_unresolved_*_mismatch() over
  6563. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6564. - // worth the time.
  6565. -
  6566. - // No match found so we have to append this entry and any unique
  6567. - // referenced entries to *merge_cp_p.
  6568. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6569. - CHECK_0);
  6570. - }
  6571. - }
  6572. -
  6573. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6574. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6575. - *merge_cp_length_p, scratch_i, _index_map_count));
  6576. -
  6577. - if (scratch_i < scratch_cp->length()) {
  6578. - // Pass 1b:
  6579. - // old_cp is smaller than scratch_cp so there are entries in
  6580. - // scratch_cp that we have not yet processed. We take care of
  6581. - // those now.
  6582. - int increment = 1;
  6583. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6584. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6585. - case JVM_CONSTANT_Double:
  6586. - case JVM_CONSTANT_Long:
  6587. - // double and long take two constant pool entries
  6588. - increment = 2;
  6589. - break;
  6590. -
  6591. - default:
  6592. - increment = 1;
  6593. - break;
  6594. - }
  6595. -
  6596. - int found_i =
  6597. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6598. - if (found_i != 0) {
  6599. - // Found a matching entry somewhere else in *merge_cp_p so
  6600. - // just need a mapping entry.
  6601. - map_index(scratch_cp, scratch_i, found_i);
  6602. - continue;
  6603. - }
  6604. -
  6605. - // No match found so we have to append this entry and any unique
  6606. - // referenced entries to *merge_cp_p.
  6607. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6608. - CHECK_0);
  6609. - }
  6610. -
  6611. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6612. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6613. - *merge_cp_length_p, scratch_i, _index_map_count));
  6614. - }
  6615. -
  6616. - return true;
  6617. -} // end merge_constant_pools()
  6618. -
  6619. -
  6620. -// Merge constant pools between the_class and scratch_class and
  6621. -// potentially rewrite bytecodes in scratch_class to use the merged
  6622. -// constant pool.
  6623. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6624. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6625. - TRAPS) {
  6626. - // worst case merged constant pool length is old and new combined
  6627. - int merge_cp_length = the_class->constants()->length()
  6628. - + scratch_class->constants()->length();
  6629. -
  6630. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6631. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6632. -
  6633. - // Constant pools are not easily reused so we allocate a new one
  6634. - // each time.
  6635. - // merge_cp is created unsafe for concurrent GC processing. It
  6636. - // should be marked safe before discarding it. Even though
  6637. - // garbage, if it crosses a card boundary, it may be scanned
  6638. - // in order to find the start of the first complete object on the card.
  6639. - constantPoolHandle merge_cp(THREAD,
  6640. - oopFactory::new_constantPool(merge_cp_length,
  6641. - oopDesc::IsUnsafeConc,
  6642. - THREAD));
  6643. - int orig_length = old_cp->orig_length();
  6644. - if (orig_length == 0) {
  6645. - // This old_cp is an actual original constant pool. We save
  6646. - // the original length in the merged constant pool so that
  6647. - // merge_constant_pools() can be more efficient. If a constant
  6648. - // pool has a non-zero orig_length() value, then that constant
  6649. - // pool was created by a merge operation in RedefineClasses.
  6650. - merge_cp->set_orig_length(old_cp->length());
  6651. - } else {
  6652. - // This old_cp is a merged constant pool from a previous
  6653. - // RedefineClasses() calls so just copy the orig_length()
  6654. - // value.
  6655. - merge_cp->set_orig_length(old_cp->orig_length());
  6656. - }
  6657. -
  6658. - ResourceMark rm(THREAD);
  6659. - _index_map_count = 0;
  6660. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6661. -
  6662. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6663. - &merge_cp_length, THREAD);
  6664. - if (!result) {
  6665. - // The merge can fail due to memory allocation failure or due
  6666. - // to robustness checks.
  6667. - return JVMTI_ERROR_INTERNAL;
  6668. - }
  6669. -
  6670. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6671. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6672. -
  6673. - if (_index_map_count == 0) {
  6674. - // there is nothing to map between the new and merged constant pools
  6675. -
  6676. - if (old_cp->length() == scratch_cp->length()) {
  6677. - // The old and new constant pools are the same length and the
  6678. - // index map is empty. This means that the three constant pools
  6679. - // are equivalent (but not the same). Unfortunately, the new
  6680. - // constant pool has not gone through link resolution nor have
  6681. - // the new class bytecodes gone through constant pool cache
  6682. - // rewriting so we can't use the old constant pool with the new
  6683. - // class.
  6684. -
  6685. - merge_cp()->set_is_conc_safe(true);
  6686. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6687. - } else if (old_cp->length() < scratch_cp->length()) {
  6688. - // The old constant pool has fewer entries than the new constant
  6689. - // pool and the index map is empty. This means the new constant
  6690. - // pool is a superset of the old constant pool. However, the old
  6691. - // class bytecodes have already gone through constant pool cache
  6692. - // rewriting so we can't use the new constant pool with the old
  6693. - // class.
  6694. -
  6695. - merge_cp()->set_is_conc_safe(true);
  6696. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6697. - } else {
  6698. - // The old constant pool has more entries than the new constant
  6699. - // pool and the index map is empty. This means that both the old
  6700. - // and merged constant pools are supersets of the new constant
  6701. - // pool.
  6702. -
  6703. - // Replace the new constant pool with a shrunken copy of the
  6704. - // merged constant pool; the previous new constant pool will
  6705. - // get GCed.
  6706. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6707. - THREAD);
  6708. - // drop local ref to the merged constant pool
  6709. - merge_cp()->set_is_conc_safe(true);
  6710. - merge_cp = constantPoolHandle();
  6711. - }
  6712. - } else {
  6713. - if (RC_TRACE_ENABLED(0x00040000)) {
  6714. - // don't want to loop unless we are tracing
  6715. - int count = 0;
  6716. - for (int i = 1; i < _index_map_p->length(); i++) {
  6717. - int value = _index_map_p->at(i);
  6718. -
  6719. - if (value != -1) {
  6720. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6721. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6722. - count++;
  6723. + void check_field(oop obj, int offset, klassOop static_type) {
  6724. + oop field_value = obj->obj_field(offset);
  6725. + if (field_value != NULL) {
  6726. + // Field is not null
  6727. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6728. + // We are OK
  6729. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6730. + obj->klass()->klass_part()->name()->as_C_string(),
  6731. + static_type->klass_part()->name()->as_C_string(),
  6732. + offset,
  6733. + field_value->klass()->klass_part()->name()->as_C_string()));
  6734. + } else {
  6735. + // Failure!
  6736. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6737. + obj->klass()->klass_part()->name()->as_C_string(),
  6738. + static_type->klass_part()->name()->as_C_string(),
  6739. + offset,
  6740. + field_value->klass()->klass_part()->name()->as_C_string()));
  6741. + _result = false;
  6742. }
  6743. }
  6744. }
  6745. -
  6746. - // We have entries mapped between the new and merged constant pools
  6747. - // so we have to rewrite some constant pool references.
  6748. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6749. - return JVMTI_ERROR_INTERNAL;
  6750. + };
  6751. +
  6752. + CheckFieldTypesClosure myObjectClosure;
  6753. +
  6754. + // make sure that heap is parsable (fills TLABs with filler objects)
  6755. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  6756. +
  6757. + // do the iteration
  6758. + // If this operation encounters a bad object when using CMS,
  6759. + // consider using safe_object_iterate() which avoids perm gen
  6760. + // objects that may contain bad references.
  6761. + Universe::heap()->object_iterate(&myObjectClosure);
  6762. +
  6763. + // when sharing is enabled we must iterate over the shared spaces
  6764. + if (UseSharedSpaces) {
  6765. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  6766. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  6767. + gen->ro_space()->object_iterate(&myObjectClosure);
  6768. + gen->rw_space()->object_iterate(&myObjectClosure);
  6769. + }
  6770. +
  6771. + return myObjectClosure.result();
  6772. +}
  6773. +
  6774. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  6775. + if (k->klass_part()->is_redefining()) {
  6776. + k = k->klass_part()->old_version();
  6777. + }
  6778. +
  6779. + // We found an instance klass!
  6780. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  6781. + cur_instance_klass->clear_type_check_information();
  6782. +}
  6783. +
  6784. +void VM_RedefineClasses::update_active_methods() {
  6785. +
  6786. + RC_TRACE(0x00000002, ("Updating active methods"));
  6787. + JavaThread *java_thread = Threads::first();
  6788. + while (java_thread != NULL) {
  6789. +
  6790. + int stack_depth = 0;
  6791. + if (java_thread->has_last_Java_frame()) {
  6792. +
  6793. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  6794. +
  6795. + // vframes are resource allocated
  6796. + Thread* current_thread = Thread::current();
  6797. + ResourceMark rm(current_thread);
  6798. + HandleMark hm(current_thread);
  6799. +
  6800. + RegisterMap reg_map(java_thread);
  6801. + frame f = java_thread->last_frame();
  6802. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6803. + frame* last_entry_frame = NULL;
  6804. +
  6805. + while (vf != NULL) {
  6806. + if (vf->is_java_frame()) {
  6807. + // java frame (interpreted, compiled, ...)
  6808. + javaVFrame *jvf = javaVFrame::cast(vf);
  6809. +
  6810. + if (!(jvf->method()->is_native())) {
  6811. + int bci = jvf->bci();
  6812. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  6813. + ResourceMark rm(Thread::current());
  6814. + HandleMark hm;
  6815. + instanceKlassHandle klass(jvf->method()->method_holder());
  6816. +
  6817. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6818. +
  6819. +
  6820. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  6821. + jvf->method()->name_and_sig_as_C_string()));
  6822. +
  6823. + if (RC_TRACE_ENABLED(0x01000000)) {
  6824. + int code_size = jvf->method()->code_size();
  6825. + char *code_base_old = (char*)jvf->method()->code_base();
  6826. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  6827. + for (int i=0; i<code_size; i++) {
  6828. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  6829. + }
  6830. + jvf->method()->print_codes_on(tty);
  6831. + jvf->method()->new_version()->print_codes_on(tty);
  6832. + }
  6833. +
  6834. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  6835. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  6836. +
  6837. +
  6838. + if (RC_TRACE_ENABLED(0x01000000)) {
  6839. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  6840. + tty->print_cr("old cp");
  6841. + for (int i=0; i<cp_old->length(); i++) {
  6842. + cp_old->entry_at(i)->print(tty, i);
  6843. + }
  6844. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  6845. + tty->print_cr("new cp");
  6846. + for (int i=0; i<cp_new->length(); i++) {
  6847. + cp_new->entry_at(i)->print(tty, i);
  6848. + }
  6849. + }
  6850. +
  6851. + iframe->set_method(jvf->method()->new_version(), bci);
  6852. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  6853. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  6854. +
  6855. + }
  6856. + }
  6857. + }
  6858. + vf = vf->sender();
  6859. + }
  6860. }
  6861. - // Replace the new constant pool with a shrunken copy of the
  6862. - // merged constant pool so now the rewritten bytecodes have
  6863. - // valid references; the previous new constant pool will get
  6864. - // GCed.
  6865. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6866. - THREAD);
  6867. - merge_cp()->set_is_conc_safe(true);
  6868. + // Advance to next thread
  6869. + java_thread = java_thread->next();
  6870. }
  6871. - assert(old_cp()->is_conc_safe(), "Just checking");
  6872. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6873. -
  6874. - return JVMTI_ERROR_NONE;
  6875. -} // end merge_cp_and_rewrite()
  6876. -
  6877. -
  6878. -// Rewrite constant pool references in klass scratch_class.
  6879. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6880. - TRAPS) {
  6881. -
  6882. - // rewrite constant pool references in the methods:
  6883. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6884. - // propagate failure back to caller
  6885. +}
  6886. +
  6887. +void VM_RedefineClasses::method_forwarding() {
  6888. +
  6889. + int forwarding_count = 0;
  6890. + JavaThread *java_thread = Threads::first();
  6891. + while (java_thread != NULL) {
  6892. +
  6893. + int stack_depth = 0;
  6894. + if (java_thread->has_last_Java_frame()) {
  6895. +
  6896. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  6897. +
  6898. + // vframes are resource allocated
  6899. + Thread* current_thread = Thread::current();
  6900. + ResourceMark rm(current_thread);
  6901. + HandleMark hm(current_thread);
  6902. +
  6903. + RegisterMap reg_map(java_thread);
  6904. + frame f = java_thread->last_frame();
  6905. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6906. + frame* last_entry_frame = NULL;
  6907. +
  6908. + while (vf != NULL) {
  6909. + if (vf->is_java_frame()) {
  6910. + // java frame (interpreted, compiled, ...)
  6911. + javaVFrame *jvf = javaVFrame::cast(vf);
  6912. +
  6913. + if (!(jvf->method()->is_native())) {
  6914. + RC_TRACE(0x00008000, ("found method: %s",
  6915. + jvf->method()->name()->as_C_string()));
  6916. + ResourceMark rm(Thread::current());
  6917. + HandleMark hm;
  6918. + instanceKlassHandle klass(jvf->method()->method_holder());
  6919. + methodOop m = jvf->method();
  6920. + int bci = jvf->bci();
  6921. + RC_TRACE(0x00008000, ("klass redef %d",
  6922. + klass->is_redefining()));
  6923. +
  6924. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  6925. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  6926. + m->name()->as_C_string()));
  6927. +
  6928. + klassOop new_klass = klass->newest_version();
  6929. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  6930. + RC_TRACE(0x00000002, ("%d %d",
  6931. + new_method,
  6932. + new_method->constMethod()->has_code_section_table()));
  6933. +
  6934. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  6935. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  6936. + new_method->name()->as_C_string()));
  6937. + m->set_forward_method(new_method);
  6938. + if (new_method->max_locals() != m->max_locals()) {
  6939. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  6940. + }
  6941. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  6942. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  6943. + if (jvf->is_interpreted_frame()) {
  6944. + if (m->is_in_code_section(bci)) {
  6945. + // We must transfer now and cannot delay until next NOP.
  6946. + int new_bci = m->calculate_forward_bci(bci, new_method);
  6947. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  6948. + RC_TRACE(0x00000002, ("Transfering execution of %s to new method old_bci=%d new_bci=%d",
  6949. + new_method->name()->as_C_string(),
  6950. + bci,
  6951. + new_bci));
  6952. + iframe->set_method(new_method, new_bci);
  6953. + } else {
  6954. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  6955. + new_method->name()->as_C_string(),
  6956. + bci));
  6957. + }
  6958. + } else {
  6959. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  6960. + new_method->name()->as_C_string()));
  6961. + }
  6962. + }
  6963. + }
  6964. + }
  6965. + }
  6966. + vf = vf->sender();
  6967. + }
  6968. + }
  6969. +
  6970. + // Advance to next thread
  6971. + java_thread = java_thread->next();
  6972. + }
  6973. +
  6974. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  6975. + forwarding_count));
  6976. +}
  6977. +
  6978. +bool VM_RedefineClasses::check_method_stacks() {
  6979. +
  6980. + JavaThread *java_thread = Threads::first();
  6981. + while (java_thread != NULL) {
  6982. +
  6983. + int stack_depth = 0;
  6984. + if (java_thread->has_last_Java_frame()) {
  6985. +
  6986. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  6987. +
  6988. + // vframes are resource allocated
  6989. + Thread* current_thread = Thread::current();
  6990. + ResourceMark rm(current_thread);
  6991. + HandleMark hm(current_thread);
  6992. +
  6993. + RegisterMap reg_map(java_thread);
  6994. + frame f = java_thread->last_frame();
  6995. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6996. + frame* last_entry_frame = NULL;
  6997. +
  6998. + while (vf != NULL) {
  6999. + if (vf->is_java_frame()) {
  7000. + // java frame (interpreted, compiled, ...)
  7001. + javaVFrame *jvf = javaVFrame::cast(vf);
  7002. +
  7003. + if (!(jvf->method()->is_native())) {
  7004. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7005. + ResourceMark rm(Thread::current());
  7006. + HandleMark hm;
  7007. + instanceKlassHandle klass(jvf->method()->method_holder());
  7008. +
  7009. + StackValueCollection *locals = jvf->locals();
  7010. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7011. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7012. +
  7013. + for (int i=0; i<locals->size(); i++) {
  7014. + StackValue *stack_value = locals->at(i);
  7015. + if (stack_value->type() == T_OBJECT) {
  7016. + Handle obj = stack_value->get_obj();
  7017. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7018. +
  7019. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7020. + bool result = false;
  7021. + methodOop method = jvf->method();
  7022. + if (method->has_localvariable_table()) {
  7023. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7024. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7025. +
  7026. + if (elem->slot == i) {
  7027. +
  7028. + // Matching index found
  7029. +
  7030. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7031. +
  7032. + // Also in range!!
  7033. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7034. + Symbol* klass_name = signature_to_class_name(signature);
  7035. +
  7036. + klassOop local_klass = SystemDictionary::find(klass_name, jvf->method()->method_holder()->klass_part()->class_loader(), jvf->method()->method_holder()->klass_part()->protection_domain(), Thread::current())->klass_part()->newest_version();
  7037. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7038. +
  7039. + // Field is not null
  7040. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7041. + // We are OK
  7042. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7043. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7044. + result = true;
  7045. + } else {
  7046. + // Failure!
  7047. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7048. + local_klass->klass_part()->name()->as_C_string(),
  7049. + cur->klass_part()->name()->as_C_string()));
  7050. + return false;
  7051. + }
  7052. + }
  7053. + }
  7054. +
  7055. + elem++;
  7056. + }
  7057. + } else {
  7058. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7059. + method->name_and_sig_as_C_string()));
  7060. + }
  7061. +
  7062. + if (!result) {
  7063. + return false;
  7064. + }
  7065. +
  7066. + RC_TRACE(0x00008000, ("Verifying class %s",
  7067. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7068. +
  7069. + Symbol* exception_name;
  7070. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7071. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7072. +
  7073. + if (TraceRedefineClasses >= 4) {
  7074. + ClassVerifier::_verify_verbose = true;
  7075. + }
  7076. +
  7077. + Thread::current()->set_pretend_new_universe(true);
  7078. + ClassVerifier split_verifier(klass, message_buffer, message_buffer_len, Thread::current());
  7079. + split_verifier.verify_method(jvf->method(), Thread::current());
  7080. + exception_name = split_verifier.result();
  7081. + Thread::current()->set_pretend_new_universe(false);
  7082. +
  7083. + if (TraceRedefineClasses >= 4) {
  7084. + ClassVerifier::_verify_verbose = false;
  7085. + }
  7086. +
  7087. + if (exception_name != NULL) {
  7088. +
  7089. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7090. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7091. + RC_TRACE(0x00000001, ("Exception: %s",
  7092. + exception_name->as_C_string()));
  7093. + RC_TRACE(0x00000001, ("Message: %s",
  7094. + message_buffer));
  7095. + Thread::current()->clear_pending_exception();
  7096. + return false;
  7097. + }
  7098. +
  7099. + }
  7100. + }
  7101. + }
  7102. + }
  7103. + }
  7104. + vf = vf->sender();
  7105. + }
  7106. + }
  7107. +
  7108. + // Advance to next thread
  7109. + java_thread = java_thread->next();
  7110. + }
  7111. +
  7112. + return true;
  7113. +}
  7114. +
  7115. +bool VM_RedefineClasses::check_method(methodOop method) {
  7116. +
  7117. +
  7118. + return true;
  7119. +}
  7120. +
  7121. +// Warning: destroys redefinition level values of klasses.
  7122. +bool VM_RedefineClasses::check_loaded_methods() {
  7123. +
  7124. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7125. +
  7126. + private:
  7127. +
  7128. + bool _result;
  7129. + GrowableArray<klassOop> *_dangerous_klasses;
  7130. +
  7131. + public:
  7132. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7133. + _result = true;
  7134. + _dangerous_klasses = dangerous_klasses;
  7135. + }
  7136. +
  7137. + bool result() {
  7138. + return _result;
  7139. + }
  7140. +
  7141. + bool is_class_dangerous(klassOop k) {
  7142. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7143. + }
  7144. +
  7145. + bool can_be_affected(instanceKlass *klass) {
  7146. +
  7147. + constantPoolOop cp = klass->constants();
  7148. +
  7149. + Thread *THREAD = Thread::current();
  7150. + klassOop k;
  7151. + Symbol* symbol;
  7152. +
  7153. + for (int i=1; i<cp->length(); i++) {
  7154. + jbyte tag = cp->tag_at(i).value();
  7155. + switch(tag) {
  7156. + case JVM_CONSTANT_Long:
  7157. + case JVM_CONSTANT_Double:
  7158. + i++;
  7159. + break;
  7160. +
  7161. + case JVM_CONSTANT_Utf8:
  7162. + case JVM_CONSTANT_Unicode:
  7163. + case JVM_CONSTANT_Integer:
  7164. + case JVM_CONSTANT_Float:
  7165. + case JVM_CONSTANT_String:
  7166. + case JVM_CONSTANT_Fieldref:
  7167. + case JVM_CONSTANT_Methodref:
  7168. + case JVM_CONSTANT_InterfaceMethodref:
  7169. + case JVM_CONSTANT_ClassIndex:
  7170. + case JVM_CONSTANT_UnresolvedString:
  7171. + case JVM_CONSTANT_StringIndex:
  7172. + case JVM_CONSTANT_UnresolvedClassInError:
  7173. + case JVM_CONSTANT_Object:
  7174. + // do nothing
  7175. + break;
  7176. +
  7177. + case JVM_CONSTANT_Class:
  7178. + k = cp->klass_at(i, CHECK_(true));
  7179. + if (is_class_dangerous(k)) {
  7180. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7181. + klass->name()->as_C_string(),
  7182. + i,
  7183. + k->klass_part()->name()->as_C_string()));
  7184. + return true;
  7185. + }
  7186. + break;
  7187. +
  7188. + case JVM_CONSTANT_NameAndType:
  7189. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7190. + if (symbol->byte_at(0) == '(') {
  7191. + // This must be a method
  7192. + SignatureStream signatureStream(symbol);
  7193. + while (true) {
  7194. +
  7195. + if (signatureStream.is_array()) {
  7196. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7197. + if (is_type_signature_dangerous(cur_signature)) {
  7198. + return true;
  7199. + }
  7200. + } else if (signatureStream.is_object()) {
  7201. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7202. + return true;
  7203. + }
  7204. + }
  7205. +
  7206. + if (signatureStream.at_return_type()) {
  7207. + break;
  7208. + }
  7209. +
  7210. + signatureStream.next();
  7211. + }
  7212. +
  7213. + } else if (is_type_signature_dangerous(symbol)) {
  7214. + return true;
  7215. + }
  7216. + break;
  7217. +
  7218. + case JVM_CONSTANT_UnresolvedClass:
  7219. + symbol = cp->unresolved_klass_at(i);
  7220. + if (is_symbol_dangerous(symbol)) {
  7221. + return true;
  7222. + }
  7223. + break;
  7224. +
  7225. + default:
  7226. + ShouldNotReachHere();
  7227. + }
  7228. + }
  7229. +
  7230. + return false;
  7231. + }
  7232. +
  7233. + bool is_type_signature_dangerous(Symbol* signature) {
  7234. + // This must be a field type
  7235. + if (FieldType::is_obj(signature)) {
  7236. + Symbol* name = signature_to_class_name(signature);
  7237. + if (is_symbol_dangerous(name)) {
  7238. + return true;
  7239. + }
  7240. + } else if (FieldType::is_array(signature)) {
  7241. + //jint dimension;
  7242. + //Symbol* object_key;
  7243. + FieldArrayInfo fd;
  7244. + FieldType::get_array_info(signature, fd, Thread::current());
  7245. + if (is_symbol_dangerous(fd.object_key())) {
  7246. + return true;
  7247. + }
  7248. + }
  7249. + return false;
  7250. + }
  7251. +
  7252. + bool is_symbol_dangerous(Symbol* symbol) {
  7253. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7254. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7255. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7256. + i,
  7257. + symbol->as_C_string()));
  7258. + return true;
  7259. + }
  7260. + }
  7261. + return false;
  7262. + }
  7263. +
  7264. + virtual void do_object(oop obj) {
  7265. +
  7266. + if (!_result) return;
  7267. +
  7268. + klassOop klassObj = (klassOop)obj;
  7269. + Thread *THREAD = Thread::current();
  7270. +
  7271. + // We found an instance klass!
  7272. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7273. + instanceKlassHandle handle(klassObj);
  7274. +
  7275. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7276. +
  7277. + if (!can_be_affected(klass)) {
  7278. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7279. + return;
  7280. + }
  7281. +
  7282. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7283. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7284. + _result = false;
  7285. + return;
  7286. + }
  7287. +
  7288. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7289. +
  7290. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7291. +
  7292. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7293. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7294. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7295. + //PENDING_EXCEPTION->print();
  7296. + CLEAR_PENDING_EXCEPTION;
  7297. + _result = false;
  7298. + }
  7299. +
  7300. + /*int method_count = klass->methods()->length();
  7301. + for (int i=0; i<method_count; i++) {
  7302. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7303. + if (!check_method(cur_method)) {
  7304. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7305. + }
  7306. + }*/
  7307. + }
  7308. + };
  7309. +
  7310. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7311. +
  7312. + GrowableArray<klassOop> dangerous_klasses;
  7313. + for (int i=0; i<_new_classes->length(); i++) {
  7314. + instanceKlassHandle handle = _new_classes->at(i);
  7315. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7316. + dangerous_klasses.append(handle());
  7317. + }
  7318. + }
  7319. +
  7320. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7321. + Thread::current()->set_pretend_new_universe(true);
  7322. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7323. + Thread::current()->set_pretend_new_universe(false);
  7324. +
  7325. +
  7326. + return checkLoadedMethodsClosure.result();
  7327. +}
  7328. +
  7329. +bool VM_RedefineClasses::check_type_consistency() {
  7330. +
  7331. + Universe::set_verify_in_progress(true);
  7332. +
  7333. + SystemDictionary::classes_do(calculate_type_check_information);
  7334. + bool result = check_field_value_types();
  7335. + SystemDictionary::classes_do(clear_type_check_information);
  7336. + if (!result) {
  7337. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7338. + Universe::set_verify_in_progress(false);
  7339. return false;
  7340. }
  7341. - // rewrite constant pool references in the class_annotations:
  7342. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  7343. - // propagate failure back to caller
  7344. + result = check_method_stacks();
  7345. + if (!result) {
  7346. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7347. + Universe::set_verify_in_progress(false);
  7348. return false;
  7349. }
  7350. - // rewrite constant pool references in the fields_annotations:
  7351. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  7352. - // propagate failure back to caller
  7353. + result = check_loaded_methods();
  7354. + if (!result) {
  7355. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7356. + Universe::set_verify_in_progress(false);
  7357. return false;
  7358. }
  7359. - // rewrite constant pool references in the methods_annotations:
  7360. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  7361. - // propagate failure back to caller
  7362. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7363. + Universe::set_verify_in_progress(false);
  7364. + return true;
  7365. +}
  7366. +
  7367. +void VM_RedefineClasses::rollback() {
  7368. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7369. + SystemDictionary::rollback_redefinition();
  7370. +
  7371. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7372. + for (int i=0; i<_new_classes->length(); i++) {
  7373. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7374. + }
  7375. +
  7376. + for (int i=0; i<_new_classes->length(); i++) {
  7377. + instanceKlassHandle new_class = _new_classes->at(i);
  7378. + new_class->set_redefining(false);
  7379. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7380. + new_class->set_old_version(NULL);
  7381. + }
  7382. +
  7383. +}
  7384. +
  7385. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7386. + T heap_oop = oopDesc::load_heap_oop(p);
  7387. + if (!oopDesc::is_null(heap_oop)) {
  7388. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7389. + if (obj->is_instanceKlass()) {
  7390. + klassOop klass = (klassOop)obj;
  7391. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7392. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7393. + obj = klass->klass_part()->new_version();
  7394. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7395. + }
  7396. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7397. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7398. + // java.lang.Class instances.
  7399. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7400. + if (klass_oop != NULL) {
  7401. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7402. + obj = klass_oop->new_version()->java_mirror();
  7403. + } else if (klass_oop->klass_part()->is_redefining()) {
  7404. + obj = klass_oop->java_mirror();
  7405. + }
  7406. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7407. +
  7408. +
  7409. + // FIXME: DCEVM: better implementation?
  7410. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7411. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7412. + // case we need to run write barrier to make sure card table is properly updated. This will
  7413. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7414. + if (Universe::heap()->is_in_reserved(p)) {
  7415. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7416. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7417. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7418. + CardTableRS* _rs = (CardTableRS*)rs;
  7419. + _rs->inline_write_ref_field_gc(p, obj);
  7420. + }
  7421. + }
  7422. + }
  7423. + }
  7424. + }
  7425. +}
  7426. +
  7427. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7428. + markOop first_mark = first->mark();
  7429. + markOop second_mark = second->mark();
  7430. + first->set_mark(second_mark);
  7431. + second->set_mark(first_mark);
  7432. +}
  7433. +
  7434. +void VM_RedefineClasses::doit() {
  7435. + Thread *thread = Thread::current();
  7436. +
  7437. + RC_TRACE(0x00000001, ("Entering doit!"));
  7438. +
  7439. +
  7440. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7441. +
  7442. + RC_TIMER_START(_timer_check_type);
  7443. +
  7444. + if (!check_type_consistency()) {
  7445. + // (tw) TODO: Rollback the class redefinition
  7446. + rollback();
  7447. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7448. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7449. + RC_TIMER_STOP(_timer_check_type);
  7450. + return;
  7451. + }
  7452. +
  7453. + RC_TIMER_STOP(_timer_check_type);
  7454. +
  7455. + } else {
  7456. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7457. + }
  7458. +
  7459. + if (UseMethodForwardPoints) {
  7460. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7461. + method_forwarding();
  7462. + }
  7463. +
  7464. + if (UseSharedSpaces) {
  7465. + // Sharing is enabled so we remap the shared readonly space to
  7466. + // shared readwrite, private just in case we need to redefine
  7467. + // a shared class. We do the remap during the doit() phase of
  7468. + // the safepoint to be safer.
  7469. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7470. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7471. + _result = JVMTI_ERROR_INTERNAL;
  7472. + return;
  7473. + }
  7474. + }
  7475. +
  7476. + RC_TIMER_START(_timer_prepare_redefinition);
  7477. + for (int i = 0; i < _new_classes->length(); i++) {
  7478. + redefine_single_class(_new_classes->at(i), thread);
  7479. + }
  7480. +
  7481. + // Deoptimize all compiled code that depends on this class
  7482. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7483. +
  7484. + // Adjust constantpool caches and vtables for all classes
  7485. + // that reference methods of the evolved class.
  7486. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7487. +
  7488. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7489. + RC_TIMER_START(_timer_redefinition);
  7490. +
  7491. + class ChangePointersOopClosure : public OopClosure {
  7492. + virtual void do_oop(oop* o) {
  7493. + do_oop_work(o);
  7494. + }
  7495. +
  7496. + virtual void do_oop(narrowOop* o) {
  7497. + do_oop_work(o);
  7498. + }
  7499. + };
  7500. +
  7501. + class ChangePointersObjectClosure : public ObjectClosure {
  7502. +
  7503. + private:
  7504. +
  7505. + OopClosure *_closure;
  7506. + bool _needs_instance_update;
  7507. + GrowableArray<oop> *_updated_oops;
  7508. +
  7509. + public:
  7510. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7511. +
  7512. + bool needs_instance_update() {
  7513. + return _needs_instance_update;
  7514. + }
  7515. +
  7516. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7517. +
  7518. + virtual void do_object(oop obj) {
  7519. + if (!obj->is_instanceKlass()) {
  7520. + obj->oop_iterate(_closure);
  7521. +
  7522. + if (obj->blueprint()->is_redefining()) {
  7523. +
  7524. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7525. + if (_updated_oops == NULL) {
  7526. + _updated_oops = new (ResourceObj::C_HEAP) GrowableArray<oop>(100, true);
  7527. + }
  7528. + _updated_oops->append(obj);
  7529. + }
  7530. +
  7531. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7532. +
  7533. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7534. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7535. +
  7536. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7537. + // We need an instance update => set back to old klass
  7538. + _needs_instance_update = true;
  7539. +
  7540. + } else {
  7541. + MarkSweep::update_fields(obj, obj);
  7542. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7543. + }
  7544. + }
  7545. + }
  7546. +
  7547. + } else {
  7548. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  7549. + if (klass->is_redefining()) {
  7550. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  7551. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  7552. + old_klass->constants()->set_pool_holder(klass->old_version());
  7553. +
  7554. + // Initialize the new class! Special static initialization that does not execute the
  7555. + // static constructor but copies static field values from the old class if name
  7556. + // and signature of a static field match.
  7557. + klass->initialize_redefined_class();
  7558. + }
  7559. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  7560. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  7561. + // idubrov: will get new version of that class
  7562. + //klass->iterate_static_fields(_closure);
  7563. + }
  7564. + }
  7565. + };
  7566. +
  7567. + ChangePointersOopClosure oopClosure;
  7568. + ChangePointersObjectClosure objectClosure(&oopClosure);
  7569. +
  7570. + {
  7571. + SharedHeap::heap()->gc_prologue(true);
  7572. + Universe::root_oops_do(&oopClosure);
  7573. + Universe::heap()->object_iterate(&objectClosure);
  7574. + SharedHeap::heap()->gc_epilogue(false);
  7575. + }
  7576. +
  7577. + // Swap marks to have same hashcodes
  7578. + for (int i=0; i<_new_classes->length(); i++) {
  7579. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  7580. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  7581. + }
  7582. +
  7583. + _updated_oops = objectClosure.updated_oops();
  7584. +
  7585. + if (objectClosure.needs_instance_update()){
  7586. +
  7587. + // Do a full garbage collection to update the instance sizes accordingly
  7588. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  7589. + Universe::set_redefining_gc_run(true);
  7590. + JvmtiGCMarker jgcm;
  7591. + notify_gc_begin(true);
  7592. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  7593. + notify_gc_end();
  7594. + Universe::set_redefining_gc_run(false);
  7595. + RC_TRACE(0x00000001, ("GC done!"));
  7596. + }
  7597. +
  7598. +
  7599. + if (RC_TRACE_ENABLED(0x00000001)) {
  7600. + if (_updated_oops != NULL) {
  7601. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  7602. + } else {
  7603. + RC_TRACE(0x00000001, ("No objects updated!"));
  7604. + }
  7605. + }
  7606. +
  7607. + // Unmark klassOops as "redefining"
  7608. + for (int i=0; i<_new_classes->length(); i++) {
  7609. + klassOop cur = _new_classes->at(i)();
  7610. + _new_classes->at(i)->set_redefining(false);
  7611. + _new_classes->at(i)->clear_update_information();
  7612. + _new_classes->at(i)->update_supers_to_newest_version();
  7613. +
  7614. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  7615. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7616. +
  7617. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  7618. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7619. +
  7620. + oop new_mirror = _new_classes->at(i)->java_mirror();
  7621. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  7622. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  7623. +
  7624. + // Transfer init state
  7625. + instanceKlass::ClassState state = instanceKlass::cast(cur->old_version())->init_state();
  7626. + if (state > instanceKlass::linked) {
  7627. + instanceKlass::cast(cur)->call_class_initializer(thread);
  7628. + }
  7629. + }
  7630. + }
  7631. +
  7632. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  7633. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  7634. + }
  7635. +
  7636. + // Disable any dependent concurrent compilations
  7637. + SystemDictionary::notice_modification();
  7638. +
  7639. + // Set flag indicating that some invariants are no longer true.
  7640. + // See jvmtiExport.hpp for detailed explanation.
  7641. + JvmtiExport::set_has_redefined_a_class();
  7642. +
  7643. + // Clean up caches in the compiler interface and compiler threads
  7644. + CompileBroker::cleanup_after_redefinition();
  7645. +
  7646. +#ifdef ASSERT
  7647. +
  7648. + // Universe::verify();
  7649. + // JNIHandles::verify();
  7650. +
  7651. + SystemDictionary::classes_do(check_class, thread);
  7652. +#endif
  7653. +
  7654. + update_active_methods();
  7655. + RC_TIMER_STOP(_timer_redefinition);
  7656. +
  7657. +}
  7658. +
  7659. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  7660. +
  7661. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  7662. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  7663. +
  7664. +
  7665. + while (curArrayKlass != NULL) {
  7666. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  7667. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  7668. + curArrayKlass->update_supers_to_newest_version();
  7669. +
  7670. + curArrayKlass = NULL;
  7671. + if (higher_dimension != NULL) {
  7672. + curArrayKlass = arrayKlass::cast(higher_dimension);
  7673. + }
  7674. + }
  7675. +
  7676. +}
  7677. +
  7678. +void VM_RedefineClasses::doit_epilogue() {
  7679. +
  7680. + RC_TIMER_START(_timer_vm_op_epilogue);
  7681. +
  7682. + unlock_threads();
  7683. +
  7684. + ResourceMark mark;
  7685. +
  7686. + VM_GC_Operation::doit_epilogue();
  7687. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  7688. +
  7689. + GrowableArray<methodHandle> instanceTransformerMethods;
  7690. +
  7691. + // Call static transformers
  7692. + for (int i=0; i<_new_classes->length(); i++) {
  7693. +
  7694. + instanceKlassHandle klass = _new_classes->at(i);
  7695. +
  7696. + // Find instance transformer method
  7697. +
  7698. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7699. +
  7700. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  7701. + klassOop cur_klass = klass();
  7702. + while (cur_klass != NULL) {
  7703. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  7704. + if (method != NULL) {
  7705. + methodHandle instanceTransformerMethod(method);
  7706. + instanceTransformerMethods.append(instanceTransformerMethod);
  7707. + break;
  7708. + } else {
  7709. + cur_klass = cur_klass->klass_part()->super();
  7710. + }
  7711. + }
  7712. + assert(cur_klass != NULL, "must have instance transformer method");
  7713. + } else {
  7714. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  7715. + }
  7716. + }
  7717. +
  7718. +
  7719. + // Call instance transformers
  7720. + if (_updated_oops != NULL) {
  7721. +
  7722. + for (int i=0; i<_updated_oops->length(); i++) {
  7723. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  7724. + Handle cur(_updated_oops->at(i));
  7725. + instanceKlassHandle klass(cur->klass());
  7726. +
  7727. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7728. +
  7729. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  7730. +
  7731. + RC_TRACE(0x00008000, ("executing transformer method"));
  7732. +
  7733. + Thread *__the_thread__ = Thread::current();
  7734. + JavaValue result(T_VOID);
  7735. + JavaCallArguments args(cur);
  7736. + JavaCalls::call(&result,
  7737. + method,
  7738. + &args,
  7739. + THREAD);
  7740. +
  7741. + // TODO: What to do with an exception here?
  7742. + if (HAS_PENDING_EXCEPTION) {
  7743. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7744. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  7745. + ex_name->as_C_string()));
  7746. + CLEAR_PENDING_EXCEPTION;
  7747. + }
  7748. + }
  7749. + }
  7750. +
  7751. + delete _updated_oops;
  7752. + _updated_oops = NULL;
  7753. + }
  7754. +
  7755. + // Free the array of scratch classes
  7756. + delete _new_classes;
  7757. + _new_classes = NULL;
  7758. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  7759. +
  7760. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  7761. +}
  7762. +
  7763. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  7764. + // classes for primitives cannot be redefined
  7765. + if (java_lang_Class::is_primitive(klass_mirror)) {
  7766. return false;
  7767. }
  7768. -
  7769. - // rewrite constant pool references in the methods_parameter_annotations:
  7770. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  7771. - THREAD)) {
  7772. - // propagate failure back to caller
  7773. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  7774. + // classes for arrays cannot be redefined
  7775. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  7776. return false;
  7777. }
  7778. -
  7779. - // rewrite constant pool references in the methods_default_annotations:
  7780. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  7781. - THREAD)) {
  7782. - // propagate failure back to caller
  7783. - return false;
  7784. + return true;
  7785. +}
  7786. +
  7787. +#ifdef ASSERT
  7788. +
  7789. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7790. + klassOop k_oop = k_oop_latest;
  7791. + while (k_oop != NULL) {
  7792. +
  7793. + instanceKlassHandle k_handle(THREAD, k_oop);
  7794. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  7795. + k_oop = k_oop->klass_part()->old_version();
  7796. }
  7797. -
  7798. - return true;
  7799. -} // end rewrite_cp_refs()
  7800. -
  7801. -
  7802. -// Rewrite constant pool references in the methods.
  7803. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  7804. - instanceKlassHandle scratch_class, TRAPS) {
  7805. -
  7806. - objArrayHandle methods(THREAD, scratch_class->methods());
  7807. -
  7808. - if (methods.is_null() || methods->length() == 0) {
  7809. - // no methods so nothing to do
  7810. - return true;
  7811. - }
  7812. -
  7813. - // rewrite constant pool references in the methods:
  7814. - for (int i = methods->length() - 1; i >= 0; i--) {
  7815. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7816. - methodHandle new_method;
  7817. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  7818. - if (!new_method.is_null()) {
  7819. - // the method has been replaced so save the new method version
  7820. - methods->obj_at_put(i, new_method());
  7821. +}
  7822. +
  7823. +#endif
  7824. +
  7825. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  7826. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  7827. +// do that, they assume that cache entry is resolved already.
  7828. +static void unpatch_bytecode(methodOop method) {
  7829. + RawBytecodeStream bcs(method);
  7830. + Bytecodes::Code code;
  7831. + Bytecodes::Code java_code;
  7832. + while (!bcs.is_last_bytecode()) {
  7833. + code = bcs.raw_next();
  7834. + address bcp = bcs.bcp();
  7835. +
  7836. + if (code == Bytecodes::_breakpoint) {
  7837. + int bci = method->bci_from(bcp);
  7838. + code = method->orig_bytecode_at(bci);
  7839. + java_code = Bytecodes::java_code(code);
  7840. + if (code != java_code &&
  7841. + (java_code == Bytecodes::_getfield ||
  7842. + java_code == Bytecodes::_putfield ||
  7843. + java_code == Bytecodes::_aload_0)) {
  7844. + // Let breakpoint table handling unpatch bytecode
  7845. + method->set_orig_bytecode_at(bci, java_code);
  7846. + }
  7847. + } else {
  7848. + java_code = Bytecodes::java_code(code);
  7849. + if (code != java_code &&
  7850. + (java_code == Bytecodes::_getfield ||
  7851. + java_code == Bytecodes::_putfield ||
  7852. + java_code == Bytecodes::_aload_0)) {
  7853. + *bcp = java_code;
  7854. + }
  7855. + }
  7856. +
  7857. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  7858. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  7859. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  7860. + assert(code2 == Bytecodes::_fast_igetfield ||
  7861. + code2 == Bytecodes::_fast_agetfield ||
  7862. + code2 == Bytecodes::_fast_fgetfield, "");
  7863. + *(bcp + 1) = Bytecodes::java_code(code2);
  7864. }
  7865. }
  7866. -
  7867. - return true;
  7868. }
  7869. -
  7870. -// Rewrite constant pool references in the specific method. This code
  7871. -// was adapted from Rewriter::rewrite_method().
  7872. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  7873. - methodHandle *new_method_p, TRAPS) {
  7874. -
  7875. - *new_method_p = methodHandle(); // default is no new method
  7876. -
  7877. - // We cache a pointer to the bytecodes here in code_base. If GC
  7878. - // moves the methodOop, then the bytecodes will also move which
  7879. - // will likely cause a crash. We create a No_Safepoint_Verifier
  7880. - // object to detect whether we pass a possible safepoint in this
  7881. - // code block.
  7882. - No_Safepoint_Verifier nsv;
  7883. -
  7884. - // Bytecodes and their length
  7885. - address code_base = method->code_base();
  7886. - int code_length = method->code_size();
  7887. -
  7888. - int bc_length;
  7889. - for (int bci = 0; bci < code_length; bci += bc_length) {
  7890. - address bcp = code_base + bci;
  7891. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  7892. -
  7893. - bc_length = Bytecodes::length_for(c);
  7894. - if (bc_length == 0) {
  7895. - // More complicated bytecodes report a length of zero so
  7896. - // we have to try again a slightly different way.
  7897. - bc_length = Bytecodes::length_at(method(), bcp);
  7898. - }
  7899. -
  7900. - assert(bc_length != 0, "impossible bytecode length");
  7901. -
  7902. - switch (c) {
  7903. - case Bytecodes::_ldc:
  7904. - {
  7905. - int cp_index = *(bcp + 1);
  7906. - int new_index = find_new_index(cp_index);
  7907. -
  7908. - if (StressLdcRewrite && new_index == 0) {
  7909. - // If we are stressing ldc -> ldc_w rewriting, then we
  7910. - // always need a new_index value.
  7911. - new_index = cp_index;
  7912. - }
  7913. - if (new_index != 0) {
  7914. - // the original index is mapped so we have more work to do
  7915. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  7916. - // The new value can still use ldc instead of ldc_w
  7917. - // unless we are trying to stress ldc -> ldc_w rewriting
  7918. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7919. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7920. - bcp, cp_index, new_index));
  7921. - *(bcp + 1) = new_index;
  7922. - } else {
  7923. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7924. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  7925. - Bytecodes::name(c), bcp, cp_index, new_index));
  7926. - // the new value needs ldc_w instead of ldc
  7927. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  7928. - bcp = (address)inst_buffer;
  7929. - // construct new instruction sequence
  7930. - *bcp = Bytecodes::_ldc_w;
  7931. - bcp++;
  7932. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  7933. - // See comment below for difference between put_Java_u2()
  7934. - // and put_native_u2().
  7935. - Bytes::put_Java_u2(bcp, new_index);
  7936. -
  7937. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  7938. - methodHandle m;
  7939. - {
  7940. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  7941. -
  7942. - // ldc is 2 bytes and ldc_w is 3 bytes
  7943. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  7944. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  7945. - guarantee(false, "insert_space_at() failed");
  7946. - }
  7947. - }
  7948. -
  7949. - // return the new method so that the caller can update
  7950. - // the containing class
  7951. - *new_method_p = method = m;
  7952. - // switch our bytecode processing loop from the old method
  7953. - // to the new method
  7954. - code_base = method->code_base();
  7955. - code_length = method->code_size();
  7956. - bcp = code_base + bci;
  7957. - c = (Bytecodes::Code)(*bcp);
  7958. - bc_length = Bytecodes::length_for(c);
  7959. - assert(bc_length != 0, "sanity check");
  7960. - } // end we need ldc_w instead of ldc
  7961. - } // end if there is a mapped index
  7962. - } break;
  7963. -
  7964. - // these bytecodes have a two-byte constant pool index
  7965. - case Bytecodes::_anewarray : // fall through
  7966. - case Bytecodes::_checkcast : // fall through
  7967. - case Bytecodes::_getfield : // fall through
  7968. - case Bytecodes::_getstatic : // fall through
  7969. - case Bytecodes::_instanceof : // fall through
  7970. - case Bytecodes::_invokeinterface: // fall through
  7971. - case Bytecodes::_invokespecial : // fall through
  7972. - case Bytecodes::_invokestatic : // fall through
  7973. - case Bytecodes::_invokevirtual : // fall through
  7974. - case Bytecodes::_ldc_w : // fall through
  7975. - case Bytecodes::_ldc2_w : // fall through
  7976. - case Bytecodes::_multianewarray : // fall through
  7977. - case Bytecodes::_new : // fall through
  7978. - case Bytecodes::_putfield : // fall through
  7979. - case Bytecodes::_putstatic :
  7980. - {
  7981. - address p = bcp + 1;
  7982. - int cp_index = Bytes::get_Java_u2(p);
  7983. - int new_index = find_new_index(cp_index);
  7984. - if (new_index != 0) {
  7985. - // the original index is mapped so update w/ new value
  7986. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7987. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7988. - bcp, cp_index, new_index));
  7989. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7990. - // situation because it is reusing the constant pool index
  7991. - // location for a native index into the constantPoolCache.
  7992. - // Since we are updating the constant pool index prior to
  7993. - // verification and constantPoolCache initialization, we
  7994. - // need to keep the new index in Java byte order.
  7995. - Bytes::put_Java_u2(p, new_index);
  7996. - }
  7997. - } break;
  7998. - }
  7999. - } // end for each bytecode
  8000. -} // end rewrite_cp_refs_in_method()
  8001. -
  8002. -
  8003. -// Rewrite constant pool references in the class_annotations field.
  8004. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  8005. - instanceKlassHandle scratch_class, TRAPS) {
  8006. -
  8007. - typeArrayHandle class_annotations(THREAD,
  8008. - scratch_class->class_annotations());
  8009. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  8010. - // no class_annotations so nothing to do
  8011. - return true;
  8012. - }
  8013. -
  8014. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8015. - ("class_annotations length=%d", class_annotations->length()));
  8016. -
  8017. - int byte_i = 0; // byte index into class_annotations
  8018. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  8019. - THREAD);
  8020. -}
  8021. -
  8022. -
  8023. -// Rewrite constant pool references in an annotations typeArray. This
  8024. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  8025. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  8026. -//
  8027. -// annotations_typeArray {
  8028. -// u2 num_annotations;
  8029. -// annotation annotations[num_annotations];
  8030. -// }
  8031. -//
  8032. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  8033. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8034. -
  8035. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8036. - // not enough room for num_annotations field
  8037. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8038. - ("length() is too small for num_annotations field"));
  8039. - return false;
  8040. - }
  8041. -
  8042. - u2 num_annotations = Bytes::get_Java_u2((address)
  8043. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8044. - byte_i_ref += 2;
  8045. -
  8046. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8047. - ("num_annotations=%d", num_annotations));
  8048. -
  8049. - int calc_num_annotations = 0;
  8050. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  8051. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8052. - byte_i_ref, THREAD)) {
  8053. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8054. - ("bad annotation_struct at %d", calc_num_annotations));
  8055. - // propagate failure back to caller
  8056. - return false;
  8057. - }
  8058. - }
  8059. - assert(num_annotations == calc_num_annotations, "sanity check");
  8060. -
  8061. - return true;
  8062. -} // end rewrite_cp_refs_in_annotations_typeArray()
  8063. -
  8064. -
  8065. -// Rewrite constant pool references in the annotation struct portion of
  8066. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  8067. -// the 2nd-edition of the VM spec:
  8068. -//
  8069. -// struct annotation {
  8070. -// u2 type_index;
  8071. -// u2 num_element_value_pairs;
  8072. -// {
  8073. -// u2 element_name_index;
  8074. -// element_value value;
  8075. -// } element_value_pairs[num_element_value_pairs];
  8076. -// }
  8077. -//
  8078. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  8079. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8080. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  8081. - // not enough room for smallest annotation_struct
  8082. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8083. - ("length() is too small for annotation_struct"));
  8084. - return false;
  8085. - }
  8086. -
  8087. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  8088. - byte_i_ref, "mapped old type_index=%d", THREAD);
  8089. -
  8090. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  8091. - annotations_typeArray->byte_at_addr(
  8092. - byte_i_ref));
  8093. - byte_i_ref += 2;
  8094. -
  8095. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8096. - ("type_index=%d num_element_value_pairs=%d", type_index,
  8097. - num_element_value_pairs));
  8098. -
  8099. - int calc_num_element_value_pairs = 0;
  8100. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  8101. - calc_num_element_value_pairs++) {
  8102. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8103. - // not enough room for another element_name_index, let alone
  8104. - // the rest of another component
  8105. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8106. - ("length() is too small for element_name_index"));
  8107. - return false;
  8108. - }
  8109. -
  8110. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  8111. - annotations_typeArray, byte_i_ref,
  8112. - "mapped old element_name_index=%d", THREAD);
  8113. -
  8114. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8115. - ("element_name_index=%d", element_name_index));
  8116. -
  8117. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  8118. - byte_i_ref, THREAD)) {
  8119. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8120. - ("bad element_value at %d", calc_num_element_value_pairs));
  8121. - // propagate failure back to caller
  8122. - return false;
  8123. - }
  8124. - } // end for each component
  8125. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  8126. - "sanity check");
  8127. -
  8128. - return true;
  8129. -} // end rewrite_cp_refs_in_annotation_struct()
  8130. -
  8131. -
  8132. -// Rewrite a constant pool reference at the current position in
  8133. -// annotations_typeArray if needed. Returns the original constant
  8134. -// pool reference if a rewrite was not needed or the new constant
  8135. -// pool reference if a rewrite was needed.
  8136. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  8137. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  8138. - const char * trace_mesg, TRAPS) {
  8139. -
  8140. - address cp_index_addr = (address)
  8141. - annotations_typeArray->byte_at_addr(byte_i_ref);
  8142. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  8143. - u2 new_cp_index = find_new_index(old_cp_index);
  8144. - if (new_cp_index != 0) {
  8145. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  8146. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  8147. - old_cp_index = new_cp_index;
  8148. - }
  8149. - byte_i_ref += 2;
  8150. - return old_cp_index;
  8151. -}
  8152. -
  8153. -
  8154. -// Rewrite constant pool references in the element_value portion of an
  8155. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  8156. -// the 2nd-edition of the VM spec:
  8157. -//
  8158. -// struct element_value {
  8159. -// u1 tag;
  8160. -// union {
  8161. -// u2 const_value_index;
  8162. -// {
  8163. -// u2 type_name_index;
  8164. -// u2 const_name_index;
  8165. -// } enum_const_value;
  8166. -// u2 class_info_index;
  8167. -// annotation annotation_value;
  8168. -// struct {
  8169. -// u2 num_values;
  8170. -// element_value values[num_values];
  8171. -// } array_value;
  8172. -// } value;
  8173. -// }
  8174. -//
  8175. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  8176. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8177. -
  8178. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  8179. - // not enough room for a tag let alone the rest of an element_value
  8180. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8181. - ("length() is too small for a tag"));
  8182. - return false;
  8183. - }
  8184. -
  8185. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  8186. - byte_i_ref++;
  8187. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  8188. -
  8189. - switch (tag) {
  8190. - // These BaseType tag values are from Table 4.2 in VM spec:
  8191. - case 'B': // byte
  8192. - case 'C': // char
  8193. - case 'D': // double
  8194. - case 'F': // float
  8195. - case 'I': // int
  8196. - case 'J': // long
  8197. - case 'S': // short
  8198. - case 'Z': // boolean
  8199. -
  8200. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  8201. - // the VM spec:
  8202. - case 's':
  8203. - {
  8204. - // For the above tag values (including the BaseType values),
  8205. - // value.const_value_index is right union field.
  8206. -
  8207. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8208. - // not enough room for a const_value_index
  8209. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8210. - ("length() is too small for a const_value_index"));
  8211. - return false;
  8212. - }
  8213. -
  8214. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8215. - annotations_typeArray, byte_i_ref,
  8216. - "mapped old const_value_index=%d", THREAD);
  8217. -
  8218. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8219. - ("const_value_index=%d", const_value_index));
  8220. - } break;
  8221. -
  8222. - case 'e':
  8223. - {
  8224. - // for the above tag value, value.enum_const_value is right union field
  8225. -
  8226. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8227. - // not enough room for a enum_const_value
  8228. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8229. - ("length() is too small for a enum_const_value"));
  8230. - return false;
  8231. - }
  8232. -
  8233. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8234. - annotations_typeArray, byte_i_ref,
  8235. - "mapped old type_name_index=%d", THREAD);
  8236. -
  8237. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8238. - annotations_typeArray, byte_i_ref,
  8239. - "mapped old const_name_index=%d", THREAD);
  8240. -
  8241. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8242. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8243. - const_name_index));
  8244. - } break;
  8245. -
  8246. - case 'c':
  8247. - {
  8248. - // for the above tag value, value.class_info_index is right union field
  8249. -
  8250. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8251. - // not enough room for a class_info_index
  8252. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8253. - ("length() is too small for a class_info_index"));
  8254. - return false;
  8255. - }
  8256. -
  8257. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8258. - annotations_typeArray, byte_i_ref,
  8259. - "mapped old class_info_index=%d", THREAD);
  8260. -
  8261. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8262. - ("class_info_index=%d", class_info_index));
  8263. - } break;
  8264. -
  8265. - case '@':
  8266. - // For the above tag value, value.attr_value is the right union
  8267. - // field. This is a nested annotation.
  8268. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8269. - byte_i_ref, THREAD)) {
  8270. - // propagate failure back to caller
  8271. - return false;
  8272. - }
  8273. - break;
  8274. -
  8275. - case '[':
  8276. - {
  8277. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8278. - // not enough room for a num_values field
  8279. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8280. - ("length() is too small for a num_values field"));
  8281. - return false;
  8282. - }
  8283. -
  8284. - // For the above tag value, value.array_value is the right union
  8285. - // field. This is an array of nested element_value.
  8286. - u2 num_values = Bytes::get_Java_u2((address)
  8287. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8288. - byte_i_ref += 2;
  8289. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8290. -
  8291. - int calc_num_values = 0;
  8292. - for (; calc_num_values < num_values; calc_num_values++) {
  8293. - if (!rewrite_cp_refs_in_element_value(
  8294. - annotations_typeArray, byte_i_ref, THREAD)) {
  8295. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8296. - ("bad nested element_value at %d", calc_num_values));
  8297. - // propagate failure back to caller
  8298. - return false;
  8299. - }
  8300. - }
  8301. - assert(num_values == calc_num_values, "sanity check");
  8302. - } break;
  8303. -
  8304. - default:
  8305. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8306. - return false;
  8307. - } // end decode tag field
  8308. -
  8309. - return true;
  8310. -} // end rewrite_cp_refs_in_element_value()
  8311. -
  8312. -
  8313. -// Rewrite constant pool references in a fields_annotations field.
  8314. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8315. - instanceKlassHandle scratch_class, TRAPS) {
  8316. -
  8317. - objArrayHandle fields_annotations(THREAD,
  8318. - scratch_class->fields_annotations());
  8319. -
  8320. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8321. - // no fields_annotations so nothing to do
  8322. - return true;
  8323. - }
  8324. -
  8325. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8326. - ("fields_annotations length=%d", fields_annotations->length()));
  8327. -
  8328. - for (int i = 0; i < fields_annotations->length(); i++) {
  8329. - typeArrayHandle field_annotations(THREAD,
  8330. - (typeArrayOop)fields_annotations->obj_at(i));
  8331. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8332. - // this field does not have any annotations so skip it
  8333. - continue;
  8334. - }
  8335. -
  8336. - int byte_i = 0; // byte index into field_annotations
  8337. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8338. - THREAD)) {
  8339. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8340. - ("bad field_annotations at %d", i));
  8341. - // propagate failure back to caller
  8342. - return false;
  8343. - }
  8344. - }
  8345. -
  8346. - return true;
  8347. -} // end rewrite_cp_refs_in_fields_annotations()
  8348. -
  8349. -
  8350. -// Rewrite constant pool references in a methods_annotations field.
  8351. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8352. - instanceKlassHandle scratch_class, TRAPS) {
  8353. -
  8354. - objArrayHandle methods_annotations(THREAD,
  8355. - scratch_class->methods_annotations());
  8356. -
  8357. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8358. - // no methods_annotations so nothing to do
  8359. - return true;
  8360. - }
  8361. -
  8362. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8363. - ("methods_annotations length=%d", methods_annotations->length()));
  8364. -
  8365. - for (int i = 0; i < methods_annotations->length(); i++) {
  8366. - typeArrayHandle method_annotations(THREAD,
  8367. - (typeArrayOop)methods_annotations->obj_at(i));
  8368. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8369. - // this method does not have any annotations so skip it
  8370. - continue;
  8371. - }
  8372. -
  8373. - int byte_i = 0; // byte index into method_annotations
  8374. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8375. - THREAD)) {
  8376. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8377. - ("bad method_annotations at %d", i));
  8378. - // propagate failure back to caller
  8379. - return false;
  8380. - }
  8381. - }
  8382. -
  8383. - return true;
  8384. -} // end rewrite_cp_refs_in_methods_annotations()
  8385. -
  8386. -
  8387. -// Rewrite constant pool references in a methods_parameter_annotations
  8388. -// field. This "structure" is adapted from the
  8389. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8390. -// 4.8.17 of the 2nd-edition of the VM spec:
  8391. -//
  8392. -// methods_parameter_annotations_typeArray {
  8393. -// u1 num_parameters;
  8394. -// {
  8395. -// u2 num_annotations;
  8396. -// annotation annotations[num_annotations];
  8397. -// } parameter_annotations[num_parameters];
  8398. -// }
  8399. -//
  8400. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8401. - instanceKlassHandle scratch_class, TRAPS) {
  8402. -
  8403. - objArrayHandle methods_parameter_annotations(THREAD,
  8404. - scratch_class->methods_parameter_annotations());
  8405. -
  8406. - if (methods_parameter_annotations.is_null()
  8407. - || methods_parameter_annotations->length() == 0) {
  8408. - // no methods_parameter_annotations so nothing to do
  8409. - return true;
  8410. - }
  8411. -
  8412. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8413. - ("methods_parameter_annotations length=%d",
  8414. - methods_parameter_annotations->length()));
  8415. -
  8416. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8417. - typeArrayHandle method_parameter_annotations(THREAD,
  8418. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8419. - if (method_parameter_annotations.is_null()
  8420. - || method_parameter_annotations->length() == 0) {
  8421. - // this method does not have any parameter annotations so skip it
  8422. - continue;
  8423. - }
  8424. -
  8425. - if (method_parameter_annotations->length() < 1) {
  8426. - // not enough room for a num_parameters field
  8427. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8428. - ("length() is too small for a num_parameters field at %d", i));
  8429. - return false;
  8430. - }
  8431. -
  8432. - int byte_i = 0; // byte index into method_parameter_annotations
  8433. -
  8434. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8435. - byte_i++;
  8436. -
  8437. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8438. - ("num_parameters=%d", num_parameters));
  8439. -
  8440. - int calc_num_parameters = 0;
  8441. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8442. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8443. - method_parameter_annotations, byte_i, THREAD)) {
  8444. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8445. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8446. - // propagate failure back to caller
  8447. - return false;
  8448. - }
  8449. - }
  8450. - assert(num_parameters == calc_num_parameters, "sanity check");
  8451. - }
  8452. -
  8453. - return true;
  8454. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8455. -
  8456. -
  8457. -// Rewrite constant pool references in a methods_default_annotations
  8458. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8459. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8460. -//
  8461. -// methods_default_annotations_typeArray {
  8462. -// element_value default_value;
  8463. -// }
  8464. -//
  8465. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8466. - instanceKlassHandle scratch_class, TRAPS) {
  8467. -
  8468. - objArrayHandle methods_default_annotations(THREAD,
  8469. - scratch_class->methods_default_annotations());
  8470. -
  8471. - if (methods_default_annotations.is_null()
  8472. - || methods_default_annotations->length() == 0) {
  8473. - // no methods_default_annotations so nothing to do
  8474. - return true;
  8475. - }
  8476. -
  8477. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8478. - ("methods_default_annotations length=%d",
  8479. - methods_default_annotations->length()));
  8480. -
  8481. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8482. - typeArrayHandle method_default_annotations(THREAD,
  8483. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8484. - if (method_default_annotations.is_null()
  8485. - || method_default_annotations->length() == 0) {
  8486. - // this method does not have any default annotations so skip it
  8487. - continue;
  8488. - }
  8489. -
  8490. - int byte_i = 0; // byte index into method_default_annotations
  8491. -
  8492. - if (!rewrite_cp_refs_in_element_value(
  8493. - method_default_annotations, byte_i, THREAD)) {
  8494. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8495. - ("bad default element_value at %d", i));
  8496. - // propagate failure back to caller
  8497. - return false;
  8498. - }
  8499. - }
  8500. -
  8501. - return true;
  8502. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8503. -
  8504. -
  8505. -// Rewrite constant pool references in the method's stackmap table.
  8506. -// These "structures" are adapted from the StackMapTable_attribute that
  8507. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8508. -// (dated 2005.10.26):
  8509. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8510. -//
  8511. -// stack_map {
  8512. -// u2 number_of_entries;
  8513. -// stack_map_frame entries[number_of_entries];
  8514. -// }
  8515. -//
  8516. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8517. - methodHandle method, TRAPS) {
  8518. -
  8519. - if (!method->has_stackmap_table()) {
  8520. - return;
  8521. - }
  8522. -
  8523. - typeArrayOop stackmap_data = method->stackmap_data();
  8524. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8525. - address stackmap_end = stackmap_p + stackmap_data->length();
  8526. -
  8527. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8528. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8529. - stackmap_p += 2;
  8530. -
  8531. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8532. - ("number_of_entries=%u", number_of_entries));
  8533. -
  8534. - // walk through each stack_map_frame
  8535. - u2 calc_number_of_entries = 0;
  8536. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8537. - // The stack_map_frame structure is a u1 frame_type followed by
  8538. - // 0 or more bytes of data:
  8539. - //
  8540. - // union stack_map_frame {
  8541. - // same_frame;
  8542. - // same_locals_1_stack_item_frame;
  8543. - // same_locals_1_stack_item_frame_extended;
  8544. - // chop_frame;
  8545. - // same_frame_extended;
  8546. - // append_frame;
  8547. - // full_frame;
  8548. - // }
  8549. -
  8550. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8551. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8552. - // issues the following warning for the first if-statement below:
  8553. - //
  8554. - // "warning: comparison is always true due to limited range of data type"
  8555. - //
  8556. - u4 frame_type = *stackmap_p;
  8557. - stackmap_p++;
  8558. -
  8559. - // same_frame {
  8560. - // u1 frame_type = SAME; /* 0-63 */
  8561. - // }
  8562. - if (frame_type >= 0 && frame_type <= 63) {
  8563. - // nothing more to do for same_frame
  8564. - }
  8565. -
  8566. - // same_locals_1_stack_item_frame {
  8567. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8568. - // verification_type_info stack[1];
  8569. - // }
  8570. - else if (frame_type >= 64 && frame_type <= 127) {
  8571. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8572. - calc_number_of_entries, frame_type, THREAD);
  8573. - }
  8574. -
  8575. - // reserved for future use
  8576. - else if (frame_type >= 128 && frame_type <= 246) {
  8577. - // nothing more to do for reserved frame_types
  8578. - }
  8579. -
  8580. - // same_locals_1_stack_item_frame_extended {
  8581. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8582. - // u2 offset_delta;
  8583. - // verification_type_info stack[1];
  8584. - // }
  8585. - else if (frame_type == 247) {
  8586. - stackmap_p += 2;
  8587. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8588. - calc_number_of_entries, frame_type, THREAD);
  8589. - }
  8590. -
  8591. - // chop_frame {
  8592. - // u1 frame_type = CHOP; /* 248-250 */
  8593. - // u2 offset_delta;
  8594. - // }
  8595. - else if (frame_type >= 248 && frame_type <= 250) {
  8596. - stackmap_p += 2;
  8597. - }
  8598. -
  8599. - // same_frame_extended {
  8600. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8601. - // u2 offset_delta;
  8602. - // }
  8603. - else if (frame_type == 251) {
  8604. - stackmap_p += 2;
  8605. - }
  8606. -
  8607. - // append_frame {
  8608. - // u1 frame_type = APPEND; /* 252-254 */
  8609. - // u2 offset_delta;
  8610. - // verification_type_info locals[frame_type - 251];
  8611. - // }
  8612. - else if (frame_type >= 252 && frame_type <= 254) {
  8613. - assert(stackmap_p + 2 <= stackmap_end,
  8614. - "no room for offset_delta");
  8615. - stackmap_p += 2;
  8616. - u1 len = frame_type - 251;
  8617. - for (u1 i = 0; i < len; i++) {
  8618. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8619. - calc_number_of_entries, frame_type, THREAD);
  8620. - }
  8621. - }
  8622. -
  8623. - // full_frame {
  8624. - // u1 frame_type = FULL_FRAME; /* 255 */
  8625. - // u2 offset_delta;
  8626. - // u2 number_of_locals;
  8627. - // verification_type_info locals[number_of_locals];
  8628. - // u2 number_of_stack_items;
  8629. - // verification_type_info stack[number_of_stack_items];
  8630. - // }
  8631. - else if (frame_type == 255) {
  8632. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8633. - "no room for smallest full_frame");
  8634. - stackmap_p += 2;
  8635. -
  8636. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8637. - stackmap_p += 2;
  8638. -
  8639. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8640. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8641. - calc_number_of_entries, frame_type, THREAD);
  8642. - }
  8643. -
  8644. - // Use the largest size for the number_of_stack_items, but only get
  8645. - // the right number of bytes.
  8646. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8647. - stackmap_p += 2;
  8648. -
  8649. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8650. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8651. - calc_number_of_entries, frame_type, THREAD);
  8652. - }
  8653. - }
  8654. - } // end while there is a stack_map_frame
  8655. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8656. -} // end rewrite_cp_refs_in_stack_map_table()
  8657. -
  8658. -
  8659. -// Rewrite constant pool references in the verification type info
  8660. -// portion of the method's stackmap table. These "structures" are
  8661. -// adapted from the StackMapTable_attribute that is described in
  8662. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8663. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8664. -//
  8665. -// The verification_type_info structure is a u1 tag followed by 0 or
  8666. -// more bytes of data:
  8667. -//
  8668. -// union verification_type_info {
  8669. -// Top_variable_info;
  8670. -// Integer_variable_info;
  8671. -// Float_variable_info;
  8672. -// Long_variable_info;
  8673. -// Double_variable_info;
  8674. -// Null_variable_info;
  8675. -// UninitializedThis_variable_info;
  8676. -// Object_variable_info;
  8677. -// Uninitialized_variable_info;
  8678. -// }
  8679. -//
  8680. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8681. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8682. - u1 frame_type, TRAPS) {
  8683. -
  8684. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8685. - u1 tag = *stackmap_p_ref;
  8686. - stackmap_p_ref++;
  8687. -
  8688. - switch (tag) {
  8689. - // Top_variable_info {
  8690. - // u1 tag = ITEM_Top; /* 0 */
  8691. - // }
  8692. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8693. - case 0: // fall through
  8694. -
  8695. - // Integer_variable_info {
  8696. - // u1 tag = ITEM_Integer; /* 1 */
  8697. - // }
  8698. - case ITEM_Integer: // fall through
  8699. -
  8700. - // Float_variable_info {
  8701. - // u1 tag = ITEM_Float; /* 2 */
  8702. - // }
  8703. - case ITEM_Float: // fall through
  8704. -
  8705. - // Double_variable_info {
  8706. - // u1 tag = ITEM_Double; /* 3 */
  8707. - // }
  8708. - case ITEM_Double: // fall through
  8709. -
  8710. - // Long_variable_info {
  8711. - // u1 tag = ITEM_Long; /* 4 */
  8712. - // }
  8713. - case ITEM_Long: // fall through
  8714. -
  8715. - // Null_variable_info {
  8716. - // u1 tag = ITEM_Null; /* 5 */
  8717. - // }
  8718. - case ITEM_Null: // fall through
  8719. -
  8720. - // UninitializedThis_variable_info {
  8721. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8722. - // }
  8723. - case ITEM_UninitializedThis:
  8724. - // nothing more to do for the above tag types
  8725. - break;
  8726. -
  8727. - // Object_variable_info {
  8728. - // u1 tag = ITEM_Object; /* 7 */
  8729. - // u2 cpool_index;
  8730. - // }
  8731. - case ITEM_Object:
  8732. - {
  8733. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8734. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8735. - u2 new_cp_index = find_new_index(cpool_index);
  8736. - if (new_cp_index != 0) {
  8737. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8738. - ("mapped old cpool_index=%d", cpool_index));
  8739. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8740. - cpool_index = new_cp_index;
  8741. - }
  8742. - stackmap_p_ref += 2;
  8743. -
  8744. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8745. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8746. - frame_type, cpool_index));
  8747. - } break;
  8748. -
  8749. - // Uninitialized_variable_info {
  8750. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8751. - // u2 offset;
  8752. - // }
  8753. - case ITEM_Uninitialized:
  8754. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8755. - stackmap_p_ref += 2;
  8756. - break;
  8757. -
  8758. - default:
  8759. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8760. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8761. - ShouldNotReachHere();
  8762. - break;
  8763. - } // end switch (tag)
  8764. -} // end rewrite_cp_refs_in_verification_type_info()
  8765. -
  8766. -
  8767. -// Change the constant pool associated with klass scratch_class to
  8768. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8769. -// are copied from scratch_cp to a smaller constant pool and the
  8770. -// smaller constant pool is associated with scratch_class.
  8771. -void VM_RedefineClasses::set_new_constant_pool(
  8772. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8773. - int scratch_cp_length, bool shrink, TRAPS) {
  8774. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  8775. -
  8776. - if (shrink) {
  8777. - // scratch_cp is a merged constant pool and has enough space for a
  8778. - // worst case merge situation. We want to associate the minimum
  8779. - // sized constant pool with the klass to save space.
  8780. - constantPoolHandle smaller_cp(THREAD,
  8781. - oopFactory::new_constantPool(scratch_cp_length,
  8782. - oopDesc::IsUnsafeConc,
  8783. - THREAD));
  8784. - // preserve orig_length() value in the smaller copy
  8785. - int orig_length = scratch_cp->orig_length();
  8786. - assert(orig_length != 0, "sanity check");
  8787. - smaller_cp->set_orig_length(orig_length);
  8788. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8789. - scratch_cp = smaller_cp;
  8790. - smaller_cp()->set_is_conc_safe(true);
  8791. - }
  8792. -
  8793. - // attach new constant pool to klass
  8794. - scratch_cp->set_pool_holder(scratch_class());
  8795. -
  8796. - // attach klass to new constant pool
  8797. - scratch_class->set_constants(scratch_cp());
  8798. -
  8799. - int i; // for portability
  8800. -
  8801. - // update each field in klass to use new constant pool indices as needed
  8802. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8803. - jshort cur_index = fs.name_index();
  8804. - jshort new_index = find_new_index(cur_index);
  8805. - if (new_index != 0) {
  8806. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8807. - ("field-name_index change: %d to %d", cur_index, new_index));
  8808. - fs.set_name_index(new_index);
  8809. - }
  8810. - cur_index = fs.signature_index();
  8811. - new_index = find_new_index(cur_index);
  8812. - if (new_index != 0) {
  8813. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8814. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8815. - fs.set_signature_index(new_index);
  8816. - }
  8817. - cur_index = fs.initval_index();
  8818. - new_index = find_new_index(cur_index);
  8819. - if (new_index != 0) {
  8820. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8821. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8822. - fs.set_initval_index(new_index);
  8823. - }
  8824. - cur_index = fs.generic_signature_index();
  8825. - new_index = find_new_index(cur_index);
  8826. - if (new_index != 0) {
  8827. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8828. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8829. - fs.set_generic_signature_index(new_index);
  8830. - }
  8831. - } // end for each field
  8832. -
  8833. - // Update constant pool indices in the inner classes info to use
  8834. - // new constant indices as needed. The inner classes info is a
  8835. - // quadruple:
  8836. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8837. - typeArrayOop inner_class_list = scratch_class->inner_classes();
  8838. - int icl_length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
  8839. - if (icl_length > 0) {
  8840. - typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
  8841. - for (int i = 0; i < icl_length;
  8842. - i += instanceKlass::inner_class_next_offset) {
  8843. - int cur_index = inner_class_list_h->ushort_at(i
  8844. - + instanceKlass::inner_class_inner_class_info_offset);
  8845. - if (cur_index == 0) {
  8846. - continue; // JVM spec. allows null inner class refs so skip it
  8847. - }
  8848. - int new_index = find_new_index(cur_index);
  8849. - if (new_index != 0) {
  8850. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8851. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8852. - inner_class_list_h->ushort_at_put(i
  8853. - + instanceKlass::inner_class_inner_class_info_offset, new_index);
  8854. - }
  8855. - cur_index = inner_class_list_h->ushort_at(i
  8856. - + instanceKlass::inner_class_outer_class_info_offset);
  8857. - new_index = find_new_index(cur_index);
  8858. - if (new_index != 0) {
  8859. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8860. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8861. - inner_class_list_h->ushort_at_put(i
  8862. - + instanceKlass::inner_class_outer_class_info_offset, new_index);
  8863. - }
  8864. - cur_index = inner_class_list_h->ushort_at(i
  8865. - + instanceKlass::inner_class_inner_name_offset);
  8866. - new_index = find_new_index(cur_index);
  8867. - if (new_index != 0) {
  8868. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8869. - ("inner_name change: %d to %d", cur_index, new_index));
  8870. - inner_class_list_h->ushort_at_put(i
  8871. - + instanceKlass::inner_class_inner_name_offset, new_index);
  8872. - }
  8873. - } // end for each inner class
  8874. - } // end if we have inner classes
  8875. -
  8876. - // Attach each method in klass to the new constant pool and update
  8877. - // to use new constant pool indices as needed:
  8878. - objArrayHandle methods(THREAD, scratch_class->methods());
  8879. - for (i = methods->length() - 1; i >= 0; i--) {
  8880. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8881. - method->set_constants(scratch_cp());
  8882. -
  8883. - int new_index = find_new_index(method->name_index());
  8884. - if (new_index != 0) {
  8885. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8886. - ("method-name_index change: %d to %d", method->name_index(),
  8887. - new_index));
  8888. - method->set_name_index(new_index);
  8889. - }
  8890. - new_index = find_new_index(method->signature_index());
  8891. - if (new_index != 0) {
  8892. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8893. - ("method-signature_index change: %d to %d",
  8894. - method->signature_index(), new_index));
  8895. - method->set_signature_index(new_index);
  8896. - }
  8897. - new_index = find_new_index(method->generic_signature_index());
  8898. - if (new_index != 0) {
  8899. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8900. - ("method-generic_signature_index change: %d to %d",
  8901. - method->generic_signature_index(), new_index));
  8902. - method->set_generic_signature_index(new_index);
  8903. - }
  8904. -
  8905. - // Update constant pool indices in the method's checked exception
  8906. - // table to use new constant indices as needed.
  8907. - int cext_length = method->checked_exceptions_length();
  8908. - if (cext_length > 0) {
  8909. - CheckedExceptionElement * cext_table =
  8910. - method->checked_exceptions_start();
  8911. - for (int j = 0; j < cext_length; j++) {
  8912. - int cur_index = cext_table[j].class_cp_index;
  8913. - int new_index = find_new_index(cur_index);
  8914. - if (new_index != 0) {
  8915. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8916. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8917. - cext_table[j].class_cp_index = (u2)new_index;
  8918. - }
  8919. - } // end for each checked exception table entry
  8920. - } // end if there are checked exception table entries
  8921. -
  8922. - // Update each catch type index in the method's exception table
  8923. - // to use new constant pool indices as needed. The exception table
  8924. - // holds quadruple entries of the form:
  8925. - // (beg_bci, end_bci, handler_bci, klass_index)
  8926. - const int beg_bci_offset = 0;
  8927. - const int end_bci_offset = 1;
  8928. - const int handler_bci_offset = 2;
  8929. - const int klass_index_offset = 3;
  8930. - const int entry_size = 4;
  8931. -
  8932. - typeArrayHandle ex_table (THREAD, method->exception_table());
  8933. - int ext_length = ex_table->length();
  8934. - assert(ext_length % entry_size == 0, "exception table format has changed");
  8935. -
  8936. - for (int j = 0; j < ext_length; j += entry_size) {
  8937. - int cur_index = ex_table->int_at(j + klass_index_offset);
  8938. - int new_index = find_new_index(cur_index);
  8939. - if (new_index != 0) {
  8940. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8941. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8942. - ex_table->int_at_put(j + klass_index_offset, new_index);
  8943. - }
  8944. - } // end for each exception table entry
  8945. -
  8946. - // Update constant pool indices in the method's local variable
  8947. - // table to use new constant indices as needed. The local variable
  8948. - // table hold sextuple entries of the form:
  8949. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8950. - int lvt_length = method->localvariable_table_length();
  8951. - if (lvt_length > 0) {
  8952. - LocalVariableTableElement * lv_table =
  8953. - method->localvariable_table_start();
  8954. - for (int j = 0; j < lvt_length; j++) {
  8955. - int cur_index = lv_table[j].name_cp_index;
  8956. - int new_index = find_new_index(cur_index);
  8957. - if (new_index != 0) {
  8958. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8959. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8960. - lv_table[j].name_cp_index = (u2)new_index;
  8961. - }
  8962. - cur_index = lv_table[j].descriptor_cp_index;
  8963. - new_index = find_new_index(cur_index);
  8964. - if (new_index != 0) {
  8965. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8966. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8967. - new_index));
  8968. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8969. - }
  8970. - cur_index = lv_table[j].signature_cp_index;
  8971. - new_index = find_new_index(cur_index);
  8972. - if (new_index != 0) {
  8973. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8974. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8975. - lv_table[j].signature_cp_index = (u2)new_index;
  8976. - }
  8977. - } // end for each local variable table entry
  8978. - } // end if there are local variable table entries
  8979. -
  8980. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8981. - } // end for each method
  8982. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8983. -} // end set_new_constant_pool()
  8984. -
  8985. -
  8986. -// Unevolving classes may point to methods of the_class directly
  8987. +// Unevolving classes may point to old methods directly
  8988. // from their constant pool caches, itables, and/or vtables. We
  8989. // use the SystemDictionary::classes_do() facility and this helper
  8990. -// to fix up these pointers.
  8991. +// to fix up these pointers. Additional field offsets and vtable indices
  8992. +// in the constant pool cache entries are fixed.
  8993. //
  8994. // Note: We currently don't support updating the vtable in
  8995. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8996. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8997. - oop initiating_loader, TRAPS) {
  8998. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8999. + klassOop k_oop = k_oop_latest;
  9000. + while (k_oop != NULL) {
  9001. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9002. +/*
  9003. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9004. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9005. +
  9006. + for (int i=0; i<_matching_methods_length; i++) {
  9007. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9008. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9009. + }*/
  9010. +
  9011. + Klass *k = k_oop->klass_part();
  9012. + if (k->oop_is_instance()) {
  9013. + HandleMark hm(THREAD);
  9014. + instanceKlass *ik = (instanceKlass *) k;
  9015. +
  9016. + constantPoolHandle other_cp;
  9017. + constantPoolCacheOop cp_cache;
  9018. +
  9019. + other_cp = constantPoolHandle(ik->constants());
  9020. +
  9021. + for (int i=0; i<other_cp->length(); i++) {
  9022. + if (other_cp->tag_at(i).is_klass()) {
  9023. + klassOop klass = other_cp->klass_at(i, THREAD);
  9024. + if (klass->klass_part()->new_version() != NULL) {
  9025. +
  9026. + // (tw) TODO: check why/if this is necessary
  9027. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9028. + }
  9029. + klass = other_cp->klass_at(i, THREAD);
  9030. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9031. + }
  9032. + }
  9033. +
  9034. + cp_cache = other_cp->cache();
  9035. +
  9036. + if (cp_cache != NULL) {
  9037. + cp_cache->adjust_entries(NULL,
  9038. + NULL,
  9039. + 0);
  9040. + }
  9041. +
  9042. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9043. + if (RewriteBytecodes) {
  9044. + ik->methods_do(unpatch_bytecode);
  9045. + }
  9046. + }
  9047. + k_oop = k_oop->klass_part()->old_version();
  9048. + }
  9049. +}
  9050. +
  9051. +void VM_RedefineClasses::update_jmethod_ids() {
  9052. + for (int j = 0; j < _matching_methods_length; ++j) {
  9053. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9054. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9055. +
  9056. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9057. + if (old_method->new_version() != NULL && jmid == NULL) {
  9058. + // (tw) Have to create jmethodID in this case
  9059. + jmid = old_method->jmethod_id();
  9060. + }
  9061. +
  9062. + if (jmid != NULL) {
  9063. + // There is a jmethodID, change it to point to the new method
  9064. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9065. + if (old_method->new_version() == NULL) {
  9066. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9067. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9068. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9069. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9070. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9071. + } else {
  9072. + jmethodID mid = new_method_h->jmethod_id();
  9073. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9074. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9075. +
  9076. + }
  9077. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9078. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9079. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9080. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9081. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9082. +
  9083. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9084. + }
  9085. + }
  9086. +}
  9087. +
  9088. +
  9089. +// Deoptimize all compiled code that depends on this class.
  9090. +//
  9091. +// If the can_redefine_classes capability is obtained in the onload
  9092. +// phase then the compiler has recorded all dependencies from startup.
  9093. +// In that case we need only deoptimize and throw away all compiled code
  9094. +// that depends on the class.
  9095. +//
  9096. +// If can_redefine_classes is obtained sometime after the onload
  9097. +// phase then the dependency information may be incomplete. In that case
  9098. +// the first call to RedefineClasses causes all compiled code to be
  9099. +// thrown away. As can_redefine_classes has been obtained then
  9100. +// all future compilations will record dependencies so second and
  9101. +// subsequent calls to RedefineClasses need only throw away code
  9102. +// that depends on the class.
  9103. +//
  9104. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9105. + assert_locked_or_safepoint(Compile_lock);
  9106. +
  9107. + // All dependencies have been recorded from startup or this is a second or
  9108. + // subsequent use of RedefineClasses
  9109. +
  9110. + // For now deopt all
  9111. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9112. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9113. + Universe::flush_evol_dependents_on(k_h);
  9114. + } else {
  9115. + CodeCache::mark_all_nmethods_for_deoptimization();
  9116. +
  9117. + ResourceMark rm(THREAD);
  9118. + DeoptimizationMarker dm;
  9119. +
  9120. + // Deoptimize all activations depending on marked nmethods
  9121. + Deoptimization::deoptimize_dependents();
  9122. +
  9123. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9124. + CodeCache::make_marked_nmethods_not_entrant();
  9125. +
  9126. + // From now on we know that the dependency information is complete
  9127. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9128. + }
  9129. +}
  9130. +
  9131. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9132. + methodOop old_method;
  9133. + methodOop new_method;
  9134. +
  9135. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9136. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9137. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9138. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9139. +
  9140. + _matching_methods_length = 0;
  9141. + _deleted_methods_length = 0;
  9142. + _added_methods_length = 0;
  9143. +
  9144. + int nj = 0;
  9145. + int oj = 0;
  9146. + while (true) {
  9147. + if (oj >= _old_methods->length()) {
  9148. + if (nj >= _new_methods->length()) {
  9149. + break; // we've looked at everything, done
  9150. + }
  9151. + // New method at the end
  9152. + new_method = (methodOop) _new_methods->obj_at(nj);
  9153. + _added_methods[_added_methods_length++] = nj;
  9154. + ++nj;
  9155. + } else if (nj >= _new_methods->length()) {
  9156. + // Old method, at the end, is deleted
  9157. + old_method = (methodOop) _old_methods->obj_at(oj);
  9158. + _deleted_methods[_deleted_methods_length++] = oj;
  9159. + ++oj;
  9160. + } else {
  9161. + old_method = (methodOop) _old_methods->obj_at(oj);
  9162. + new_method = (methodOop) _new_methods->obj_at(nj);
  9163. + if (old_method->name() == new_method->name()) {
  9164. + if (old_method->signature() == new_method->signature()) {
  9165. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9166. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9167. + ++nj;
  9168. + ++oj;
  9169. + } else {
  9170. + // added overloaded have already been moved to the end,
  9171. + // so this is a deleted overloaded method
  9172. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9173. + ++oj;
  9174. + }
  9175. + } else { // names don't match
  9176. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9177. + // new method
  9178. + _added_methods[_added_methods_length++] = nj;//new_method;
  9179. + ++nj;
  9180. + } else {
  9181. + // deleted method
  9182. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9183. + ++oj;
  9184. + }
  9185. + }
  9186. + }
  9187. + }
  9188. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9189. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9190. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9191. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9192. +}
  9193. +
  9194. +
  9195. +
  9196. +// Install the redefinition of a class:
  9197. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9198. +// dependent compiled code)
  9199. +// - adjusting constant pool caches and vtables in other classes
  9200. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9201. +
  9202. + ResourceMark rm(THREAD);
  9203. +
  9204. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9205. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9206. +
  9207. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9208. +
  9209. +#ifndef JVMTI_KERNEL
  9210. + // Remove all breakpoints in methods of this class
  9211. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9212. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9213. +#endif // !JVMTI_KERNEL
  9214. +
  9215. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9216. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9217. + // cached and users of the cache care about each active version of
  9218. + // the method so we have to track this previous version.
  9219. + // Do this before methods get switched
  9220. + Universe::reflect_invoke_cache()->add_previous_version(
  9221. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9222. + }
  9223. +
  9224. + _old_methods = the_old_class->methods();
  9225. + _new_methods = the_new_class->methods();
  9226. + _the_class_oop = the_old_class();
  9227. + compute_added_deleted_matching_methods();
  9228. +
  9229. + // track which methods are EMCP for add_previous_version() call below
  9230. +
  9231. + // (tw) TODO: Check if we need the concept of EMCP?
  9232. + BitMap emcp_methods(_old_methods->length());
  9233. + int emcp_method_count = 0;
  9234. + emcp_methods.clear(); // clears 0..(length() - 1)
  9235. +
  9236. + // We need to mark methods as old!!
  9237. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9238. + update_jmethod_ids();
  9239. +
  9240. + // keep track of previous versions of this class
  9241. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9242. + emcp_method_count);
  9243. +
  9244. + // TODO:
  9245. + transfer_old_native_function_registrations(the_old_class);
  9246. +
  9247. +
  9248. +#ifdef ASSERT
  9249. +
  9250. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9251. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9252. +
  9253. + //JNIHandles::verify();
  9254. +
  9255. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9256. +
  9257. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9258. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9259. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9260. +
  9261. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9262. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9263. + }
  9264. +
  9265. + _old_methods->verify();
  9266. + _new_methods->verify();
  9267. +
  9268. + the_new_class->vtable()->verify(tty);
  9269. + the_old_class->vtable()->verify(tty);
  9270. +
  9271. +#endif
  9272. +
  9273. + // increment the classRedefinedCount field in the_class and in any
  9274. + // direct and indirect subclasses of the_class
  9275. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9276. +
  9277. +}
  9278. +
  9279. +
  9280. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9281. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9282. + *emcp_method_count_p = 0;
  9283. + int obsolete_count = 0;
  9284. + int old_index = 0;
  9285. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9286. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9287. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9288. + methodOop old_array_method;
  9289. +
  9290. + // Maintain an old_index into the _old_methods array by skipping
  9291. + // deleted methods
  9292. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9293. + != old_method) {
  9294. + ++old_index;
  9295. + }
  9296. +
  9297. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9298. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9299. + // the same with the exception of constant pool indices which may
  9300. + // differ. However, the constants referred to by those indices
  9301. + // must be the same.
  9302. + //
  9303. + // We use methods_EMCP() for comparison since constant pool
  9304. + // merging can remove duplicate constant pool entries that were
  9305. + // present in the old method and removed from the rewritten new
  9306. + // method. A faster binary comparison function would consider the
  9307. + // old and new methods to be different when they are actually
  9308. + // EMCP.
  9309. +
  9310. + // track which methods are EMCP for add_previous_version() call
  9311. + emcp_methods->set_bit(old_index);
  9312. + (*emcp_method_count_p)++;
  9313. +
  9314. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9315. + // different jmethodID than the current method. An EMCP method
  9316. + // has the same jmethodID as the current method. Having the
  9317. + // same jmethodID for all EMCP versions of a method allows for
  9318. + // a consistent view of the EMCP methods regardless of which
  9319. + // EMCP method you happen to have in hand. For example, a
  9320. + // breakpoint set in one EMCP method will work for all EMCP
  9321. + // versions of the method including the current one.
  9322. +
  9323. + old_method->set_new_version(new_method);
  9324. + new_method->set_old_version(old_method);
  9325. +
  9326. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9327. +
  9328. + // Transfer breakpoints
  9329. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9330. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9331. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9332. + RC_TRACE(0x00000002, ("%d / %d",
  9333. + bp->match(old_method), bp->match(new_method)));
  9334. + if (bp->match(old_method)) {
  9335. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9336. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9337. + new_method->set_breakpoint(bp->bci());
  9338. + }
  9339. + }
  9340. +
  9341. +
  9342. +
  9343. + } else {
  9344. + // mark obsolete methods as such
  9345. + old_method->set_is_obsolete();
  9346. + obsolete_count++;
  9347. +
  9348. + // With tracing we try not to "yack" too much. The position of
  9349. + // this trace assumes there are fewer obsolete methods than
  9350. + // EMCP methods.
  9351. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9352. + old_method->name()->as_C_string(),
  9353. + old_method->signature()->as_C_string()));
  9354. + }
  9355. + old_method->set_is_old();
  9356. + }
  9357. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9358. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9359. +
  9360. + //assert(old_method->vtable_index() < 0,
  9361. + // "cannot delete methods with vtable entries");;
  9362. +
  9363. + // Mark all deleted methods as old and obsolete
  9364. + old_method->set_is_old();
  9365. + old_method->set_is_obsolete();
  9366. + ++obsolete_count;
  9367. + // With tracing we try not to "yack" too much. The position of
  9368. + // this trace assumes there are fewer obsolete methods than
  9369. + // EMCP methods.
  9370. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9371. + old_method->name()->as_C_string(),
  9372. + old_method->signature()->as_C_string()));
  9373. + }
  9374. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9375. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9376. +}
  9377. +
  9378. +// Increment the classRedefinedCount field in the specific instanceKlass
  9379. +// and in all direct and indirect subclasses.
  9380. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9381. + oop class_mirror = ik->java_mirror();
  9382. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9383. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9384. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9385. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9386. +}
  9387. +
  9388. +#ifndef PRODUCT
  9389. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9390. Klass *k = k_oop->klass_part();
  9391. if (k->oop_is_instance()) {
  9392. HandleMark hm(THREAD);
  9393. instanceKlass *ik = (instanceKlass *) k;
  9394. -
  9395. - // HotSpot specific optimization! HotSpot does not currently
  9396. - // support delegation from the bootstrap class loader to a
  9397. - // user-defined class loader. This means that if the bootstrap
  9398. - // class loader is the initiating class loader, then it will also
  9399. - // be the defining class loader. This also means that classes
  9400. - // loaded by the bootstrap class loader cannot refer to classes
  9401. - // loaded by a user-defined class loader. Note: a user-defined
  9402. - // class loader can delegate to the bootstrap class loader.
  9403. - //
  9404. - // If the current class being redefined has a user-defined class
  9405. - // loader as its defining class loader, then we can skip all
  9406. - // classes loaded by the bootstrap class loader.
  9407. - bool is_user_defined =
  9408. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  9409. - if (is_user_defined && ik->class_loader() == NULL) {
  9410. - return;
  9411. - }
  9412. -
  9413. - // This is a very busy routine. We don't want too much tracing
  9414. - // printed out.
  9415. - bool trace_name_printed = false;
  9416. -
  9417. - // Very noisy: only enable this call if you are trying to determine
  9418. - // that a specific class gets found by this routine.
  9419. - // RC_TRACE macro has an embedded ResourceMark
  9420. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  9421. - // ("adjust check: name=%s", ik->external_name()));
  9422. - // trace_name_printed = true;
  9423. -
  9424. - // Fix the vtable embedded in the_class and subclasses of the_class,
  9425. - // if one exists. We discard scratch_class and we don't keep an
  9426. - // instanceKlass around to hold obsolete methods so we don't have
  9427. - // any other instanceKlass embedded vtables to update. The vtable
  9428. - // holds the methodOops for virtual (but not final) methods.
  9429. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  9430. - // ik->vtable() creates a wrapper object; rm cleans it up
  9431. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9432. +
  9433. + if (ik->vtable_length() > 0) {
  9434. ResourceMark rm(THREAD);
  9435. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  9436. - _matching_new_methods,
  9437. - _matching_methods_length,
  9438. - &trace_name_printed);
  9439. - }
  9440. -
  9441. - // If the current class has an itable and we are either redefining an
  9442. - // interface or if the current class is a subclass of the_class, then
  9443. - // we potentially have to fix the itable. If we are redefining an
  9444. - // interface, then we have to call adjust_method_entries() for
  9445. - // every instanceKlass that has an itable since there isn't a
  9446. - // subclass relationship between an interface and an instanceKlass.
  9447. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  9448. - || ik->is_subclass_of(_the_class_oop))) {
  9449. - // ik->itable() creates a wrapper object; rm cleans it up
  9450. - ResourceMark rm(THREAD);
  9451. - ik->itable()->adjust_method_entries(_matching_old_methods,
  9452. - _matching_new_methods,
  9453. - _matching_methods_length,
  9454. - &trace_name_printed);
  9455. - }
  9456. -
  9457. - // The constant pools in other classes (other_cp) can refer to
  9458. - // methods in the_class. We have to update method information in
  9459. - // other_cp's cache. If other_cp has a previous version, then we
  9460. - // have to repeat the process for each previous version. The
  9461. - // constant pool cache holds the methodOops for non-virtual
  9462. - // methods and for virtual, final methods.
  9463. - //
  9464. - // Special case: if the current class is the_class, then new_cp
  9465. - // has already been attached to the_class and old_cp has already
  9466. - // been added as a previous version. The new_cp doesn't have any
  9467. - // cached references to old methods so it doesn't need to be
  9468. - // updated. We can simply start with the previous version(s) in
  9469. - // that case.
  9470. - constantPoolHandle other_cp;
  9471. - constantPoolCacheOop cp_cache;
  9472. -
  9473. - if (k_oop != _the_class_oop) {
  9474. - // this klass' constant pool cache may need adjustment
  9475. - other_cp = constantPoolHandle(ik->constants());
  9476. - cp_cache = other_cp->cache();
  9477. - if (cp_cache != NULL) {
  9478. - cp_cache->adjust_method_entries(_matching_old_methods,
  9479. - _matching_new_methods,
  9480. - _matching_methods_length,
  9481. - &trace_name_printed);
  9482. + if (!ik->vtable()->check_no_old_entries()) {
  9483. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9484. + k_oop->size()));
  9485. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9486. + ik->signature_name()));
  9487. + assert(false, "OLD method found");
  9488. }
  9489. - }
  9490. - {
  9491. - ResourceMark rm(THREAD);
  9492. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9493. - // contain a GrowableArray of handles. We have to clean up the
  9494. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9495. - // has destroyed the handles.
  9496. - {
  9497. - // the previous versions' constant pool caches may need adjustment
  9498. - PreviousVersionWalker pvw(ik);
  9499. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9500. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9501. - other_cp = pv_info->prev_constant_pool_handle();
  9502. - cp_cache = other_cp->cache();
  9503. - if (cp_cache != NULL) {
  9504. - cp_cache->adjust_method_entries(_matching_old_methods,
  9505. - _matching_new_methods,
  9506. - _matching_methods_length,
  9507. - &trace_name_printed);
  9508. - }
  9509. - }
  9510. - } // pvw is cleaned up
  9511. - } // rm is cleaned up
  9512. - }
  9513. -}
  9514. -
  9515. -void VM_RedefineClasses::update_jmethod_ids() {
  9516. - for (int j = 0; j < _matching_methods_length; ++j) {
  9517. - methodOop old_method = _matching_old_methods[j];
  9518. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  9519. - if (jmid != NULL) {
  9520. - // There is a jmethodID, change it to point to the new method
  9521. - methodHandle new_method_h(_matching_new_methods[j]);
  9522. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9523. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9524. - "should be replaced");
  9525. +
  9526. + ik->vtable()->verify(tty, true);
  9527. }
  9528. }
  9529. }
  9530. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9531. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9532. - *emcp_method_count_p = 0;
  9533. - int obsolete_count = 0;
  9534. - int old_index = 0;
  9535. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9536. - methodOop old_method = _matching_old_methods[j];
  9537. - methodOop new_method = _matching_new_methods[j];
  9538. - methodOop old_array_method;
  9539. -
  9540. - // Maintain an old_index into the _old_methods array by skipping
  9541. - // deleted methods
  9542. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9543. - != old_method) {
  9544. - ++old_index;
  9545. +#endif
  9546. +
  9547. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9548. +{
  9549. + assert(original_klasses != NULL && result != NULL, "");
  9550. + this->_original_klasses = original_klasses;
  9551. + this->_result = result;
  9552. + SystemDictionary::classes_do(this);
  9553. +}
  9554. +
  9555. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9556. +{
  9557. + klassOop klass = (klassOop)obj;
  9558. + assert(!_result->contains(klass), "must not occur more than once!");
  9559. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9560. +
  9561. + for(int i=0; i<_original_klasses->length(); i++) {
  9562. + instanceKlassHandle cur = _original_klasses->at(i);
  9563. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9564. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9565. + _result->append(klass);
  9566. + break;
  9567. }
  9568. -
  9569. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9570. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9571. - // the same with the exception of constant pool indices which may
  9572. - // differ. However, the constants referred to by those indices
  9573. - // must be the same.
  9574. - //
  9575. - // We use methods_EMCP() for comparison since constant pool
  9576. - // merging can remove duplicate constant pool entries that were
  9577. - // present in the old method and removed from the rewritten new
  9578. - // method. A faster binary comparison function would consider the
  9579. - // old and new methods to be different when they are actually
  9580. - // EMCP.
  9581. - //
  9582. - // The old and new methods are EMCP and you would think that we
  9583. - // could get rid of one of them here and now and save some space.
  9584. - // However, the concept of EMCP only considers the bytecodes and
  9585. - // the constant pool entries in the comparison. Other things,
  9586. - // e.g., the line number table (LNT) or the local variable table
  9587. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9588. - // method can have a new LNT that we need so we can't just
  9589. - // overwrite the new method with the old method.
  9590. - //
  9591. - // When this routine is called, we have already attached the new
  9592. - // methods to the_class so the old methods are effectively
  9593. - // overwritten. However, if an old method is still executing,
  9594. - // then the old method cannot be collected until sometime after
  9595. - // the old method call has returned. So the overwriting of old
  9596. - // methods by new methods will save us space except for those
  9597. - // (hopefully few) old methods that are still executing.
  9598. - //
  9599. - // A method refers to a constMethodOop and this presents another
  9600. - // possible avenue to space savings. The constMethodOop in the
  9601. - // new method contains possibly new attributes (LNT, LVT, etc).
  9602. - // At first glance, it seems possible to save space by replacing
  9603. - // the constMethodOop in the old method with the constMethodOop
  9604. - // from the new method. The old and new methods would share the
  9605. - // same constMethodOop and we would save the space occupied by
  9606. - // the old constMethodOop. However, the constMethodOop contains
  9607. - // a back reference to the containing method. Sharing the
  9608. - // constMethodOop between two methods could lead to confusion in
  9609. - // the code that uses the back reference. This would lead to
  9610. - // brittle code that could be broken in non-obvious ways now or
  9611. - // in the future.
  9612. - //
  9613. - // Another possibility is to copy the constMethodOop from the new
  9614. - // method to the old method and then overwrite the new method with
  9615. - // the old method. Since the constMethodOop contains the bytecodes
  9616. - // for the method embedded in the oop, this option would change
  9617. - // the bytecodes out from under any threads executing the old
  9618. - // method and make the thread's bcp invalid. Since EMCP requires
  9619. - // that the bytecodes be the same modulo constant pool indices, it
  9620. - // is straight forward to compute the correct new bcp in the new
  9621. - // constMethodOop from the old bcp in the old constMethodOop. The
  9622. - // time consuming part would be searching all the frames in all
  9623. - // of the threads to find all of the calls to the old method.
  9624. - //
  9625. - // It looks like we will have to live with the limited savings
  9626. - // that we get from effectively overwriting the old methods
  9627. - // when the new methods are attached to the_class.
  9628. -
  9629. - // track which methods are EMCP for add_previous_version() call
  9630. - emcp_methods->set_bit(old_index);
  9631. - (*emcp_method_count_p)++;
  9632. -
  9633. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9634. - // different jmethodID than the current method. An EMCP method
  9635. - // has the same jmethodID as the current method. Having the
  9636. - // same jmethodID for all EMCP versions of a method allows for
  9637. - // a consistent view of the EMCP methods regardless of which
  9638. - // EMCP method you happen to have in hand. For example, a
  9639. - // breakpoint set in one EMCP method will work for all EMCP
  9640. - // versions of the method including the current one.
  9641. - } else {
  9642. - // mark obsolete methods as such
  9643. - old_method->set_is_obsolete();
  9644. - obsolete_count++;
  9645. -
  9646. - // obsolete methods need a unique idnum
  9647. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9648. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9649. -// u2 old_num = old_method->method_idnum();
  9650. - old_method->set_method_idnum(num);
  9651. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9652. + }
  9653. +}
  9654. +
  9655. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9656. +{
  9657. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9658. +
  9659. + for (int i=0; i<class_count; i++) {
  9660. +
  9661. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9662. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9663. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9664. + Handle the_class_loader(THREAD, the_class->class_loader());
  9665. + Handle protection_domain(THREAD, the_class->protection_domain());
  9666. +
  9667. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9668. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9669. + ClassFileParser cfp(&st);
  9670. +
  9671. + GrowableArray<Symbol*> symbolArr;
  9672. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9673. + the_class->name()->as_C_string()));
  9674. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9675. +
  9676. + for (int j=0; j<symbolArr.length(); j++) {
  9677. + Symbol* sym = symbolArr.at(j);
  9678. +
  9679. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9680. +
  9681. + for (int k=0; k<arr->length(); k++) {
  9682. + klassOop curOop = arr->at(k)();
  9683. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9684. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9685. + RC_TRACE(0x00000002, ("Found class to link"));
  9686. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9687. + break;
  9688. + }
  9689. }
  9690. - // With tracing we try not to "yack" too much. The position of
  9691. - // this trace assumes there are fewer obsolete methods than
  9692. - // EMCP methods.
  9693. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9694. - old_method->name()->as_C_string(),
  9695. - old_method->signature()->as_C_string()));
  9696. }
  9697. - old_method->set_is_old();
  9698. }
  9699. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9700. - methodOop old_method = _deleted_methods[i];
  9701. -
  9702. - assert(old_method->vtable_index() < 0,
  9703. - "cannot delete methods with vtable entries");;
  9704. -
  9705. - // Mark all deleted methods as old and obsolete
  9706. - old_method->set_is_old();
  9707. - old_method->set_is_obsolete();
  9708. - ++obsolete_count;
  9709. - // With tracing we try not to "yack" too much. The position of
  9710. - // this trace assumes there are fewer obsolete methods than
  9711. - // EMCP methods.
  9712. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9713. - old_method->name()->as_C_string(),
  9714. - old_method->signature()->as_C_string()));
  9715. +
  9716. +
  9717. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9718. +
  9719. + for (int i=0; i<affected->length(); i++) {
  9720. +
  9721. + instanceKlassHandle klass = affected->at(i);
  9722. +
  9723. + klassOop superKlass = klass->super();
  9724. + if (affected->contains(superKlass)) {
  9725. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9726. + }
  9727. +
  9728. + objArrayOop superInterfaces = klass->local_interfaces();
  9729. + for (int j=0; j<superInterfaces->length(); j++) {
  9730. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9731. + if (arr->contains(interfaceKlass)) {
  9732. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9733. + }
  9734. + }
  9735. }
  9736. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9737. - "sanity check");
  9738. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9739. - obsolete_count));
  9740. +
  9741. + if (RC_TRACE_ENABLED(0x00000002)) {
  9742. + RC_TRACE(0x00000002, ("Identified links: "));
  9743. + for (int i=0; i<links->length(); i++) {
  9744. + RC_TRACE(0x00000002, ("%s to %s",
  9745. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9746. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9747. + }
  9748. + }
  9749. +
  9750. + for (int i=0; i<arr->length(); i++) {
  9751. +
  9752. + int j;
  9753. + for (j=i; j<arr->length(); j++) {
  9754. +
  9755. + int k;
  9756. + for (k=0; k<links->length(); k++) {
  9757. +
  9758. + klassOop k1 = links->adr_at(k)->right();
  9759. + klassOop k2 = arr->at(j)();
  9760. + if (k1 == k2) {
  9761. + break;
  9762. + }
  9763. + }
  9764. +
  9765. + if (k == links->length()) {
  9766. + break;
  9767. + }
  9768. + }
  9769. +
  9770. + if (j == arr->length()) {
  9771. + // circle detected
  9772. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9773. + }
  9774. +
  9775. + for (int k=0; k<links->length(); k++) {
  9776. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9777. + links->at_put(k, links->at(links->length() - 1));
  9778. + links->remove_at(links->length() - 1);
  9779. + k--;
  9780. + }
  9781. + }
  9782. +
  9783. + instanceKlassHandle tmp = arr->at(j);
  9784. + arr->at_put(j, arr->at(i));
  9785. + arr->at_put(i, tmp);
  9786. + }
  9787. +
  9788. + return JVMTI_ERROR_NONE;
  9789. }
  9790. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9791. +
  9792. + if (_updated_oops != NULL) {
  9793. + for (int i=0; i<_updated_oops->length(); i++) {
  9794. + closure->do_oop(_updated_oops->adr_at(i));
  9795. + }
  9796. + }
  9797. +}
  9798. +
  9799. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9800. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9801. + to->set_is_field_access_watched(from->is_field_access_watched());
  9802. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9803. + RC_TRACE(0x00000002, ("Transfered watch for field %s",
  9804. + from->name()->as_C_string()));
  9805. + }
  9806. + update_klass_field_access_flag(to);
  9807. +}
  9808. +
  9809. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9810. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9811. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9812. + fi->set_access_flags(fd->access_flags().as_short());
  9813. +}
  9814. +
  9815. +
  9816. // This internal class transfers the native function registration from old methods
  9817. // to new methods. It is designed to handle both the simple case of unchanged
  9818. // native methods and the complex cases of native method prefixes being added and/or
  9819. @@ -2842,7 +3167,7 @@
  9820. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9821. //
  9822. class TransferNativeFunctionRegistration {
  9823. - private:
  9824. +private:
  9825. instanceKlassHandle the_class;
  9826. int prefix_count;
  9827. char** prefixes;
  9828. @@ -2855,42 +3180,42 @@
  9829. // (2) with the prefix.
  9830. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9831. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9832. - Symbol* signature) {
  9833. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9834. - if (name_symbol != NULL) {
  9835. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9836. - if (method != NULL) {
  9837. - // Even if prefixed, intermediate methods must exist.
  9838. - if (method->is_native()) {
  9839. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9840. - return method;
  9841. - }
  9842. - if (depth < prefix_count) {
  9843. - // Try applying further prefixes (other than this one).
  9844. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9845. - if (method != NULL) {
  9846. - return method; // found
  9847. + Symbol* signature) {
  9848. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9849. + if (name_symbol != NULL) {
  9850. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  9851. + if (method != NULL) {
  9852. + // Even if prefixed, intermediate methods must exist.
  9853. + if (method->is_native()) {
  9854. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9855. + return method;
  9856. }
  9857. -
  9858. - // Try adding this prefix to the method name and see if it matches
  9859. - // another method name.
  9860. - char* prefix = prefixes[depth];
  9861. - size_t prefix_len = strlen(prefix);
  9862. - size_t trial_len = name_len + prefix_len;
  9863. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9864. - strcpy(trial_name_str, prefix);
  9865. - strcat(trial_name_str, name_str);
  9866. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9867. - signature);
  9868. - if (method != NULL) {
  9869. - // If found along this branch, it was prefixed, mark as such
  9870. - method->set_is_prefixed_native();
  9871. - return method; // found
  9872. + if (depth < prefix_count) {
  9873. + // Try applying further prefixes (other than this one).
  9874. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9875. + if (method != NULL) {
  9876. + return method; // found
  9877. + }
  9878. +
  9879. + // Try adding this prefix to the method name and see if it matches
  9880. + // another method name.
  9881. + char* prefix = prefixes[depth];
  9882. + size_t prefix_len = strlen(prefix);
  9883. + size_t trial_len = name_len + prefix_len;
  9884. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9885. + strcpy(trial_name_str, prefix);
  9886. + strcat(trial_name_str, name_str);
  9887. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9888. + signature);
  9889. + if (method != NULL) {
  9890. + // If found along this branch, it was prefixed, mark as such
  9891. + method->set_is_prefixed_native();
  9892. + return method; // found
  9893. + }
  9894. }
  9895. }
  9896. }
  9897. - }
  9898. - return NULL; // This whole branch bore nothing
  9899. + return NULL; // This whole branch bore nothing
  9900. }
  9901. // Return the method name with old prefixes stripped away.
  9902. @@ -2915,10 +3240,10 @@
  9903. ResourceMark rm;
  9904. char* name_str = method_name_without_prefixes(method);
  9905. return search_prefix_name_space(0, name_str, strlen(name_str),
  9906. - method->signature());
  9907. + method->signature());
  9908. }
  9909. - public:
  9910. +public:
  9911. // Construct a native method transfer processor for this class.
  9912. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9913. @@ -2929,9 +3254,9 @@
  9914. }
  9915. // Attempt to transfer any of the old or deleted methods that are native
  9916. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  9917. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  9918. for (int j = 0; j < methods_length; j++) {
  9919. - methodOop old_method = old_methods[j];
  9920. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  9921. if (old_method->is_native() && old_method->has_native_function()) {
  9922. methodOop new_method = strip_and_search_for_new_native(old_method);
  9923. @@ -2940,7 +3265,9 @@
  9924. // Redefine does not send events (except CFLH), certainly not this
  9925. // behind the scenes re-registration.
  9926. new_method->set_native_function(old_method->native_function(),
  9927. - !methodOopDesc::native_bind_event_is_interesting);
  9928. + !methodOopDesc::native_bind_event_is_interesting);
  9929. +
  9930. + RC_TRACE(0x00008000, ("Transfering native function for method %s", old_method->name()->as_C_string()));
  9931. }
  9932. }
  9933. }
  9934. @@ -2948,494 +3275,8 @@
  9935. };
  9936. // Don't lose the association between a native method and its JNI function.
  9937. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  9938. - TransferNativeFunctionRegistration transfer(the_class);
  9939. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  9940. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  9941. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  9942. + TransferNativeFunctionRegistration transfer(old_klass);
  9943. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  9944. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  9945. }
  9946. -
  9947. -// Deoptimize all compiled code that depends on this class.
  9948. -//
  9949. -// If the can_redefine_classes capability is obtained in the onload
  9950. -// phase then the compiler has recorded all dependencies from startup.
  9951. -// In that case we need only deoptimize and throw away all compiled code
  9952. -// that depends on the class.
  9953. -//
  9954. -// If can_redefine_classes is obtained sometime after the onload
  9955. -// phase then the dependency information may be incomplete. In that case
  9956. -// the first call to RedefineClasses causes all compiled code to be
  9957. -// thrown away. As can_redefine_classes has been obtained then
  9958. -// all future compilations will record dependencies so second and
  9959. -// subsequent calls to RedefineClasses need only throw away code
  9960. -// that depends on the class.
  9961. -//
  9962. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9963. - assert_locked_or_safepoint(Compile_lock);
  9964. -
  9965. - // All dependencies have been recorded from startup or this is a second or
  9966. - // subsequent use of RedefineClasses
  9967. - if (JvmtiExport::all_dependencies_are_recorded()) {
  9968. - Universe::flush_evol_dependents_on(k_h);
  9969. - } else {
  9970. - CodeCache::mark_all_nmethods_for_deoptimization();
  9971. -
  9972. - ResourceMark rm(THREAD);
  9973. - DeoptimizationMarker dm;
  9974. -
  9975. - // Deoptimize all activations depending on marked nmethods
  9976. - Deoptimization::deoptimize_dependents();
  9977. -
  9978. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9979. - CodeCache::make_marked_nmethods_not_entrant();
  9980. -
  9981. - // From now on we know that the dependency information is complete
  9982. - JvmtiExport::set_all_dependencies_are_recorded(true);
  9983. - }
  9984. -}
  9985. -
  9986. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9987. - methodOop old_method;
  9988. - methodOop new_method;
  9989. -
  9990. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9991. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9992. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  9993. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9994. -
  9995. - _matching_methods_length = 0;
  9996. - _deleted_methods_length = 0;
  9997. - _added_methods_length = 0;
  9998. -
  9999. - int nj = 0;
  10000. - int oj = 0;
  10001. - while (true) {
  10002. - if (oj >= _old_methods->length()) {
  10003. - if (nj >= _new_methods->length()) {
  10004. - break; // we've looked at everything, done
  10005. - }
  10006. - // New method at the end
  10007. - new_method = (methodOop) _new_methods->obj_at(nj);
  10008. - _added_methods[_added_methods_length++] = new_method;
  10009. - ++nj;
  10010. - } else if (nj >= _new_methods->length()) {
  10011. - // Old method, at the end, is deleted
  10012. - old_method = (methodOop) _old_methods->obj_at(oj);
  10013. - _deleted_methods[_deleted_methods_length++] = old_method;
  10014. - ++oj;
  10015. - } else {
  10016. - old_method = (methodOop) _old_methods->obj_at(oj);
  10017. - new_method = (methodOop) _new_methods->obj_at(nj);
  10018. - if (old_method->name() == new_method->name()) {
  10019. - if (old_method->signature() == new_method->signature()) {
  10020. - _matching_old_methods[_matching_methods_length ] = old_method;
  10021. - _matching_new_methods[_matching_methods_length++] = new_method;
  10022. - ++nj;
  10023. - ++oj;
  10024. - } else {
  10025. - // added overloaded have already been moved to the end,
  10026. - // so this is a deleted overloaded method
  10027. - _deleted_methods[_deleted_methods_length++] = old_method;
  10028. - ++oj;
  10029. - }
  10030. - } else { // names don't match
  10031. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10032. - // new method
  10033. - _added_methods[_added_methods_length++] = new_method;
  10034. - ++nj;
  10035. - } else {
  10036. - // deleted method
  10037. - _deleted_methods[_deleted_methods_length++] = old_method;
  10038. - ++oj;
  10039. - }
  10040. - }
  10041. - }
  10042. - }
  10043. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10044. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10045. -}
  10046. -
  10047. -
  10048. -
  10049. -// Install the redefinition of a class:
  10050. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10051. -// dependent compiled code)
  10052. -// - replacing parts in the_class with parts from scratch_class
  10053. -// - adding a weak reference to track the obsolete but interesting
  10054. -// parts of the_class
  10055. -// - adjusting constant pool caches and vtables in other classes
  10056. -// that refer to methods in the_class. These adjustments use the
  10057. -// SystemDictionary::classes_do() facility which only allows
  10058. -// a helper method to be specified. The interesting parameters
  10059. -// that we would like to pass to the helper method are saved in
  10060. -// static global fields in the VM operation.
  10061. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10062. - instanceKlassHandle scratch_class, TRAPS) {
  10063. -
  10064. - RC_TIMER_START(_timer_rsc_phase1);
  10065. -
  10066. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10067. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10068. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10069. -
  10070. -#ifndef JVMTI_KERNEL
  10071. - // Remove all breakpoints in methods of this class
  10072. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10073. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10074. -#endif // !JVMTI_KERNEL
  10075. -
  10076. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10077. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10078. - // cached and users of the cache care about each active version of
  10079. - // the method so we have to track this previous version.
  10080. - // Do this before methods get switched
  10081. - Universe::reflect_invoke_cache()->add_previous_version(
  10082. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10083. - }
  10084. -
  10085. - // Deoptimize all compiled code that depends on this class
  10086. - flush_dependent_code(the_class, THREAD);
  10087. -
  10088. - _old_methods = the_class->methods();
  10089. - _new_methods = scratch_class->methods();
  10090. - _the_class_oop = the_class_oop;
  10091. - compute_added_deleted_matching_methods();
  10092. - update_jmethod_ids();
  10093. -
  10094. - // Attach new constant pool to the original klass. The original
  10095. - // klass still refers to the old constant pool (for now).
  10096. - scratch_class->constants()->set_pool_holder(the_class());
  10097. -
  10098. -#if 0
  10099. - // In theory, with constant pool merging in place we should be able
  10100. - // to save space by using the new, merged constant pool in place of
  10101. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10102. - // the klass version we are replacing now and any constant pool(s) in
  10103. - // previous versions of klass. Nice theory, doesn't work in practice.
  10104. - // When this code is enabled, even simple programs throw NullPointer
  10105. - // exceptions. I'm guessing that this is caused by some constant pool
  10106. - // cache difference between the new, merged constant pool and the
  10107. - // constant pool that was just being used by the klass. I'm keeping
  10108. - // this code around to archive the idea, but the code has to remain
  10109. - // disabled for now.
  10110. -
  10111. - // Attach each old method to the new constant pool. This can be
  10112. - // done here since we are past the bytecode verification and
  10113. - // constant pool optimization phases.
  10114. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10115. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10116. - method->set_constants(scratch_class->constants());
  10117. - }
  10118. -
  10119. - {
  10120. - // walk all previous versions of the klass
  10121. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10122. - PreviousVersionWalker pvw(ik);
  10123. - instanceKlassHandle ikh;
  10124. - do {
  10125. - ikh = pvw.next_previous_version();
  10126. - if (!ikh.is_null()) {
  10127. - ik = ikh();
  10128. -
  10129. - // attach previous version of klass to the new constant pool
  10130. - ik->set_constants(scratch_class->constants());
  10131. -
  10132. - // Attach each method in the previous version of klass to the
  10133. - // new constant pool
  10134. - objArrayOop prev_methods = ik->methods();
  10135. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10136. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10137. - method->set_constants(scratch_class->constants());
  10138. - }
  10139. - }
  10140. - } while (!ikh.is_null());
  10141. - }
  10142. -#endif
  10143. -
  10144. - // Replace methods and constantpool
  10145. - the_class->set_methods(_new_methods);
  10146. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10147. - // and to be able to undo operation easily.
  10148. -
  10149. - constantPoolOop old_constants = the_class->constants();
  10150. - the_class->set_constants(scratch_class->constants());
  10151. - scratch_class->set_constants(old_constants); // See the previous comment.
  10152. -#if 0
  10153. - // We are swapping the guts of "the new class" with the guts of "the
  10154. - // class". Since the old constant pool has just been attached to "the
  10155. - // new class", it seems logical to set the pool holder in the old
  10156. - // constant pool also. However, doing this will change the observable
  10157. - // class hierarchy for any old methods that are still executing. A
  10158. - // method can query the identity of its "holder" and this query uses
  10159. - // the method's constant pool link to find the holder. The change in
  10160. - // holding class from "the class" to "the new class" can confuse
  10161. - // things.
  10162. - //
  10163. - // Setting the old constant pool's holder will also cause
  10164. - // verification done during vtable initialization below to fail.
  10165. - // During vtable initialization, the vtable's class is verified to be
  10166. - // a subtype of the method's holder. The vtable's class is "the
  10167. - // class" and the method's holder is gotten from the constant pool
  10168. - // link in the method itself. For "the class"'s directly implemented
  10169. - // methods, the method holder is "the class" itself (as gotten from
  10170. - // the new constant pool). The check works fine in this case. The
  10171. - // check also works fine for methods inherited from super classes.
  10172. - //
  10173. - // Miranda methods are a little more complicated. A miranda method is
  10174. - // provided by an interface when the class implementing the interface
  10175. - // does not provide its own method. These interfaces are implemented
  10176. - // internally as an instanceKlass. These special instanceKlasses
  10177. - // share the constant pool of the class that "implements" the
  10178. - // interface. By sharing the constant pool, the method holder of a
  10179. - // miranda method is the class that "implements" the interface. In a
  10180. - // non-redefine situation, the subtype check works fine. However, if
  10181. - // the old constant pool's pool holder is modified, then the check
  10182. - // fails because there is no class hierarchy relationship between the
  10183. - // vtable's class and "the new class".
  10184. -
  10185. - old_constants->set_pool_holder(scratch_class());
  10186. -#endif
  10187. -
  10188. - // track which methods are EMCP for add_previous_version() call below
  10189. - BitMap emcp_methods(_old_methods->length());
  10190. - int emcp_method_count = 0;
  10191. - emcp_methods.clear(); // clears 0..(length() - 1)
  10192. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10193. - transfer_old_native_function_registrations(the_class);
  10194. -
  10195. - // The class file bytes from before any retransformable agents mucked
  10196. - // with them was cached on the scratch class, move to the_class.
  10197. - // Note: we still want to do this if nothing needed caching since it
  10198. - // should get cleared in the_class too.
  10199. - if (the_class->get_cached_class_file_bytes() == 0) {
  10200. - // the_class doesn't have a cache yet so copy it
  10201. - the_class->set_cached_class_file(
  10202. - scratch_class->get_cached_class_file_bytes(),
  10203. - scratch_class->get_cached_class_file_len());
  10204. - }
  10205. -#ifndef PRODUCT
  10206. - else {
  10207. - assert(the_class->get_cached_class_file_bytes() ==
  10208. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10209. - assert(the_class->get_cached_class_file_len() ==
  10210. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10211. - }
  10212. -#endif
  10213. -
  10214. - // Replace inner_classes
  10215. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10216. - the_class->set_inner_classes(scratch_class->inner_classes());
  10217. - scratch_class->set_inner_classes(old_inner_classes);
  10218. -
  10219. - // Initialize the vtable and interface table after
  10220. - // methods have been rewritten
  10221. - {
  10222. - ResourceMark rm(THREAD);
  10223. - // no exception should happen here since we explicitly
  10224. - // do not check loader constraints.
  10225. - // compare_and_normalize_class_versions has already checked:
  10226. - // - classloaders unchanged, signatures unchanged
  10227. - // - all instanceKlasses for redefined classes reused & contents updated
  10228. - the_class->vtable()->initialize_vtable(false, THREAD);
  10229. - the_class->itable()->initialize_itable(false, THREAD);
  10230. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10231. - }
  10232. -
  10233. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10234. -
  10235. - // Copy the "source file name" attribute from new class version
  10236. - the_class->set_source_file_name(scratch_class->source_file_name());
  10237. -
  10238. - // Copy the "source debug extension" attribute from new class version
  10239. - the_class->set_source_debug_extension(
  10240. - scratch_class->source_debug_extension());
  10241. -
  10242. - // Use of javac -g could be different in the old and the new
  10243. - if (scratch_class->access_flags().has_localvariable_table() !=
  10244. - the_class->access_flags().has_localvariable_table()) {
  10245. -
  10246. - AccessFlags flags = the_class->access_flags();
  10247. - if (scratch_class->access_flags().has_localvariable_table()) {
  10248. - flags.set_has_localvariable_table();
  10249. - } else {
  10250. - flags.clear_has_localvariable_table();
  10251. - }
  10252. - the_class->set_access_flags(flags);
  10253. - }
  10254. -
  10255. - // Replace class annotation fields values
  10256. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10257. - the_class->set_class_annotations(scratch_class->class_annotations());
  10258. - scratch_class->set_class_annotations(old_class_annotations);
  10259. -
  10260. - // Replace fields annotation fields values
  10261. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10262. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10263. - scratch_class->set_fields_annotations(old_fields_annotations);
  10264. -
  10265. - // Replace methods annotation fields values
  10266. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10267. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10268. - scratch_class->set_methods_annotations(old_methods_annotations);
  10269. -
  10270. - // Replace methods parameter annotation fields values
  10271. - objArrayOop old_methods_parameter_annotations =
  10272. - the_class->methods_parameter_annotations();
  10273. - the_class->set_methods_parameter_annotations(
  10274. - scratch_class->methods_parameter_annotations());
  10275. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10276. -
  10277. - // Replace methods default annotation fields values
  10278. - objArrayOop old_methods_default_annotations =
  10279. - the_class->methods_default_annotations();
  10280. - the_class->set_methods_default_annotations(
  10281. - scratch_class->methods_default_annotations());
  10282. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10283. -
  10284. - // Replace minor version number of class file
  10285. - u2 old_minor_version = the_class->minor_version();
  10286. - the_class->set_minor_version(scratch_class->minor_version());
  10287. - scratch_class->set_minor_version(old_minor_version);
  10288. -
  10289. - // Replace major version number of class file
  10290. - u2 old_major_version = the_class->major_version();
  10291. - the_class->set_major_version(scratch_class->major_version());
  10292. - scratch_class->set_major_version(old_major_version);
  10293. -
  10294. - // Replace CP indexes for class and name+type of enclosing method
  10295. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10296. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10297. - the_class->set_enclosing_method_indices(
  10298. - scratch_class->enclosing_method_class_index(),
  10299. - scratch_class->enclosing_method_method_index());
  10300. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10301. -
  10302. - // keep track of previous versions of this class
  10303. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10304. - emcp_method_count);
  10305. -
  10306. - RC_TIMER_STOP(_timer_rsc_phase1);
  10307. - RC_TIMER_START(_timer_rsc_phase2);
  10308. -
  10309. - // Adjust constantpool caches and vtables for all classes
  10310. - // that reference methods of the evolved class.
  10311. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10312. -
  10313. - if (the_class->oop_map_cache() != NULL) {
  10314. - // Flush references to any obsolete methods from the oop map cache
  10315. - // so that obsolete methods are not pinned.
  10316. - the_class->oop_map_cache()->flush_obsolete_entries();
  10317. - }
  10318. -
  10319. - // increment the classRedefinedCount field in the_class and in any
  10320. - // direct and indirect subclasses of the_class
  10321. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10322. -
  10323. - // RC_TRACE macro has an embedded ResourceMark
  10324. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10325. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10326. - the_class->external_name(),
  10327. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10328. - os::available_memory() >> 10));
  10329. -
  10330. - RC_TIMER_STOP(_timer_rsc_phase2);
  10331. -} // end redefine_single_class()
  10332. -
  10333. -
  10334. -// Increment the classRedefinedCount field in the specific instanceKlass
  10335. -// and in all direct and indirect subclasses.
  10336. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10337. - oop class_mirror = ik->java_mirror();
  10338. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10339. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10340. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10341. -
  10342. - if (class_oop != _the_class_oop) {
  10343. - // _the_class_oop count is printed at end of redefine_single_class()
  10344. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10345. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10346. - }
  10347. -
  10348. - for (Klass *subk = ik->subklass(); subk != NULL;
  10349. - subk = subk->next_sibling()) {
  10350. - if (subk->oop_is_instance()) {
  10351. - // Only update instanceKlasses
  10352. - instanceKlass *subik = (instanceKlass*)subk;
  10353. - // recursively do subclasses of the current subclass
  10354. - increment_class_counter(subik, THREAD);
  10355. - }
  10356. - }
  10357. -}
  10358. -
  10359. -#ifndef PRODUCT
  10360. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10361. - oop initiating_loader, TRAPS) {
  10362. - Klass *k = k_oop->klass_part();
  10363. - if (k->oop_is_instance()) {
  10364. - HandleMark hm(THREAD);
  10365. - instanceKlass *ik = (instanceKlass *) k;
  10366. -
  10367. - if (ik->vtable_length() > 0) {
  10368. - ResourceMark rm(THREAD);
  10369. - if (!ik->vtable()->check_no_old_entries()) {
  10370. - tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  10371. - ik->vtable()->dump_vtable();
  10372. - dump_methods();
  10373. - assert(false, "OLD method found");
  10374. - }
  10375. - }
  10376. - }
  10377. -}
  10378. -
  10379. -void VM_RedefineClasses::dump_methods() {
  10380. - int j;
  10381. - tty->print_cr("_old_methods --");
  10382. - for (j = 0; j < _old_methods->length(); ++j) {
  10383. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10384. - tty->print("%4d (%5d) ", j, m->vtable_index());
  10385. - m->access_flags().print_on(tty);
  10386. - tty->print(" -- ");
  10387. - m->print_name(tty);
  10388. - tty->cr();
  10389. - }
  10390. - tty->print_cr("_new_methods --");
  10391. - for (j = 0; j < _new_methods->length(); ++j) {
  10392. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10393. - tty->print("%4d (%5d) ", j, m->vtable_index());
  10394. - m->access_flags().print_on(tty);
  10395. - tty->print(" -- ");
  10396. - m->print_name(tty);
  10397. - tty->cr();
  10398. - }
  10399. - tty->print_cr("_matching_(old/new)_methods --");
  10400. - for (j = 0; j < _matching_methods_length; ++j) {
  10401. - methodOop m = _matching_old_methods[j];
  10402. - tty->print("%4d (%5d) ", j, m->vtable_index());
  10403. - m->access_flags().print_on(tty);
  10404. - tty->print(" -- ");
  10405. - m->print_name(tty);
  10406. - tty->cr();
  10407. - m = _matching_new_methods[j];
  10408. - tty->print(" (%5d) ", m->vtable_index());
  10409. - m->access_flags().print_on(tty);
  10410. - tty->cr();
  10411. - }
  10412. - tty->print_cr("_deleted_methods --");
  10413. - for (j = 0; j < _deleted_methods_length; ++j) {
  10414. - methodOop m = _deleted_methods[j];
  10415. - tty->print("%4d (%5d) ", j, m->vtable_index());
  10416. - m->access_flags().print_on(tty);
  10417. - tty->print(" -- ");
  10418. - m->print_name(tty);
  10419. - tty->cr();
  10420. - }
  10421. - tty->print_cr("_added_methods --");
  10422. - for (j = 0; j < _added_methods_length; ++j) {
  10423. - methodOop m = _added_methods[j];
  10424. - tty->print("%4d (%5d) ", j, m->vtable_index());
  10425. - m->access_flags().print_on(tty);
  10426. - tty->print(" -- ");
  10427. - m->print_name(tty);
  10428. - tty->cr();
  10429. - }
  10430. -}
  10431. -#endif
  10432. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10433. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10434. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10435. @@ -1,26 +1,29 @@
  10436. /*
  10437. - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  10438. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10439. - *
  10440. - * This code is free software; you can redistribute it and/or modify it
  10441. - * under the terms of the GNU General Public License version 2 only, as
  10442. - * published by the Free Software Foundation.
  10443. - *
  10444. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10445. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10446. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10447. - * version 2 for more details (a copy is included in the LICENSE file that
  10448. - * accompanied this code).
  10449. - *
  10450. - * You should have received a copy of the GNU General Public License version
  10451. - * 2 along with this work; if not, write to the Free Software Foundation,
  10452. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10453. - *
  10454. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10455. - * or visit www.oracle.com if you need additional information or have any
  10456. - * questions.
  10457. - *
  10458. - */
  10459. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10460. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10461. +*
  10462. +* This code is free software; you can redistribute it and/or modify it
  10463. +* under the terms of the GNU General Public License version 2 only, as
  10464. +* published by the Free Software Foundation.
  10465. +*
  10466. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10467. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10468. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10469. +* version 2 for more details (a copy is included in the LICENSE file that
  10470. +* accompanied this code).
  10471. +*
  10472. +* You should have received a copy of the GNU General Public License version
  10473. +* 2 along with this work; if not, write to the Free Software Foundation,
  10474. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10475. +*
  10476. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10477. +* or visit www.oracle.com if you need additional information or have any
  10478. +* questions.
  10479. +*
  10480. +*/
  10481. +
  10482. +// New version that allows arbitrary changes to already loaded classes.
  10483. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10484. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10485. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10486. @@ -32,331 +35,28 @@
  10487. #include "oops/objArrayOop.hpp"
  10488. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10489. #include "runtime/vm_operations.hpp"
  10490. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10491. -// Introduction:
  10492. -//
  10493. -// The RedefineClasses() API is used to change the definition of one or
  10494. -// more classes. While the API supports redefining more than one class
  10495. -// in a single call, in general, the API is discussed in the context of
  10496. -// changing the definition of a single current class to a single new
  10497. -// class. For clarity, the current class is will always be called
  10498. -// "the_class" and the new class will always be called "scratch_class".
  10499. -//
  10500. -// The name "the_class" is used because there is only one structure
  10501. -// that represents a specific class; redefinition does not replace the
  10502. -// structure, but instead replaces parts of the structure. The name
  10503. -// "scratch_class" is used because the structure that represents the
  10504. -// new definition of a specific class is simply used to carry around
  10505. -// the parts of the new definition until they are used to replace the
  10506. -// appropriate parts in the_class. Once redefinition of a class is
  10507. -// complete, scratch_class is thrown away.
  10508. -//
  10509. -//
  10510. -// Implementation Overview:
  10511. -//
  10512. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10513. -// does the real work. The work is split in varying degrees between
  10514. -// doit_prologue(), doit() and doit_epilogue().
  10515. -//
  10516. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10517. -// safepoint. It does parameter verification and loads scratch_class
  10518. -// which involves:
  10519. -// - parsing the incoming class definition using the_class' class
  10520. -// loader and security context
  10521. -// - linking scratch_class
  10522. -// - merging constant pools and rewriting bytecodes as needed
  10523. -// for the merged constant pool
  10524. -// - verifying the bytecodes in scratch_class
  10525. -// - setting up the constant pool cache and rewriting bytecodes
  10526. -// as needed to use the cache
  10527. -// - finally, scratch_class is compared to the_class to verify
  10528. -// that it is a valid replacement class
  10529. -// - if everything is good, then scratch_class is saved in an
  10530. -// instance field in the VM operation for the doit() call
  10531. -//
  10532. -// Note: A JavaThread must do the above work.
  10533. -//
  10534. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10535. -// the new class definition(s) which involves:
  10536. -// - retrieving the scratch_class from the instance field in the
  10537. -// VM operation
  10538. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10539. -// dependent compiled code)
  10540. -// - replacing parts in the_class with parts from scratch_class
  10541. -// - adding weak reference(s) to track the obsolete but interesting
  10542. -// parts of the_class
  10543. -// - adjusting constant pool caches and vtables in other classes
  10544. -// that refer to methods in the_class. These adjustments use the
  10545. -// SystemDictionary::classes_do() facility which only allows
  10546. -// a helper method to be specified. The interesting parameters
  10547. -// that we would like to pass to the helper method are saved in
  10548. -// static global fields in the VM operation.
  10549. -// - telling the SystemDictionary to notice our changes
  10550. -//
  10551. -// Note: the above work must be done by the VMThread to be safe.
  10552. -//
  10553. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10554. -// is finished and the safepoint is done. It simply cleans up
  10555. -// memory allocated in doit_prologue() and used in doit().
  10556. -//
  10557. -//
  10558. -// Constant Pool Details:
  10559. -//
  10560. -// When the_class is redefined, we cannot just replace the constant
  10561. -// pool in the_class with the constant pool from scratch_class because
  10562. -// that could confuse obsolete methods that may still be running.
  10563. -// Instead, the constant pool from the_class, old_cp, is merged with
  10564. -// the constant pool from scratch_class, scratch_cp. The resulting
  10565. -// constant pool, merge_cp, replaces old_cp in the_class.
  10566. -//
  10567. -// The key part of any merging algorithm is the entry comparison
  10568. -// function so we have to know the types of entries in a constant pool
  10569. -// in order to merge two of them together. Constant pools can contain
  10570. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10571. -// is not presently used so we only have to worry about the other 11
  10572. -// entry types. For the purposes of constant pool merging, it is
  10573. -// helpful to know that the 11 entry types fall into 3 different
  10574. -// subtypes: "direct", "indirect" and "double-indirect".
  10575. -//
  10576. -// Direct CP entries contain data and do not contain references to
  10577. -// other CP entries. The following are direct CP entries:
  10578. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10579. -//
  10580. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10581. -// and no other data. The following are indirect CP entries:
  10582. -// JVM_CONSTANT_{Class,NameAndType,String}
  10583. -//
  10584. -// Double-indirect CP entries contain two references to indirect CP
  10585. -// entries and no other data. The following are double-indirect CP
  10586. -// entries:
  10587. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10588. -//
  10589. -// When comparing entries between two constant pools, the entry types
  10590. -// are compared first and if they match, then further comparisons are
  10591. -// made depending on the entry subtype. Comparing direct CP entries is
  10592. -// simply a matter of comparing the data associated with each entry.
  10593. -// Comparing both indirect and double-indirect CP entries requires
  10594. -// recursion.
  10595. -//
  10596. -// Fortunately, the recursive combinations are limited because indirect
  10597. -// CP entries can only refer to direct CP entries and double-indirect
  10598. -// CP entries can only refer to indirect CP entries. The following is
  10599. -// an example illustration of the deepest set of indirections needed to
  10600. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10601. -//
  10602. -// JVM_CONSTANT_Fieldref {
  10603. -// class_index => JVM_CONSTANT_Class {
  10604. -// name_index => JVM_CONSTANT_Utf8 {
  10605. -// <data-1>
  10606. -// }
  10607. -// }
  10608. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10609. -// name_index => JVM_CONSTANT_Utf8 {
  10610. -// <data-2>
  10611. -// }
  10612. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10613. -// <data-3>
  10614. -// }
  10615. -// }
  10616. -// }
  10617. -//
  10618. -// The above illustration is not a data structure definition for any
  10619. -// computer language. The curly braces ('{' and '}') are meant to
  10620. -// delimit the context of the "fields" in the CP entry types shown.
  10621. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10622. -// "=>", e.g., the class_index is used to indirectly reference a
  10623. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10624. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10625. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10626. -// have to do a total of 5 indirections just to get to the CP entries
  10627. -// that contain the interesting pieces of data and then we have to
  10628. -// fetch the three pieces of data. This means we have to do a total of
  10629. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10630. -// entries.
  10631. -//
  10632. -// Here is the indirection, data and dereference count for each entry
  10633. -// type:
  10634. -//
  10635. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10636. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10637. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10638. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10639. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10640. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10641. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10642. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10643. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10644. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10645. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10646. -//
  10647. -// So different subtypes of CP entries require different amounts of
  10648. -// work for a proper comparison.
  10649. -//
  10650. -// Now that we've talked about the different entry types and how to
  10651. -// compare them we need to get back to merging. This is not a merge in
  10652. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10653. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10654. -// preserving entry order. Next we append all the unique entries from
  10655. -// scratch_cp to merge_cp and we track the index changes from the
  10656. -// location in scratch_cp to the possibly new location in merge_cp.
  10657. -// When we are done, any obsolete code that is still running that
  10658. -// uses old_cp should not be able to observe any difference if it
  10659. -// were to use merge_cp. As for the new code in scratch_class, it is
  10660. -// modified to use the appropriate index values in merge_cp before it
  10661. -// is used to replace the code in the_class.
  10662. -//
  10663. -// There is one small complication in copying the entries from old_cp
  10664. -// to merge_cp. Two of the CP entry types are special in that they are
  10665. -// lazily resolved. Before explaining the copying complication, we need
  10666. -// to digress into CP entry resolution.
  10667. -//
  10668. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10669. -// the class file, but are not stored in memory as such until they are
  10670. -// resolved. The entries are not resolved unless they are used because
  10671. -// resolution is expensive. During class file parsing the entries are
  10672. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10673. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10674. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10675. -// have been parsed, but the index values in the entries have not been
  10676. -// validated. After the entire constant pool has been parsed, the index
  10677. -// values can be validated and then the entries are converted into
  10678. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10679. -// entries. During this conversion process, the UTF8 values that are
  10680. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10681. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10682. -// entries are modified to refer to the Symbol*s. This optimization
  10683. -// eliminates one level of indirection for those two CP entry types and
  10684. -// gets the entries ready for verification. During class file parsing
  10685. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10686. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10687. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10688. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10689. -// entries.
  10690. -//
  10691. -// Now we can get back to the copying complication. When we copy
  10692. -// entries from old_cp to merge_cp, we have to revert any
  10693. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10694. -// or verification will fail.
  10695. -//
  10696. -// It is important to explicitly state that the merging algorithm
  10697. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10698. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10699. -// entries in the merge_cp. This is done both to make verification
  10700. -// happy and to avoid adding more brittleness between RedefineClasses
  10701. -// and the constant pool cache. By allowing the constant pool cache
  10702. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10703. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10704. -// about those algorithms in RedefineClasses.
  10705. -//
  10706. -// Appending unique entries from scratch_cp to merge_cp is straight
  10707. -// forward for direct CP entries and most indirect CP entries. For the
  10708. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10709. -// indirect CP entry types, the presence of more than one piece of
  10710. -// interesting data makes appending the entries more complicated.
  10711. -//
  10712. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10713. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10714. -// If the index in scratch_cp is different than the destination index
  10715. -// in merge_cp, then the change in index value is tracked.
  10716. -//
  10717. -// Note: the above discussion for the direct CP entries also applies
  10718. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10719. -//
  10720. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10721. -// one data element at the end of the recursion, we know that we have
  10722. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10723. -// unique then it is appended to merge_cp before the current entry.
  10724. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10725. -// is updated to refer to the duplicate entry in merge_cp before it is
  10726. -// appended to merge_cp. Again, any changes in index values are tracked
  10727. -// as needed.
  10728. -//
  10729. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10730. -// types is theoretical. Since those entry types have already been
  10731. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10732. -// they are handled as direct CP entries.
  10733. -//
  10734. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10735. -// data elements at the end of the recursions, we know that we have
  10736. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10737. -// entries are appended to merge_cp before the current entry. For any
  10738. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10739. -// updated to refer to the duplicate entry in merge_cp before it is
  10740. -// appended to merge_cp. Again, any changes in index values are tracked
  10741. -// as needed.
  10742. -//
  10743. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10744. -// types, since there are two indirect CP entries and three data
  10745. -// elements at the end of the recursions, we know that we have between
  10746. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10747. -// above for an example of all six entries. The uniqueness algorithm
  10748. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10749. -// covered above. Any unique entries are appended to merge_cp before
  10750. -// the current entry. For any entries that are not unique, the current
  10751. -// entry is updated to refer to the duplicate entry in merge_cp before
  10752. -// it is appended to merge_cp. Again, any changes in index values are
  10753. -// tracked as needed.
  10754. -//
  10755. -//
  10756. -// Other Details:
  10757. -//
  10758. -// Details for other parts of RedefineClasses need to be written.
  10759. -// This is a placeholder section.
  10760. -//
  10761. -//
  10762. -// Open Issues (in no particular order):
  10763. -//
  10764. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10765. -//
  10766. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10767. -// domain since the initial version. This has been changed to pass
  10768. -// the_class->protection_domain(). This change has been tested with
  10769. -// all NSK tests and nothing broke, but what will adding it now break
  10770. -// in ways that we don't test?
  10771. -//
  10772. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10773. -// (indirect) use of the Relocator class that the max instruction
  10774. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10775. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10776. -// what it does to the bytecodes. More investigation is needed.
  10777. -//
  10778. -// - java.lang.Object methods can be called on arrays. This is
  10779. -// implemented via the arrayKlassOop vtable which we don't
  10780. -// update. For example, if we redefine java.lang.Object.toString(),
  10781. -// then the new version of the method will not be called for array
  10782. -// objects.
  10783. -//
  10784. -// - How do we know if redefine_single_class() and the guts of
  10785. -// instanceKlass are out of sync? I don't think this can be
  10786. -// automated, but we should probably order the work in
  10787. -// redefine_single_class() to match the order of field
  10788. -// definitions in instanceKlass. We also need to add some
  10789. -// comments about keeping things in sync.
  10790. -//
  10791. -// - set_new_constant_pool() is huge and we should consider refactoring
  10792. -// it into smaller chunks of work.
  10793. -//
  10794. -// - The exception table update code in set_new_constant_pool() defines
  10795. -// const values that are also defined in a local context elsewhere.
  10796. -// The same literal values are also used in elsewhere. We need to
  10797. -// coordinate a cleanup of these constants with Runtime.
  10798. -//
  10799. +#define RC_ABORT(error) { _result = error; return false; }
  10800. -class VM_RedefineClasses: public VM_Operation {
  10801. +class VM_RedefineClasses: public VM_GC_Operation {
  10802. private:
  10803. +
  10804. // These static fields are needed by SystemDictionary::classes_do()
  10805. // facility and the adjust_cpool_cache_and_vtable() helper:
  10806. static objArrayOop _old_methods;
  10807. static objArrayOop _new_methods;
  10808. - static methodOop* _matching_old_methods;
  10809. - static methodOop* _matching_new_methods;
  10810. - static methodOop* _deleted_methods;
  10811. - static methodOop* _added_methods;
  10812. + static int* _matching_old_methods;
  10813. + static int* _matching_new_methods;
  10814. + static int* _deleted_methods;
  10815. + static int* _added_methods;
  10816. static int _matching_methods_length;
  10817. static int _deleted_methods_length;
  10818. static int _added_methods_length;
  10819. static klassOop _the_class_oop;
  10820. + static int _revision_number;
  10821. +
  10822. // The instance fields are used to pass information from
  10823. // doit_prologue() to doit() and doit_epilogue().
  10824. jint _class_count;
  10825. @@ -370,36 +70,29 @@
  10826. // _index_map_p contains any entries.
  10827. int _index_map_count;
  10828. intArray * _index_map_p;
  10829. - // ptr to _class_count scratch_classes
  10830. - instanceKlassHandle * _scratch_classes;
  10831. - jvmtiError _res;
  10832. + GrowableArray<instanceKlassHandle>* _new_classes;
  10833. + GrowableArray<oop>* _updated_oops;
  10834. + jvmtiError _result;
  10835. + int _max_redefinition_flags;
  10836. // Performance measurement support. These timers do not cover all
  10837. // the work done for JVM/TI RedefineClasses() but they do cover
  10838. // the heavy lifting.
  10839. - elapsedTimer _timer_rsc_phase1;
  10840. - elapsedTimer _timer_rsc_phase2;
  10841. - elapsedTimer _timer_vm_op_prologue;
  10842. + elapsedTimer _timer_total;
  10843. + elapsedTimer _timer_prologue;
  10844. + elapsedTimer _timer_class_linking;
  10845. + elapsedTimer _timer_class_loading;
  10846. + elapsedTimer _timer_check_type;
  10847. + elapsedTimer _timer_prepare_redefinition;
  10848. + elapsedTimer _timer_wait_for_locks;
  10849. + elapsedTimer _timer_redefinition;
  10850. + elapsedTimer _timer_vm_op_epilogue;
  10851. - // These routines are roughly in call order unless otherwise noted.
  10852. -
  10853. - // Load the caller's new class definition(s) into _scratch_classes.
  10854. - // Constant pool merging work is done here as needed. Also calls
  10855. - // compare_and_normalize_class_versions() to verify the class
  10856. - // definition(s).
  10857. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  10858. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  10859. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  10860. jvmtiError load_new_class_versions(TRAPS);
  10861. - // Verify that the caller provided class definition(s) that meet
  10862. - // the restrictions of RedefineClasses. Normalize the order of
  10863. - // overloaded methods as needed.
  10864. - jvmtiError compare_and_normalize_class_versions(
  10865. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  10866. -
  10867. - // Swap annotations[i] with annotations[j]
  10868. - // Used by compare_and_normalize_class_versions() when normalizing
  10869. - // overloaded methods or changing idnum as when adding or deleting methods.
  10870. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  10871. -
  10872. // Figure out which new methods match old methods in name and signature,
  10873. // which methods have been added, and which are no longer present
  10874. void compute_added_deleted_matching_methods();
  10875. @@ -407,96 +100,100 @@
  10876. // Change jmethodIDs to point to the new methods
  10877. void update_jmethod_ids();
  10878. - // In addition to marking methods as obsolete, this routine
  10879. - // records which methods are EMCP (Equivalent Module Constant
  10880. - // Pool) in the emcp_methods BitMap and returns the number of
  10881. - // EMCP methods via emcp_method_count_p. This information is
  10882. - // used when information about the previous version of the_class
  10883. - // is squirreled away.
  10884. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  10885. - int * emcp_method_count_p);
  10886. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10887. + class FindAffectedKlassesClosure : public ObjectClosure {
  10888. - // Unevolving classes may point to methods of the_class directly
  10889. - // from their constant pool caches, itables, and/or vtables. We
  10890. - // use the SystemDictionary::classes_do() facility and this helper
  10891. - // to fix up these pointers.
  10892. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  10893. + private:
  10894. + GrowableArray<instanceKlassHandle> *_original_klasses;
  10895. + GrowableArray<instanceKlassHandle> *_result;
  10896. +
  10897. + public:
  10898. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  10899. +
  10900. + virtual void do_object(oop obj);
  10901. + };
  10902. +
  10903. +
  10904. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  10905. // Install the redefinition of a class
  10906. - void redefine_single_class(jclass the_jclass,
  10907. - instanceKlassHandle scratch_class, TRAPS);
  10908. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  10909. // Increment the classRedefinedCount field in the specific instanceKlass
  10910. // and in all direct and indirect subclasses.
  10911. void increment_class_counter(instanceKlass *ik, TRAPS);
  10912. - // Support for constant pool merging (these routines are in alpha
  10913. - // order):
  10914. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  10915. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10916. - int find_new_index(int old_index);
  10917. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  10918. - constantPoolHandle cp2, int index2);
  10919. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  10920. - constantPoolHandle cp2, int index2);
  10921. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  10922. - bool merge_constant_pools(constantPoolHandle old_cp,
  10923. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  10924. - int *merge_cp_length_p, TRAPS);
  10925. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  10926. - instanceKlassHandle scratch_class, TRAPS);
  10927. - u2 rewrite_cp_ref_in_annotation_data(
  10928. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  10929. - const char * trace_mesg, TRAPS);
  10930. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  10931. - bool rewrite_cp_refs_in_annotation_struct(
  10932. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10933. - bool rewrite_cp_refs_in_annotations_typeArray(
  10934. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  10935. - bool rewrite_cp_refs_in_class_annotations(
  10936. - instanceKlassHandle scratch_class, TRAPS);
  10937. - bool rewrite_cp_refs_in_element_value(
  10938. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10939. - bool rewrite_cp_refs_in_fields_annotations(
  10940. - instanceKlassHandle scratch_class, TRAPS);
  10941. - void rewrite_cp_refs_in_method(methodHandle method,
  10942. - methodHandle * new_method_p, TRAPS);
  10943. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  10944. - bool rewrite_cp_refs_in_methods_annotations(
  10945. - instanceKlassHandle scratch_class, TRAPS);
  10946. - bool rewrite_cp_refs_in_methods_default_annotations(
  10947. - instanceKlassHandle scratch_class, TRAPS);
  10948. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  10949. - instanceKlassHandle scratch_class, TRAPS);
  10950. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  10951. - void rewrite_cp_refs_in_verification_type_info(
  10952. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  10953. - u1 frame_size, TRAPS);
  10954. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  10955. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  10956. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  10957. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS) PRODUCT_RETURN;
  10958. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  10959. - static void dump_methods() PRODUCT_RETURN;
  10960. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  10961. +
  10962. +#ifdef ASSERT
  10963. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  10964. +#endif
  10965. +
  10966. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  10967. + void calculate_instance_update_information(klassOop new_version);
  10968. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  10969. +
  10970. + static void calculate_type_check_information(klassOop k);
  10971. + static void clear_type_check_information(klassOop k);
  10972. public:
  10973. - VM_RedefineClasses(jint class_count,
  10974. - const jvmtiClassDefinition *class_defs,
  10975. - JvmtiClassLoadKind class_load_kind);
  10976. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  10977. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  10978. + virtual ~VM_RedefineClasses();
  10979. +
  10980. + bool check_arguments();
  10981. bool doit_prologue();
  10982. void doit();
  10983. void doit_epilogue();
  10984. + void rollback();
  10985. - bool allow_nested_vm_operations() const { return true; }
  10986. - jvmtiError check_error() { return _res; }
  10987. + jvmtiError check_exception() const;
  10988. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  10989. + bool skip_operation() const { return false; }
  10990. + bool allow_nested_vm_operations() const { return true; }
  10991. + jvmtiError check_error() { return _result; }
  10992. +
  10993. + void update_active_methods();
  10994. +
  10995. + // Checks for type consistency after hierarchy change
  10996. + bool check_type_consistency();
  10997. + void calculate_type_check_information();
  10998. + bool check_field_value_types();
  10999. + void clear_type_check_information();
  11000. + bool check_method_stacks();
  11001. + bool check_loaded_methods();
  11002. + bool check_method(methodOop method);
  11003. + static Symbol* signature_to_class_name(Symbol* signature);
  11004. +
  11005. + void method_forwarding();
  11006. +
  11007. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11008. // Modifiable test must be shared between IsModifiableClass query
  11009. // and redefine implementation
  11010. static bool is_modifiable_class(oop klass_mirror);
  11011. +
  11012. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11013. + void oops_do(OopClosure* f);
  11014. +
  11015. + // Utility methods for transfering field access flags
  11016. +
  11017. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11018. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11019. +
  11020. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11021. +
  11022. + void lock_threads();
  11023. + void unlock_threads();
  11024. +
  11025. + template <class T> static void do_oop_work(T* p);
  11026. +
  11027. + static void swap_marks(oop first, oop second);
  11028. +
  11029. };
  11030. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11031. +
  11032. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  11033. --- a/src/share/vm/prims/methodComparator.cpp
  11034. +++ b/src/share/vm/prims/methodComparator.cpp
  11035. @@ -65,6 +65,37 @@
  11036. if (! args_same(c_old, c_new))
  11037. return false;
  11038. }
  11039. +
  11040. + // DCEVM: Added exception table comparison to EMCP comparison
  11041. +
  11042. + typeArrayOop ex_old = old_method->constMethod()->exception_table();
  11043. + typeArrayOop ex_new = new_method->constMethod()->exception_table();
  11044. +
  11045. + if (ex_old == NULL && ex_new != NULL) return false;
  11046. + if (ex_old != NULL && ex_new == NULL) return false;
  11047. +
  11048. + if (ex_old != NULL && ex_new != NULL && ex_old->length() == ex_new->length()) {
  11049. + // Per entry:
  11050. + /* start */
  11051. + /* limit */
  11052. + /* goto pc */
  11053. + /* cp index */
  11054. + for (int i=0; i<ex_old->length(); i++) {
  11055. + int old_val = ex_old->int_at(i);
  11056. + int new_val = ex_new->int_at(i);
  11057. + if ((i + 1) % 4 == 0) {
  11058. + if (old_val == 0 || new_val == 0) {
  11059. + if (old_val != new_val) return false;
  11060. + } else if ((_old_cp->klass_at_noresolve(old_val) != _new_cp->klass_at_noresolve(new_val)))
  11061. + return false;
  11062. + } else {
  11063. + if (old_val != new_val) {
  11064. + return false;
  11065. + }
  11066. + }
  11067. + }
  11068. + }
  11069. +
  11070. return true;
  11071. }
  11072. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  11073. --- a/src/share/vm/prims/nativeLookup.cpp
  11074. +++ b/src/share/vm/prims/nativeLookup.cpp
  11075. @@ -35,6 +35,7 @@
  11076. #include "oops/symbol.hpp"
  11077. #include "prims/jvm_misc.hpp"
  11078. #include "prims/nativeLookup.hpp"
  11079. +#include "prims/jvmtiRedefineClasses.hpp"
  11080. #include "runtime/arguments.hpp"
  11081. #include "runtime/handles.inline.hpp"
  11082. #include "runtime/javaCalls.hpp"
  11083. @@ -53,7 +54,6 @@
  11084. # include "os_bsd.inline.hpp"
  11085. #endif
  11086. -
  11087. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11088. char* bytes = (char*)name->bytes() + begin;
  11089. char* end_bytes = (char*)name->bytes() + end;
  11090. @@ -136,6 +136,40 @@
  11091. { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) }
  11092. };
  11093. +// Helper function to call redefineClasses from Java Code
  11094. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11095. + ResourceMark rm(THREAD);
  11096. +
  11097. + JavaThread* current_thread = JavaThread::current();
  11098. + jbyte* bytecodes = NULL;
  11099. + const int class_count = 1;
  11100. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11101. +
  11102. + {
  11103. + ThreadToNativeFromVM ttnfv(thread);
  11104. + jboolean is_copy = JNI_FALSE;
  11105. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11106. + class_definitions[0].klass = target;
  11107. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11108. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11109. + }
  11110. +
  11111. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11112. + VMThread::execute(&op);
  11113. + int result = op.check_error();
  11114. +
  11115. + {
  11116. + ThreadToNativeFromVM ttnfv(thread);
  11117. + if (env->ExceptionOccurred()) {
  11118. + return -1;
  11119. + }
  11120. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11121. + }
  11122. +
  11123. + return result;
  11124. +JVM_END
  11125. +
  11126. +
  11127. static address lookup_special_native(char* jni_name) {
  11128. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11129. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11130. @@ -175,6 +209,9 @@
  11131. return entry;
  11132. }
  11133. }
  11134. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11135. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11136. + }
  11137. // Otherwise call static method findNative in ClassLoader
  11138. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11139. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  11140. --- a/src/share/vm/runtime/arguments.cpp
  11141. +++ b/src/share/vm/runtime/arguments.cpp
  11142. @@ -1747,6 +1747,15 @@
  11143. status = false;
  11144. }
  11145. + // (tw) Must use serial GC
  11146. + if (!UseSerialGC && i >= 1) {
  11147. + jio_fprintf(defaultStream::error_stream(),
  11148. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11149. + status = false;
  11150. + } else {
  11151. + UseSerialGC = true;
  11152. + }
  11153. +
  11154. return status;
  11155. }
  11156. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  11157. --- a/src/share/vm/runtime/deoptimization.cpp
  11158. +++ b/src/share/vm/runtime/deoptimization.cpp
  11159. @@ -595,6 +595,38 @@
  11160. // Cleanup thread deopt data
  11161. cleanup_deopt_info(thread, array);
  11162. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11163. + {
  11164. + ResourceMark res_mark;
  11165. +
  11166. + // Verify that the just-unpacked frames match the interpreter's
  11167. + // notions of expression stack and locals
  11168. + vframeArray* cur_array = thread->vframe_array_last();
  11169. + RegisterMap rm(thread, false);
  11170. + rm.set_include_argument_oops(false);
  11171. + for (int i = 0; i < cur_array->frames(); i++) {
  11172. + vframeArrayElement* el = cur_array->element(i);
  11173. + frame* frame = el->iframe();
  11174. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11175. + RegisterMap reg_map(thread);
  11176. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11177. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11178. + methodOop method = iframe->method();
  11179. + int bci = iframe->bci();
  11180. + method = method->newest_version();
  11181. + iframe->set_method(method, bci);
  11182. +
  11183. + methodOop forward_method = method->forward_method();
  11184. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11185. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11186. + if (TraceRedefineClasses >= 2) {
  11187. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  11188. + }
  11189. + iframe->set_method(forward_method, new_bci);
  11190. + }
  11191. + }
  11192. + }
  11193. +
  11194. #ifndef PRODUCT
  11195. if (VerifyStack) {
  11196. ResourceMark res_mark;
  11197. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  11198. --- a/src/share/vm/runtime/frame.cpp
  11199. +++ b/src/share/vm/runtime/frame.cpp
  11200. @@ -403,6 +403,12 @@
  11201. *interpreter_frame_method_addr() = method;
  11202. }
  11203. +// (tw) Sets constant pool cache oop
  11204. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11205. + assert(is_interpreted_frame(), "interpreted frame expected");
  11206. + *interpreter_frame_cache_addr() = cp;
  11207. +}
  11208. +
  11209. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11210. assert(is_interpreted_frame(), "Not an interpreted frame");
  11211. if (ProfileInterpreter) {
  11212. @@ -418,19 +424,27 @@
  11213. // The bcx was just converted from bci to bcp.
  11214. // Convert the mdx in parallel.
  11215. methodDataOop mdo = interpreter_frame_method()->method_data();
  11216. - assert(mdo != NULL, "");
  11217. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11218. - address mdp = mdo->di_to_dp(mdi);
  11219. - interpreter_frame_set_mdx((intptr_t)mdp);
  11220. + if (mdo == NULL) {
  11221. + interpreter_frame_set_mdx(0);
  11222. + } else {
  11223. + assert(mdo != NULL, "");
  11224. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11225. + address mdp = mdo->di_to_dp(mdi);
  11226. + interpreter_frame_set_mdx((intptr_t)mdp);
  11227. + }
  11228. }
  11229. } else {
  11230. if (is_now_bci) {
  11231. // The bcx was just converted from bcp to bci.
  11232. // Convert the mdx in parallel.
  11233. methodDataOop mdo = interpreter_frame_method()->method_data();
  11234. - assert(mdo != NULL, "");
  11235. - int mdi = mdo->dp_to_di((address)mdx);
  11236. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11237. + if (mdo == NULL) {
  11238. + interpreter_frame_set_mdx(0);
  11239. + } else {
  11240. + assert(mdo != NULL, "");
  11241. + int mdi = mdo->dp_to_di((address)mdx);
  11242. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11243. + }
  11244. }
  11245. }
  11246. }
  11247. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  11248. --- a/src/share/vm/runtime/frame.hpp
  11249. +++ b/src/share/vm/runtime/frame.hpp
  11250. @@ -346,6 +346,7 @@
  11251. // Method & constant pool cache
  11252. methodOop interpreter_frame_method() const;
  11253. void interpreter_frame_set_method(methodOop method);
  11254. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11255. methodOop* interpreter_frame_method_addr() const;
  11256. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11257. #ifdef PPC
  11258. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  11259. --- a/src/share/vm/runtime/globals.hpp
  11260. +++ b/src/share/vm/runtime/globals.hpp
  11261. @@ -1309,9 +1309,23 @@
  11262. product(bool, StressLdcRewrite, false, \
  11263. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11264. \
  11265. + product(bool, UseMethodForwardPoints, false, \
  11266. + "Use method forward points") \
  11267. + \
  11268. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11269. + "Maximum number of locals in forwarding method") \
  11270. + \
  11271. + product(intx, MethodForwardPointsMaxStack, 300, \
  11272. + "Maximum number of stack slots in forwarding method") \
  11273. + \
  11274. product(intx, TraceRedefineClasses, 0, \
  11275. "Trace level for JVMTI RedefineClasses") \
  11276. \
  11277. + product(bool, TimeRedefineClasses, false, \
  11278. + "Measure timing for JVMTI RedefineClasses") \
  11279. + \
  11280. + product(bool, AllowAdvancedClassRedefinition, true, \
  11281. + "Allow advanced class redefinition beyond swapping method bodies")\
  11282. develop(bool, StressMethodComparator, false, \
  11283. "run the MethodComparator on all loaded methods") \
  11284. \
  11285. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  11286. --- a/src/share/vm/runtime/interfaceSupport.hpp
  11287. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  11288. @@ -296,7 +296,7 @@
  11289. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11290. // We are leaving the VM at this point and going directly to native code.
  11291. // Block, if we are in the middle of a safepoint synchronization.
  11292. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11293. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11294. thread->frame_anchor()->make_walkable(thread);
  11295. trans_and_fence(_thread_in_vm, _thread_in_native);
  11296. // Check for pending. async. exceptions or suspends.
  11297. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11298. --- a/src/share/vm/runtime/javaCalls.cpp
  11299. +++ b/src/share/vm/runtime/javaCalls.cpp
  11300. @@ -60,7 +60,7 @@
  11301. bool clear_pending_exception = true;
  11302. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11303. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11304. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11305. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11306. _result = result;
  11307. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11308. --- a/src/share/vm/runtime/jniHandles.cpp
  11309. +++ b/src/share/vm/runtime/jniHandles.cpp
  11310. @@ -112,6 +112,10 @@
  11311. }
  11312. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11313. + if (mh->newest_version() != mh()) {
  11314. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11315. + return (jmethodID) make_weak_global(mh_new);
  11316. + }
  11317. return (jmethodID) make_weak_global(mh);
  11318. }
  11319. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11320. --- a/src/share/vm/runtime/mutex.cpp
  11321. +++ b/src/share/vm/runtime/mutex.cpp
  11322. @@ -1227,7 +1227,7 @@
  11323. // in increasing rank order (modulo any native ranks)
  11324. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11325. if (tmp->next() != NULL) {
  11326. - assert(tmp->rank() == Mutex::native ||
  11327. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11328. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11329. }
  11330. }
  11331. @@ -1247,7 +1247,7 @@
  11332. // in increasing rank order (modulo any native ranks)
  11333. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11334. if (tmp->next() != NULL) {
  11335. - assert(tmp->rank() == Mutex::native ||
  11336. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11337. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11338. }
  11339. }
  11340. @@ -1310,6 +1310,7 @@
  11341. // already hold Terminator_lock - may happen because of periodic safepoints
  11342. if (this->rank() != Mutex::native &&
  11343. this->rank() != Mutex::suspend_resume &&
  11344. + this->rank() != Mutex::redefine_classes &&
  11345. locks != NULL && locks->rank() <= this->rank() &&
  11346. !SafepointSynchronize::is_at_safepoint() &&
  11347. this != Interrupt_lock && this != ProfileVM_lock &&
  11348. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11349. --- a/src/share/vm/runtime/mutex.hpp
  11350. +++ b/src/share/vm/runtime/mutex.hpp
  11351. @@ -109,7 +109,8 @@
  11352. barrier = safepoint + 1,
  11353. nonleaf = barrier + 1,
  11354. max_nonleaf = nonleaf + 900,
  11355. - native = max_nonleaf + 1
  11356. + native = max_nonleaf + 1,
  11357. + redefine_classes = native + 1
  11358. };
  11359. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11360. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11361. --- a/src/share/vm/runtime/mutexLocker.cpp
  11362. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11363. @@ -49,6 +49,7 @@
  11364. // Consider using GCC's __read_mostly.
  11365. Mutex* Patching_lock = NULL;
  11366. +Mutex* RedefineClasses_lock = NULL;
  11367. Monitor* SystemDictionary_lock = NULL;
  11368. Mutex* PackageTable_lock = NULL;
  11369. Mutex* CompiledIC_lock = NULL;
  11370. @@ -90,6 +91,7 @@
  11371. Mutex* DirtyCardQ_FL_lock = NULL;
  11372. Monitor* DirtyCardQ_CBL_mon = NULL;
  11373. Mutex* Shared_DirtyCardQ_lock = NULL;
  11374. +Monitor* RedefinitionSync_lock = NULL;
  11375. Mutex* ParGCRareEvent_lock = NULL;
  11376. Mutex* EvacFailureStack_lock = NULL;
  11377. Mutex* DerivedPointerTableGC_lock = NULL;
  11378. @@ -205,6 +207,7 @@
  11379. def(HotCardCache_lock , Mutex , special , true );
  11380. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11381. }
  11382. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11383. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11384. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11385. def(CodeCache_lock , Mutex , special, true );
  11386. @@ -279,6 +282,7 @@
  11387. def(Debug2_lock , Mutex , nonleaf+4, true );
  11388. def(Debug3_lock , Mutex , nonleaf+4, true );
  11389. def(ProfileVM_lock , Monitor, nonleaf+4, false); // used for profiling of the VMThread
  11390. + def(RedefineClasses_lock , Mutex, nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11391. def(CompileThread_lock , Monitor, nonleaf+5, false );
  11392. def(JfrQuery_lock , Monitor, nonleaf, true); // JFR locks, keep these in consecutive order
  11393. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11394. --- a/src/share/vm/runtime/mutexLocker.hpp
  11395. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11396. @@ -43,6 +43,8 @@
  11397. // Mutexes used in the VM.
  11398. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11399. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11400. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11401. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11402. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11403. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11404. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11405. --- a/src/share/vm/runtime/reflection.cpp
  11406. +++ b/src/share/vm/runtime/reflection.cpp
  11407. @@ -469,7 +469,8 @@
  11408. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11409. if ( JDK_Version::is_gte_jdk14x_version()
  11410. && UseNewReflection
  11411. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11412. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11413. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11414. return true;
  11415. }
  11416. @@ -525,6 +526,12 @@
  11417. AccessFlags access,
  11418. bool classloader_only,
  11419. bool protected_restriction) {
  11420. +
  11421. + // (tw) Decide accessibility based on active version
  11422. + if (current_class != NULL) {
  11423. + current_class = current_class->klass_part()->active_version();
  11424. + }
  11425. +
  11426. // Verify that current_class can access a field of field_class, where that
  11427. // field's access bits are "access". We assume that we've already verified
  11428. // that current_class can access field_class.
  11429. @@ -566,7 +573,8 @@
  11430. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11431. if ( JDK_Version::is_gte_jdk14x_version()
  11432. && UseNewReflection
  11433. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11434. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11435. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11436. return true;
  11437. }
  11438. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11439. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11440. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11441. @@ -1139,7 +1139,20 @@
  11442. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11443. int retry_count = 0;
  11444. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11445. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11446. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11447. +
  11448. + // DCEVM: If we are executing an old method, this is OK!
  11449. + {
  11450. + ResourceMark rm(thread);
  11451. + RegisterMap cbl_map(thread, false);
  11452. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11453. +
  11454. + CodeBlob* caller_cb = caller_frame.cb();
  11455. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11456. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11457. + if (caller_nm->method()->is_old()) break;
  11458. + }
  11459. +
  11460. // If has a pending exception then there is no need to re-try to
  11461. // resolve this method.
  11462. // If the method has been redefined, we need to try again.
  11463. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11464. --- a/src/share/vm/runtime/thread.cpp
  11465. +++ b/src/share/vm/runtime/thread.cpp
  11466. @@ -212,6 +212,8 @@
  11467. set_self_raw_id(0);
  11468. set_lgrp_id(-1);
  11469. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11470. +
  11471. // allocated data structures
  11472. set_osthread(NULL);
  11473. set_resource_area(new ResourceArea());
  11474. @@ -246,6 +248,7 @@
  11475. omFreeProvision = 32 ;
  11476. omInUseList = NULL ;
  11477. omInUseCount = 0 ;
  11478. + _pretend_new_universe = false;
  11479. #ifdef ASSERT
  11480. _visited_for_critical_count = false;
  11481. @@ -857,6 +860,15 @@
  11482. return false;
  11483. }
  11484. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11485. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11486. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11487. + return true;
  11488. + }
  11489. + }
  11490. + return false;
  11491. +}
  11492. +
  11493. #endif
  11494. @@ -1507,7 +1519,7 @@
  11495. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11496. assert(JavaThread::current() == this, "sanity check");
  11497. - assert(!Thread::current()->owns_locks(), "sanity check");
  11498. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11499. DTRACE_THREAD_PROBE(start, this);
  11500. @@ -3045,7 +3057,7 @@
  11501. // Create a CompilerThread
  11502. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11503. -: JavaThread(&compiler_thread_entry) {
  11504. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11505. _env = NULL;
  11506. _log = NULL;
  11507. _task = NULL;
  11508. @@ -3053,6 +3065,7 @@
  11509. _counters = counters;
  11510. _buffer_blob = NULL;
  11511. _scanned_nmethod = NULL;
  11512. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11513. #ifndef PRODUCT
  11514. _ideal_graph_printer = NULL;
  11515. @@ -3082,6 +3095,7 @@
  11516. int Threads::_number_of_non_daemon_threads = 0;
  11517. int Threads::_return_code = 0;
  11518. size_t JavaThread::_stack_size_at_create = 0;
  11519. +bool Threads::_wait_at_instrumentation_entry = false;
  11520. // All JavaThreads
  11521. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11522. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11523. --- a/src/share/vm/runtime/thread.hpp
  11524. +++ b/src/share/vm/runtime/thread.hpp
  11525. @@ -197,11 +197,14 @@
  11526. void enter_signal_handler() { _num_nested_signal++; }
  11527. void leave_signal_handler() { _num_nested_signal--; }
  11528. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11529. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11530. private:
  11531. // Debug tracing
  11532. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11533. + Mutex* _redefine_classes_mutex;
  11534. +
  11535. // Active_handles points to a block of handles
  11536. JNIHandleBlock* _active_handles;
  11537. @@ -522,10 +525,15 @@
  11538. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11539. int _lgrp_id;
  11540. +
  11541. + bool _pretend_new_universe;
  11542. +
  11543. public:
  11544. // Stack overflow support
  11545. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11546. + 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; } }
  11547. + bool pretend_new_universe() { return _pretend_new_universe; }
  11548. void set_stack_base(address base) { _stack_base = base; }
  11549. size_t stack_size() const { return _stack_size; }
  11550. void set_stack_size(size_t size) { _stack_size = size; }
  11551. @@ -563,6 +571,7 @@
  11552. void print_owned_locks() const { print_owned_locks_on(tty); }
  11553. Monitor* owned_locks() const { return _owned_locks; }
  11554. bool owns_locks() const { return owned_locks() != NULL; }
  11555. + bool owns_locks_but_redefine_classes_lock() const;
  11556. bool owns_locks_but_compiled_lock() const;
  11557. // Deadlock detection
  11558. @@ -1745,6 +1754,8 @@
  11559. CompileTask* _task;
  11560. CompileQueue* _queue;
  11561. BufferBlob* _buffer_blob;
  11562. + bool _should_bailout;
  11563. + Mutex* _compilation_mutex;
  11564. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11565. @@ -1754,12 +1765,16 @@
  11566. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11567. + bool should_bailout() const { return _should_bailout; }
  11568. + void set_should_bailout(bool b) { _should_bailout = false; }
  11569. +
  11570. bool is_Compiler_thread() const { return true; }
  11571. // Hide this compiler thread from external view.
  11572. bool is_hidden_from_external_view() const { return true; }
  11573. CompileQueue* queue() { return _queue; }
  11574. CompilerCounters* counters() { return _counters; }
  11575. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11576. // Get/set the thread's compilation environment.
  11577. ciEnv* env() { return _env; }
  11578. @@ -1814,6 +1829,7 @@
  11579. static int _number_of_threads;
  11580. static int _number_of_non_daemon_threads;
  11581. static int _return_code;
  11582. + static bool _wait_at_instrumentation_entry;
  11583. public:
  11584. // Thread management
  11585. @@ -1825,6 +1841,9 @@
  11586. static JavaThread* first() { return _thread_list; }
  11587. static void threads_do(ThreadClosure* tc);
  11588. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11589. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11590. +
  11591. // Initializes the vm and creates the vm thread
  11592. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11593. static void convert_vm_init_libraries_to_agents();
  11594. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11595. --- a/src/share/vm/runtime/vframe.cpp
  11596. +++ b/src/share/vm/runtime/vframe.cpp
  11597. @@ -253,6 +253,46 @@
  11598. return fr().interpreter_frame_method();
  11599. }
  11600. +// (tw) Sets interpreter frame method.
  11601. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11602. + methodOop old_method = fr().interpreter_frame_method();
  11603. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11604. + if (old_method == new_method) return;
  11605. + u_char *old_bcp = bcp();
  11606. + int old_bci = bci();
  11607. + fr().interpreter_frame_set_method(new_method);
  11608. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11609. + u_char *new_bcp = new_method->code_base() + new_bci;
  11610. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11611. +
  11612. + set_bcp(new_bcp);
  11613. +
  11614. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11615. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11616. +
  11617. + switch (code) {
  11618. + case Bytecodes::_invokevirtual :
  11619. + case Bytecodes::_invokespecial :
  11620. + case Bytecodes::_invokestatic :
  11621. + case Bytecodes::_invokeinterface: {
  11622. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11623. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11624. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11625. + break;
  11626. + }
  11627. +
  11628. + case Bytecodes::_invokedynamic: {
  11629. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11630. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11631. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11632. + break;
  11633. + }
  11634. + }
  11635. +
  11636. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11637. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11638. +}
  11639. +
  11640. StackValueCollection* interpretedVFrame::locals() const {
  11641. int length = method()->max_locals();
  11642. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11643. --- a/src/share/vm/runtime/vframe.hpp
  11644. +++ b/src/share/vm/runtime/vframe.hpp
  11645. @@ -163,6 +163,7 @@
  11646. StackValueCollection* locals() const;
  11647. StackValueCollection* expressions() const;
  11648. GrowableArray<MonitorInfo*>* monitors() const;
  11649. + void set_method(methodOop method, int new_bci);
  11650. void set_locals(StackValueCollection* values) const;
  11651. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11652. --- a/src/share/vm/runtime/vmThread.cpp
  11653. +++ b/src/share/vm/runtime/vmThread.cpp
  11654. @@ -671,6 +671,9 @@
  11655. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11656. Thread::oops_do(f, cf);
  11657. _vm_queue->oops_do(f);
  11658. + if (_cur_vm_operation != NULL) {
  11659. + _cur_vm_operation->oops_do(f);
  11660. + }
  11661. }
  11662. //------------------------------------------------------------------------------------------------------------------
  11663. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11664. --- a/src/share/vm/utilities/exceptions.cpp
  11665. +++ b/src/share/vm/utilities/exceptions.cpp
  11666. @@ -251,6 +251,8 @@
  11667. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11668. assert(!thread->has_pending_exception(), "already has exception");
  11669. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11670. + Thread::current()->set_pretend_new_universe(false);
  11671. Handle h_exception;
  11672. // Resolve exception klass
  11673. @@ -298,6 +300,8 @@
  11674. h_exception = Handle(thread, thread->pending_exception());
  11675. thread->clear_pending_exception();
  11676. }
  11677. +
  11678. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11679. return h_exception;
  11680. }
  11681. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11682. --- a/src/share/vm/utilities/growableArray.hpp
  11683. +++ b/src/share/vm/utilities/growableArray.hpp
  11684. @@ -135,6 +135,33 @@
  11685. assert(on_stack(), "fast ResourceObj path only");
  11686. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11687. }
  11688. +
  11689. +};
  11690. +
  11691. +template<class E, class F> class Pair : public StackObj
  11692. +{
  11693. +private:
  11694. + E _left;
  11695. + F _right;
  11696. +
  11697. +public:
  11698. +
  11699. + Pair() {
  11700. +
  11701. + }
  11702. +
  11703. + Pair(E left, F right) {
  11704. + this->_left = left;
  11705. + this->_right = right;
  11706. + }
  11707. +
  11708. + E left() {
  11709. + return _left;
  11710. + }
  11711. +
  11712. + F right() {
  11713. + return _right;
  11714. + }
  11715. };
  11716. template<class E> class GrowableArray : public GenericGrowableArray {