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

dcevm-jdk7u51-b13.patch 431KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138
  1. diff --git a/make/openjdk_distro b/make/openjdk_distro
  2. index 520b33d..ea7eff0 100644
  3. --- a/make/openjdk_distro
  4. +++ b/make/openjdk_distro
  5. @@ -27,6 +27,6 @@
  6. #
  7. # Don't put quotes (fail windows build).
  8. -HOTSPOT_VM_DISTRO=OpenJDK
  9. +HOTSPOT_VM_DISTRO=Dynamic Code Evolution
  10. COMPANY_NAME=
  11. PRODUCT_NAME=OpenJDK
  12. diff --git a/src/cpu/x86/vm/interp_masm_x86_32.cpp b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  13. index b0ebcfd..6366d68 100644
  14. --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp
  15. +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp
  16. @@ -1364,7 +1364,7 @@ void InterpreterMacroAssembler::notify_method_entry() {
  17. }
  18. // RedefineClasses() tracing support for obsolete method entry
  19. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  20. + IF_TRACE_RC4 {
  21. get_thread(rcx);
  22. get_method(rbx);
  23. call_VM_leaf(
  24. diff --git a/src/cpu/x86/vm/interp_masm_x86_64.cpp b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  25. index 2790c2a..c315b18 100644
  26. --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp
  27. +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp
  28. @@ -1427,7 +1427,7 @@ void InterpreterMacroAssembler::notify_method_entry() {
  29. }
  30. // RedefineClasses() tracing support for obsolete method entry
  31. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  32. + IF_TRACE_RC4 {
  33. get_method(c_rarg1);
  34. call_VM_leaf(
  35. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  36. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  37. index 16958cd..09d6300 100644
  38. --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  39. +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  40. @@ -1976,7 +1976,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
  41. }
  42. // RedefineClasses() tracing support for obsolete method entry
  43. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  44. + IF_TRACE_RC4 {
  45. __ movoop(rax, JNIHandles::make_local(method()));
  46. __ call_VM_leaf(
  47. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  48. diff --git a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  49. index 7dc4e62..86c8c95 100644
  50. --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  51. +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  52. @@ -2235,7 +2235,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
  53. }
  54. // RedefineClasses() tracing support for obsolete method entry
  55. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  56. + IF_TRACE_RC4 {
  57. // protect the args we've loaded
  58. save_args(masm, total_c_args, c_arg, out_regs);
  59. __ movoop(c_rarg1, JNIHandles::make_local(method()));
  60. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  61. index 9a8ca61..83e6f54 100644
  62. --- a/src/share/vm/c1/c1_Compilation.hpp
  63. +++ b/src/share/vm/c1/c1_Compilation.hpp
  64. @@ -242,8 +242,9 @@ class Compilation: public StackObj {
  65. #define BAILOUT(msg) { bailout(msg); return; }
  66. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  67. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  68. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  69. +// (tw) Also checks a thread local flag that can be set to trigger compiler bailout from another thread.
  70. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  71. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  72. class InstructionMark: public StackObj {
  73. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  74. index e0ab96b..db8e551 100644
  75. --- a/src/share/vm/ci/ciObjectFactory.cpp
  76. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  77. @@ -764,3 +764,26 @@ void ciObjectFactory::print() {
  78. _unloaded_instances->length(),
  79. _unloaded_klasses->length());
  80. }
  81. +
  82. +int ciObjectFactory::compare_ciobjects(ciObject** a, ciObject** b) {
  83. + oop oop1 = (*a)->get_oop();
  84. + oop oop2 = (*b)->get_oop();
  85. + return ((oop1 > oop2) ? 1 : ((oop1 == oop2) ? 0 : -1));
  86. +}
  87. +
  88. +// (DCEVM) Resoring the ciObject arrays after class redefinition
  89. +void ciObjectFactory::resort_shared_ci_objects() {
  90. + _shared_ci_objects->sort(ciObjectFactory::compare_ciobjects);
  91. +
  92. +#ifdef ASSERT
  93. + if (CIObjectFactoryVerify) {
  94. + oop last = NULL;
  95. + for (int j = 0; j < _shared_ci_objects->length(); j++) {
  96. + oop o = _shared_ci_objects->at(j)->get_oop();
  97. + assert(last < o, "out of order");
  98. + last = o;
  99. + }
  100. + }
  101. +#endif // ASSERT
  102. +}
  103. +
  104. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  105. index 26cc2c3..d99d3d6 100644
  106. --- a/src/share/vm/ci/ciObjectFactory.hpp
  107. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  108. @@ -88,6 +88,7 @@ private:
  109. ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
  110. + static int compare_ciobjects(ciObject** a, ciObject** b);
  111. public:
  112. static bool is_initialized() { return _initialized; }
  113. @@ -137,6 +138,8 @@ public:
  114. void print_contents();
  115. void print();
  116. +
  117. + static void resort_shared_ci_objects();
  118. };
  119. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  120. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  121. index 5ea1d43..8590ad1 100644
  122. --- a/src/share/vm/classfile/classFileParser.cpp
  123. +++ b/src/share/vm/classfile/classFileParser.cpp
  124. @@ -795,6 +795,7 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  125. Handle class_loader,
  126. Handle protection_domain,
  127. Symbol* class_name,
  128. + KlassHandle old_klass,
  129. TRAPS) {
  130. ClassFileStream* cfs = stream();
  131. assert(length > 0, "only called for length>0");
  132. @@ -813,6 +814,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  133. interface_index, CHECK_(nullHandle));
  134. if (cp->tag_at(interface_index).is_klass()) {
  135. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  136. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  137. + interf = KlassHandle(THREAD, interf->newest_version());
  138. + }
  139. } else {
  140. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  141. @@ -825,6 +829,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  142. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  143. unresolved_klass, class_loader, protection_domain,
  144. false, CHECK_(nullHandle));
  145. + if (!old_klass.is_null()) {
  146. + k = k->klass_part()->newest_version();
  147. + }
  148. interf = KlassHandle(THREAD, k);
  149. }
  150. @@ -2921,8 +2928,10 @@ typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annota
  151. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  152. Handle class_loader,
  153. Handle protection_domain,
  154. + KlassHandle old_klass,
  155. KlassHandle host_klass,
  156. GrowableArray<Handle>* cp_patches,
  157. + GrowableArray<Symbol*>* parsed_super_symbols,
  158. TempNewSymbol& parsed_name,
  159. bool verify,
  160. TRAPS) {
  161. @@ -2948,7 +2957,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  162. init_parsed_class_attributes();
  163. - if (JvmtiExport::should_post_class_file_load_hook()) {
  164. + if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
  165. // Get the cached class file bytes (if any) from the class that
  166. // is being redefined or retransformed. We use jvmti_thread_state()
  167. // instead of JvmtiThreadState::state_for(jt) so we don't allocate
  168. @@ -2971,10 +2980,13 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  169. unsigned char* ptr = cfs->buffer();
  170. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  171. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  172. + Thread::current()->set_pretend_new_universe(false);
  173. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  174. &ptr, &end_ptr,
  175. &cached_class_file_bytes,
  176. &cached_class_file_length);
  177. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  178. if (ptr != cfs->buffer()) {
  179. // JVMTI agent has modified class file data.
  180. @@ -3090,6 +3102,30 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  181. CHECK_(nullHandle));
  182. }
  183. + // (tw) Do not parse full class file, only get super symbols and return.
  184. + if (parsed_super_symbols != NULL) {
  185. + u2 super_class_index = cfs->get_u2_fast();
  186. +
  187. + if (super_class_index != 0) {
  188. + parsed_super_symbols->append(cp->klass_name_at(super_class_index));
  189. + }
  190. +
  191. + // Interfaces
  192. + u2 itfs_len = cfs->get_u2_fast();
  193. + objArrayHandle local_interfaces;
  194. + if (itfs_len == 0) {
  195. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  196. + } else {
  197. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_NULL);
  198. + }
  199. +
  200. + for (int i=0; i<local_interfaces->length(); i++) {
  201. + oop o = local_interfaces->obj_at(i);
  202. + parsed_super_symbols->append(((klassOop)o)->klass_part()->name());
  203. + }
  204. + return NULL;
  205. + }
  206. +
  207. klassOop preserve_this_klass; // for storing result across HandleMark
  208. // release all handles when parsing is done
  209. @@ -3130,7 +3166,11 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  210. // However, make sure it is not an array type.
  211. bool is_array = false;
  212. if (cp->tag_at(super_class_index).is_klass()) {
  213. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  214. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  215. + if (!old_klass.is_null()) {
  216. + resolved_klass = resolved_klass->klass_part()->newest_version();
  217. + }
  218. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  219. if (_need_verify)
  220. is_array = super_klass->oop_is_array();
  221. } else if (_need_verify) {
  222. @@ -3148,7 +3188,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  223. if (itfs_len == 0) {
  224. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  225. } else {
  226. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  227. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  228. }
  229. u2 java_fields_count = 0;
  230. @@ -3202,7 +3242,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  231. protection_domain,
  232. true,
  233. CHECK_(nullHandle));
  234. -
  235. + if (!old_klass.is_null()) {
  236. + k = k->klass_part()->newest_version();
  237. + }
  238. KlassHandle kh (THREAD, k);
  239. super_klass = instanceKlassHandle(THREAD, kh());
  240. }
  241. @@ -3591,6 +3633,19 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  242. rt = REF_NONE;
  243. } else {
  244. rt = super_klass->reference_type();
  245. +
  246. + // (tw) With class redefinition, it can also happen that special classes are loaded.
  247. + if (name == vmSymbols::java_lang_ref_Reference()) {
  248. + rt = REF_OTHER;
  249. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  250. + rt = REF_SOFT;
  251. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  252. + rt = REF_WEAK;
  253. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  254. + rt = REF_FINAL;
  255. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  256. + rt = REF_PHANTOM;
  257. + }
  258. }
  259. // We can now create the basic klassOop for this klass
  260. @@ -3599,6 +3654,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  261. total_oop_map_count,
  262. access_flags,
  263. rt, host_klass,
  264. + old_klass,
  265. CHECK_(nullHandle));
  266. instanceKlassHandle this_klass (THREAD, ik);
  267. @@ -3691,7 +3747,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  268. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  269. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  270. - set_precomputed_flags(this_klass);
  271. + set_precomputed_flags(this_klass, old_klass);
  272. // reinitialize modifiers, using the InnerClasses attribute
  273. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  274. @@ -3711,6 +3767,10 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  275. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  276. }
  277. + if (rt == REF_OTHER) {
  278. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  279. + }
  280. +
  281. // Allocate mirror and initialize static fields
  282. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  283. @@ -3856,7 +3916,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  284. }
  285. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  286. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  287. klassOop super = k->super();
  288. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  289. @@ -3864,7 +3924,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  290. if (!_has_empty_finalizer) {
  291. if (_has_finalizer ||
  292. (super != NULL && super->klass_part()->has_finalizer())) {
  293. - k->set_has_finalizer();
  294. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  295. + k->set_has_finalizer();
  296. + }
  297. }
  298. }
  299. @@ -3880,7 +3942,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  300. // Check if this klass supports the java.lang.Cloneable interface
  301. if (SystemDictionary::Cloneable_klass_loaded()) {
  302. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  303. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  304. k->set_is_cloneable();
  305. }
  306. }
  307. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  308. index 314ec5e..5fca1da 100644
  309. --- a/src/share/vm/classfile/classFileParser.hpp
  310. +++ b/src/share/vm/classfile/classFileParser.hpp
  311. @@ -151,6 +151,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  312. Handle class_loader,
  313. Handle protection_domain,
  314. Symbol* class_name,
  315. + KlassHandle old_klass,
  316. TRAPS);
  317. // Field parsing
  318. @@ -237,7 +238,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  319. unsigned int nonstatic_oop_map_count,
  320. int* nonstatic_oop_offsets,
  321. unsigned int* nonstatic_oop_counts);
  322. - void set_precomputed_flags(instanceKlassHandle k);
  323. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  324. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  325. objArrayHandle local_ifs, TRAPS);
  326. @@ -349,17 +350,20 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  327. instanceKlassHandle parseClassFile(Symbol* name,
  328. Handle class_loader,
  329. Handle protection_domain,
  330. + KlassHandle old_klass,
  331. TempNewSymbol& parsed_name,
  332. bool verify,
  333. TRAPS) {
  334. KlassHandle no_host_klass;
  335. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  336. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
  337. }
  338. instanceKlassHandle parseClassFile(Symbol* name,
  339. Handle class_loader,
  340. Handle protection_domain,
  341. + KlassHandle old_klass,
  342. KlassHandle host_klass,
  343. GrowableArray<Handle>* cp_patches,
  344. + GrowableArray<Symbol*>* parsed_super_symbols,
  345. TempNewSymbol& parsed_name,
  346. bool verify,
  347. TRAPS);
  348. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  349. index a2e61a4..450e19f 100644
  350. --- a/src/share/vm/classfile/classLoader.cpp
  351. +++ b/src/share/vm/classfile/classLoader.cpp
  352. @@ -915,6 +915,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
  353. instanceKlassHandle result = parser.parseClassFile(h_name,
  354. class_loader,
  355. protection_domain,
  356. + KlassHandle(),
  357. parsed_name,
  358. false,
  359. CHECK_(h));
  360. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  361. index 78e76cc..d167c98 100644
  362. --- a/src/share/vm/classfile/dictionary.cpp
  363. +++ b/src/share/vm/classfile/dictionary.cpp
  364. @@ -144,87 +144,10 @@ bool Dictionary::do_unloading(BoolObjectClosure* is_alive) {
  365. probe = *p;
  366. klassOop e = probe->klass();
  367. oop class_loader = probe->loader();
  368. -
  369. instanceKlass* ik = instanceKlass::cast(e);
  370. - if (ik->previous_versions() != NULL) {
  371. - // This klass has previous versions so see what we can cleanup
  372. - // while it is safe to do so.
  373. -
  374. - int gc_count = 0; // leave debugging breadcrumbs
  375. - int live_count = 0;
  376. -
  377. - // RC_TRACE macro has an embedded ResourceMark
  378. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  379. - ik->external_name(), ik->previous_versions()->length()));
  380. -
  381. - for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  382. - // check the previous versions array for GC'ed weak refs
  383. - PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
  384. - jobject cp_ref = pv_node->prev_constant_pool();
  385. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  386. - if (cp_ref == NULL) {
  387. - delete pv_node;
  388. - ik->previous_versions()->remove_at(i);
  389. - // Since we are traversing the array backwards, we don't have to
  390. - // do anything special with the index.
  391. - continue; // robustness
  392. - }
  393. -
  394. - constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  395. - if (pvcp == NULL) {
  396. - // this entry has been GC'ed so remove it
  397. - delete pv_node;
  398. - ik->previous_versions()->remove_at(i);
  399. - // Since we are traversing the array backwards, we don't have to
  400. - // do anything special with the index.
  401. - gc_count++;
  402. - continue;
  403. - } else {
  404. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  405. - if (is_alive->do_object_b(pvcp)) {
  406. - live_count++;
  407. - } else {
  408. - guarantee(false, "sanity check");
  409. - }
  410. - }
  411. -
  412. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  413. - if (method_refs != NULL) {
  414. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  415. - method_refs->length()));
  416. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  417. - jweak method_ref = method_refs->at(j);
  418. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  419. - if (method_ref == NULL) {
  420. - method_refs->remove_at(j);
  421. - // Since we are traversing the array backwards, we don't have to
  422. - // do anything special with the index.
  423. - continue; // robustness
  424. - }
  425. -
  426. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  427. - if (method == NULL) {
  428. - // this method entry has been GC'ed so remove it
  429. - JNIHandles::destroy_weak_global(method_ref);
  430. - method_refs->remove_at(j);
  431. - } else {
  432. - // RC_TRACE macro has an embedded ResourceMark
  433. - RC_TRACE(0x00000200,
  434. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  435. - method->name()->as_C_string(),
  436. - method->signature()->as_C_string(), j, i));
  437. - }
  438. - }
  439. - }
  440. - }
  441. - assert(ik->previous_versions()->length() == live_count, "sanity check");
  442. - RC_TRACE(0x00000200,
  443. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  444. - gc_count));
  445. - }
  446. -
  447. +
  448. // Non-unloadable classes were handled in always_strong_oops_do
  449. - if (!is_strongly_reachable(class_loader, e)) {
  450. + if (!ik->is_redefining() && !is_strongly_reachable(class_loader, e)) {
  451. // Entry was not visited in phase1 (negated test from phase1)
  452. assert(class_loader != NULL, "unloading entry with null class loader");
  453. oop k_def_class_loader = ik->class_loader();
  454. @@ -326,6 +249,7 @@ void Dictionary::classes_do(void f(klassOop)) {
  455. }
  456. }
  457. +
  458. // Added for initialize_itable_for_klass to handle exceptions
  459. // Just the classes from defining class loaders
  460. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  461. @@ -433,6 +357,33 @@ void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
  462. add_entry(index, entry);
  463. }
  464. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  465. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  466. +
  467. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  468. + bool found = false;
  469. + for (int index = 0; index < table_size(); index++) {
  470. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  471. + if (entry->klass() == old_class()) {
  472. + entry->set_literal(k());
  473. + found = true;
  474. + }
  475. + }
  476. + }
  477. +
  478. + return found;
  479. +}
  480. +
  481. +// (tw) Undo previous updates to the system dictionary
  482. +void Dictionary::rollback_redefinition() {
  483. + for (int index = 0; index < table_size(); index++) {
  484. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  485. + if (entry->klass()->klass_part()->is_redefining()) {
  486. + entry->set_literal(entry->klass()->klass_part()->old_version());
  487. + }
  488. + }
  489. + }
  490. +}
  491. // This routine does not lock the system dictionary.
  492. //
  493. @@ -459,12 +410,21 @@ DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
  494. return NULL;
  495. }
  496. +klassOop Dictionary::intercept_for_version(klassOop k) {
  497. + if (k == NULL) return k;
  498. +
  499. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  500. + return k->klass_part()->old_version();
  501. + }
  502. +
  503. + return k;
  504. +}
  505. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  506. Handle loader, Handle protection_domain, TRAPS) {
  507. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  508. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  509. - return entry->klass();
  510. + return intercept_for_version(entry->klass());
  511. } else {
  512. return NULL;
  513. }
  514. @@ -477,7 +437,7 @@ klassOop Dictionary::find_class(int index, unsigned int hash,
  515. assert (index == index_for(name, loader), "incorrect index?");
  516. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  517. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  518. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  519. }
  520. @@ -489,7 +449,7 @@ klassOop Dictionary::find_shared_class(int index, unsigned int hash,
  521. assert (index == index_for(name, Handle()), "incorrect index?");
  522. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  523. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  524. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  525. }
  526. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  527. index bd33760..ea1fe3c 100644
  528. --- a/src/share/vm/classfile/dictionary.hpp
  529. +++ b/src/share/vm/classfile/dictionary.hpp
  530. @@ -73,6 +73,10 @@ public:
  531. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  532. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  533. +
  534. + void rollback_redefinition();
  535. +
  536. klassOop find_class(int index, unsigned int hash,
  537. Symbol* name, Handle loader);
  538. @@ -105,6 +109,7 @@ public:
  539. bool do_unloading(BoolObjectClosure* is_alive);
  540. // Protection domains
  541. + static klassOop intercept_for_version(klassOop k);
  542. klassOop find(int index, unsigned int hash, Symbol* name,
  543. Handle loader, Handle protection_domain, TRAPS);
  544. bool is_valid_protection_domain(int index, unsigned int hash,
  545. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  546. index f8b10b3..c417a29 100644
  547. --- a/src/share/vm/classfile/javaClasses.cpp
  548. +++ b/src/share/vm/classfile/javaClasses.cpp
  549. @@ -621,6 +621,10 @@ klassOop java_lang_Class::as_klassOop(oop java_class) {
  550. assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  551. klassOop k = klassOop(java_class->obj_field(_klass_offset));
  552. assert(k == NULL || k->is_klass(), "type check");
  553. + // Necessary to make old verifier work.
  554. + if (Thread::current()->pretend_new_universe()) {
  555. + k = k->klass_part()->newest_version();
  556. + }
  557. return k;
  558. }
  559. @@ -1541,6 +1545,7 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, methodHandle met
  560. skip_throwableInit_check = true;
  561. }
  562. }
  563. + method = method->newest_version();
  564. if (method->is_hidden()) {
  565. if (skip_hidden) continue;
  566. }
  567. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  568. index b741cfa..5412831 100644
  569. --- a/src/share/vm/classfile/javaClasses.hpp
  570. +++ b/src/share/vm/classfile/javaClasses.hpp
  571. @@ -213,6 +213,7 @@ class java_lang_String : AllStatic {
  572. class java_lang_Class : AllStatic {
  573. friend class VMStructs;
  574. + friend class VM_RedefineClasses;
  575. private:
  576. // The fake offsets are added by the class loader when java.lang.Class is loaded
  577. @@ -248,7 +249,7 @@ class java_lang_Class : AllStatic {
  578. static void print_signature(oop java_class, outputStream *st);
  579. // Testing
  580. static bool is_instance(oop obj) {
  581. - return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
  582. + return obj != NULL && (obj->klass()->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version());
  583. }
  584. static bool is_primitive(oop java_class);
  585. static BasicType primitive_type(oop java_class);
  586. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  587. index 8650cd9..965cce2 100644
  588. --- a/src/share/vm/classfile/loaderConstraints.cpp
  589. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  590. @@ -449,7 +449,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
  591. if (k != NULL) {
  592. // We found the class in the system dictionary, so we should
  593. // make sure that the klassOop matches what we already have.
  594. - guarantee(k == probe->klass(), "klass should be in dictionary");
  595. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  596. } else {
  597. // If we don't find the class in the system dictionary, it
  598. // has to be in the placeholders table.
  599. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  600. index 899153a..3f64268 100644
  601. --- a/src/share/vm/classfile/systemDictionary.cpp
  602. +++ b/src/share/vm/classfile/systemDictionary.cpp
  603. @@ -157,6 +157,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_load
  604. // can return a null klass
  605. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  606. }
  607. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  608. return klass;
  609. }
  610. @@ -199,7 +200,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
  611. // Forwards to resolve_instance_class_or_null
  612. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  613. - assert(!THREAD->is_Compiler_thread(),
  614. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  615. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  616. class_name->as_C_string(),
  617. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  618. @@ -961,8 +962,10 @@ klassOop SystemDictionary::parse_stream(Symbol* class_name,
  619. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  620. class_loader,
  621. protection_domain,
  622. + KlassHandle(),
  623. host_klass,
  624. cp_patches,
  625. + NULL,
  626. parsed_name,
  627. true,
  628. THREAD);
  629. @@ -1022,7 +1025,15 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  630. Handle protection_domain,
  631. ClassFileStream* st,
  632. bool verify,
  633. + KlassHandle old_class,
  634. TRAPS) {
  635. +
  636. + bool redefine_classes_locked = false;
  637. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  638. + Thread::current()->redefine_classes_mutex()->lock();
  639. + redefine_classes_locked = true;
  640. + }
  641. +
  642. // Classloaders that support parallelism, e.g. bootstrap classloader,
  643. // or all classloaders with UnsyncloadClass do not acquire lock here
  644. bool DoObjectLock = true;
  645. @@ -1050,9 +1061,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  646. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  647. class_loader,
  648. protection_domain,
  649. + old_class,
  650. parsed_name,
  651. verify,
  652. THREAD);
  653. + if (!old_class.is_null() && !k.is_null()) {
  654. + k->set_redefining(true);
  655. + k->set_old_version(old_class());
  656. + }
  657. const char* pkg = "java/";
  658. if (!HAS_PENDING_EXCEPTION &&
  659. @@ -1087,13 +1103,18 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  660. // Add class just loaded
  661. // If a class loader supports parallel classloading handle parallel define requests
  662. // find_or_define_instance_class may return a different instanceKlass
  663. - if (is_parallelCapable(class_loader)) {
  664. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  665. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  666. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  667. } else {
  668. - define_instance_class(k, THREAD);
  669. + define_instance_class(k, old_class, THREAD);
  670. }
  671. }
  672. + if (redefine_classes_locked) {
  673. + Thread::current()->redefine_classes_mutex()->unlock();
  674. + }
  675. +
  676. // If parsing the class file or define_instance_class failed, we
  677. // need to remove the placeholder added on our behalf. But we
  678. // must make sure parsed_name is valid first (it won't be if we had
  679. @@ -1122,7 +1143,7 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  680. MutexLocker mu(SystemDictionary_lock, THREAD);
  681. klassOop check = find_class(parsed_name, class_loader);
  682. - assert(check == k(), "should be present in the dictionary");
  683. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  684. klassOop check2 = find_class(h_name, h_loader);
  685. assert(check == check2, "name inconsistancy in SystemDictionary");
  686. @@ -1349,7 +1370,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
  687. }
  688. }
  689. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  690. +void SystemDictionary::rollback_redefinition() {
  691. + dictionary()->rollback_redefinition();
  692. +}
  693. +
  694. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  695. Handle class_loader_h(THREAD, k->class_loader());
  696. @@ -1376,13 +1401,23 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  697. Symbol* name_h = k->name();
  698. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  699. int d_index = dictionary()->hash_to_index(d_hash);
  700. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  701. +
  702. + // (tw) Update version of the klassOop in the system dictionary
  703. + // TODO: Check for thread safety!
  704. + if (!old_class.is_null()) {
  705. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  706. + assert (ok, "must have found old class and updated!");
  707. + }
  708. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  709. +
  710. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  711. // Register class just loaded with class loader (placed in Vector)
  712. // Note we do this before updating the dictionary, as this can
  713. // fail with an OutOfMemoryError (if it does, we will *not* put this
  714. // class in the dictionary and will not update the class hierarchy).
  715. - if (k->class_loader() != NULL) {
  716. + // (tw) Only register if not redefining a class.
  717. + if (k->class_loader() != NULL && old_class.is_null()) {
  718. methodHandle m(THREAD, Universe::loader_addClass_method());
  719. JavaValue result(T_VOID);
  720. JavaCallArguments args(class_loader_h);
  721. @@ -1408,8 +1443,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  722. }
  723. k->eager_initialize(THREAD);
  724. + // (tw) Only notify jvmti if not redefining a class.
  725. // notify jvmti
  726. - if (JvmtiExport::should_post_class_load()) {
  727. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  728. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  729. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  730. @@ -1482,7 +1518,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
  731. }
  732. }
  733. - define_instance_class(k, THREAD);
  734. + define_instance_class(k, KlassHandle(), THREAD);
  735. Handle linkage_exception = Handle(); // null handle
  736. @@ -1612,6 +1648,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
  737. Universe::flush_dependents_on(k);
  738. }
  739. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  740. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  741. + assert(k.not_null(), "just checking");
  742. +
  743. + k->remove_from_sibling_list();
  744. +
  745. + // TODO (tw): Remove from interfaces.
  746. +}
  747. // ----------------------------------------------------------------------------
  748. // GC support
  749. @@ -1869,9 +1913,12 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) {
  750. // Preload ref klasses and set reference types
  751. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  752. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  753. +
  754. + // (tw) This is now done in parseClassFile in order to support class redefinition
  755. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  756. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  757. + // TODO(tw): Check that the following is also not necessary?
  758. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  759. instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
  760. instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
  761. @@ -1955,7 +2002,7 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
  762. // also holds array classes
  763. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  764. - if ((defining == true) || (k() != check)) {
  765. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  766. linkage_error = "loader (instance of %s): attempted duplicate class "
  767. "definition for name: \"%s\"";
  768. } else {
  769. @@ -2602,8 +2649,10 @@ void SystemDictionary::verify_obj_klass_present(Handle obj,
  770. name = find_placeholder(class_name, class_loader);
  771. }
  772. }
  773. - guarantee(probe != NULL || name != NULL,
  774. - "Loaded klasses should be in SystemDictionary");
  775. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  776. + guarantee(probe != NULL &&
  777. + (!probe->is_klass() || (!((klassOop)(obj()))->klass_part()->is_redefining()) || ((klassOop)probe)->klass_part()->is_same_or_older_version((klassOop)(obj()))) || ((klassOop)(obj()))->klass_part()->is_redefining(),
  778. + "Loaded klasses should be in SystemDictionary");
  779. }
  780. // utility function for posting class load event
  781. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  782. index adf82e5..00cf392 100644
  783. --- a/src/share/vm/classfile/systemDictionary.hpp
  784. +++ b/src/share/vm/classfile/systemDictionary.hpp
  785. @@ -268,7 +268,7 @@ public:
  786. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  787. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  788. Handle protection_domain,
  789. - ClassFileStream* st, bool verify, TRAPS);
  790. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  791. // Lookup an already loaded class. If not found NULL is returned.
  792. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  793. @@ -343,6 +343,8 @@ public:
  794. // System loader lock
  795. static oop system_loader_lock() { return _system_loader_lock_obj; }
  796. + // Remove link to hierarchy
  797. + static void remove_from_hierarchy(instanceKlassHandle k);
  798. private:
  799. // Traverses preloaded oops: various system classes. These are
  800. // guaranteed to be in the perm gen.
  801. @@ -415,6 +417,8 @@ public:
  802. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  803. }
  804. + static void rollback_redefinition();
  805. +
  806. public:
  807. #define WK_KLASS_DECLARE(name, symbol, option) \
  808. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  809. @@ -596,7 +600,7 @@ private:
  810. // after waiting, but before reentering SystemDictionary_lock
  811. // to preserve lock order semantics.
  812. static void double_lock_wait(Handle lockObject, TRAPS);
  813. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  814. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  815. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  816. Handle class_loader,
  817. instanceKlassHandle k, TRAPS);
  818. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  819. index da188bb..097c50c 100644
  820. --- a/src/share/vm/classfile/verifier.cpp
  821. +++ b/src/share/vm/classfile/verifier.cpp
  822. @@ -106,7 +106,7 @@ bool Verifier::relax_verify_for(oop loader) {
  823. return !need_verify;
  824. }
  825. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  826. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  827. HandleMark hm;
  828. ResourceMark rm(THREAD);
  829. @@ -117,6 +117,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  830. const char* klassName = klass->external_name();
  831. bool can_failover = FailOverToOldVerifier &&
  832. + may_use_old_verifier &&
  833. klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  834. // If the class should be verified, first see if we can use the split
  835. @@ -138,6 +139,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  836. tty->print_cr(
  837. "Fail over class verification to old verifier for: %s", klassName);
  838. }
  839. + assert(may_use_old_verifier, "");
  840. exception_name = inference_verify(
  841. klass, message_buffer, message_buffer_len, THREAD);
  842. }
  843. @@ -145,6 +147,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  844. exception_message = split_verifier.exception_message();
  845. }
  846. } else {
  847. + assert(may_use_old_verifier, "");
  848. exception_name = inference_verify(
  849. klass, message_buffer, message_buffer_len, THREAD);
  850. }
  851. @@ -210,7 +213,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
  852. // NOTE: this is called too early in the bootstrapping process to be
  853. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  854. (refl_magic_klass == NULL ||
  855. - !klass->is_subtype_of(refl_magic_klass) ||
  856. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  857. VerifyReflectionBytecodes)
  858. );
  859. }
  860. @@ -517,7 +520,7 @@ void ErrorContext::stackmap_details(outputStream* ss, methodOop method) const {
  861. ClassVerifier::ClassVerifier(
  862. instanceKlassHandle klass, TRAPS)
  863. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  864. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  865. _this_type = VerificationType::reference_type(klass->name());
  866. // Create list to hold symbols in reference area.
  867. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  868. @@ -547,7 +550,7 @@ void ClassVerifier::verify_class(TRAPS) {
  869. _klass->external_name());
  870. }
  871. - objArrayHandle methods(THREAD, _klass->methods());
  872. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  873. int num_methods = methods->length();
  874. for (int index = 0; index < num_methods; index++) {
  875. @@ -2444,7 +2447,8 @@ void ClassVerifier::verify_invoke_instructions(
  876. VerificationType stack_object_type =
  877. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  878. if (current_type() != stack_object_type) {
  879. - assert(cp->cache() == NULL, "not rewritten yet");
  880. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  881. + //assert(cp->cache() == NULL, "not rewritten yet");
  882. Symbol* ref_class_name =
  883. cp->klass_name_at(cp->klass_ref_index_at(index));
  884. // See the comments in verify_field_instructions() for
  885. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  886. index 4457f4a..b1b96f2 100644
  887. --- a/src/share/vm/classfile/verifier.hpp
  888. +++ b/src/share/vm/classfile/verifier.hpp
  889. @@ -47,7 +47,7 @@ class Verifier : AllStatic {
  890. * Otherwise, no exception is thrown and the return indicates the
  891. * error.
  892. */
  893. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  894. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  895. // Return false if the class is loaded by the bootstrap loader,
  896. // or if defineClass was called requesting skipping verification
  897. @@ -256,7 +256,10 @@ class ClassVerifier : public StackObj {
  898. ErrorContext _error_context; // contains information about an error
  899. +public:
  900. void verify_method(methodHandle method, TRAPS);
  901. +
  902. +private:
  903. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  904. void verify_exception_handler_table(u4 code_length, char* code_data,
  905. int& min, int& max, TRAPS);
  906. @@ -329,6 +332,7 @@ class ClassVerifier : public StackObj {
  907. VerificationType object_type() const;
  908. + instanceKlassHandle _klass_to_verify;
  909. instanceKlassHandle _klass; // the class being verified
  910. methodHandle _method; // current method being verified
  911. VerificationType _this_type; // the verification type of the current class
  912. diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
  913. index 21c9413..59f5f7e 100644
  914. --- a/src/share/vm/code/nmethod.cpp
  915. +++ b/src/share/vm/code/nmethod.cpp
  916. @@ -2074,15 +2074,14 @@ bool nmethod::is_evol_dependent_on(klassOop dependee) {
  917. methodOop method = deps.method_argument(0);
  918. for (int j = 0; j < dependee_methods->length(); j++) {
  919. if ((methodOop) dependee_methods->obj_at(j) == method) {
  920. - // RC_TRACE macro has an embedded ResourceMark
  921. - RC_TRACE(0x01000000,
  922. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  923. + ResourceMark rm(Thread::current());
  924. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  925. _method->method_holder()->klass_part()->external_name(),
  926. _method->name()->as_C_string(),
  927. _method->signature()->as_C_string(), compile_id(),
  928. method->method_holder()->klass_part()->external_name(),
  929. method->name()->as_C_string(),
  930. - method->signature()->as_C_string()));
  931. + method->signature()->as_C_string());
  932. if (TraceDependencies || LogCompilation)
  933. deps.log_dependency(dependee);
  934. return true;
  935. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  936. index 0feca89..1c4b014 100644
  937. --- a/src/share/vm/compiler/compileBroker.cpp
  938. +++ b/src/share/vm/compiler/compileBroker.cpp
  939. @@ -1592,6 +1592,9 @@ void CompileBroker::compiler_thread_loop() {
  940. // Never compile a method if breakpoints are present in it
  941. if (method()->number_of_breakpoints() == 0) {
  942. + // (tw) Obtain a compilation lock. Class redefinition requires that there is no compilation in parallel.
  943. + thread->compilation_mutex()->lock();
  944. + thread->set_should_bailout(false);
  945. // Compile the method.
  946. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  947. #ifdef COMPILER1
  948. @@ -1615,6 +1618,7 @@ void CompileBroker::compiler_thread_loop() {
  949. // After compilation is disabled, remove remaining methods from queue
  950. method->clear_queued_for_compilation();
  951. }
  952. + thread->compilation_mutex()->unlock();
  953. }
  954. }
  955. }
  956. @@ -1780,7 +1784,11 @@ void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
  957. //assert(false, "compiler should always document failure");
  958. // The compiler elected, without comment, not to register a result.
  959. // Do not attempt further compilations of this method.
  960. - ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
  961. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  962. + ci_env.record_failure("compile externally aborted");
  963. + } else {
  964. + ci_env.record_method_not_compilable("compile failed");
  965. + }
  966. }
  967. // Copy this bit to the enclosing block:
  968. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  969. index b0c9ec8..7feadf9 100644
  970. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  971. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  972. @@ -162,6 +162,13 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
  973. }
  974. }
  975. +
  976. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  977. + CompactPoint* cp, HeapWord* compact_top) {
  978. + ShouldNotReachHere();
  979. + return NULL;
  980. +}
  981. +
  982. // Like CompactibleSpace forward() but always calls cross_threshold() to
  983. // update the block offset table. Removed initialize_threshold call because
  984. // CFLS does not use a block offset array for contiguous spaces.
  985. @@ -2118,7 +2125,7 @@ bool CompactibleFreeListSpace::should_concurrent_collect() const {
  986. // Support for compaction
  987. void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
  988. - SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
  989. + SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
  990. // prepare_for_compaction() uses the space between live objects
  991. // so that later phase can skip dead space quickly. So verification
  992. // of the free lists doesn't work after.
  993. @@ -2139,7 +2146,7 @@ void CompactibleFreeListSpace::adjust_pointers() {
  994. }
  995. void CompactibleFreeListSpace::compact() {
  996. - SCAN_AND_COMPACT(obj_size);
  997. + SCAN_AND_COMPACT(obj_size, false);
  998. }
  999. // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
  1000. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1001. index 3b7bb9a..de7e54b 100644
  1002. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1003. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1004. @@ -149,6 +149,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
  1005. // Support for compacting cms
  1006. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1007. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1008. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1009. // Initialization helpers.
  1010. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1011. index 29841d8..d1386c7 100644
  1012. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1013. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1014. @@ -32,6 +32,8 @@
  1015. #include "oops/objArrayKlass.inline.hpp"
  1016. #include "oops/oop.inline.hpp"
  1017. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1018. +
  1019. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1020. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1021. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1022. @@ -357,3 +359,97 @@ void MarkSweep::trace(const char* msg) {
  1023. }
  1024. #endif
  1025. +
  1026. +// (tw) Copy the rescued objects to their destination address after compaction.
  1027. +void MarkSweep::copy_rescued_objects_back() {
  1028. +
  1029. + if (_rescued_oops != NULL) {
  1030. +
  1031. + for (int i=0; i<_rescued_oops->length(); i++) {
  1032. + oop rescued_obj = _rescued_oops->at(i);
  1033. +
  1034. + int size = rescued_obj->size();
  1035. + oop new_obj = rescued_obj->forwardee();
  1036. +
  1037. + assert(rescued_obj->blueprint()->new_version() != NULL, "just checking");
  1038. +
  1039. + if (rescued_obj->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1040. + MarkSweep::update_fields(rescued_obj, new_obj);
  1041. + } else {
  1042. + rescued_obj->set_klass_no_check(rescued_obj->blueprint()->new_version());
  1043. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1044. + }
  1045. +
  1046. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1047. +
  1048. + new_obj->init_mark();
  1049. + assert(new_obj->is_oop(), "must be a valid oop");
  1050. + }
  1051. + _rescued_oops->clear();
  1052. + _rescued_oops = NULL;
  1053. + }
  1054. +}
  1055. +
  1056. +// (tw) Update instances of a class whose fields changed.
  1057. +void MarkSweep::update_fields(oop q, oop new_location) {
  1058. +
  1059. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1060. +
  1061. + klassOop old_klass_oop = q->klass();
  1062. + klassOop new_klass_oop = q->blueprint()->new_version();
  1063. +
  1064. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1065. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1066. +
  1067. + int size = q->size_given_klass(old_klass);
  1068. + int new_size = q->size_given_klass(new_klass);
  1069. +
  1070. + oop tmp_obj = q;
  1071. +
  1072. + // Save object somewhere, there is an overlap in fields
  1073. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1074. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1075. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1076. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1077. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1078. + }
  1079. + }
  1080. +
  1081. + tmp_obj->set_klass_no_check(new_klass_oop);
  1082. + int *cur = new_klass_oop->klass_part()->update_information();
  1083. + assert(cur != NULL, "just checking");
  1084. + MarkSweep::update_fields(new_location, tmp_obj, cur);
  1085. +
  1086. + if (tmp_obj != q) {
  1087. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1088. + }
  1089. +}
  1090. +
  1091. +void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
  1092. + assert(cur != NULL, "just checking");
  1093. + char* to = (char*)new_location;
  1094. + while (*cur != 0) {
  1095. + int size = *cur;
  1096. + if (size > 0) {
  1097. + cur++;
  1098. + int offset = *cur;
  1099. + HeapWord* from = (HeapWord*)(((char *)tmp_obj) + offset);
  1100. + if (size == HeapWordSize) {
  1101. + *((HeapWord*)to) = *from;
  1102. + } else if (size == HeapWordSize * 2) {
  1103. + *((HeapWord*)to) = *from;
  1104. + *(((HeapWord*)to) + 1) = *(from + 1);
  1105. + } else {
  1106. + Copy::conjoint_jbytes(from, to, size);
  1107. + }
  1108. + to += size;
  1109. + cur++;
  1110. + } else {
  1111. + assert(size < 0, "");
  1112. + int skip = -*cur;
  1113. + Copy::fill_to_bytes(to, skip, 0);
  1114. + to += skip;
  1115. + cur++;
  1116. + }
  1117. + }
  1118. +}
  1119. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1120. index eb8252c..40118db 100644
  1121. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1122. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1123. @@ -117,8 +117,12 @@ class MarkSweep : AllStatic {
  1124. friend class AdjustPointerClosure;
  1125. friend class KeepAliveClosure;
  1126. friend class VM_MarkSweep;
  1127. + friend class GenMarkSweep;
  1128. friend void marksweep_init();
  1129. +public:
  1130. + static GrowableArray<oop>* _rescued_oops;
  1131. +
  1132. //
  1133. // Vars
  1134. //
  1135. @@ -208,6 +212,9 @@ class MarkSweep : AllStatic {
  1136. template <class T> static inline void mark_and_push(T* p);
  1137. static inline void push_objarray(oop obj, size_t index);
  1138. + static void copy_rescued_objects_back();
  1139. + static void update_fields(oop q, oop new_location);
  1140. + static void update_fields(oop new_location, oop tmp_obj, int *cur);
  1141. static void follow_stack(); // Empty marking stack.
  1142. static void preserve_mark(oop p, markOop mark);
  1143. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1144. index 32c0bdb..448d673 100644
  1145. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1146. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1147. @@ -402,7 +402,7 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
  1148. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1149. assert(h_exception->is_oop(), "just checking");
  1150. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1151. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1152. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1153. if (ExitVMOnVerifyError) vm_exit(-1);
  1154. ShouldNotReachHere();
  1155. }
  1156. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1157. index b17f405..1c96783 100644
  1158. --- a/src/share/vm/interpreter/linkResolver.cpp
  1159. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1160. @@ -153,8 +153,8 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass
  1161. // Klass resolution
  1162. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1163. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1164. - sel_klass->as_klassOop(),
  1165. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1166. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1167. true)) {
  1168. ResourceMark rm(THREAD);
  1169. Exceptions::fthrow(
  1170. @@ -338,7 +338,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
  1171. // We'll check for the method name first, as that's most likely
  1172. // to be false (so we'll short-circuit out of these tests).
  1173. if (sel_method->name() == vmSymbols::clone_name() &&
  1174. - sel_klass() == SystemDictionary::Object_klass() &&
  1175. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1176. resolved_klass->oop_is_array()) {
  1177. // We need to change "protected" to "public".
  1178. assert(flags.is_protected(), "clone not protected?");
  1179. @@ -634,7 +634,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  1180. }
  1181. // Final fields can only be accessed from its own class.
  1182. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1183. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1184. THROW(vmSymbols::java_lang_IllegalAccessError());
  1185. }
  1186. @@ -839,7 +839,7 @@ void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHand
  1187. bool check_access, bool check_null_and_abstract, TRAPS) {
  1188. methodHandle resolved_method;
  1189. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1190. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1191. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1192. }
  1193. // throws linktime exceptions
  1194. @@ -869,6 +869,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  1195. KlassHandle resolved_klass,
  1196. Handle recv,
  1197. KlassHandle recv_klass,
  1198. + KlassHandle current_klass,
  1199. bool check_null_and_abstract,
  1200. TRAPS) {
  1201. @@ -917,6 +918,9 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  1202. // recv_klass might be an arrayKlassOop but all vtables start at
  1203. // the same place. The cast is to avoid virtual call and assertion.
  1204. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1205. +
  1206. + // (tw) Check that the receiver is a subtype of the holder of the resolved method.
  1207. + assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
  1208. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  1209. }
  1210. }
  1211. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  1212. index dfd74f9..6ca1b54 100644
  1213. --- a/src/share/vm/interpreter/linkResolver.hpp
  1214. +++ b/src/share/vm/interpreter/linkResolver.hpp
  1215. @@ -110,7 +110,8 @@ class CallInfo: public LinkInfo {
  1216. // It does all necessary link-time checks & throws exceptions if necessary.
  1217. class LinkResolver: AllStatic {
  1218. - private:
  1219. +private:
  1220. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  1221. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1222. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1223. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  1224. @@ -133,7 +134,7 @@ class LinkResolver: AllStatic {
  1225. 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);
  1226. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  1227. - 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);
  1228. + 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);
  1229. 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);
  1230. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  1231. diff --git a/src/share/vm/interpreter/oopMapCache.cpp b/src/share/vm/interpreter/oopMapCache.cpp
  1232. index 01d5753..6816b3a 100644
  1233. --- a/src/share/vm/interpreter/oopMapCache.cpp
  1234. +++ b/src/share/vm/interpreter/oopMapCache.cpp
  1235. @@ -536,9 +536,9 @@ void OopMapCache::flush_obsolete_entries() {
  1236. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  1237. // Cache entry is occupied by an old redefined method and we don't want
  1238. // to pin it down so flush the entry.
  1239. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  1240. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  1241. _array[i].method()->name()->as_C_string(),
  1242. - _array[i].method()->signature()->as_C_string(), i));
  1243. + _array[i].method()->signature()->as_C_string(), i);
  1244. _array[i].flush();
  1245. }
  1246. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  1247. index 76e18d8..6af7c14 100644
  1248. --- a/src/share/vm/memory/genMarkSweep.cpp
  1249. +++ b/src/share/vm/memory/genMarkSweep.cpp
  1250. @@ -421,6 +421,7 @@ void GenMarkSweep::mark_sweep_phase4() {
  1251. // in the same order in phase2, phase3 and phase4. We don't quite do that
  1252. // here (perm_gen first rather than last), so we tell the validate code
  1253. // to use a higher index (saved from phase2) when verifying perm_gen.
  1254. + assert(_rescued_oops == NULL, "must be empty before processing");
  1255. GenCollectedHeap* gch = GenCollectedHeap::heap();
  1256. Generation* pg = gch->perm_gen();
  1257. @@ -433,10 +434,14 @@ void GenMarkSweep::mark_sweep_phase4() {
  1258. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  1259. + MarkSweep::copy_rescued_objects_back();
  1260. +
  1261. GenCompactClosure blk;
  1262. gch->generation_iterate(&blk, true);
  1263. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  1264. + MarkSweep::copy_rescued_objects_back();
  1265. +
  1266. pg->post_compact(); // Shared spaces verification.
  1267. }
  1268. diff --git a/src/share/vm/memory/iterator.hpp b/src/share/vm/memory/iterator.hpp
  1269. index b5f8e0e..856cfce 100644
  1270. --- a/src/share/vm/memory/iterator.hpp
  1271. +++ b/src/share/vm/memory/iterator.hpp
  1272. @@ -101,6 +101,12 @@ class OopClosure : public Closure {
  1273. #endif
  1274. };
  1275. +class OopClosureNoHeader : public OopClosure {
  1276. +public:
  1277. + // If "true", invoke on header klass field.
  1278. + bool do_header() { return false; } // Note that this is non-virtual.
  1279. +};
  1280. +
  1281. // ObjectClosure is used for iterating through an object space
  1282. class ObjectClosure : public Closure {
  1283. diff --git a/src/share/vm/memory/oopFactory.cpp b/src/share/vm/memory/oopFactory.cpp
  1284. index def88cc..016d7eb 100644
  1285. --- a/src/share/vm/memory/oopFactory.cpp
  1286. +++ b/src/share/vm/memory/oopFactory.cpp
  1287. @@ -129,11 +129,11 @@ klassOop oopFactory::new_instanceKlass(Symbol* name, int vtable_len, int itable_
  1288. unsigned int nonstatic_oop_map_count,
  1289. AccessFlags access_flags,
  1290. ReferenceType rt,
  1291. - KlassHandle host_klass, TRAPS) {
  1292. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  1293. instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj());
  1294. return ikk->allocate_instance_klass(name, vtable_len, itable_len,
  1295. static_field_size, nonstatic_oop_map_count,
  1296. - access_flags, rt, host_klass, CHECK_NULL);
  1297. + access_flags, rt, host_klass, old_klass, CHECK_NULL);
  1298. }
  1299. diff --git a/src/share/vm/memory/oopFactory.hpp b/src/share/vm/memory/oopFactory.hpp
  1300. index e7e22d4..ce39ada 100644
  1301. --- a/src/share/vm/memory/oopFactory.hpp
  1302. +++ b/src/share/vm/memory/oopFactory.hpp
  1303. @@ -80,7 +80,7 @@ class oopFactory: AllStatic {
  1304. unsigned int nonstatic_oop_map_count,
  1305. AccessFlags access_flags,
  1306. ReferenceType rt,
  1307. - KlassHandle host_klass, TRAPS);
  1308. + KlassHandle host_klass, KlassHandle old_klass, TRAPS);
  1309. // Methods
  1310. private:
  1311. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  1312. index f97bc34..c8563b2 100644
  1313. --- a/src/share/vm/memory/space.cpp
  1314. +++ b/src/share/vm/memory/space.cpp
  1315. @@ -378,9 +378,8 @@ void CompactibleSpace::clear(bool mangle_space) {
  1316. _compaction_top = bottom();
  1317. }
  1318. -HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1319. - CompactPoint* cp, HeapWord* compact_top) {
  1320. - // q is alive
  1321. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  1322. +HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
  1323. // First check if we should switch compaction space
  1324. assert(this == cp->space, "'this' should be current compaction space.");
  1325. size_t compaction_max_size = pointer_delta(end(), compact_top);
  1326. @@ -400,8 +399,15 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1327. compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  1328. }
  1329. + return compact_top;
  1330. +}
  1331. +
  1332. +HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1333. + CompactPoint* cp, HeapWord* compact_top) {
  1334. + compact_top = forward_compact_top(size, cp, compact_top);
  1335. +
  1336. // store the forwarding pointer into the mark word
  1337. - if ((HeapWord*)q != compact_top) {
  1338. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  1339. q->forward_to(oop(compact_top));
  1340. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  1341. } else {
  1342. @@ -423,6 +429,58 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  1343. return compact_top;
  1344. }
  1345. +// Compute the forward sizes and leave out objects whose position could
  1346. +// possibly overlap other objects.
  1347. +HeapWord* CompactibleSpace::forward_with_rescue(oop q, size_t size,
  1348. + CompactPoint* cp, HeapWord* compact_top) {
  1349. + size_t forward_size = size;
  1350. +
  1351. + // (DCEVM) There is a new version of the class of q => different size
  1352. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  1353. +
  1354. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1355. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1356. + forward_size = new_size;
  1357. + }
  1358. +
  1359. + compact_top = forward_compact_top(forward_size, cp, compact_top);
  1360. +
  1361. + if (must_rescue(oop(q), oop(compact_top))) {
  1362. + if (MarkSweep::_rescued_oops == NULL) {
  1363. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1364. + }
  1365. + MarkSweep::_rescued_oops->append(oop(q));
  1366. + return compact_top;
  1367. + }
  1368. +
  1369. + return forward(q, forward_size, cp, compact_top);
  1370. +}
  1371. +
  1372. +// Compute the forwarding addresses for the objects that need to be rescued.
  1373. +HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
  1374. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  1375. + if (MarkSweep::_rescued_oops != NULL) {
  1376. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  1377. + oop q = MarkSweep::_rescued_oops->at(i);
  1378. +
  1379. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  1380. + size_t size = block_size((HeapWord*)q);
  1381. +
  1382. + // (tw) There is a new version of the class of q => different size
  1383. + if (oop(q)->blueprint()->new_version() != NULL) {
  1384. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  1385. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  1386. + size = new_size;
  1387. + }
  1388. +
  1389. + compact_top = cp->space->forward(oop(q), size, cp, compact_top);
  1390. + assert(compact_top <= end(), "must not write over end of space!");
  1391. + }
  1392. + MarkSweep::_rescued_oops->clear();
  1393. + MarkSweep::_rescued_oops = NULL;
  1394. + }
  1395. + return compact_top;
  1396. +}
  1397. bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1398. HeapWord* q, size_t deadlength) {
  1399. @@ -444,12 +502,17 @@ bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  1400. #define adjust_obj_size(s) s
  1401. void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  1402. - SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
  1403. + SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
  1404. }
  1405. // Faster object search.
  1406. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  1407. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  1408. + if (!Universe::is_redefining_gc_run()) {
  1409. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
  1410. + } else {
  1411. + // Redefinition run
  1412. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
  1413. + }
  1414. }
  1415. void Space::adjust_pointers() {
  1416. @@ -490,6 +553,111 @@ void Space::adjust_pointers() {
  1417. assert(q == t, "just checking");
  1418. }
  1419. +
  1420. +#ifdef ASSERT
  1421. +
  1422. +int CompactibleSpace::space_index(oop obj) {
  1423. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  1424. +
  1425. + if (heap->is_in_permanent(obj)) {
  1426. + return -1;
  1427. + }
  1428. +
  1429. + int index = 0;
  1430. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1431. + Generation* gen = heap->get_gen(i);
  1432. + CompactibleSpace* space = gen->first_compaction_space();
  1433. + while (space != NULL) {
  1434. + if (space->is_in_reserved(obj)) {
  1435. + return index;
  1436. + }
  1437. + space = space->next_compaction_space();
  1438. + index++;
  1439. + }
  1440. + }
  1441. +
  1442. + tty->print_cr("could not compute space_index for %08xh", obj);
  1443. + index = 0;
  1444. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  1445. + Generation* gen = heap->get_gen(i);
  1446. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  1447. +
  1448. + CompactibleSpace* space = gen->first_compaction_space();
  1449. + while (space != NULL) {
  1450. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  1451. + space = space->next_compaction_space();
  1452. + index++;
  1453. + }
  1454. + }
  1455. +
  1456. + ShouldNotReachHere();
  1457. + return 0;
  1458. +}
  1459. +#endif
  1460. +
  1461. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  1462. + // Only redefined objects can have the need to be rescued.
  1463. + if (oop(old_obj)->blueprint()->new_version() == NULL) return false;
  1464. +
  1465. + if (old_obj->is_perm()) {
  1466. + // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
  1467. + return true;
  1468. + }
  1469. +
  1470. + int new_size = old_obj->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  1471. + int original_size = old_obj->size();
  1472. +
  1473. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  1474. + bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
  1475. + bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
  1476. + if (old_in_tenured == new_in_tenured) {
  1477. + // Rescue if object may overlap with a higher memory address.
  1478. + bool overlap = (old_obj + original_size < new_obj + new_size);
  1479. + if (old_in_tenured) {
  1480. + // Old and new address are in same space, so just compare the address.
  1481. + // Must rescue if object moves towards the top of the space.
  1482. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  1483. + } else {
  1484. + // In the new generation, eden is located before the from space, so a
  1485. + // simple pointer comparison is sufficient.
  1486. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1487. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1488. + assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  1489. + }
  1490. + return overlap;
  1491. +
  1492. + } else {
  1493. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  1494. + if (tenured_gen->is_in_reserved(new_obj)) {
  1495. + // Must never rescue when moving from the new into the old generation.
  1496. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1497. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  1498. + return false;
  1499. +
  1500. + } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
  1501. + // Must always rescue when moving from the old into the new generation.
  1502. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1503. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  1504. + return true;
  1505. + }
  1506. + }
  1507. +}
  1508. +
  1509. +oop CompactibleSpace::rescue(oop old_obj) {
  1510. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  1511. +
  1512. + int size = old_obj->size();
  1513. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1514. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  1515. +
  1516. + if (MarkSweep::_rescued_oops == NULL) {
  1517. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  1518. + }
  1519. +
  1520. + MarkSweep::_rescued_oops->append(rescued_obj);
  1521. + return rescued_obj;
  1522. +}
  1523. +
  1524. void CompactibleSpace::adjust_pointers() {
  1525. // Check first is there is any work to do.
  1526. if (used() == 0) {
  1527. @@ -500,7 +668,13 @@ void CompactibleSpace::adjust_pointers() {
  1528. }
  1529. void CompactibleSpace::compact() {
  1530. - SCAN_AND_COMPACT(obj_size);
  1531. +
  1532. + if(!Universe::is_redefining_gc_run()) {
  1533. + SCAN_AND_COMPACT(obj_size, false);
  1534. + } else {
  1535. + // Redefinition run
  1536. + SCAN_AND_COMPACT(obj_size, true)
  1537. + }
  1538. }
  1539. void Space::print_short() const { print_short_on(tty); }
  1540. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  1541. index ef2f2c6..ff95a8b 100644
  1542. --- a/src/share/vm/memory/space.hpp
  1543. +++ b/src/share/vm/memory/space.hpp
  1544. @@ -445,6 +445,9 @@ public:
  1545. // indicates when the next such action should be taken.
  1546. virtual void prepare_for_compaction(CompactPoint* cp);
  1547. // MarkSweep support phase3
  1548. + DEBUG_ONLY(int space_index(oop obj));
  1549. + bool must_rescue(oop old_obj, oop new_obj);
  1550. + oop rescue(oop old_obj);
  1551. virtual void adjust_pointers();
  1552. // MarkSweep support phase4
  1553. virtual void compact();
  1554. @@ -474,6 +477,15 @@ public:
  1555. // accordingly".
  1556. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  1557. HeapWord* compact_top);
  1558. + // (DCEVM) same as forwad, but can rescue objects. Invoked only during
  1559. + // redefinition runs
  1560. + HeapWord* forward_with_rescue(oop q, size_t size, CompactPoint* cp,
  1561. + HeapWord* compact_top);
  1562. +
  1563. + HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
  1564. +
  1565. + // (tw) Compute new compact top without actually forwarding the object.
  1566. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1567. // Return a size with adjusments as required of the space.
  1568. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  1569. @@ -504,7 +516,7 @@ protected:
  1570. size_t word_len);
  1571. };
  1572. -#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
  1573. +#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
  1574. /* Compute the new addresses for the live objects and store it in the mark \
  1575. * Used by universe::mark_sweep_phase2() \
  1576. */ \
  1577. @@ -564,7 +576,17 @@ protected:
  1578. Prefetch::write(q, interval); \
  1579. /* size_t size = oop(q)->size(); changing this for cms for perm gen */\
  1580. size_t size = block_size(q); \
  1581. - compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1582. + if (redefinition_run) { \
  1583. + compact_top = cp->space->forward_with_rescue(oop(q), size, \
  1584. + cp, compact_top); \
  1585. + if (q < first_dead && oop(q)->is_gc_marked()) { \
  1586. + /* Was moved (otherwise, forward would reset mark), \
  1587. + set first_dead to here */ \
  1588. + first_dead = q; \
  1589. + } \
  1590. + } else { \
  1591. + compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1592. + } \
  1593. q += size; \
  1594. end_of_live = q; \
  1595. } else { \
  1596. @@ -613,6 +635,8 @@ protected:
  1597. } \
  1598. } \
  1599. \
  1600. + if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
  1601. + \
  1602. assert(q == t, "just checking"); \
  1603. if (liveRange != NULL) { \
  1604. liveRange->set_end(q); \
  1605. @@ -665,13 +689,8 @@ protected:
  1606. q += size; \
  1607. } \
  1608. \
  1609. - if (_first_dead == t) { \
  1610. - q = t; \
  1611. - } else { \
  1612. - /* $$$ This is funky. Using this to read the previously written \
  1613. - * LiveRange. See also use below. */ \
  1614. - q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
  1615. - } \
  1616. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1617. + q = _first_dead; \
  1618. } \
  1619. \
  1620. const intx interval = PrefetchScanIntervalInBytes; \
  1621. @@ -702,7 +721,7 @@ protected:
  1622. assert(q == t, "just checking"); \
  1623. }
  1624. -#define SCAN_AND_COMPACT(obj_size) { \
  1625. +#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
  1626. /* Copy all live objects to their new location \
  1627. * Used by MarkSweep::mark_sweep_phase4() */ \
  1628. \
  1629. @@ -728,12 +747,8 @@ protected:
  1630. } \
  1631. ) /* debug_only */ \
  1632. \
  1633. - if (_first_dead == t) { \
  1634. - q = t; \
  1635. - } else { \
  1636. - /* $$$ Funky */ \
  1637. - q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
  1638. - } \
  1639. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1640. + q = _first_dead; \
  1641. } \
  1642. \
  1643. const intx scan_interval = PrefetchScanIntervalInBytes; \
  1644. @@ -752,13 +767,36 @@ protected:
  1645. size_t size = obj_size(q); \
  1646. HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
  1647. \
  1648. + if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
  1649. + oop dest_obj = rescue(oop(q)); \
  1650. + debug_only(Copy::fill_to_words(q, size, 0)); \
  1651. + q += size; \
  1652. + continue; \
  1653. + } \
  1654. + \
  1655. /* prefetch beyond compaction_top */ \
  1656. Prefetch::write(compaction_top, copy_interval); \
  1657. \
  1658. /* copy object and reinit its mark */ \
  1659. VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, \
  1660. compaction_top)); \
  1661. - assert(q != compaction_top, "everything in this pass should be moving"); \
  1662. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, \
  1663. + "everything in this pass should be moving"); \
  1664. + if (redefinition_run && oop(q)->blueprint()->new_version() != NULL) { \
  1665. + klassOop new_version = oop(q)->blueprint()->new_version(); \
  1666. + if (new_version->klass_part()->update_information() == NULL) { \
  1667. + Copy::aligned_conjoint_words(q, compaction_top, size); \
  1668. + oop(compaction_top)->set_klass_no_check(new_version); \
  1669. + } else { \
  1670. + MarkSweep::update_fields(oop(q), oop(compaction_top)); \
  1671. + } \
  1672. + oop(compaction_top)->init_mark(); \
  1673. + assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1674. + \
  1675. + debug_only(prev_q = q); \
  1676. + q += size; \
  1677. + continue; \
  1678. + } \
  1679. Copy::aligned_conjoint_words(q, compaction_top, size); \
  1680. oop(compaction_top)->init_mark(); \
  1681. assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1682. diff --git a/src/share/vm/memory/specialized_oop_closures.hpp b/src/share/vm/memory/specialized_oop_closures.hpp
  1683. index 4d7c50b..671787e 100644
  1684. --- a/src/share/vm/memory/specialized_oop_closures.hpp
  1685. +++ b/src/share/vm/memory/specialized_oop_closures.hpp
  1686. @@ -37,6 +37,7 @@
  1687. // Forward declarations.
  1688. class OopClosure;
  1689. +class OopClosureNoHeader;
  1690. class OopsInGenClosure;
  1691. // DefNew
  1692. class ScanClosure;
  1693. @@ -74,6 +75,7 @@ class CMSInnerParMarkAndPushClosure;
  1694. #endif
  1695. #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
  1696. + f(OopClosureNoHeader,_v) \
  1697. f(ScanClosure,_nv) \
  1698. f(FastScanClosure,_nv) \
  1699. f(FilteringClosure,_nv)
  1700. @@ -132,6 +134,7 @@ class CMSInnerParMarkAndPushClosure;
  1701. #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
  1702. f(OopClosure,_v) \
  1703. + f(OopClosureNoHeader,_v) \
  1704. SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
  1705. #endif // SERIALGC
  1706. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  1707. index 8ce17d9..fe37993 100644
  1708. --- a/src/share/vm/memory/universe.cpp
  1709. +++ b/src/share/vm/memory/universe.cpp
  1710. @@ -100,6 +100,8 @@
  1711. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  1712. #endif
  1713. +bool Universe::_is_redefining_gc_run = false;
  1714. +
  1715. // Known objects
  1716. klassOop Universe::_boolArrayKlassObj = NULL;
  1717. klassOop Universe::_byteArrayKlassObj = NULL;
  1718. @@ -204,6 +206,42 @@ void Universe::system_classes_do(void f(klassOop)) {
  1719. f(systemObjArrayKlassObj());
  1720. }
  1721. +// (tw) This method should iterate all pointers that are not within heap objects.
  1722. +void Universe::root_oops_do(OopClosure *oopClosure) {
  1723. +
  1724. + class AlwaysTrueClosure: public BoolObjectClosure {
  1725. + public:
  1726. + void do_object(oop p) { ShouldNotReachHere(); }
  1727. + bool do_object_b(oop p) { return true; }
  1728. + };
  1729. + AlwaysTrueClosure always_true;
  1730. +
  1731. + Universe::oops_do(oopClosure);
  1732. +// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
  1733. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  1734. + Threads::oops_do(oopClosure, NULL);
  1735. + ObjectSynchronizer::oops_do(oopClosure);
  1736. + FlatProfiler::oops_do(oopClosure);
  1737. + JvmtiExport::oops_do(oopClosure);
  1738. +
  1739. + // Now adjust pointers in remaining weak roots. (All of which should
  1740. + // have been cleared if they pointed to non-surviving objects.)
  1741. + // Global (weak) JNI handles
  1742. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  1743. +
  1744. + CodeCache::oops_do(oopClosure);
  1745. + StringTable::oops_do(oopClosure);
  1746. +
  1747. + // (tw) TODO: Check if this is correct?
  1748. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  1749. + //Management::oops_do(oopClosure);
  1750. + //ref_processor()->weak_oops_do(&oopClosure);
  1751. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  1752. +
  1753. + // SO_AllClasses
  1754. + SystemDictionary::oops_do(oopClosure);
  1755. +}
  1756. +
  1757. void Universe::oops_do(OopClosure* f, bool do_all) {
  1758. f->do_oop((oop*) &_int_mirror);
  1759. @@ -1590,10 +1628,9 @@ void ActiveMethodOopsCache::add_previous_version(const methodOop method) {
  1760. }
  1761. // RC_TRACE macro has an embedded ResourceMark
  1762. - RC_TRACE(0x00000100,
  1763. - ("add: %s(%s): adding prev version ref for cached method @%d",
  1764. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  1765. method->name()->as_C_string(), method->signature()->as_C_string(),
  1766. - _prev_methods->length()));
  1767. + _prev_methods->length());
  1768. methodHandle method_h(method);
  1769. jweak method_ref = JNIHandles::make_weak_global(method_h);
  1770. @@ -1620,9 +1657,8 @@ void ActiveMethodOopsCache::add_previous_version(const methodOop method) {
  1771. JNIHandles::destroy_weak_global(method_ref);
  1772. _prev_methods->remove_at(i);
  1773. } else {
  1774. - // RC_TRACE macro has an embedded ResourceMark
  1775. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  1776. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  1777. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  1778. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  1779. }
  1780. }
  1781. } // end add_previous_version()
  1782. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  1783. index da21a8b..676675e 100644
  1784. --- a/src/share/vm/memory/universe.hpp
  1785. +++ b/src/share/vm/memory/universe.hpp
  1786. @@ -127,6 +127,8 @@ class Universe: AllStatic {
  1787. friend class SystemDictionary;
  1788. friend class VMStructs;
  1789. friend class CompactingPermGenGen;
  1790. + friend class Space;
  1791. + friend class ContiguousSpace;
  1792. friend class VM_PopulateDumpSharedSpace;
  1793. friend jint universe_init();
  1794. @@ -258,7 +260,18 @@ class Universe: AllStatic {
  1795. static void compute_verify_oop_data();
  1796. + static bool _is_redefining_gc_run;
  1797. +
  1798. public:
  1799. +
  1800. + static bool is_redefining_gc_run() {
  1801. + return _is_redefining_gc_run;
  1802. + }
  1803. +
  1804. + static void set_redefining_gc_run(bool b) {
  1805. + _is_redefining_gc_run = b;
  1806. + }
  1807. +
  1808. // Known classes in the VM
  1809. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  1810. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  1811. @@ -403,6 +416,8 @@ class Universe: AllStatic {
  1812. // Iteration
  1813. + static void root_oops_do(OopClosure *f);
  1814. +
  1815. // Apply "f" to the addresses of all the direct heap pointers maintained
  1816. // as static fields of "Universe".
  1817. static void oops_do(OopClosure* f, bool do_all = false);
  1818. @@ -419,6 +434,7 @@ class Universe: AllStatic {
  1819. // Debugging
  1820. static bool verify_in_progress() { return _verify_in_progress; }
  1821. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  1822. static void verify(bool silent, VerifyOption option);
  1823. static void verify(bool silent) {
  1824. verify(silent, VerifyOption_Default /* option */);
  1825. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  1826. index ad62921..1cd422c 100644
  1827. --- a/src/share/vm/oops/cpCacheOop.cpp
  1828. +++ b/src/share/vm/oops/cpCacheOop.cpp
  1829. @@ -40,6 +40,11 @@
  1830. void ConstantPoolCacheEntry::initialize_entry(int index) {
  1831. assert(0 < index && index < 0x10000, "sanity check");
  1832. _indices = index;
  1833. +// (DCEVM) Should put something else to force JVM to fail if these invalid entries are accessed!
  1834. +//#ifdef ASSERT
  1835. + _f1 = NULL;
  1836. + _f2 = 0;
  1837. +//#endif
  1838. assert(constant_pool_index() == index, "");
  1839. }
  1840. @@ -162,7 +167,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  1841. int vtable_index) {
  1842. assert(!is_secondary_entry(), "");
  1843. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  1844. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1845. + // (tw) No longer valid assert
  1846. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  1847. int byte_no = -1;
  1848. bool change_to_virtual = false;
  1849. @@ -516,116 +522,6 @@ void ConstantPoolCacheEntry::update_pointers() {
  1850. }
  1851. #endif // SERIALGC
  1852. -// RedefineClasses() API support:
  1853. -// If this constantPoolCacheEntry refers to old_method then update it
  1854. -// to refer to new_method.
  1855. -bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  1856. - methodOop new_method, bool * trace_name_printed) {
  1857. -
  1858. - if (is_vfinal()) {
  1859. - // virtual and final so _f2 contains method ptr instead of vtable index
  1860. - if (f2_as_vfinal_method() == old_method) {
  1861. - // match old_method so need an update
  1862. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  1863. - _f2 = (intptr_t)new_method;
  1864. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1865. - if (!(*trace_name_printed)) {
  1866. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1867. - RC_TRACE_MESG(("adjust: name=%s",
  1868. - Klass::cast(old_method->method_holder())->external_name()));
  1869. - *trace_name_printed = true;
  1870. - }
  1871. - // RC_TRACE macro has an embedded ResourceMark
  1872. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  1873. - new_method->name()->as_C_string(),
  1874. - new_method->signature()->as_C_string()));
  1875. - }
  1876. -
  1877. - return true;
  1878. - }
  1879. -
  1880. - // f1() is not used with virtual entries so bail out
  1881. - return false;
  1882. - }
  1883. -
  1884. - if ((oop)_f1 == NULL) {
  1885. - // NULL f1() means this is a virtual entry so bail out
  1886. - // We are assuming that the vtable index does not need change.
  1887. - return false;
  1888. - }
  1889. -
  1890. - if ((oop)_f1 == old_method) {
  1891. - _f1 = new_method;
  1892. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  1893. - if (!(*trace_name_printed)) {
  1894. - // RC_TRACE_MESG macro has an embedded ResourceMark
  1895. - RC_TRACE_MESG(("adjust: name=%s",
  1896. - Klass::cast(old_method->method_holder())->external_name()));
  1897. - *trace_name_printed = true;
  1898. - }
  1899. - // RC_TRACE macro has an embedded ResourceMark
  1900. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  1901. - new_method->name()->as_C_string(),
  1902. - new_method->signature()->as_C_string()));
  1903. - }
  1904. -
  1905. - return true;
  1906. - }
  1907. -
  1908. - return false;
  1909. -}
  1910. -
  1911. -// a constant pool cache entry should never contain old or obsolete methods
  1912. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  1913. - if (is_vfinal()) {
  1914. - // virtual and final so _f2 contains method ptr instead of vtable index
  1915. - methodOop m = (methodOop)_f2;
  1916. - // Return false if _f2 refers to an old or an obsolete method.
  1917. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  1918. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  1919. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  1920. - // _f1 == NULL || !_f1->is_method() are OK here
  1921. - return true;
  1922. - }
  1923. -
  1924. - methodOop m = (methodOop)_f1;
  1925. - // return false if _f1 refers to an old or an obsolete method
  1926. - return (!m->is_old() && !m->is_obsolete());
  1927. -}
  1928. -
  1929. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  1930. - if (!is_method_entry()) {
  1931. - // not a method entry so not interesting by default
  1932. - return false;
  1933. - }
  1934. -
  1935. - methodOop m = NULL;
  1936. - if (is_vfinal()) {
  1937. - // virtual and final so _f2 contains method ptr instead of vtable index
  1938. - m = f2_as_vfinal_method();
  1939. - } else if (is_f1_null()) {
  1940. - // NULL _f1 means this is a virtual entry so also not interesting
  1941. - return false;
  1942. - } else {
  1943. - oop f1 = _f1; // _f1 is volatile
  1944. - if (!f1->is_method()) {
  1945. - // _f1 can also contain a klassOop for an interface
  1946. - return false;
  1947. - }
  1948. - m = f1_as_method();
  1949. - }
  1950. -
  1951. - assert(m != NULL && m->is_method(), "sanity check");
  1952. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  1953. - // robustness for above sanity checks or method is not in
  1954. - // the interesting class
  1955. - return false;
  1956. - }
  1957. -
  1958. - // the method is in the interesting class so the entry is interesting
  1959. - return true;
  1960. -}
  1961. -
  1962. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  1963. // print separator
  1964. if (index == 0) st->print_cr(" -------------");
  1965. @@ -663,60 +559,10 @@ void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
  1966. }
  1967. }
  1968. -// RedefineClasses() API support:
  1969. -// If any entry of this constantPoolCache points to any of
  1970. -// old_methods, replace it with the corresponding new_method.
  1971. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  1972. - int methods_length, bool * trace_name_printed) {
  1973. -
  1974. - if (methods_length == 0) {
  1975. - // nothing to do if there are no methods
  1976. - return;
  1977. - }
  1978. -
  1979. - // get shorthand for the interesting class
  1980. - klassOop old_holder = old_methods[0]->method_holder();
  1981. +void constantPoolCacheOopDesc::adjust_entries() {
  1982. for (int i = 0; i < length(); i++) {
  1983. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  1984. - // skip uninteresting methods
  1985. - continue;
  1986. - }
  1987. -
  1988. - // The constantPoolCache contains entries for several different
  1989. - // things, but we only care about methods. In fact, we only care
  1990. - // about methods in the same class as the one that contains the
  1991. - // old_methods. At this point, we have an interesting entry.
  1992. -
  1993. - for (int j = 0; j < methods_length; j++) {
  1994. - methodOop old_method = old_methods[j];
  1995. - methodOop new_method = new_methods[j];
  1996. -
  1997. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  1998. - trace_name_printed)) {
  1999. - // current old_method matched this entry and we updated it so
  2000. - // break out and get to the next interesting entry if there one
  2001. - break;
  2002. - }
  2003. - }
  2004. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  2005. }
  2006. }
  2007. -// the constant pool cache should never contain old or obsolete methods
  2008. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  2009. - for (int i = 1; i < length(); i++) {
  2010. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  2011. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  2012. - return false;
  2013. - }
  2014. - }
  2015. - return true;
  2016. -}
  2017. -
  2018. -void constantPoolCacheOopDesc::dump_cache() {
  2019. - for (int i = 1; i < length(); i++) {
  2020. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  2021. - entry_at(i)->print(tty, i);
  2022. - }
  2023. - }
  2024. -}
  2025. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  2026. index ef26775..a270d0d 100644
  2027. --- a/src/share/vm/oops/cpCacheOop.hpp
  2028. +++ b/src/share/vm/oops/cpCacheOop.hpp
  2029. @@ -355,17 +355,6 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  2030. void update_pointers();
  2031. - // RedefineClasses() API support:
  2032. - // If this constantPoolCacheEntry refers to old_method then update it
  2033. - // to refer to new_method.
  2034. - // trace_name_printed is set to true if the current call has
  2035. - // printed the klass name so that other routines in the adjust_*
  2036. - // group don't print the klass name.
  2037. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  2038. - bool * trace_name_printed);
  2039. - bool check_no_old_or_obsolete_entries();
  2040. - bool is_interesting_method_entry(klassOop k);
  2041. -
  2042. // Debugging & Printing
  2043. void print (outputStream* st, int index) const;
  2044. void verify(outputStream* st) const;
  2045. @@ -485,16 +474,8 @@ class constantPoolCacheOopDesc: public oopDesc {
  2046. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  2047. }
  2048. - // RedefineClasses() API support:
  2049. - // If any entry of this constantPoolCache points to any of
  2050. - // old_methods, replace it with the corresponding new_method.
  2051. - // trace_name_printed is set to true if the current call has
  2052. - // printed the klass name so that other routines in the adjust_*
  2053. - // group don't print the klass name.
  2054. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  2055. - int methods_length, bool * trace_name_printed);
  2056. - bool check_no_old_or_obsolete_entries();
  2057. - void dump_cache();
  2058. + // (tw) Clear references to methods and fields from this cache.
  2059. + void adjust_entries();
  2060. };
  2061. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  2062. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  2063. index cd3dce0..666ffdf 100644
  2064. --- a/src/share/vm/oops/instanceKlass.cpp
  2065. +++ b/src/share/vm/oops/instanceKlass.cpp
  2066. @@ -255,7 +255,7 @@ bool instanceKlass::verify_code(
  2067. // 1) Verify the bytecodes
  2068. Verifier::Mode mode =
  2069. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  2070. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  2071. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  2072. }
  2073. @@ -362,7 +362,13 @@ bool instanceKlass::link_class_impl(
  2074. jt->get_thread_stat()->perf_recursion_counts_addr(),
  2075. jt->get_thread_stat()->perf_timers_addr(),
  2076. PerfClassTraceTime::CLASS_VERIFY);
  2077. + if (this_oop->is_redefining()) {
  2078. + Thread::current()->set_pretend_new_universe(true);
  2079. + }
  2080. bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  2081. + if (this_oop->is_redefining()) {
  2082. + Thread::current()->set_pretend_new_universe(false);
  2083. + }
  2084. if (!verify_ok) {
  2085. return false;
  2086. }
  2087. @@ -400,7 +406,8 @@ bool instanceKlass::link_class_impl(
  2088. }
  2089. #endif
  2090. this_oop->set_init_state(linked);
  2091. - if (JvmtiExport::should_post_class_prepare()) {
  2092. + // (tw) Must check for old version in order to prevent infinite loops.
  2093. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  2094. Thread *thread = THREAD;
  2095. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  2096. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  2097. @@ -454,7 +461,9 @@ void instanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) {
  2098. // If we were to use wait() instead of waitInterruptibly() then
  2099. // we might end up throwing IE from link/symbol resolution sites
  2100. // that aren't expected to throw. This would wreak havoc. See 6320309.
  2101. - while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
  2102. + // (tw) Wait also for the old class version to be fully initialized.
  2103. + while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
  2104. + || (this_oop->old_version() != NULL && ((instanceKlass*)this_oop->old_version()->klass_part())->is_being_initialized())) {
  2105. wait = true;
  2106. ol.waitUninterruptibly(CHECK);
  2107. }
  2108. @@ -673,6 +682,18 @@ bool instanceKlass::implements_interface(klassOop k) const {
  2109. return false;
  2110. }
  2111. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  2112. + k = k->klass_part()->newest_version();
  2113. + if (this->newest_version() == k) return true;
  2114. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  2115. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  2116. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  2117. + return true;
  2118. + }
  2119. + }
  2120. + return false;
  2121. +}
  2122. +
  2123. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  2124. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  2125. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  2126. @@ -949,6 +970,18 @@ void instanceKlass::methods_do(void f(methodOop method)) {
  2127. }
  2128. }
  2129. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  2130. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  2131. + for (int i=0; i<values.length(); i++) {
  2132. + arr[i] = values.at(i);
  2133. + }
  2134. + set_update_information(arr);
  2135. +}
  2136. +
  2137. +void instanceKlass::clear_update_information() {
  2138. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  2139. + set_update_information(NULL);
  2140. +}
  2141. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  2142. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  2143. @@ -1368,6 +1401,20 @@ jmethodID instanceKlass::jmethod_id_or_null(methodOop method) {
  2144. return id;
  2145. }
  2146. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  2147. + size_t idnum = (size_t)method->method_idnum();
  2148. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  2149. + size_t length; // length assigned as debugging crumb
  2150. + jmethodID id = NULL;
  2151. + if (jmeths != NULL && // If there is a cache
  2152. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  2153. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  2154. + return true;
  2155. + }
  2156. +
  2157. + return false;
  2158. +}
  2159. +
  2160. // Cache an itable index
  2161. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  2162. @@ -1527,6 +1574,13 @@ void instanceKlass::remove_dependent_nmethod(nmethod* nm) {
  2163. last = b;
  2164. b = b->next();
  2165. }
  2166. +
  2167. + // (tw) Hack as dependencies get wrong version of klassOop
  2168. + if(this->old_version() != NULL) {
  2169. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  2170. + return;
  2171. + }
  2172. +
  2173. #ifdef ASSERT
  2174. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  2175. nm->print();
  2176. @@ -1922,16 +1976,6 @@ void instanceKlass::release_C_heap_structures() {
  2177. assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2178. }
  2179. - // deallocate information about previous versions
  2180. - if (_previous_versions != NULL) {
  2181. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2182. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2183. - delete pv_node;
  2184. - }
  2185. - delete _previous_versions;
  2186. - _previous_versions = NULL;
  2187. - }
  2188. -
  2189. // deallocate the cached class file
  2190. if (_cached_class_file_bytes != NULL) {
  2191. os::free(_cached_class_file_bytes, mtClass);
  2192. @@ -2545,275 +2589,10 @@ void instanceKlass::set_init_state(ClassState state) {
  2193. }
  2194. #endif
  2195. -
  2196. -// RedefineClasses() support for previous versions:
  2197. -
  2198. -// Add an information node that contains weak references to the
  2199. -// interesting parts of the previous version of the_class.
  2200. -// This is also where we clean out any unused weak references.
  2201. -// Note that while we delete nodes from the _previous_versions
  2202. -// array, we never delete the array itself until the klass is
  2203. -// unloaded. The has_been_redefined() query depends on that fact.
  2204. -//
  2205. -void instanceKlass::add_previous_version(instanceKlassHandle ikh,
  2206. - BitMap* emcp_methods, int emcp_method_count) {
  2207. - assert(Thread::current()->is_VM_thread(),
  2208. - "only VMThread can add previous versions");
  2209. -
  2210. - if (_previous_versions == NULL) {
  2211. - // This is the first previous version so make some space.
  2212. - // Start with 2 elements under the assumption that the class
  2213. - // won't be redefined much.
  2214. - _previous_versions = new (ResourceObj::C_HEAP, mtClass)
  2215. - GrowableArray<PreviousVersionNode *>(2, true);
  2216. - }
  2217. -
  2218. - // RC_TRACE macro has an embedded ResourceMark
  2219. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  2220. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  2221. - constantPoolHandle cp_h(ikh->constants());
  2222. - jobject cp_ref;
  2223. - if (cp_h->is_shared()) {
  2224. - // a shared ConstantPool requires a regular reference; a weak
  2225. - // reference would be collectible
  2226. - cp_ref = JNIHandles::make_global(cp_h);
  2227. - } else {
  2228. - cp_ref = JNIHandles::make_weak_global(cp_h);
  2229. - }
  2230. - PreviousVersionNode * pv_node = NULL;
  2231. - objArrayOop old_methods = ikh->methods();
  2232. -
  2233. - if (emcp_method_count == 0) {
  2234. - // non-shared ConstantPool gets a weak reference
  2235. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  2236. - RC_TRACE(0x00000400,
  2237. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  2238. - } else {
  2239. - int local_count = 0;
  2240. - GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass)
  2241. - GrowableArray<jweak>(emcp_method_count, true);
  2242. - for (int i = 0; i < old_methods->length(); i++) {
  2243. - if (emcp_methods->at(i)) {
  2244. - // this old method is EMCP so save a weak ref
  2245. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2246. - methodHandle old_method_h(old_method);
  2247. - jweak method_ref = JNIHandles::make_weak_global(old_method_h);
  2248. - method_refs->append(method_ref);
  2249. - if (++local_count >= emcp_method_count) {
  2250. - // no more EMCP methods so bail out now
  2251. - break;
  2252. - }
  2253. - }
  2254. - }
  2255. - // non-shared ConstantPool gets a weak reference
  2256. - pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs);
  2257. - }
  2258. -
  2259. - _previous_versions->append(pv_node);
  2260. -
  2261. - // Using weak references allows the interesting parts of previous
  2262. - // classes to be GC'ed when they are no longer needed. Since the
  2263. - // caller is the VMThread and we are at a safepoint, this is a good
  2264. - // time to clear out unused weak references.
  2265. -
  2266. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  2267. - _previous_versions->length()));
  2268. -
  2269. - // skip the last entry since we just added it
  2270. - for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  2271. - // check the previous versions array for a GC'ed weak refs
  2272. - pv_node = _previous_versions->at(i);
  2273. - cp_ref = pv_node->prev_constant_pool();
  2274. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2275. - if (cp_ref == NULL) {
  2276. - delete pv_node;
  2277. - _previous_versions->remove_at(i);
  2278. - // Since we are traversing the array backwards, we don't have to
  2279. - // do anything special with the index.
  2280. - continue; // robustness
  2281. - }
  2282. -
  2283. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2284. - if (cp == NULL) {
  2285. - // this entry has been GC'ed so remove it
  2286. - delete pv_node;
  2287. - _previous_versions->remove_at(i);
  2288. - // Since we are traversing the array backwards, we don't have to
  2289. - // do anything special with the index.
  2290. - continue;
  2291. - } else {
  2292. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  2293. - }
  2294. -
  2295. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2296. - if (method_refs != NULL) {
  2297. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  2298. - method_refs->length()));
  2299. - for (int j = method_refs->length() - 1; j >= 0; j--) {
  2300. - jweak method_ref = method_refs->at(j);
  2301. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2302. - if (method_ref == NULL) {
  2303. - method_refs->remove_at(j);
  2304. - // Since we are traversing the array backwards, we don't have to
  2305. - // do anything special with the index.
  2306. - continue; // robustness
  2307. - }
  2308. -
  2309. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2310. - if (method == NULL || emcp_method_count == 0) {
  2311. - // This method entry has been GC'ed or the current
  2312. - // RedefineClasses() call has made all methods obsolete
  2313. - // so remove it.
  2314. - JNIHandles::destroy_weak_global(method_ref);
  2315. - method_refs->remove_at(j);
  2316. - } else {
  2317. - // RC_TRACE macro has an embedded ResourceMark
  2318. - RC_TRACE(0x00000400,
  2319. - ("add: %s(%s): previous method @%d in version @%d is alive",
  2320. - method->name()->as_C_string(), method->signature()->as_C_string(),
  2321. - j, i));
  2322. - }
  2323. - }
  2324. - }
  2325. - }
  2326. -
  2327. - int obsolete_method_count = old_methods->length() - emcp_method_count;
  2328. -
  2329. - if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  2330. - _previous_versions->length() > 1) {
  2331. - // We have a mix of obsolete and EMCP methods. If there is more
  2332. - // than the previous version that we just added, then we have to
  2333. - // clear out any matching EMCP method entries the hard way.
  2334. - int local_count = 0;
  2335. - for (int i = 0; i < old_methods->length(); i++) {
  2336. - if (!emcp_methods->at(i)) {
  2337. - // only obsolete methods are interesting
  2338. - methodOop old_method = (methodOop) old_methods->obj_at(i);
  2339. - Symbol* m_name = old_method->name();
  2340. - Symbol* m_signature = old_method->signature();
  2341. -
  2342. - // skip the last entry since we just added it
  2343. - for (int j = _previous_versions->length() - 2; j >= 0; j--) {
  2344. - // check the previous versions array for a GC'ed weak refs
  2345. - pv_node = _previous_versions->at(j);
  2346. - cp_ref = pv_node->prev_constant_pool();
  2347. - assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  2348. - if (cp_ref == NULL) {
  2349. - delete pv_node;
  2350. - _previous_versions->remove_at(j);
  2351. - // Since we are traversing the array backwards, we don't have to
  2352. - // do anything special with the index.
  2353. - continue; // robustness
  2354. - }
  2355. -
  2356. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2357. - if (cp == NULL) {
  2358. - // this entry has been GC'ed so remove it
  2359. - delete pv_node;
  2360. - _previous_versions->remove_at(j);
  2361. - // Since we are traversing the array backwards, we don't have to
  2362. - // do anything special with the index.
  2363. - continue;
  2364. - }
  2365. -
  2366. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2367. - if (method_refs == NULL) {
  2368. - // We have run into a PreviousVersion generation where
  2369. - // all methods were made obsolete during that generation's
  2370. - // RedefineClasses() operation. At the time of that
  2371. - // operation, all EMCP methods were flushed so we don't
  2372. - // have to go back any further.
  2373. - //
  2374. - // A NULL method_refs is different than an empty method_refs.
  2375. - // We cannot infer any optimizations about older generations
  2376. - // from an empty method_refs for the current generation.
  2377. - break;
  2378. - }
  2379. -
  2380. - for (int k = method_refs->length() - 1; k >= 0; k--) {
  2381. - jweak method_ref = method_refs->at(k);
  2382. - assert(method_ref != NULL,
  2383. - "weak method ref was unexpectedly cleared");
  2384. - if (method_ref == NULL) {
  2385. - method_refs->remove_at(k);
  2386. - // Since we are traversing the array backwards, we don't
  2387. - // have to do anything special with the index.
  2388. - continue; // robustness
  2389. - }
  2390. -
  2391. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2392. - if (method == NULL) {
  2393. - // this method entry has been GC'ed so skip it
  2394. - JNIHandles::destroy_weak_global(method_ref);
  2395. - method_refs->remove_at(k);
  2396. - continue;
  2397. - }
  2398. -
  2399. - if (method->name() == m_name &&
  2400. - method->signature() == m_signature) {
  2401. - // The current RedefineClasses() call has made all EMCP
  2402. - // versions of this method obsolete so mark it as obsolete
  2403. - // and remove the weak ref.
  2404. - RC_TRACE(0x00000400,
  2405. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  2406. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  2407. -
  2408. - method->set_is_obsolete();
  2409. - JNIHandles::destroy_weak_global(method_ref);
  2410. - method_refs->remove_at(k);
  2411. - break;
  2412. - }
  2413. - }
  2414. -
  2415. - // The previous loop may not find a matching EMCP method, but
  2416. - // that doesn't mean that we can optimize and not go any
  2417. - // further back in the PreviousVersion generations. The EMCP
  2418. - // method for this generation could have already been GC'ed,
  2419. - // but there still may be an older EMCP method that has not
  2420. - // been GC'ed.
  2421. - }
  2422. -
  2423. - if (++local_count >= obsolete_method_count) {
  2424. - // no more obsolete methods so bail out now
  2425. - break;
  2426. - }
  2427. - }
  2428. - }
  2429. - }
  2430. -} // end add_previous_version()
  2431. -
  2432. -
  2433. // Determine if instanceKlass has a previous version.
  2434. bool instanceKlass::has_previous_version() const {
  2435. - if (_previous_versions == NULL) {
  2436. - // no previous versions array so answer is easy
  2437. - return false;
  2438. - }
  2439. -
  2440. - for (int i = _previous_versions->length() - 1; i >= 0; i--) {
  2441. - // Check the previous versions array for an info node that hasn't
  2442. - // been GC'ed
  2443. - PreviousVersionNode * pv_node = _previous_versions->at(i);
  2444. -
  2445. - jobject cp_ref = pv_node->prev_constant_pool();
  2446. - assert(cp_ref != NULL, "cp reference was unexpectedly cleared");
  2447. - if (cp_ref == NULL) {
  2448. - continue; // robustness
  2449. - }
  2450. -
  2451. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2452. - if (cp != NULL) {
  2453. - // we have at least one previous version
  2454. - return true;
  2455. - }
  2456. -
  2457. - // We don't have to check the method refs. If the constant pool has
  2458. - // been GC'ed then so have the methods.
  2459. - }
  2460. -
  2461. - // all of the underlying nodes' info has been GC'ed
  2462. - return false;
  2463. -} // end has_previous_version()
  2464. + return _old_version != NULL;
  2465. +}
  2466. methodOop instanceKlass::method_with_idnum(int idnum) {
  2467. methodOop m = NULL;
  2468. @@ -2854,153 +2633,3 @@ void instanceKlass::set_methods_annotations_of(int idnum, typeArrayOop anno, obj
  2469. } // if no array and idnum isn't included there is nothing to do
  2470. }
  2471. -// Construct a PreviousVersionNode entry for the array hung off
  2472. -// the instanceKlass.
  2473. -PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool,
  2474. - bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) {
  2475. -
  2476. - _prev_constant_pool = prev_constant_pool;
  2477. - _prev_cp_is_weak = prev_cp_is_weak;
  2478. - _prev_EMCP_methods = prev_EMCP_methods;
  2479. -}
  2480. -
  2481. -
  2482. -// Destroy a PreviousVersionNode
  2483. -PreviousVersionNode::~PreviousVersionNode() {
  2484. - if (_prev_constant_pool != NULL) {
  2485. - if (_prev_cp_is_weak) {
  2486. - JNIHandles::destroy_weak_global(_prev_constant_pool);
  2487. - } else {
  2488. - JNIHandles::destroy_global(_prev_constant_pool);
  2489. - }
  2490. - }
  2491. -
  2492. - if (_prev_EMCP_methods != NULL) {
  2493. - for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) {
  2494. - jweak method_ref = _prev_EMCP_methods->at(i);
  2495. - if (method_ref != NULL) {
  2496. - JNIHandles::destroy_weak_global(method_ref);
  2497. - }
  2498. - }
  2499. - delete _prev_EMCP_methods;
  2500. - }
  2501. -}
  2502. -
  2503. -
  2504. -// Construct a PreviousVersionInfo entry
  2505. -PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) {
  2506. - _prev_constant_pool_handle = constantPoolHandle(); // NULL handle
  2507. - _prev_EMCP_method_handles = NULL;
  2508. -
  2509. - jobject cp_ref = pv_node->prev_constant_pool();
  2510. - assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared");
  2511. - if (cp_ref == NULL) {
  2512. - return; // robustness
  2513. - }
  2514. -
  2515. - constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref);
  2516. - if (cp == NULL) {
  2517. - // Weak reference has been GC'ed. Since the constant pool has been
  2518. - // GC'ed, the methods have also been GC'ed.
  2519. - return;
  2520. - }
  2521. -
  2522. - // make the constantPoolOop safe to return
  2523. - _prev_constant_pool_handle = constantPoolHandle(cp);
  2524. -
  2525. - GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  2526. - if (method_refs == NULL) {
  2527. - // the instanceKlass did not have any EMCP methods
  2528. - return;
  2529. - }
  2530. -
  2531. - _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10);
  2532. -
  2533. - int n_methods = method_refs->length();
  2534. - for (int i = 0; i < n_methods; i++) {
  2535. - jweak method_ref = method_refs->at(i);
  2536. - assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  2537. - if (method_ref == NULL) {
  2538. - continue; // robustness
  2539. - }
  2540. -
  2541. - methodOop method = (methodOop)JNIHandles::resolve(method_ref);
  2542. - if (method == NULL) {
  2543. - // this entry has been GC'ed so skip it
  2544. - continue;
  2545. - }
  2546. -
  2547. - // make the methodOop safe to return
  2548. - _prev_EMCP_method_handles->append(methodHandle(method));
  2549. - }
  2550. -}
  2551. -
  2552. -
  2553. -// Destroy a PreviousVersionInfo
  2554. -PreviousVersionInfo::~PreviousVersionInfo() {
  2555. - // Since _prev_EMCP_method_handles is not C-heap allocated, we
  2556. - // don't have to delete it.
  2557. -}
  2558. -
  2559. -
  2560. -// Construct a helper for walking the previous versions array
  2561. -PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) {
  2562. - _previous_versions = ik->previous_versions();
  2563. - _current_index = 0;
  2564. - // _hm needs no initialization
  2565. - _current_p = NULL;
  2566. -}
  2567. -
  2568. -
  2569. -// Destroy a PreviousVersionWalker
  2570. -PreviousVersionWalker::~PreviousVersionWalker() {
  2571. - // Delete the current info just in case the caller didn't walk to
  2572. - // the end of the previous versions list. No harm if _current_p is
  2573. - // already NULL.
  2574. - delete _current_p;
  2575. -
  2576. - // When _hm is destroyed, all the Handles returned in
  2577. - // PreviousVersionInfo objects will be destroyed.
  2578. - // Also, after this destructor is finished it will be
  2579. - // safe to delete the GrowableArray allocated in the
  2580. - // PreviousVersionInfo objects.
  2581. -}
  2582. -
  2583. -
  2584. -// Return the interesting information for the next previous version
  2585. -// of the klass. Returns NULL if there are no more previous versions.
  2586. -PreviousVersionInfo* PreviousVersionWalker::next_previous_version() {
  2587. - if (_previous_versions == NULL) {
  2588. - // no previous versions so nothing to return
  2589. - return NULL;
  2590. - }
  2591. -
  2592. - delete _current_p; // cleanup the previous info for the caller
  2593. - _current_p = NULL; // reset to NULL so we don't delete same object twice
  2594. -
  2595. - int length = _previous_versions->length();
  2596. -
  2597. - while (_current_index < length) {
  2598. - PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
  2599. - PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass)
  2600. - PreviousVersionInfo(pv_node);
  2601. -
  2602. - constantPoolHandle cp_h = pv_info->prev_constant_pool_handle();
  2603. - if (cp_h.is_null()) {
  2604. - delete pv_info;
  2605. -
  2606. - // The underlying node's info has been GC'ed so try the next one.
  2607. - // We don't have to check the methods. If the constant pool has
  2608. - // GC'ed then so have the methods.
  2609. - continue;
  2610. - }
  2611. -
  2612. - // Found a node with non GC'ed info so return it. The caller will
  2613. - // need to delete pv_info when they are done with it.
  2614. - _current_p = pv_info;
  2615. - return pv_info;
  2616. - }
  2617. -
  2618. - // all of the underlying nodes' info has been GC'ed
  2619. - return NULL;
  2620. -} // end next_previous_version()
  2621. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  2622. index 8a849cb..53163b6 100644
  2623. --- a/src/share/vm/oops/instanceKlass.hpp
  2624. +++ b/src/share/vm/oops/instanceKlass.hpp
  2625. @@ -271,9 +271,6 @@ class instanceKlass: public Klass {
  2626. nmethodBucket* _dependencies; // list of dependent nmethods
  2627. nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
  2628. BreakpointInfo* _breakpoints; // bpt lists, managed by methodOop
  2629. - // Array of interesting part(s) of the previous version(s) of this
  2630. - // instanceKlass. See PreviousVersionWalker below.
  2631. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2632. // JVMTI fields can be moved to their own structure - see 6315920
  2633. unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH
  2634. jint _cached_class_file_len; // JVMTI: length of above
  2635. @@ -571,20 +568,11 @@ class instanceKlass: public Klass {
  2636. _nonstatic_oop_map_size = words;
  2637. }
  2638. - // RedefineClasses() support for previous versions:
  2639. - void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
  2640. - int emcp_method_count);
  2641. // If the _previous_versions array is non-NULL, then this klass
  2642. // has been redefined at least once even if we aren't currently
  2643. // tracking a previous version.
  2644. - bool has_been_redefined() const { return _previous_versions != NULL; }
  2645. + bool has_been_redefined() const { return _old_version != NULL; }
  2646. bool has_previous_version() const;
  2647. - void init_previous_versions() {
  2648. - _previous_versions = NULL;
  2649. - }
  2650. - GrowableArray<PreviousVersionNode *>* previous_versions() const {
  2651. - return _previous_versions;
  2652. - }
  2653. // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
  2654. void set_cached_class_file(unsigned char *class_file_bytes,
  2655. @@ -629,6 +617,7 @@ class instanceKlass: public Klass {
  2656. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  2657. size_t *length_p, jmethodID* id_p);
  2658. jmethodID jmethod_id_or_null(methodOop method);
  2659. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  2660. // cached itable index support
  2661. void set_cached_itable_index(size_t idnum, int index);
  2662. @@ -711,6 +700,7 @@ class instanceKlass: public Klass {
  2663. // subclass/subinterface checks
  2664. bool implements_interface(klassOop k) const;
  2665. + bool implements_interface_any_version(klassOop k) const;
  2666. // Access to the implementor of an interface.
  2667. klassOop implementor() const
  2668. @@ -760,6 +750,9 @@ class instanceKlass: public Klass {
  2669. void do_local_static_fields(FieldClosure* cl);
  2670. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  2671. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  2672. + void store_update_information(GrowableArray<int> &values);
  2673. + void clear_update_information();
  2674. +
  2675. void methods_do(void f(methodOop method));
  2676. void array_klasses_do(void f(klassOop k));
  2677. @@ -895,7 +888,6 @@ class instanceKlass: public Klass {
  2678. ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
  2679. #endif // !SERIALGC
  2680. -private:
  2681. // initialization state
  2682. #ifdef ASSERT
  2683. void set_init_state(ClassState state);
  2684. @@ -1057,106 +1049,6 @@ class JNIid: public CHeapObj<mtClass> {
  2685. void verify(klassOop holder);
  2686. };
  2687. -
  2688. -// If breakpoints are more numerous than just JVMTI breakpoints,
  2689. -// consider compressing this data structure.
  2690. -// It is currently a simple linked list defined in methodOop.hpp.
  2691. -
  2692. -class BreakpointInfo;
  2693. -
  2694. -
  2695. -// A collection point for interesting information about the previous
  2696. -// version(s) of an instanceKlass. This class uses weak references to
  2697. -// the information so that the information may be collected as needed
  2698. -// by the system. If the information is shared, then a regular
  2699. -// reference must be used because a weak reference would be seen as
  2700. -// collectible. A GrowableArray of PreviousVersionNodes is attached
  2701. -// to the instanceKlass as needed. See PreviousVersionWalker below.
  2702. -class PreviousVersionNode : public CHeapObj<mtClass> {
  2703. - private:
  2704. - // A shared ConstantPool is never collected so we'll always have
  2705. - // a reference to it so we can update items in the cache. We'll
  2706. - // have a weak reference to a non-shared ConstantPool until all
  2707. - // of the methods (EMCP or obsolete) have been collected; the
  2708. - // non-shared ConstantPool becomes collectible at that point.
  2709. - jobject _prev_constant_pool; // regular or weak reference
  2710. - bool _prev_cp_is_weak; // true if not a shared ConstantPool
  2711. -
  2712. - // If the previous version of the instanceKlass doesn't have any
  2713. - // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
  2714. - // EMCP methods have been collected, then _prev_EMCP_methods can
  2715. - // have a length of zero.
  2716. - GrowableArray<jweak>* _prev_EMCP_methods;
  2717. -
  2718. -public:
  2719. - PreviousVersionNode(jobject prev_constant_pool, bool prev_cp_is_weak,
  2720. - GrowableArray<jweak>* prev_EMCP_methods);
  2721. - ~PreviousVersionNode();
  2722. - jobject prev_constant_pool() const {
  2723. - return _prev_constant_pool;
  2724. - }
  2725. - GrowableArray<jweak>* prev_EMCP_methods() const {
  2726. - return _prev_EMCP_methods;
  2727. - }
  2728. -};
  2729. -
  2730. -
  2731. -// A Handle-ized version of PreviousVersionNode.
  2732. -class PreviousVersionInfo : public ResourceObj {
  2733. - private:
  2734. - constantPoolHandle _prev_constant_pool_handle;
  2735. - // If the previous version of the instanceKlass doesn't have any
  2736. - // EMCP methods, then _prev_EMCP_methods will be NULL. Since the
  2737. - // methods cannot be collected while we hold a handle,
  2738. - // _prev_EMCP_methods should never have a length of zero.
  2739. - GrowableArray<methodHandle>* _prev_EMCP_method_handles;
  2740. -
  2741. -public:
  2742. - PreviousVersionInfo(PreviousVersionNode *pv_node);
  2743. - ~PreviousVersionInfo();
  2744. - constantPoolHandle prev_constant_pool_handle() const {
  2745. - return _prev_constant_pool_handle;
  2746. - }
  2747. - GrowableArray<methodHandle>* prev_EMCP_method_handles() const {
  2748. - return _prev_EMCP_method_handles;
  2749. - }
  2750. -};
  2751. -
  2752. -
  2753. -// Helper object for walking previous versions. This helper cleans up
  2754. -// the Handles that it allocates when the helper object is destroyed.
  2755. -// The PreviousVersionInfo object returned by next_previous_version()
  2756. -// is only valid until a subsequent call to next_previous_version() or
  2757. -// the helper object is destroyed.
  2758. -class PreviousVersionWalker : public StackObj {
  2759. - private:
  2760. - GrowableArray<PreviousVersionNode *>* _previous_versions;
  2761. - int _current_index;
  2762. - // Fields for cleaning up when we are done walking the previous versions:
  2763. - // A HandleMark for the PreviousVersionInfo handles:
  2764. - HandleMark _hm;
  2765. -
  2766. - // It would be nice to have a ResourceMark field in this helper also,
  2767. - // but the ResourceMark code says to be careful to delete handles held
  2768. - // in GrowableArrays _before_ deleting the GrowableArray. Since we
  2769. - // can't guarantee the order in which the fields are destroyed, we
  2770. - // have to let the creator of the PreviousVersionWalker object do
  2771. - // the right thing. Also, adding a ResourceMark here causes an
  2772. - // include loop.
  2773. -
  2774. - // A pointer to the current info object so we can handle the deletes.
  2775. - PreviousVersionInfo * _current_p;
  2776. -
  2777. - public:
  2778. - PreviousVersionWalker(instanceKlass *ik);
  2779. - ~PreviousVersionWalker();
  2780. -
  2781. - // Return the interesting information for the next previous version
  2782. - // of the klass. Returns NULL if there are no more previous versions.
  2783. - PreviousVersionInfo* next_previous_version();
  2784. -};
  2785. -
  2786. -
  2787. //
  2788. // nmethodBucket is used to record dependent nmethods for
  2789. // deoptimization. nmethod dependencies are actually <klass, method>
  2790. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  2791. index 8e7dc12..5b9b266 100644
  2792. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  2793. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  2794. @@ -358,7 +358,7 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it
  2795. unsigned nonstatic_oop_map_count,
  2796. AccessFlags access_flags,
  2797. ReferenceType rt,
  2798. - KlassHandle host_klass, TRAPS) {
  2799. + KlassHandle host_klass, KlassHandle old_klass, TRAPS) {
  2800. const int nonstatic_oop_map_size =
  2801. instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count);
  2802. @@ -435,7 +435,6 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it
  2803. ik->set_jni_ids(NULL);
  2804. ik->set_osr_nmethods_head(NULL);
  2805. ik->set_breakpoints(NULL);
  2806. - ik->init_previous_versions();
  2807. ik->set_generic_signature(NULL);
  2808. ik->release_set_methods_jmethod_ids(NULL);
  2809. ik->release_set_methods_cached_itable_indices(NULL);
  2810. @@ -480,6 +479,28 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  2811. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  2812. klassKlass::oop_print_on(obj, st);
  2813. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  2814. +
  2815. + st->print(BULLET"revision: %d", ik->revision_number());
  2816. +
  2817. + if (ik->new_version() != NULL) {
  2818. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  2819. + }
  2820. +
  2821. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  2822. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  2823. + }
  2824. +
  2825. + if (ik->old_version() != NULL) {
  2826. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  2827. + }
  2828. +
  2829. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  2830. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  2831. + }
  2832. +
  2833. + st->cr();
  2834. +
  2835. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  2836. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  2837. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  2838. @@ -537,26 +558,6 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  2839. st->cr();
  2840. }
  2841. - {
  2842. - ResourceMark rm;
  2843. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  2844. - // contain a GrowableArray of handles. We have to clean up the
  2845. - // GrowableArray _after_ the PreviousVersionWalker destructor
  2846. - // has destroyed the handles.
  2847. - {
  2848. - bool have_pv = false;
  2849. - PreviousVersionWalker pvw(ik);
  2850. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  2851. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  2852. - if (!have_pv)
  2853. - st->print(BULLET"previous version: ");
  2854. - have_pv = true;
  2855. - pv_info->prev_constant_pool_handle()()->print_value_on(st);
  2856. - }
  2857. - if (have_pv) st->cr();
  2858. - } // pvw is cleaned up
  2859. - } // rm is cleaned up
  2860. -
  2861. if (ik->generic_signature() != NULL) {
  2862. st->print(BULLET"generic signature: ");
  2863. ik->generic_signature()->print_value_on(st);
  2864. @@ -663,7 +664,7 @@ void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
  2865. }
  2866. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  2867. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  2868. - guarantee(sib->super() == super, "siblings should have same superklass");
  2869. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  2870. sib = sib->next_sibling();
  2871. }
  2872. diff --git a/src/share/vm/oops/instanceKlassKlass.hpp b/src/share/vm/oops/instanceKlassKlass.hpp
  2873. index df674a9..45d0b66 100644
  2874. --- a/src/share/vm/oops/instanceKlassKlass.hpp
  2875. +++ b/src/share/vm/oops/instanceKlassKlass.hpp
  2876. @@ -50,6 +50,7 @@ class instanceKlassKlass : public klassKlass {
  2877. AccessFlags access_flags,
  2878. ReferenceType rt,
  2879. KlassHandle host_klass,
  2880. + KlassHandle old_klass,
  2881. TRAPS);
  2882. // Casting from klassOop
  2883. diff --git a/src/share/vm/oops/instanceMirrorKlass.cpp b/src/share/vm/oops/instanceMirrorKlass.cpp
  2884. index e0dd7d7..a7eec08 100644
  2885. --- a/src/share/vm/oops/instanceMirrorKlass.cpp
  2886. +++ b/src/share/vm/oops/instanceMirrorKlass.cpp
  2887. @@ -156,6 +156,13 @@ void instanceMirrorKlass::oop_follow_contents(oop obj) {
  2888. assert_is_in_closed_subset)
  2889. }
  2890. +void instanceMirrorKlass::oop_fields_iterate(oop obj, OopClosure* blk) {
  2891. + InstanceMirrorKlass_OOP_ITERATE( \
  2892. + start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
  2893. + blk->do_oop(p), \
  2894. + assert_is_in_closed_subset)
  2895. +}
  2896. +
  2897. #ifndef SERIALGC
  2898. void instanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm,
  2899. oop obj) {
  2900. diff --git a/src/share/vm/oops/instanceMirrorKlass.hpp b/src/share/vm/oops/instanceMirrorKlass.hpp
  2901. index 2b8b2f4..31969c7 100644
  2902. --- a/src/share/vm/oops/instanceMirrorKlass.hpp
  2903. +++ b/src/share/vm/oops/instanceMirrorKlass.hpp
  2904. @@ -79,6 +79,9 @@ class instanceMirrorKlass: public instanceKlass {
  2905. DEFINE_ALLOCATE_PERMANENT(instanceMirrorKlass);
  2906. instanceOop allocate_instance(KlassHandle k, TRAPS);
  2907. + // Class redefinition, iterate static fields
  2908. + static void oop_fields_iterate(oop obj, OopClosure* blk);
  2909. +
  2910. // Garbage collection
  2911. int oop_adjust_pointers(oop obj);
  2912. void oop_follow_contents(oop obj);
  2913. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  2914. index 7db4f03..1171487 100644
  2915. --- a/src/share/vm/oops/instanceRefKlass.cpp
  2916. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  2917. @@ -455,10 +455,13 @@ void instanceRefKlass::update_nonstatic_oop_maps(klassOop k) {
  2918. instanceKlass* ik = instanceKlass::cast(k);
  2919. // Check that we have the right class
  2920. - debug_only(static bool first_time = true);
  2921. - assert(k == SystemDictionary::Reference_klass() && first_time,
  2922. - "Invalid update of maps");
  2923. - debug_only(first_time = false);
  2924. +
  2925. + // (tw) Asserts no longer valid for class redefinition
  2926. + // debug_only(static bool first_time = true);
  2927. +
  2928. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  2929. + // "Invalid update of maps");
  2930. + //debug_only(first_time = false);
  2931. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  2932. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  2933. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  2934. index 596d5ad..a928777 100644
  2935. --- a/src/share/vm/oops/klass.cpp
  2936. +++ b/src/share/vm/oops/klass.cpp
  2937. @@ -161,6 +161,13 @@ klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
  2938. kl->set_alloc_size(0);
  2939. TRACE_INIT_ID(kl);
  2940. + kl->set_redefinition_flags(Klass::NoRedefinition);
  2941. + kl->set_redefining(false);
  2942. + kl->set_new_version(NULL);
  2943. + kl->set_old_version(NULL);
  2944. + kl->set_redefinition_index(-1);
  2945. + kl->set_revision_number(-1);
  2946. +
  2947. kl->set_prototype_header(markOopDesc::prototype());
  2948. kl->set_biased_lock_revocation_count(0);
  2949. kl->set_last_biased_lock_bulk_revocation_time(0);
  2950. @@ -232,7 +239,7 @@ void Klass::initialize_supers(klassOop k, TRAPS) {
  2951. set_super(NULL);
  2952. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  2953. assert(super_depth() == 0, "Object must already be initialized properly");
  2954. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  2955. + } else if (k != super() || k->klass_part()->super() == NULL) {
  2956. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  2957. "initialize this only once to a non-trivial value");
  2958. set_super(k);
  2959. @@ -385,7 +392,7 @@ void Klass::append_to_sibling_list() {
  2960. void Klass::remove_from_sibling_list() {
  2961. // remove receiver from sibling list
  2962. instanceKlass* super = superklass();
  2963. - assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
  2964. + assert(super != NULL || as_klassOop()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version(), "should have super");
  2965. if (super == NULL) return; // special case: class Object
  2966. if (super->subklass() == this) {
  2967. // first subklass
  2968. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  2969. index bcbd4e7..bf242d9 100644
  2970. --- a/src/share/vm/oops/klass.hpp
  2971. +++ b/src/share/vm/oops/klass.hpp
  2972. @@ -170,6 +170,7 @@ class Klass_vtbl {
  2973. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  2974. };
  2975. +template<class L, class R> class Pair;
  2976. class Klass : public Klass_vtbl {
  2977. friend class VMStructs;
  2978. @@ -222,6 +223,31 @@ class Klass : public Klass_vtbl {
  2979. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  2980. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  2981. + // (tw) Different class redefinition flags of code evolution.
  2982. + enum RedefinitionFlags {
  2983. +
  2984. + // This class is not redefined at all!
  2985. + NoRedefinition,
  2986. +
  2987. + // There are changes to the class meta data.
  2988. + ModifyClass = 1,
  2989. +
  2990. + // The size of the class meta data changes.
  2991. + ModifyClassSize = ModifyClass << 1,
  2992. +
  2993. + // There are change to the instance format.
  2994. + ModifyInstances = ModifyClassSize << 1,
  2995. +
  2996. + // The size of instances changes.
  2997. + ModifyInstanceSize = ModifyInstances << 1,
  2998. +
  2999. + // A super type of this class is removed.
  3000. + RemoveSuperType = ModifyInstanceSize << 1,
  3001. +
  3002. + // This class has been marked as an affected class.
  3003. + MarkedAsAffected = RemoveSuperType << 1
  3004. + };
  3005. +
  3006. protected:
  3007. //
  3008. // The oop block. All oop fields must be declared here and only oop fields
  3009. @@ -241,6 +267,10 @@ class Klass : public Klass_vtbl {
  3010. oop _java_mirror;
  3011. // Superclass
  3012. klassOop _super;
  3013. + // Old class
  3014. + klassOop _old_version;
  3015. + // New class
  3016. + klassOop _new_version;
  3017. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3018. klassOop _subklass;
  3019. // Sibling link (or NULL); links all subklasses of a klass
  3020. @@ -253,6 +283,16 @@ class Klass : public Klass_vtbl {
  3021. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3022. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3023. + // (tw) Non-oop fields for enhanced class redefinition
  3024. + jint _revision_number; // The revision number for redefined classes
  3025. + jint _redefinition_index; // Index of this class when performing the redefinition
  3026. + bool _subtype_changed;
  3027. + int _redefinition_flags; // Level of class redefinition
  3028. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3029. + bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
  3030. + int * _update_information; // Update information
  3031. + bool _is_redefining;
  3032. +
  3033. #ifndef PRODUCT
  3034. int _verify_count; // to avoid redundant verifies
  3035. #endif
  3036. @@ -301,6 +341,75 @@ class Klass : public Klass_vtbl {
  3037. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3038. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3039. + // BEGIN class redefinition utilities
  3040. +
  3041. + // double links between new and old version of a class
  3042. + klassOop old_version() const { return _old_version; }
  3043. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3044. + klassOop new_version() const { return _new_version; }
  3045. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3046. +
  3047. + // A subtype of this class is no longer a subtype
  3048. + bool has_subtype_changed() const { return _subtype_changed; }
  3049. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3050. + _subtype_changed = b; }
  3051. + // state of being redefined
  3052. + int redefinition_index() const { return _redefinition_index; }
  3053. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3054. + void set_redefining(bool b) { _is_redefining = b; }
  3055. + bool is_redefining() const { return _is_redefining; }
  3056. + int redefinition_flags() const { return _redefinition_flags; }
  3057. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3058. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3059. + void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
  3060. + void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
  3061. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3062. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3063. +
  3064. + // update information
  3065. + int *update_information() const { return _update_information; }
  3066. + void set_update_information(int *info) { _update_information = info; }
  3067. +
  3068. + bool is_same_or_older_version(klassOop klass) const {
  3069. + if (Klass::cast(klass) == this) { return true; }
  3070. + else if (_old_version == NULL) { return false; }
  3071. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3072. + }
  3073. +
  3074. + // Revision number for redefined classes, -1 for originally loaded classes
  3075. + jint revision_number() const {
  3076. + return _revision_number;
  3077. + }
  3078. +
  3079. + bool was_redefined() const {
  3080. + return _revision_number != -1;
  3081. + }
  3082. +
  3083. + void set_revision_number(jint number) {
  3084. + _revision_number = number;
  3085. + }
  3086. +
  3087. + klassOop oldest_version() const {
  3088. + if (_old_version == NULL) { return this->as_klassOop(); }
  3089. + else { return _old_version->klass_part()->oldest_version(); };
  3090. + }
  3091. +
  3092. + klassOop newest_version() const {
  3093. + if (_new_version == NULL) { return this->as_klassOop(); }
  3094. + else { return _new_version->klass_part()->newest_version(); };
  3095. + }
  3096. +
  3097. + klassOop active_version() const {
  3098. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3099. + else { return _new_version->klass_part()->active_version(); };
  3100. + }
  3101. +
  3102. + bool is_newest_version() const {
  3103. + return _new_version == NULL;
  3104. + }
  3105. +
  3106. + // END class redefinition utilities
  3107. +
  3108. objArrayOop secondary_supers() const { return _secondary_supers; }
  3109. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3110. @@ -361,6 +470,8 @@ class Klass : public Klass_vtbl {
  3111. void set_next_sibling(klassOop s);
  3112. oop* adr_super() const { return (oop*)&_super; }
  3113. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3114. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3115. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3116. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3117. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3118. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3119. index 06809d5..1050eda 100644
  3120. --- a/src/share/vm/oops/klassKlass.cpp
  3121. +++ b/src/share/vm/oops/klassKlass.cpp
  3122. @@ -68,6 +68,8 @@ void klassKlass::oop_follow_contents(oop obj) {
  3123. Klass* k = Klass::cast(klassOop(obj));
  3124. // If we are alive it is valid to keep our superclass and subtype caches alive
  3125. MarkSweep::mark_and_push(k->adr_super());
  3126. + MarkSweep::mark_and_push(k->adr_old_version());
  3127. + MarkSweep::mark_and_push(k->adr_new_version());
  3128. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3129. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3130. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3131. @@ -87,6 +89,8 @@ void klassKlass::oop_follow_contents(ParCompactionManager* cm,
  3132. Klass* k = Klass::cast(klassOop(obj));
  3133. // If we are alive it is valid to keep our superclass and subtype caches alive
  3134. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3135. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3136. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3137. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3138. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3139. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3140. @@ -106,6 +110,8 @@ int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  3141. int size = oop_size(obj);
  3142. Klass* k = Klass::cast(klassOop(obj));
  3143. blk->do_oop(k->adr_super());
  3144. + blk->do_oop(k->adr_old_version());
  3145. + blk->do_oop(k->adr_new_version());
  3146. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3147. blk->do_oop(k->adr_primary_supers()+i);
  3148. blk->do_oop(k->adr_secondary_super_cache());
  3149. @@ -134,6 +140,10 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  3150. oop* adr;
  3151. adr = k->adr_super();
  3152. if (mr.contains(adr)) blk->do_oop(adr);
  3153. + adr = k->adr_old_version();
  3154. + if (mr.contains(adr)) blk->do_oop(adr);
  3155. + adr = k->adr_new_version();
  3156. + if (mr.contains(adr)) blk->do_oop(adr);
  3157. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3158. adr = k->adr_primary_supers()+i;
  3159. if (mr.contains(adr)) blk->do_oop(adr);
  3160. @@ -167,6 +177,8 @@ int klassKlass::oop_adjust_pointers(oop obj) {
  3161. Klass* k = Klass::cast(klassOop(obj));
  3162. MarkSweep::adjust_pointer(k->adr_super());
  3163. + MarkSweep::adjust_pointer(k->adr_new_version());
  3164. + MarkSweep::adjust_pointer(k->adr_old_version());
  3165. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3166. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3167. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3168. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  3169. index 94e2e04..a683a4b 100644
  3170. --- a/src/share/vm/oops/klassVtable.cpp
  3171. +++ b/src/share/vm/oops/klassVtable.cpp
  3172. @@ -628,17 +628,13 @@ void klassVtable::adjust_method_entries(methodOop* old_methods, methodOop* new_m
  3173. if (unchecked_method_at(index) == old_method) {
  3174. put_method_at(new_method, index);
  3175. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3176. + IF_TRACE_RC4 {
  3177. if (!(*trace_name_printed)) {
  3178. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3179. - RC_TRACE_MESG(("adjust: name=%s",
  3180. - Klass::cast(old_method->method_holder())->external_name()));
  3181. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3182. *trace_name_printed = true;
  3183. }
  3184. - // RC_TRACE macro has an embedded ResourceMark
  3185. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  3186. - new_method->name()->as_C_string(),
  3187. - new_method->signature()->as_C_string()));
  3188. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  3189. + new_method->signature()->as_C_string());
  3190. }
  3191. // cannot 'break' here; see for-loop comment above.
  3192. }
  3193. @@ -1008,17 +1004,13 @@ void klassItable::adjust_method_entries(methodOop* old_methods, methodOop* new_m
  3194. if (ime->method() == old_method) {
  3195. ime->initialize(new_method);
  3196. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3197. + IF_TRACE_RC4 {
  3198. if (!(*trace_name_printed)) {
  3199. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3200. - RC_TRACE_MESG(("adjust: name=%s",
  3201. - Klass::cast(old_method->method_holder())->external_name()));
  3202. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3203. *trace_name_printed = true;
  3204. }
  3205. - // RC_TRACE macro has an embedded ResourceMark
  3206. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  3207. - new_method->name()->as_C_string(),
  3208. - new_method->signature()->as_C_string()));
  3209. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  3210. + new_method->signature()->as_C_string());
  3211. }
  3212. // cannot 'break' here; see for-loop comment above.
  3213. }
  3214. @@ -1241,6 +1233,7 @@ void klassVtable::verify(outputStream* st, bool forced) {
  3215. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  3216. vtableEntry* vte = &vt->table()[index];
  3217. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  3218. if (vte->method()->name() != table()[index].method()->name() ||
  3219. vte->method()->signature() != table()[index].method()->signature()) {
  3220. fatal("mismatched name/signature of vtable entries");
  3221. @@ -1260,6 +1253,8 @@ void klassVtable::print() {
  3222. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3223. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  3224. + // (tw) TODO: Check: Does not hold?
  3225. + if (method() != NULL) {
  3226. assert(method() != NULL, "must have set method");
  3227. method()->verify();
  3228. // we sub_type, because it could be a miranda method
  3229. @@ -1267,7 +1262,13 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3230. #ifndef PRODUCT
  3231. print();
  3232. #endif
  3233. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  3234. + klassOop first_klass = vt->klass()();
  3235. + klassOop second_klass = method()->method_holder();
  3236. + // (tw) the following fatal does not work for old versions of classes
  3237. + if (first_klass->klass_part()->is_newest_version()) {
  3238. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  3239. + }
  3240. + }
  3241. }
  3242. }
  3243. @@ -1275,8 +1276,8 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3244. void vtableEntry::print() {
  3245. ResourceMark rm;
  3246. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  3247. if (Verbose) {
  3248. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  3249. tty->print("m %#lx ", (address)method());
  3250. }
  3251. }
  3252. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  3253. index 75d0b09..c4be146 100644
  3254. --- a/src/share/vm/oops/methodKlass.cpp
  3255. +++ b/src/share/vm/oops/methodKlass.cpp
  3256. @@ -93,6 +93,9 @@ methodOop methodKlass::allocate(constMethodHandle xconst,
  3257. m->set_adapter_entry(NULL);
  3258. m->clear_code(); // from_c/from_i get set to c2i/i2i
  3259. + m->set_new_version(NULL);
  3260. + m->set_old_version(NULL);
  3261. +
  3262. if (access_flags.is_native()) {
  3263. m->clear_native_function();
  3264. m->set_signature_handler(NULL);
  3265. @@ -122,6 +125,8 @@ void methodKlass::oop_follow_contents(oop obj) {
  3266. // Performance tweak: We skip iterating over the klass pointer since we
  3267. // know that Universe::methodKlassObj never moves.
  3268. MarkSweep::mark_and_push(m->adr_constMethod());
  3269. + MarkSweep::mark_and_push(m->adr_new_version());
  3270. + MarkSweep::mark_and_push(m->adr_old_version());
  3271. if (m->method_data() != NULL) {
  3272. MarkSweep::mark_and_push(m->adr_method_data());
  3273. }
  3274. @@ -135,6 +140,8 @@ void methodKlass::oop_follow_contents(ParCompactionManager* cm,
  3275. // Performance tweak: We skip iterating over the klass pointer since we
  3276. // know that Universe::methodKlassObj never moves.
  3277. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  3278. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  3279. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  3280. #ifdef COMPILER2
  3281. if (m->method_data() != NULL) {
  3282. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  3283. @@ -152,6 +159,8 @@ int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  3284. // Performance tweak: We skip iterating over the klass pointer since we
  3285. // know that Universe::methodKlassObj never moves
  3286. blk->do_oop(m->adr_constMethod());
  3287. + blk->do_oop(m->adr_new_version());
  3288. + blk->do_oop(m->adr_old_version());
  3289. if (m->method_data() != NULL) {
  3290. blk->do_oop(m->adr_method_data());
  3291. }
  3292. @@ -170,6 +179,10 @@ int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  3293. oop* adr;
  3294. adr = m->adr_constMethod();
  3295. if (mr.contains(adr)) blk->do_oop(adr);
  3296. + adr = m->adr_new_version();
  3297. + if (mr.contains(adr)) blk->do_oop(adr);
  3298. + adr = m->adr_old_version();
  3299. + if (mr.contains(adr)) blk->do_oop(adr);
  3300. if (m->method_data() != NULL) {
  3301. adr = m->adr_method_data();
  3302. if (mr.contains(adr)) blk->do_oop(adr);
  3303. @@ -187,6 +200,8 @@ int methodKlass::oop_adjust_pointers(oop obj) {
  3304. // Performance tweak: We skip iterating over the klass pointer since we
  3305. // know that Universe::methodKlassObj never moves.
  3306. MarkSweep::adjust_pointer(m->adr_constMethod());
  3307. + MarkSweep::adjust_pointer(m->adr_new_version());
  3308. + MarkSweep::adjust_pointer(m->adr_old_version());
  3309. if (m->method_data() != NULL) {
  3310. MarkSweep::adjust_pointer(m->adr_method_data());
  3311. }
  3312. @@ -202,6 +217,8 @@ int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
  3313. assert(obj->is_method(), "should be method");
  3314. methodOop m = methodOop(obj);
  3315. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  3316. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  3317. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  3318. #ifdef COMPILER2
  3319. if (m->method_data() != NULL) {
  3320. PSParallelCompact::adjust_pointer(m->adr_method_data());
  3321. @@ -222,7 +239,18 @@ void methodKlass::oop_print_on(oop obj, outputStream* st) {
  3322. methodOop m = methodOop(obj);
  3323. // get the effect of PrintOopAddress, always, for methods:
  3324. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  3325. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  3326. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  3327. +
  3328. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  3329. + st->print(" (old)");
  3330. + }
  3331. + st->cr();
  3332. +
  3333. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  3334. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  3335. + st->print_cr(" - new version: "INTPTR_FORMAT, (address)m->new_version());
  3336. + st->print_cr(" - old version: "INTPTR_FORMAT, (address)m->old_version());
  3337. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  3338. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  3339. m->constants()->print_value_on(st); st->cr();
  3340. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  3341. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  3342. index 4f59d3a..32cb4cf 100644
  3343. --- a/src/share/vm/oops/methodOop.cpp
  3344. +++ b/src/share/vm/oops/methodOop.cpp
  3345. @@ -1061,6 +1061,8 @@ methodHandle methodOopDesc::clone_with_new_data(methodHandle m, u_char* new_code
  3346. // Reset correct method/const method, method size, and parameter info
  3347. newm->set_constMethod(newcm);
  3348. + newm->set_new_version(newm->new_version());
  3349. + newm->set_old_version(newm->old_version());
  3350. newm->constMethod()->set_code_size(new_code_length);
  3351. newm->constMethod()->set_constMethod_size(new_const_method_size);
  3352. newm->set_method_size(new_method_size);
  3353. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  3354. index 486e106..e35d5ed 100644
  3355. --- a/src/share/vm/oops/methodOop.hpp
  3356. +++ b/src/share/vm/oops/methodOop.hpp
  3357. @@ -114,6 +114,10 @@ class methodOopDesc : public oopDesc {
  3358. AccessFlags _access_flags; // Access flags
  3359. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  3360. // note: can have vtables with >2**16 elements (because of inheritance)
  3361. + // (tw) Newer version of method available?
  3362. + methodOop _new_version;
  3363. + methodOop _old_version;
  3364. +
  3365. #ifdef CC_INTERP
  3366. int _result_index; // C++ interpreter needs for converting results to/from stack
  3367. #endif
  3368. @@ -175,6 +179,29 @@ class methodOopDesc : public oopDesc {
  3369. int name_index() const { return constMethod()->name_index(); }
  3370. void set_name_index(int index) { constMethod()->set_name_index(index); }
  3371. + methodOop new_version() const {return _new_version; }
  3372. + void set_new_version(methodOop m) { _new_version = m; }
  3373. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  3374. +
  3375. + methodOop old_version() const {return _old_version; };
  3376. + void set_old_version(methodOop m) {
  3377. + if (m == NULL) {
  3378. + _old_version = NULL;
  3379. + return;
  3380. + }
  3381. +
  3382. + assert(_old_version == NULL, "may only be set once");
  3383. + assert(this->code_size() == m->code_size(), "must have same code length");
  3384. + _old_version = m;
  3385. + }
  3386. +
  3387. + methodOop oldest_version() const {
  3388. + if(_old_version == NULL) return (methodOop)this;
  3389. + else {
  3390. + return old_version()->oldest_version();
  3391. + }
  3392. + }
  3393. +
  3394. // signature
  3395. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  3396. int signature_index() const { return constMethod()->signature_index(); }
  3397. @@ -734,6 +761,8 @@ class methodOopDesc : public oopDesc {
  3398. // Garbage collection support
  3399. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  3400. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3401. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3402. oop* adr_method_data() const { return (oop*)&_method_data; }
  3403. };
  3404. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  3405. index 5982c88..4873fca 100644
  3406. --- a/src/share/vm/oops/oop.hpp
  3407. +++ b/src/share/vm/oops/oop.hpp
  3408. @@ -95,6 +95,7 @@ class oopDesc {
  3409. narrowOop* compressed_klass_addr();
  3410. void set_klass(klassOop k);
  3411. + void set_klass_no_check(klassOop k);
  3412. // For klass field compression
  3413. int klass_gap() const;
  3414. @@ -135,6 +136,7 @@ class oopDesc {
  3415. bool is_array() const;
  3416. bool is_objArray() const;
  3417. bool is_klass() const;
  3418. + bool is_instanceKlass() const;
  3419. bool is_thread() const;
  3420. bool is_method() const;
  3421. bool is_constMethod() const;
  3422. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  3423. index f4eb2f7..0acb346 100644
  3424. --- a/src/share/vm/oops/oop.inline.hpp
  3425. +++ b/src/share/vm/oops/oop.inline.hpp
  3426. @@ -123,6 +123,14 @@ inline void oopDesc::set_klass(klassOop k) {
  3427. }
  3428. }
  3429. +inline void oopDesc::set_klass_no_check(klassOop k) {
  3430. + if (UseCompressedOops) {
  3431. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  3432. + } else {
  3433. + oop_store_without_check(klass_addr(), (oop) k);
  3434. + }
  3435. +}
  3436. +
  3437. inline int oopDesc::klass_gap() const {
  3438. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  3439. }
  3440. @@ -156,6 +164,7 @@ inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_
  3441. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  3442. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  3443. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  3444. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  3445. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  3446. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  3447. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  3448. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  3449. index 2123991..6cbd78c 100644
  3450. --- a/src/share/vm/prims/jni.cpp
  3451. +++ b/src/share/vm/prims/jni.cpp
  3452. @@ -406,7 +406,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
  3453. }
  3454. }
  3455. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3456. - Handle(), &st, true,
  3457. + Handle(), &st, true, KlassHandle(),
  3458. CHECK_NULL);
  3459. if (TraceClassResolution && k != NULL) {
  3460. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  3461. index 7dcd968..d59052f 100644
  3462. --- a/src/share/vm/prims/jvm.cpp
  3463. +++ b/src/share/vm/prims/jvm.cpp
  3464. @@ -872,7 +872,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
  3465. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  3466. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  3467. protection_domain, &st,
  3468. - verify != 0,
  3469. + verify != 0, KlassHandle(),
  3470. CHECK_NULL);
  3471. if (TraceClassResolution && k != NULL) {
  3472. diff --git a/src/share/vm/prims/jvm_misc.hpp b/src/share/vm/prims/jvm_misc.hpp
  3473. index 2b46e36..549e949 100644
  3474. --- a/src/share/vm/prims/jvm_misc.hpp
  3475. +++ b/src/share/vm/prims/jvm_misc.hpp
  3476. @@ -84,6 +84,7 @@ extern "C" {
  3477. (JNIEnv *env, jobject obj, jfieldID fieldID);
  3478. }
  3479. +// TODO(tw): Check if we need to "unquicken" because of class redefinition.
  3480. void quicken_jni_functions();
  3481. address jni_GetBooleanField_addr();
  3482. address jni_GetByteField_addr();
  3483. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  3484. index 4ac6b82..30b8e84 100644
  3485. --- a/src/share/vm/prims/jvmtiEnv.cpp
  3486. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  3487. @@ -290,7 +290,10 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  3488. class_definitions[index].klass = jcls;
  3489. }
  3490. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  3491. - VMThread::execute(&op);
  3492. + {
  3493. + MutexLocker sd_mutex(RedefineClasses_lock);
  3494. + VMThread::execute(&op);
  3495. + }
  3496. return (op.check_error());
  3497. } /* end RetransformClasses */
  3498. @@ -299,9 +302,12 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  3499. // class_definitions - pre-checked for NULL
  3500. jvmtiError
  3501. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  3502. -//TODO: add locking
  3503. +
  3504. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  3505. - VMThread::execute(&op);
  3506. + {
  3507. + MutexLocker sd_mutex(RedefineClasses_lock);
  3508. + VMThread::execute(&op);
  3509. + }
  3510. return (op.check_error());
  3511. } /* end RedefineClasses */
  3512. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  3513. index ec8ede3..2bd5983 100644
  3514. --- a/src/share/vm/prims/jvmtiExport.cpp
  3515. +++ b/src/share/vm/prims/jvmtiExport.cpp
  3516. @@ -2296,7 +2296,7 @@ JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(N
  3517. // iterate over any code blob descriptors collected and post a
  3518. // DYNAMIC_CODE_GENERATED event to the profiler.
  3519. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  3520. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  3521. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  3522. // iterate over any code blob descriptors that we collected
  3523. if (_code_blobs != NULL) {
  3524. for (int i=0; i<_code_blobs->length(); i++) {
  3525. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  3526. index d3fa140..31a8a19 100644
  3527. --- a/src/share/vm/prims/jvmtiImpl.cpp
  3528. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  3529. @@ -284,60 +284,11 @@ address JvmtiBreakpoint::getBcp() {
  3530. }
  3531. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  3532. - ((methodOopDesc*)_method->*meth_act)(_bci);
  3533. -
  3534. - // add/remove breakpoint to/from versions of the method that
  3535. - // are EMCP. Directly or transitively obsolete methods are
  3536. - // not saved in the PreviousVersionInfo.
  3537. - Thread *thread = Thread::current();
  3538. - instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder());
  3539. - Symbol* m_name = _method->name();
  3540. - Symbol* m_signature = _method->signature();
  3541. -
  3542. - {
  3543. - ResourceMark rm(thread);
  3544. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  3545. - // contain a GrowableArray of handles. We have to clean up the
  3546. - // GrowableArray _after_ the PreviousVersionWalker destructor
  3547. - // has destroyed the handles.
  3548. - {
  3549. - // search previous versions if they exist
  3550. - PreviousVersionWalker pvw((instanceKlass *)ikh()->klass_part());
  3551. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  3552. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  3553. - GrowableArray<methodHandle>* methods =
  3554. - pv_info->prev_EMCP_method_handles();
  3555. -
  3556. - if (methods == NULL) {
  3557. - // We have run into a PreviousVersion generation where
  3558. - // all methods were made obsolete during that generation's
  3559. - // RedefineClasses() operation. At the time of that
  3560. - // operation, all EMCP methods were flushed so we don't
  3561. - // have to go back any further.
  3562. - //
  3563. - // A NULL methods array is different than an empty methods
  3564. - // array. We cannot infer any optimizations about older
  3565. - // generations from an empty methods array for the current
  3566. - // generation.
  3567. - break;
  3568. - }
  3569. -
  3570. - for (int i = methods->length() - 1; i >= 0; i--) {
  3571. - methodHandle method = methods->at(i);
  3572. - if (method->name() == m_name && method->signature() == m_signature) {
  3573. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  3574. - meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  3575. - method->name()->as_C_string(),
  3576. - method->signature()->as_C_string()));
  3577. - assert(!method->is_obsolete(), "only EMCP methods here");
  3578. -
  3579. - ((methodOopDesc*)method()->*meth_act)(_bci);
  3580. - break;
  3581. - }
  3582. - }
  3583. - }
  3584. - } // pvw is cleaned up
  3585. - } // rm is cleaned up
  3586. + methodOop method = _method;
  3587. + while (method != NULL) {
  3588. + ((methodOopDesc*)method->*meth_act)(_bci);
  3589. + method = method->old_version();
  3590. + }
  3591. }
  3592. void JvmtiBreakpoint::set() {
  3593. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3594. index eb52388..432e15a 100644
  3595. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3596. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  3597. @@ -1,5 +1,5 @@
  3598. /*
  3599. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  3600. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  3601. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3602. *
  3603. * This code is free software; you can redistribute it and/or modify it
  3604. @@ -38,490 +38,669 @@
  3605. #include "runtime/deoptimization.hpp"
  3606. #include "runtime/relocator.hpp"
  3607. #include "utilities/bitMap.inline.hpp"
  3608. +#include "prims/jvmtiClassFileReconstituter.hpp"
  3609. +#include "compiler/compileBroker.hpp"
  3610. +#include "oops/instanceMirrorKlass.hpp"
  3611. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  3612. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  3613. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  3614. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  3615. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  3616. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  3617. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  3618. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  3619. +int* VM_RedefineClasses::_deleted_methods = NULL;
  3620. +int* VM_RedefineClasses::_added_methods = NULL;
  3621. int VM_RedefineClasses::_matching_methods_length = 0;
  3622. int VM_RedefineClasses::_deleted_methods_length = 0;
  3623. int VM_RedefineClasses::_added_methods_length = 0;
  3624. -klassOop VM_RedefineClasses::_the_class_oop = NULL;
  3625. +GrowableArray<instanceKlassHandle>* VM_RedefineClasses::_affected_klasses = NULL;
  3626. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  3627. - const jvmtiClassDefinition *class_defs,
  3628. - JvmtiClassLoadKind class_load_kind) {
  3629. +// Holds the revision number of the current class redefinition
  3630. +int VM_RedefineClasses::_revision_number = -1;
  3631. +
  3632. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  3633. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
  3634. + RC_TIMER_START(_timer_total);
  3635. _class_count = class_count;
  3636. _class_defs = class_defs;
  3637. _class_load_kind = class_load_kind;
  3638. - _res = JVMTI_ERROR_NONE;
  3639. + _result = JVMTI_ERROR_NONE;
  3640. }
  3641. -bool VM_RedefineClasses::doit_prologue() {
  3642. - if (_class_count == 0) {
  3643. - _res = JVMTI_ERROR_NONE;
  3644. - return false;
  3645. +VM_RedefineClasses::~VM_RedefineClasses() {
  3646. + unlock_threads();
  3647. + RC_TIMER_STOP(_timer_total);
  3648. +
  3649. + if (TimeRedefineClasses) {
  3650. + tty->print_cr("");
  3651. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  3652. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  3653. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  3654. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  3655. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  3656. + tty->print_cr("Timing Heap Iteration: %d", _timer_heap_iteration.milliseconds());
  3657. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  3658. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  3659. + tty->print_cr("------------------------------------------------------------------");
  3660. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  3661. + tty->print_cr("");
  3662. }
  3663. - if (_class_defs == NULL) {
  3664. - _res = JVMTI_ERROR_NULL_POINTER;
  3665. - return false;
  3666. +}
  3667. +
  3668. +void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  3669. + typeArrayOop save;
  3670. +
  3671. + save = scratch_class->get_method_annotations_of(i);
  3672. + scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  3673. + scratch_class->set_method_annotations_of(j, save);
  3674. +
  3675. + save = scratch_class->get_method_parameter_annotations_of(i);
  3676. + scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  3677. + scratch_class->set_method_parameter_annotations_of(j, save);
  3678. +
  3679. + save = scratch_class->get_method_default_annotations_of(i);
  3680. + scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  3681. + scratch_class->set_method_default_annotations_of(j, save);
  3682. +}
  3683. +
  3684. +void VM_RedefineClasses::add_affected_klasses( klassOop klass )
  3685. +{
  3686. + assert(!_affected_klasses->contains(klass), "must not occur more than once!");
  3687. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  3688. +
  3689. + Klass* k = klass->klass_part();
  3690. +
  3691. + if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3692. + _affected_klasses->append(klass);
  3693. + return;
  3694. }
  3695. - for (int i = 0; i < _class_count; i++) {
  3696. - if (_class_defs[i].klass == NULL) {
  3697. - _res = JVMTI_ERROR_INVALID_CLASS;
  3698. - return false;
  3699. - }
  3700. - if (_class_defs[i].class_byte_count == 0) {
  3701. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3702. - return false;
  3703. +
  3704. + for (juint i = 0; i < k->super_depth(); i++) {
  3705. + klassOop primary_oop = k->primary_super_of_depth(i);
  3706. + // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
  3707. + if (primary_oop == NULL) break;
  3708. + Klass* primary = Klass::cast(primary_oop);
  3709. + if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3710. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  3711. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  3712. + _affected_klasses->append(klass);
  3713. + return;
  3714. }
  3715. - if (_class_defs[i].class_bytes == NULL) {
  3716. - _res = JVMTI_ERROR_NULL_POINTER;
  3717. - return false;
  3718. + }
  3719. +
  3720. + // Check secondary supers
  3721. + int cnt = k->secondary_supers()->length();
  3722. + for (int i = 0; i < cnt; i++) {
  3723. + Klass* secondary = Klass::cast((klassOop) k->secondary_supers()->obj_at(i));
  3724. + if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3725. + TRACE_RC3("Found affected class: %s", k->name()->as_C_string());
  3726. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  3727. + _affected_klasses->append(klass);
  3728. + return;
  3729. }
  3730. }
  3731. +}
  3732. - // Start timer after all the sanity checks; not quite accurate, but
  3733. - // better than adding a bunch of stop() calls.
  3734. - RC_TIMER_START(_timer_vm_op_prologue);
  3735. - // We first load new class versions in the prologue, because somewhere down the
  3736. - // call chain it is required that the current thread is a Java thread.
  3737. - _res = load_new_class_versions(Thread::current());
  3738. - if (_res != JVMTI_ERROR_NONE) {
  3739. - // Free os::malloc allocated memory in load_new_class_version.
  3740. - os::free(_scratch_classes);
  3741. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3742. - return false;
  3743. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  3744. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes() {
  3745. +
  3746. + assert(_affected_klasses, "");
  3747. + for (int i = 0; i < _class_count; i++) {
  3748. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  3749. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  3750. + klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
  3751. + assert(klass_handle->new_version() == NULL, "Must be new class");
  3752. }
  3753. - RC_TIMER_STOP(_timer_vm_op_prologue);
  3754. - return true;
  3755. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  3756. + SystemDictionary::classes_do(VM_RedefineClasses::add_affected_klasses);
  3757. + TRACE_RC1("%d classes affected", _affected_klasses->length());
  3758. +
  3759. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  3760. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
  3761. + IF_TRACE_RC2 {
  3762. + TRACE_RC2("Redefine order: ");
  3763. + for (int i = 0; i < _affected_klasses->length(); i++) {
  3764. + TRACE_RC2("%s", _affected_klasses->at(i)->name()->as_C_string());
  3765. + }
  3766. + }
  3767. +
  3768. + return result;
  3769. }
  3770. -void VM_RedefineClasses::doit() {
  3771. - Thread *thread = Thread::current();
  3772. +// Searches for the class bytes of the given class and returns them as a byte array.
  3773. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  3774. - if (UseSharedSpaces) {
  3775. - // Sharing is enabled so we remap the shared readonly space to
  3776. - // shared readwrite, private just in case we need to redefine
  3777. - // a shared class. We do the remap during the doit() phase of
  3778. - // the safepoint to be safer.
  3779. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  3780. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  3781. - ("failed to remap shared readonly space to readwrite, private"));
  3782. - _res = JVMTI_ERROR_INTERNAL;
  3783. - return;
  3784. + *not_changed = false;
  3785. +
  3786. + // Search for the index in the redefinition array that corresponds to the current class
  3787. + int j;
  3788. + for (j=0; j<_class_count; j++) {
  3789. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  3790. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  3791. + if (the_class_oop == the_class()) {
  3792. + break;
  3793. }
  3794. }
  3795. - for (int i = 0; i < _class_count; i++) {
  3796. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  3797. - }
  3798. - // Disable any dependent concurrent compilations
  3799. - SystemDictionary::notice_modification();
  3800. + if (j == _class_count) {
  3801. - // Set flag indicating that some invariants are no longer true.
  3802. - // See jvmtiExport.hpp for detailed explanation.
  3803. - JvmtiExport::set_has_redefined_a_class();
  3804. + *not_changed = true;
  3805. -// check_class() is optionally called for product bits, but is
  3806. -// always called for non-product bits.
  3807. -#ifdef PRODUCT
  3808. - if (RC_TRACE_ENABLED(0x00004000)) {
  3809. -#endif
  3810. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  3811. - SystemDictionary::classes_do(check_class, thread);
  3812. -#ifdef PRODUCT
  3813. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  3814. + // so the user did not specify a different bytecode for that class.
  3815. +
  3816. + if (the_class->get_cached_class_file_bytes() == NULL) {
  3817. + // not cached, we need to reconstitute the class file from VM representation
  3818. + constantPoolHandle constants(Thread::current(), the_class->constants());
  3819. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  3820. +
  3821. + JvmtiClassFileReconstituter reconstituter(the_class);
  3822. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  3823. + return reconstituter.get_error();
  3824. + }
  3825. +
  3826. + *class_byte_count = (jint)reconstituter.class_file_size();
  3827. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  3828. +
  3829. + TRACE_RC3("Reconstituted class bytes");
  3830. +
  3831. + } else {
  3832. +
  3833. + // it is cached, get it from the cache
  3834. + *class_byte_count = the_class->get_cached_class_file_len();
  3835. + *class_bytes = the_class->get_cached_class_file_bytes();
  3836. +
  3837. +
  3838. + TRACE_RC3("Retrieved cached class bytes");
  3839. + }
  3840. +
  3841. + } else {
  3842. +
  3843. + // Redefine with bytecodes at index j
  3844. + *class_bytes = _class_defs[j].class_bytes;
  3845. + *class_byte_count = _class_defs[j].class_byte_count;
  3846. }
  3847. -#endif
  3848. +
  3849. + return JVMTI_ERROR_NONE;
  3850. }
  3851. -void VM_RedefineClasses::doit_epilogue() {
  3852. - // Free os::malloc allocated memory.
  3853. - // The memory allocated in redefine will be free'ed in next VM operation.
  3854. - os::free(_scratch_classes);
  3855. -
  3856. - if (RC_TRACE_ENABLED(0x00000004)) {
  3857. - // Used to have separate timers for "doit" and "all", but the timer
  3858. - // overhead skewed the measurements.
  3859. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  3860. - _timer_rsc_phase2.milliseconds();
  3861. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  3862. -
  3863. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  3864. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  3865. - _timer_vm_op_prologue.milliseconds(), doit_time));
  3866. - RC_TRACE(0x00000004,
  3867. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  3868. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  3869. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  3870. +bool VM_RedefineClasses::doit_prologue() {
  3871. +
  3872. + _revision_number++;
  3873. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  3874. + lock_threads();
  3875. +
  3876. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  3877. + RC_TIMER_START(_timer_prologue);
  3878. +
  3879. + if (!check_arguments()) {
  3880. + RC_TIMER_STOP(_timer_prologue);
  3881. + return false;
  3882. }
  3883. -}
  3884. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  3885. - // classes for primitives cannot be redefined
  3886. - if (java_lang_Class::is_primitive(klass_mirror)) {
  3887. + // We first load new class versions in the prologue, because somewhere down the
  3888. + // call chain it is required that the current thread is a Java thread.
  3889. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  3890. +
  3891. + assert(_affected_klasses == NULL, "");
  3892. + _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
  3893. +
  3894. +
  3895. + _result = load_new_class_versions(Thread::current());
  3896. +
  3897. + TRACE_RC1("Loaded new class versions!");
  3898. + if (_result != JVMTI_ERROR_NONE) {
  3899. + TRACE_RC1("error occured: %d!", _result);
  3900. + delete _new_classes;
  3901. + _new_classes = NULL;
  3902. + delete _affected_klasses;
  3903. + _affected_klasses = NULL;
  3904. + RC_TIMER_STOP(_timer_prologue);
  3905. return false;
  3906. }
  3907. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  3908. - // classes for arrays cannot be redefined
  3909. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  3910. +
  3911. + TRACE_RC2("nearly finished");
  3912. + VM_GC_Operation::doit_prologue();
  3913. + RC_TIMER_STOP(_timer_prologue);
  3914. + TRACE_RC2("doit_prologue finished!");
  3915. + return true;
  3916. +}
  3917. +
  3918. +// Checks basic properties of the arguments of the redefinition command.
  3919. +jvmtiError VM_RedefineClasses::check_arguments_error() {
  3920. + if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
  3921. + for (int i = 0; i < _class_count; i++) {
  3922. + if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
  3923. + if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3924. + if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
  3925. + }
  3926. + return JVMTI_ERROR_NONE;
  3927. +}
  3928. +
  3929. +// Returns false and sets an result error code if the redefinition should be aborted.
  3930. +bool VM_RedefineClasses::check_arguments() {
  3931. + jvmtiError error = check_arguments_error();
  3932. + if (error != JVMTI_ERROR_NONE || _class_count == 0) {
  3933. + _result = error;
  3934. return false;
  3935. }
  3936. return true;
  3937. }
  3938. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  3939. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  3940. -// direct CP entries, there is just the current entry to append. For
  3941. -// indirect and double-indirect CP entries, there are zero or more
  3942. -// referenced CP entries along with the current entry to append.
  3943. -// Indirect and double-indirect CP entries are handled by recursive
  3944. -// calls to append_entry() as needed. The referenced CP entries are
  3945. -// always appended to *merge_cp_p before the referee CP entry. These
  3946. -// referenced CP entries may already exist in *merge_cp_p in which case
  3947. -// there is nothing extra to append and only the current entry is
  3948. -// appended.
  3949. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  3950. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  3951. - TRAPS) {
  3952. -
  3953. - // append is different depending on entry tag type
  3954. - switch (scratch_cp->tag_at(scratch_i).value()) {
  3955. -
  3956. - // The old verifier is implemented outside the VM. It loads classes,
  3957. - // but does not resolve constant pool entries directly so we never
  3958. - // see Class entries here with the old verifier. Similarly the old
  3959. - // verifier does not like Class entries in the input constant pool.
  3960. - // The split-verifier is implemented in the VM so it can optionally
  3961. - // and directly resolve constant pool entries to load classes. The
  3962. - // split-verifier can accept either Class entries or UnresolvedClass
  3963. - // entries in the input constant pool. We revert the appended copy
  3964. - // back to UnresolvedClass so that either verifier will be happy
  3965. - // with the constant pool entry.
  3966. - case JVM_CONSTANT_Class:
  3967. - {
  3968. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  3969. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  3970. - scratch_cp->klass_name_at(scratch_i));
  3971. -
  3972. - if (scratch_i != *merge_cp_length_p) {
  3973. - // The new entry in *merge_cp_p is at a different index than
  3974. - // the new entry in scratch_cp so we need to map the index values.
  3975. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  3976. - }
  3977. - (*merge_cp_length_p)++;
  3978. - } break;
  3979. +jvmtiError VM_RedefineClasses::check_exception() const {
  3980. + Thread* THREAD = Thread::current();
  3981. + if (HAS_PENDING_EXCEPTION) {
  3982. +
  3983. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  3984. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  3985. + if (TraceRedefineClasses >= 1) {
  3986. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  3987. + tty->print_cr("");
  3988. + }
  3989. + CLEAR_PENDING_EXCEPTION;
  3990. +
  3991. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  3992. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  3993. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  3994. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  3995. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  3996. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  3997. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  3998. + // The message will be "XXX (wrong name: YYY)"
  3999. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4000. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4001. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4002. + } else {
  4003. + // Just in case more exceptions can be thrown..
  4004. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4005. + }
  4006. + }
  4007. - // these are direct CP entries so they can be directly appended,
  4008. - // but double and long take two constant pool entries
  4009. - case JVM_CONSTANT_Double: // fall through
  4010. - case JVM_CONSTANT_Long:
  4011. - {
  4012. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4013. - THREAD);
  4014. + return JVMTI_ERROR_NONE;
  4015. +}
  4016. - if (scratch_i != *merge_cp_length_p) {
  4017. - // The new entry in *merge_cp_p is at a different index than
  4018. - // the new entry in scratch_cp so we need to map the index values.
  4019. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4020. - }
  4021. - (*merge_cp_length_p) += 2;
  4022. - } break;
  4023. -
  4024. - // these are direct CP entries so they can be directly appended
  4025. - case JVM_CONSTANT_Float: // fall through
  4026. - case JVM_CONSTANT_Integer: // fall through
  4027. - case JVM_CONSTANT_Utf8: // fall through
  4028. -
  4029. - // This was an indirect CP entry, but it has been changed into
  4030. - // an interned string so this entry can be directly appended.
  4031. - case JVM_CONSTANT_String: // fall through
  4032. -
  4033. - // These were indirect CP entries, but they have been changed into
  4034. - // Symbol*s so these entries can be directly appended.
  4035. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4036. - case JVM_CONSTANT_UnresolvedString:
  4037. - {
  4038. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4039. - THREAD);
  4040. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4041. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4042. - if (scratch_i != *merge_cp_length_p) {
  4043. - // The new entry in *merge_cp_p is at a different index than
  4044. - // the new entry in scratch_cp so we need to map the index values.
  4045. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4046. - }
  4047. - (*merge_cp_length_p)++;
  4048. - } break;
  4049. + ResourceMark rm(THREAD);
  4050. - // this is an indirect CP entry so it needs special handling
  4051. - case JVM_CONSTANT_NameAndType:
  4052. - {
  4053. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4054. - int new_name_ref_i = 0;
  4055. - bool match = (name_ref_i < *merge_cp_length_p) &&
  4056. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  4057. - THREAD);
  4058. - if (!match) {
  4059. - // forward reference in *merge_cp_p or not a direct match
  4060. -
  4061. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  4062. - THREAD);
  4063. - if (found_i != 0) {
  4064. - guarantee(found_i != name_ref_i,
  4065. - "compare_entry_to() and find_matching_entry() do not agree");
  4066. -
  4067. - // Found a matching entry somewhere else in *merge_cp_p so
  4068. - // just need a mapping entry.
  4069. - new_name_ref_i = found_i;
  4070. - map_index(scratch_cp, name_ref_i, found_i);
  4071. - } else {
  4072. - // no match found so we have to append this entry to *merge_cp_p
  4073. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  4074. - THREAD);
  4075. - // The above call to append_entry() can only append one entry
  4076. - // so the post call query of *merge_cp_length_p is only for
  4077. - // the sake of consistency.
  4078. - new_name_ref_i = *merge_cp_length_p - 1;
  4079. + TRACE_RC1("===================================================================");
  4080. + TRACE_RC1("redefinition started by thread \"%s\"", THREAD->name());
  4081. + TRACE_RC1("load new class versions (%d)", _class_count);
  4082. +
  4083. + // Retrieve an array of all classes that need to be redefined
  4084. + jvmtiError err = find_sorted_affected_classes();
  4085. + if (err != JVMTI_ERROR_NONE) {
  4086. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  4087. + return err;
  4088. + }
  4089. +
  4090. +
  4091. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4092. +
  4093. + _max_redefinition_flags = Klass::NoRedefinition;
  4094. + jvmtiError result = JVMTI_ERROR_NONE;
  4095. +
  4096. + for (int i=0; i<_affected_klasses->length(); i++) {
  4097. + TRACE_RC2("Processing affected class %d of %d", i+1, _affected_klasses->length());
  4098. +
  4099. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4100. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  4101. +
  4102. + the_class->link_class(THREAD);
  4103. + result = check_exception();
  4104. + if (result != JVMTI_ERROR_NONE) break;
  4105. +
  4106. + // Find new class bytes
  4107. + const unsigned char* class_bytes;
  4108. + jint class_byte_count;
  4109. + jvmtiError error;
  4110. + jboolean not_changed;
  4111. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4112. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  4113. + result = error;
  4114. + break;
  4115. + }
  4116. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4117. +
  4118. +
  4119. + // Set redefined class handle in JvmtiThreadState class.
  4120. + // This redefined class is sent to agent event handler for class file
  4121. + // load hook event.
  4122. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4123. +
  4124. + TRACE_RC2("Before resolving from stream");
  4125. +
  4126. + RC_TIMER_STOP(_timer_prologue);
  4127. + RC_TIMER_START(_timer_class_loading);
  4128. +
  4129. +
  4130. + // Parse the stream.
  4131. + Handle the_class_loader(THREAD, the_class->class_loader());
  4132. + Handle protection_domain(THREAD, the_class->protection_domain());
  4133. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4134. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class->name(),
  4135. + the_class_loader,
  4136. + protection_domain,
  4137. + &st,
  4138. + true,
  4139. + the_class,
  4140. + THREAD));
  4141. +
  4142. + RC_TIMER_STOP(_timer_class_loading);
  4143. + RC_TIMER_START(_timer_prologue);
  4144. +
  4145. + TRACE_RC2("After resolving class from stream!");
  4146. + // Clear class_being_redefined just to be sure.
  4147. + state->clear_class_being_redefined();
  4148. +
  4149. + result = check_exception();
  4150. + if (result != JVMTI_ERROR_NONE) break;
  4151. +
  4152. + not_changed = false;
  4153. +
  4154. +#ifdef ASSERT
  4155. +
  4156. + assert(new_class() != NULL, "Class could not be loaded!");
  4157. + assert(new_class() != the_class(), "must be different");
  4158. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4159. +
  4160. +
  4161. + objArrayOop k_interfaces = new_class->local_interfaces();
  4162. + for (int j=0; j<k_interfaces->length(); j++) {
  4163. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4164. + }
  4165. +
  4166. + if (!THREAD->is_Compiler_thread()) {
  4167. +
  4168. + TRACE_RC2("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT, the_class->name()->as_C_string(), the_class->class_loader(), the_class->protection_domain());
  4169. + // If we are on the compiler thread, we must not try to resolve a class.
  4170. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4171. +
  4172. + if (systemLookup != NULL) {
  4173. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4174. +
  4175. +
  4176. + Klass *subklass = new_class()->klass_part()->subklass();
  4177. + while (subklass != NULL) {
  4178. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4179. + subklass = subklass->next_sibling();
  4180. }
  4181. + } else {
  4182. + // This can happen for reflection generated classes.. ?
  4183. + CLEAR_PENDING_EXCEPTION;
  4184. }
  4185. + }
  4186. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  4187. - int new_signature_ref_i = 0;
  4188. - match = (signature_ref_i < *merge_cp_length_p) &&
  4189. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  4190. - signature_ref_i, THREAD);
  4191. - if (!match) {
  4192. - // forward reference in *merge_cp_p or not a direct match
  4193. -
  4194. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  4195. - *merge_cp_p, THREAD);
  4196. - if (found_i != 0) {
  4197. - guarantee(found_i != signature_ref_i,
  4198. - "compare_entry_to() and find_matching_entry() do not agree");
  4199. -
  4200. - // Found a matching entry somewhere else in *merge_cp_p so
  4201. - // just need a mapping entry.
  4202. - new_signature_ref_i = found_i;
  4203. - map_index(scratch_cp, signature_ref_i, found_i);
  4204. - } else {
  4205. - // no match found so we have to append this entry to *merge_cp_p
  4206. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  4207. - merge_cp_length_p, THREAD);
  4208. - // The above call to append_entry() can only append one entry
  4209. - // so the post call query of *merge_cp_length_p is only for
  4210. - // the sake of consistency.
  4211. - new_signature_ref_i = *merge_cp_length_p - 1;
  4212. - }
  4213. +#endif
  4214. +
  4215. + IF_TRACE_RC1 {
  4216. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4217. + TRACE_RC1("Instance size change for class %s: new=%d old=%d", new_class->name()->as_C_string(), new_class->layout_helper(), the_class->layout_helper());
  4218. }
  4219. + }
  4220. - // If the referenced entries already exist in *merge_cp_p, then
  4221. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  4222. - // In that case, all we are appending is the current entry.
  4223. - if (new_name_ref_i == 0) {
  4224. - new_name_ref_i = name_ref_i;
  4225. - } else {
  4226. - RC_TRACE(0x00080000,
  4227. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  4228. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  4229. + // Set the new version of the class
  4230. + new_class->set_revision_number(_revision_number);
  4231. + new_class->set_redefinition_index(i);
  4232. + the_class->set_new_version(new_class());
  4233. + _new_classes->append(new_class);
  4234. +
  4235. + assert(new_class->new_version() == NULL, "");
  4236. +
  4237. + int redefinition_flags = Klass::NoRedefinition;
  4238. +
  4239. + if (not_changed) {
  4240. + redefinition_flags = Klass::NoRedefinition;
  4241. + } else if (AllowAdvancedClassRedefinition) {
  4242. + redefinition_flags = calculate_redefinition_flags(new_class);
  4243. + if (redefinition_flags >= Klass::RemoveSuperType) {
  4244. + TRACE_RC1("Remove super type is not allowed");
  4245. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4246. + break;
  4247. }
  4248. - if (new_signature_ref_i == 0) {
  4249. - new_signature_ref_i = signature_ref_i;
  4250. - } else {
  4251. - RC_TRACE(0x00080000,
  4252. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  4253. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  4254. + } else {
  4255. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4256. + if (allowed != JVMTI_ERROR_NONE) {
  4257. + TRACE_RC1("Error redefinition not allowed!");
  4258. + result = allowed;
  4259. + break;
  4260. }
  4261. + redefinition_flags = Klass::ModifyClass;
  4262. + }
  4263. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  4264. - new_name_ref_i, new_signature_ref_i);
  4265. - if (scratch_i != *merge_cp_length_p) {
  4266. - // The new entry in *merge_cp_p is at a different index than
  4267. - // the new entry in scratch_cp so we need to map the index values.
  4268. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4269. + if (new_class->super() != NULL) {
  4270. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4271. + }
  4272. +
  4273. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4274. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4275. + }
  4276. +
  4277. + new_class->set_redefinition_flags(redefinition_flags);
  4278. +
  4279. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4280. +
  4281. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4282. + // TODO: Check if watch access flags of static fields are updated correctly.
  4283. + calculate_instance_update_information(_new_classes->at(i)());
  4284. + } else {
  4285. + // Fields were not changed, transfer special flags only
  4286. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4287. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4288. +
  4289. + JavaFieldStream old_fs(the_class);
  4290. + JavaFieldStream new_fs(new_class);
  4291. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4292. + AccessFlags flags = new_fs.access_flags();
  4293. + flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
  4294. + flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
  4295. + new_fs.set_access_flags(flags);
  4296. }
  4297. - (*merge_cp_length_p)++;
  4298. - } break;
  4299. + }
  4300. - // this is a double-indirect CP entry so it needs special handling
  4301. - case JVM_CONSTANT_Fieldref: // fall through
  4302. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  4303. - case JVM_CONSTANT_Methodref:
  4304. - {
  4305. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  4306. - int new_klass_ref_i = 0;
  4307. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  4308. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  4309. - THREAD);
  4310. - if (!match) {
  4311. - // forward reference in *merge_cp_p or not a direct match
  4312. -
  4313. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  4314. - THREAD);
  4315. - if (found_i != 0) {
  4316. - guarantee(found_i != klass_ref_i,
  4317. - "compare_entry_to() and find_matching_entry() do not agree");
  4318. -
  4319. - // Found a matching entry somewhere else in *merge_cp_p so
  4320. - // just need a mapping entry.
  4321. - new_klass_ref_i = found_i;
  4322. - map_index(scratch_cp, klass_ref_i, found_i);
  4323. - } else {
  4324. - // no match found so we have to append this entry to *merge_cp_p
  4325. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  4326. - THREAD);
  4327. - // The above call to append_entry() can only append one entry
  4328. - // so the post call query of *merge_cp_length_p is only for
  4329. - // the sake of consistency. Without the optimization where we
  4330. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  4331. - // could be appended.
  4332. - new_klass_ref_i = *merge_cp_length_p - 1;
  4333. - }
  4334. + IF_TRACE_RC3 {
  4335. + if (new_class->super() != NULL) {
  4336. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  4337. }
  4338. + }
  4339. - int name_and_type_ref_i =
  4340. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  4341. - int new_name_and_type_ref_i = 0;
  4342. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  4343. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  4344. - name_and_type_ref_i, THREAD);
  4345. - if (!match) {
  4346. - // forward reference in *merge_cp_p or not a direct match
  4347. -
  4348. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  4349. - *merge_cp_p, THREAD);
  4350. - if (found_i != 0) {
  4351. - guarantee(found_i != name_and_type_ref_i,
  4352. - "compare_entry_to() and find_matching_entry() do not agree");
  4353. -
  4354. - // Found a matching entry somewhere else in *merge_cp_p so
  4355. - // just need a mapping entry.
  4356. - new_name_and_type_ref_i = found_i;
  4357. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  4358. - } else {
  4359. - // no match found so we have to append this entry to *merge_cp_p
  4360. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  4361. - merge_cp_length_p, THREAD);
  4362. - // The above call to append_entry() can append more than
  4363. - // one entry so the post call query of *merge_cp_length_p
  4364. - // is required in order to get the right index for the
  4365. - // JVM_CONSTANT_NameAndType entry.
  4366. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  4367. +#ifdef ASSERT
  4368. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4369. +
  4370. + the_class->vtable()->verify(tty);
  4371. + new_class->vtable()->verify(tty);
  4372. +#endif
  4373. +
  4374. + TRACE_RC2("Verification done!");
  4375. +
  4376. + if (i == _affected_klasses->length() - 1) {
  4377. +
  4378. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4379. +
  4380. + for (int j=0; j<_affected_klasses->length(); j++) {
  4381. +
  4382. + klassOop initial_klass = _affected_klasses->at(j)();
  4383. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4384. + Klass *cur_klass = initial_subklass;
  4385. + while(cur_klass != NULL) {
  4386. +
  4387. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
  4388. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4389. + if (!_affected_klasses->contains(handle)) {
  4390. +
  4391. + int k = i + 1;
  4392. + for (; k<_affected_klasses->length(); k++) {
  4393. + if (_affected_klasses->at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4394. + break;
  4395. + }
  4396. + }
  4397. + _affected_klasses->insert_before(k, handle);
  4398. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  4399. + }
  4400. + }
  4401. +
  4402. + cur_klass = cur_klass->next_sibling();
  4403. }
  4404. }
  4405. - // If the referenced entries already exist in *merge_cp_p, then
  4406. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  4407. - // 0. In that case, all we are appending is the current entry.
  4408. - if (new_klass_ref_i == 0) {
  4409. - new_klass_ref_i = klass_ref_i;
  4410. - }
  4411. - if (new_name_and_type_ref_i == 0) {
  4412. - new_name_and_type_ref_i = name_and_type_ref_i;
  4413. - }
  4414. + int new_count = _affected_klasses->length() - 1 - i;
  4415. + if (new_count != 0) {
  4416. - const char *entry_name;
  4417. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4418. - case JVM_CONSTANT_Fieldref:
  4419. - entry_name = "Fieldref";
  4420. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  4421. - new_name_and_type_ref_i);
  4422. - break;
  4423. - case JVM_CONSTANT_InterfaceMethodref:
  4424. - entry_name = "IFMethodref";
  4425. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  4426. - new_klass_ref_i, new_name_and_type_ref_i);
  4427. - break;
  4428. - case JVM_CONSTANT_Methodref:
  4429. - entry_name = "Methodref";
  4430. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  4431. - new_name_and_type_ref_i);
  4432. - break;
  4433. - default:
  4434. - guarantee(false, "bad switch");
  4435. - break;
  4436. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  4437. }
  4438. + }
  4439. + }
  4440. - if (klass_ref_i != new_klass_ref_i) {
  4441. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  4442. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  4443. - }
  4444. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  4445. - RC_TRACE(0x00080000,
  4446. - ("%s entry@%d name_and_type_index changed: %d to %d",
  4447. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  4448. - new_name_and_type_ref_i));
  4449. - }
  4450. + if (result != JVMTI_ERROR_NONE) {
  4451. + rollback();
  4452. + return result;
  4453. + }
  4454. - if (scratch_i != *merge_cp_length_p) {
  4455. - // The new entry in *merge_cp_p is at a different index than
  4456. - // the new entry in scratch_cp so we need to map the index values.
  4457. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4458. - }
  4459. - (*merge_cp_length_p)++;
  4460. - } break;
  4461. + RC_TIMER_STOP(_timer_prologue);
  4462. + RC_TIMER_START(_timer_class_linking);
  4463. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4464. + for (int i=0; i<_affected_klasses->length(); i++) {
  4465. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4466. + instanceKlassHandle new_class(the_class->new_version());
  4467. - // At this stage, Class or UnresolvedClass could be here, but not
  4468. - // ClassIndex
  4469. - case JVM_CONSTANT_ClassIndex: // fall through
  4470. + TRACE_RC2("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string());
  4471. + new_class->link_class(THREAD);
  4472. - // Invalid is used as the tag for the second constant pool entry
  4473. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  4474. - // not be seen by itself.
  4475. - case JVM_CONSTANT_Invalid: // fall through
  4476. + result = check_exception();
  4477. + if (result != JVMTI_ERROR_NONE) break;
  4478. + }
  4479. + RC_TIMER_STOP(_timer_class_linking);
  4480. + RC_TIMER_START(_timer_prologue);
  4481. - // At this stage, String or UnresolvedString could be here, but not
  4482. - // StringIndex
  4483. - case JVM_CONSTANT_StringIndex: // fall through
  4484. + if (result != JVMTI_ERROR_NONE) {
  4485. + rollback();
  4486. + return result;
  4487. + }
  4488. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  4489. - // here
  4490. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  4491. + TRACE_RC2("All classes loaded!");
  4492. - default:
  4493. - {
  4494. - // leave a breadcrumb
  4495. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  4496. - ShouldNotReachHere();
  4497. - } break;
  4498. - } // end switch tag value
  4499. -} // end append_entry()
  4500. +#ifdef ASSERT
  4501. + for (int i=0; i<_affected_klasses->length(); i++) {
  4502. + instanceKlassHandle the_class = _affected_klasses->at(i);
  4503. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4504. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  4505. + assert(new_version->new_version() == NULL, "Must be newest version");
  4506. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  4507. + new_version()->print();
  4508. + new_version->super()->print();
  4509. + }
  4510. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  4511. + }
  4512. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  4513. - typeArrayOop save;
  4514. + SystemDictionary::classes_do(check_class, THREAD);
  4515. - save = scratch_class->get_method_annotations_of(i);
  4516. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  4517. - scratch_class->set_method_annotations_of(j, save);
  4518. +#endif
  4519. - save = scratch_class->get_method_parameter_annotations_of(i);
  4520. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  4521. - scratch_class->set_method_parameter_annotations_of(j, save);
  4522. + TRACE_RC1("Finished verification!");
  4523. + return JVMTI_ERROR_NONE;
  4524. +}
  4525. - save = scratch_class->get_method_default_annotations_of(i);
  4526. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  4527. - scratch_class->set_method_default_annotations_of(j, save);
  4528. +void VM_RedefineClasses::lock_threads() {
  4529. +
  4530. + RC_TIMER_START(_timer_wait_for_locks);
  4531. +
  4532. +
  4533. + JavaThread *javaThread = Threads::first();
  4534. + while (javaThread != NULL) {
  4535. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4536. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4537. + compilerThread->set_should_bailout(true);
  4538. + }
  4539. + javaThread = javaThread->next();
  4540. + }
  4541. +
  4542. + int cnt = 0;
  4543. + javaThread = Threads::first();
  4544. + while (javaThread != NULL) {
  4545. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4546. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4547. + compilerThread->compilation_mutex()->lock();
  4548. + cnt++;
  4549. + }
  4550. + javaThread = javaThread->next();
  4551. + }
  4552. +
  4553. + TRACE_RC2("Locked %d compiler threads", cnt);
  4554. +
  4555. + cnt = 0;
  4556. + javaThread = Threads::first();
  4557. + while (javaThread != NULL) {
  4558. + if (javaThread != Thread::current()) {
  4559. + javaThread->redefine_classes_mutex()->lock();
  4560. + cnt++;
  4561. + }
  4562. + javaThread = javaThread->next();
  4563. + }
  4564. +
  4565. +
  4566. + TRACE_RC2("Locked %d threads", cnt);
  4567. +
  4568. + RC_TIMER_STOP(_timer_wait_for_locks);
  4569. +}
  4570. +
  4571. +void VM_RedefineClasses::unlock_threads() {
  4572. +
  4573. + int cnt = 0;
  4574. + JavaThread *javaThread = Threads::first();
  4575. + Thread *thread = Thread::current();
  4576. + while (javaThread != NULL) {
  4577. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4578. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4579. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  4580. + compilerThread->compilation_mutex()->unlock();
  4581. + cnt++;
  4582. + }
  4583. + }
  4584. + javaThread = javaThread->next();
  4585. + }
  4586. +
  4587. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  4588. +
  4589. + cnt = 0;
  4590. + javaThread = Threads::first();
  4591. + while (javaThread != NULL) {
  4592. + if (javaThread != Thread::current()) {
  4593. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  4594. + javaThread->redefine_classes_mutex()->unlock();
  4595. + cnt++;
  4596. + }
  4597. + }
  4598. + javaThread = javaThread->next();
  4599. + }
  4600. +
  4601. + TRACE_RC2("Unlocked %d threads", cnt);
  4602. }
  4603. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  4604. +
  4605. +
  4606. +
  4607. + // Compatibility mode => check for unsupported modification
  4608. +
  4609. +
  4610. + assert(scratch_class->old_version() != NULL, "must have old version");
  4611. + instanceKlassHandle the_class(scratch_class->old_version());
  4612. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4613. - instanceKlassHandle the_class,
  4614. - instanceKlassHandle scratch_class) {
  4615. int i;
  4616. // Check superclasses, or rather their names, since superclasses themselves can be
  4617. // requested to replace.
  4618. // Check for NULL superclass first since this might be java.lang.Object
  4619. if (the_class->super() != scratch_class->super() &&
  4620. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  4621. - Klass::cast(the_class->super())->name() !=
  4622. - Klass::cast(scratch_class->super())->name())) {
  4623. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4624. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  4625. + Klass::cast(the_class->super())->name() !=
  4626. + Klass::cast(scratch_class->super())->name())) {
  4627. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4628. }
  4629. // Check if the number, names and order of directly implemented interfaces are the same.
  4630. @@ -539,8 +718,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4631. }
  4632. for (i = 0; i < n_intfs; i++) {
  4633. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  4634. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4635. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4636. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  4637. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4638. }
  4639. }
  4640. @@ -578,14 +757,283 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4641. Symbol* name_sym2 = scratch_class->constants()->symbol_at(new_fs.name_index());
  4642. Symbol* sig_sym2 = scratch_class->constants()->symbol_at(new_fs.signature_index());
  4643. if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  4644. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4645. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4646. + }
  4647. + }
  4648. +
  4649. + // If both streams aren't done then we have a differing number of
  4650. + // fields.
  4651. + if (!old_fs.done() || !new_fs.done()) {
  4652. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4653. + }
  4654. +
  4655. + // Do a parallel walk through the old and new methods. Detect
  4656. + // cases where they match (exist in both), have been added in
  4657. + // the new methods, or have been deleted (exist only in the
  4658. + // old methods). The class file parser places methods in order
  4659. + // by method name, but does not order overloaded methods by
  4660. + // signature. In order to determine what fate befell the methods,
  4661. + // this code places the overloaded new methods that have matching
  4662. + // old methods in the same order as the old methods and places
  4663. + // new overloaded methods at the end of overloaded methods of
  4664. + // that name. The code for this order normalization is adapted
  4665. + // from the algorithm used in instanceKlass::find_method().
  4666. + // Since we are swapping out of order entries as we find them,
  4667. + // we only have to search forward through the overloaded methods.
  4668. + // Methods which are added and have the same name as an existing
  4669. + // method (but different signature) will be put at the end of
  4670. + // the methods with that name, and the name mismatch code will
  4671. + // handle them.
  4672. + objArrayHandle k_old_methods(the_class->methods());
  4673. + objArrayHandle k_new_methods(scratch_class->methods());
  4674. + int n_old_methods = k_old_methods->length();
  4675. + int n_new_methods = k_new_methods->length();
  4676. +
  4677. + int ni = 0;
  4678. + int oi = 0;
  4679. + while (true) {
  4680. + methodOop k_old_method;
  4681. + methodOop k_new_method;
  4682. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  4683. +
  4684. + if (oi >= n_old_methods) {
  4685. + if (ni >= n_new_methods) {
  4686. + break; // we've looked at everything, done
  4687. + }
  4688. + // New method at the end
  4689. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4690. + method_was = added;
  4691. + } else if (ni >= n_new_methods) {
  4692. + // Old method, at the end, is deleted
  4693. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4694. + method_was = deleted;
  4695. + } else {
  4696. + // There are more methods in both the old and new lists
  4697. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  4698. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  4699. + if (k_old_method->name() != k_new_method->name()) {
  4700. + // Methods are sorted by method name, so a mismatch means added
  4701. + // or deleted
  4702. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  4703. + method_was = added;
  4704. + } else {
  4705. + method_was = deleted;
  4706. + }
  4707. + } else if (k_old_method->signature() == k_new_method->signature()) {
  4708. + // Both the name and signature match
  4709. + method_was = matched;
  4710. + } else {
  4711. + // The name matches, but the signature doesn't, which means we have to
  4712. + // search forward through the new overloaded methods.
  4713. + int nj; // outside the loop for post-loop check
  4714. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  4715. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  4716. + if (k_old_method->name() != m->name()) {
  4717. + // reached another method name so no more overloaded methods
  4718. + method_was = deleted;
  4719. + break;
  4720. + }
  4721. + if (k_old_method->signature() == m->signature()) {
  4722. + // found a match so swap the methods
  4723. + k_new_methods->obj_at_put(ni, m);
  4724. + k_new_methods->obj_at_put(nj, k_new_method);
  4725. + k_new_method = m;
  4726. + method_was = matched;
  4727. + break;
  4728. + }
  4729. + }
  4730. +
  4731. + if (nj >= n_new_methods) {
  4732. + // reached the end without a match; so method was deleted
  4733. + method_was = deleted;
  4734. + }
  4735. + }
  4736. + }
  4737. +
  4738. + switch (method_was) {
  4739. + case matched:
  4740. + // methods match, be sure modifiers do too
  4741. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4742. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4743. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4744. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED;
  4745. + }
  4746. + {
  4747. + u2 new_num = k_new_method->method_idnum();
  4748. + u2 old_num = k_old_method->method_idnum();
  4749. + if (new_num != old_num) {
  4750. + methodOop idnum_owner = scratch_class->method_with_idnum(old_num);
  4751. + if (idnum_owner != NULL) {
  4752. + // There is already a method assigned this idnum -- switch them
  4753. + idnum_owner->set_method_idnum(new_num);
  4754. + }
  4755. + k_new_method->set_method_idnum(old_num);
  4756. + }
  4757. + }
  4758. + // advance to next pair of methods
  4759. + ++oi;
  4760. + ++ni;
  4761. + break;
  4762. + case added:
  4763. + // method added, see if it is OK
  4764. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4765. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  4766. + // hack: private should be treated as final, but alas
  4767. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4768. + ) {
  4769. + // new methods must be private
  4770. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4771. + }
  4772. + {
  4773. + u2 num = the_class->next_method_idnum();
  4774. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  4775. + // cannot add any more methods
  4776. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4777. + }
  4778. + u2 new_num = k_new_method->method_idnum();
  4779. + methodOop idnum_owner = scratch_class->method_with_idnum(num);
  4780. + if (idnum_owner != NULL) {
  4781. + // There is already a method assigned this idnum -- switch them
  4782. + idnum_owner->set_method_idnum(new_num);
  4783. + }
  4784. + k_new_method->set_method_idnum(num);
  4785. + }
  4786. + ++ni; // advance to next new method
  4787. + break;
  4788. + case deleted:
  4789. + // method deleted, see if it is OK
  4790. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4791. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  4792. + // hack: private should be treated as final, but alas
  4793. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4794. + ) {
  4795. + // deleted methods must be private
  4796. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  4797. + }
  4798. + ++oi; // advance to next old method
  4799. + break;
  4800. + default:
  4801. + ShouldNotReachHere();
  4802. + }
  4803. + }
  4804. +
  4805. + return JVMTI_ERROR_NONE;
  4806. +}
  4807. +
  4808. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  4809. +
  4810. + int result = Klass::NoRedefinition;
  4811. +
  4812. +
  4813. +
  4814. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  4815. +
  4816. + assert(new_class->old_version() != NULL, "must have old version");
  4817. + instanceKlassHandle the_class(new_class->old_version());
  4818. +
  4819. + // Check whether class is in the error init state.
  4820. + if (the_class->is_in_error_state()) {
  4821. + // TBD #5057930: special error code is needed in 1.6
  4822. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  4823. + }
  4824. +
  4825. + int i;
  4826. +
  4827. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4828. + // Check superclasses
  4829. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  4830. + if (the_class->super() != new_class->super()) {
  4831. + // Super class changed
  4832. +
  4833. + klassOop cur_klass = the_class->super();
  4834. + while (cur_klass != NULL) {
  4835. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  4836. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  4837. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  4838. +
  4839. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  4840. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  4841. + cur_klass->klass_part()->set_subtype_changed(true);
  4842. + }
  4843. + }
  4844. +
  4845. + cur_klass = cur_klass->klass_part()->super();
  4846. + }
  4847. +
  4848. + cur_klass = new_class->super();
  4849. + while (cur_klass != NULL) {
  4850. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  4851. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  4852. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  4853. + }
  4854. + cur_klass = cur_klass->klass_part()->super();
  4855. + }
  4856. + }
  4857. +
  4858. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  4859. + // Check interfaces
  4860. +
  4861. + // Interfaces removed?
  4862. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  4863. + for (i = 0; i<old_interfaces->length(); i++) {
  4864. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  4865. + if (!new_class->implements_interface_any_version(old_interface())) {
  4866. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  4867. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  4868. +
  4869. + if (!old_interface->has_subtype_changed()) {
  4870. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  4871. + old_interface->set_subtype_changed(true);
  4872. + }
  4873. + }
  4874. + }
  4875. +
  4876. + // Interfaces added?
  4877. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  4878. + for (i = 0; i<new_interfaces->length(); i++) {
  4879. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  4880. + result = result | Klass::ModifyClass;
  4881. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  4882. + }
  4883. + }
  4884. +
  4885. +
  4886. + // Check whether class modifiers are the same.
  4887. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  4888. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  4889. + if (old_flags != new_flags) {
  4890. + // TODO (tw): Can this have any effects?
  4891. + }
  4892. +
  4893. + // Check if the number, names, types and order of fields declared in these classes
  4894. + // are the same.
  4895. + JavaFieldStream old_fs(the_class);
  4896. + JavaFieldStream new_fs(new_class);
  4897. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  4898. + // access
  4899. + old_flags = old_fs.access_flags().as_short();
  4900. + new_flags = new_fs.access_flags().as_short();
  4901. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  4902. + // TODO (tw) can this have any effect?
  4903. + }
  4904. + // offset
  4905. + if (old_fs.offset() != new_fs.offset()) {
  4906. + result = result | Klass::ModifyInstances;
  4907. + }
  4908. + // name and signature
  4909. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  4910. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  4911. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  4912. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  4913. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  4914. + result = result | Klass::ModifyInstances;
  4915. }
  4916. }
  4917. // If both streams aren't done then we have a differing number of
  4918. // fields.
  4919. if (!old_fs.done() || !new_fs.done()) {
  4920. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  4921. + result = result | Klass::ModifyInstances;
  4922. }
  4923. // Do a parallel walk through the old and new methods. Detect
  4924. @@ -606,7 +1054,7 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4925. // the methods with that name, and the name mismatch code will
  4926. // handle them.
  4927. objArrayHandle k_old_methods(the_class->methods());
  4928. - objArrayHandle k_new_methods(scratch_class->methods());
  4929. + objArrayHandle k_new_methods(new_class->methods());
  4930. int n_old_methods = k_old_methods->length();
  4931. int n_new_methods = k_new_methods->length();
  4932. @@ -672,2278 +1120,701 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  4933. }
  4934. switch (method_was) {
  4935. - case matched:
  4936. - // methods match, be sure modifiers do too
  4937. - old_flags = (jushort) k_old_method->access_flags().get_flags();
  4938. - new_flags = (jushort) k_new_method->access_flags().get_flags();
  4939. - if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4940. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED;
  4941. - }
  4942. - {
  4943. - u2 new_num = k_new_method->method_idnum();
  4944. - u2 old_num = k_old_method->method_idnum();
  4945. - if (new_num != old_num) {
  4946. - methodOop idnum_owner = scratch_class->method_with_idnum(old_num);
  4947. - if (idnum_owner != NULL) {
  4948. - // There is already a method assigned this idnum -- switch them
  4949. - idnum_owner->set_method_idnum(new_num);
  4950. - }
  4951. - k_new_method->set_method_idnum(old_num);
  4952. - swap_all_method_annotations(old_num, new_num, scratch_class);
  4953. - }
  4954. - }
  4955. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  4956. - k_new_method->name_and_sig_as_C_string(), ni,
  4957. - k_old_method->name_and_sig_as_C_string(), oi));
  4958. - // advance to next pair of methods
  4959. - ++oi;
  4960. - ++ni;
  4961. - break;
  4962. - case added:
  4963. - // method added, see if it is OK
  4964. - new_flags = (jushort) k_new_method->access_flags().get_flags();
  4965. - if ((new_flags & JVM_ACC_PRIVATE) == 0
  4966. - // hack: private should be treated as final, but alas
  4967. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  4968. - ) {
  4969. - // new methods must be private
  4970. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4971. - }
  4972. - {
  4973. - u2 num = the_class->next_method_idnum();
  4974. - if (num == constMethodOopDesc::UNSET_IDNUM) {
  4975. - // cannot add any more methods
  4976. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  4977. - }
  4978. - u2 new_num = k_new_method->method_idnum();
  4979. - methodOop idnum_owner = scratch_class->method_with_idnum(num);
  4980. + case matched:
  4981. + // methods match, be sure modifiers do too
  4982. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  4983. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  4984. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  4985. + // (tw) Can this have any effects? Probably yes on vtables?
  4986. + result = result | Klass::ModifyClass;
  4987. + }
  4988. + {
  4989. + u2 new_num = k_new_method->method_idnum();
  4990. + u2 old_num = k_old_method->method_idnum();
  4991. + if (new_num != old_num) {
  4992. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  4993. if (idnum_owner != NULL) {
  4994. // There is already a method assigned this idnum -- switch them
  4995. idnum_owner->set_method_idnum(new_num);
  4996. }
  4997. - k_new_method->set_method_idnum(num);
  4998. - swap_all_method_annotations(new_num, num, scratch_class);
  4999. - }
  5000. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5001. - k_new_method->name_and_sig_as_C_string(), ni));
  5002. - ++ni; // advance to next new method
  5003. - break;
  5004. - case deleted:
  5005. - // method deleted, see if it is OK
  5006. - old_flags = (jushort) k_old_method->access_flags().get_flags();
  5007. - if ((old_flags & JVM_ACC_PRIVATE) == 0
  5008. - // hack: private should be treated as final, but alas
  5009. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5010. - ) {
  5011. - // deleted methods must be private
  5012. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5013. - }
  5014. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5015. - k_old_method->name_and_sig_as_C_string(), oi));
  5016. - ++oi; // advance to next old method
  5017. - break;
  5018. - default:
  5019. - ShouldNotReachHere();
  5020. - }
  5021. - }
  5022. -
  5023. - return JVMTI_ERROR_NONE;
  5024. -}
  5025. -
  5026. -
  5027. -// Find new constant pool index value for old constant pool index value
  5028. -// by seaching the index map. Returns zero (0) if there is no mapped
  5029. -// value for the old constant pool index.
  5030. -int VM_RedefineClasses::find_new_index(int old_index) {
  5031. - if (_index_map_count == 0) {
  5032. - // map is empty so nothing can be found
  5033. - return 0;
  5034. - }
  5035. -
  5036. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5037. - // The old_index is out of range so it is not mapped. This should
  5038. - // not happen in regular constant pool merging use, but it can
  5039. - // happen if a corrupt annotation is processed.
  5040. - return 0;
  5041. - }
  5042. -
  5043. - int value = _index_map_p->at(old_index);
  5044. - if (value == -1) {
  5045. - // the old_index is not mapped
  5046. - return 0;
  5047. - }
  5048. -
  5049. - return value;
  5050. -} // end find_new_index()
  5051. -
  5052. -
  5053. -// Returns true if the current mismatch is due to a resolved/unresolved
  5054. -// class pair. Otherwise, returns false.
  5055. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5056. - int index1, constantPoolHandle cp2, int index2) {
  5057. -
  5058. - jbyte t1 = cp1->tag_at(index1).value();
  5059. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5060. - return false; // wrong entry type; not our special case
  5061. - }
  5062. -
  5063. - jbyte t2 = cp2->tag_at(index2).value();
  5064. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5065. - return false; // wrong entry type; not our special case
  5066. - }
  5067. -
  5068. - if (t1 == t2) {
  5069. - return false; // not a mismatch; not our special case
  5070. - }
  5071. -
  5072. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5073. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5074. - if (strcmp(s1, s2) != 0) {
  5075. - return false; // strings don't match; not our special case
  5076. - }
  5077. -
  5078. - return true; // made it through the gauntlet; this is our special case
  5079. -} // end is_unresolved_class_mismatch()
  5080. -
  5081. -
  5082. -// Returns true if the current mismatch is due to a resolved/unresolved
  5083. -// string pair. Otherwise, returns false.
  5084. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5085. - int index1, constantPoolHandle cp2, int index2) {
  5086. -
  5087. - jbyte t1 = cp1->tag_at(index1).value();
  5088. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5089. - return false; // wrong entry type; not our special case
  5090. - }
  5091. -
  5092. - jbyte t2 = cp2->tag_at(index2).value();
  5093. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5094. - return false; // wrong entry type; not our special case
  5095. - }
  5096. -
  5097. - if (t1 == t2) {
  5098. - return false; // not a mismatch; not our special case
  5099. - }
  5100. -
  5101. - char *s1 = cp1->string_at_noresolve(index1);
  5102. - char *s2 = cp2->string_at_noresolve(index2);
  5103. - if (strcmp(s1, s2) != 0) {
  5104. - return false; // strings don't match; not our special case
  5105. - }
  5106. -
  5107. - return true; // made it through the gauntlet; this is our special case
  5108. -} // end is_unresolved_string_mismatch()
  5109. -
  5110. -
  5111. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5112. - // For consistency allocate memory using os::malloc wrapper.
  5113. - _scratch_classes = (instanceKlassHandle *)
  5114. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5115. - if (_scratch_classes == NULL) {
  5116. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5117. - }
  5118. -
  5119. - ResourceMark rm(THREAD);
  5120. -
  5121. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5122. - // state can only be NULL if the current thread is exiting which
  5123. - // should not happen since we're trying to do a RedefineClasses
  5124. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5125. - for (int i = 0; i < _class_count; i++) {
  5126. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5127. - // classes for primitives cannot be redefined
  5128. - if (!is_modifiable_class(mirror)) {
  5129. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5130. - }
  5131. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5132. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5133. - Symbol* the_class_sym = the_class->name();
  5134. -
  5135. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5136. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5137. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5138. - the_class->external_name(), _class_load_kind,
  5139. - os::available_memory() >> 10));
  5140. -
  5141. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5142. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5143. -
  5144. - // Parse the stream.
  5145. - Handle the_class_loader(THREAD, the_class->class_loader());
  5146. - Handle protection_domain(THREAD, the_class->protection_domain());
  5147. - // Set redefined class handle in JvmtiThreadState class.
  5148. - // This redefined class is sent to agent event handler for class file
  5149. - // load hook event.
  5150. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5151. -
  5152. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5153. - the_class_loader,
  5154. - protection_domain,
  5155. - &st,
  5156. - THREAD);
  5157. - // Clear class_being_redefined just to be sure.
  5158. - state->clear_class_being_redefined();
  5159. -
  5160. - // TODO: if this is retransform, and nothing changed we can skip it
  5161. -
  5162. - instanceKlassHandle scratch_class (THREAD, k);
  5163. -
  5164. - if (HAS_PENDING_EXCEPTION) {
  5165. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5166. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5167. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5168. - ex_name->as_C_string()));
  5169. - CLEAR_PENDING_EXCEPTION;
  5170. -
  5171. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5172. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5173. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5174. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5175. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5176. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5177. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5178. - // The message will be "XXX (wrong name: YYY)"
  5179. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5180. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5181. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5182. - } else { // Just in case more exceptions can be thrown..
  5183. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5184. - }
  5185. - }
  5186. -
  5187. - // Ensure class is linked before redefine
  5188. - if (!the_class->is_linked()) {
  5189. - the_class->link_class(THREAD);
  5190. - if (HAS_PENDING_EXCEPTION) {
  5191. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5192. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5193. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5194. - ex_name->as_C_string()));
  5195. - CLEAR_PENDING_EXCEPTION;
  5196. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5197. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5198. - } else {
  5199. - return JVMTI_ERROR_INTERNAL;
  5200. - }
  5201. + k_new_method->set_method_idnum(old_num);
  5202. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  5203. + swap_all_method_annotations(old_num, new_num, new_class);
  5204. }
  5205. }
  5206. -
  5207. - // Do the validity checks in compare_and_normalize_class_versions()
  5208. - // before verifying the byte codes. By doing these checks first, we
  5209. - // limit the number of functions that require redirection from
  5210. - // the_class to scratch_class. In particular, we don't have to
  5211. - // modify JNI GetSuperclass() and thus won't change its performance.
  5212. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5213. - scratch_class);
  5214. - if (res != JVMTI_ERROR_NONE) {
  5215. - return res;
  5216. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  5217. + k_new_method->name_and_sig_as_C_string(), ni,
  5218. + k_old_method->name_and_sig_as_C_string(), oi);
  5219. + // advance to next pair of methods
  5220. + ++oi;
  5221. + ++ni;
  5222. + break;
  5223. + case added:
  5224. + // method added, see if it is OK
  5225. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5226. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5227. + // hack: private should be treated as final, but alas
  5228. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5229. + ) {
  5230. + // new methods must be private
  5231. + result = result | Klass::ModifyClass;
  5232. }
  5233. -
  5234. - // verify what the caller passed us
  5235. {
  5236. - // The bug 6214132 caused the verification to fail.
  5237. - // Information about the_class and scratch_class is temporarily
  5238. - // recorded into jvmtiThreadState. This data is used to redirect
  5239. - // the_class to scratch_class in the JVM_* functions called by the
  5240. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5241. - // description.
  5242. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5243. - Verifier::verify(
  5244. - scratch_class, Verifier::ThrowException, true, THREAD);
  5245. - }
  5246. -
  5247. - if (HAS_PENDING_EXCEPTION) {
  5248. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5249. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5250. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5251. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5252. - CLEAR_PENDING_EXCEPTION;
  5253. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5254. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5255. - } else {
  5256. - // tell the caller the bytecodes are bad
  5257. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5258. - }
  5259. - }
  5260. -
  5261. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5262. - if (res != JVMTI_ERROR_NONE) {
  5263. - return res;
  5264. - }
  5265. -
  5266. - if (VerifyMergedCPBytecodes) {
  5267. - // verify what we have done during constant pool merging
  5268. - {
  5269. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5270. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  5271. - }
  5272. -
  5273. - if (HAS_PENDING_EXCEPTION) {
  5274. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5275. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5276. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5277. - ("verify_byte_codes post merge-CP exception: '%s'",
  5278. - ex_name->as_C_string()));
  5279. - CLEAR_PENDING_EXCEPTION;
  5280. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5281. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5282. - } else {
  5283. - // tell the caller that constant pool merging screwed up
  5284. - return JVMTI_ERROR_INTERNAL;
  5285. - }
  5286. - }
  5287. - }
  5288. -
  5289. - Rewriter::rewrite(scratch_class, THREAD);
  5290. - if (!HAS_PENDING_EXCEPTION) {
  5291. - Rewriter::relocate_and_link(scratch_class, THREAD);
  5292. - }
  5293. - if (HAS_PENDING_EXCEPTION) {
  5294. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5295. - CLEAR_PENDING_EXCEPTION;
  5296. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5297. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5298. - } else {
  5299. - return JVMTI_ERROR_INTERNAL;
  5300. - }
  5301. - }
  5302. -
  5303. - _scratch_classes[i] = scratch_class;
  5304. -
  5305. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5306. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5307. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  5308. - the_class->external_name(), os::available_memory() >> 10));
  5309. - }
  5310. -
  5311. - return JVMTI_ERROR_NONE;
  5312. -}
  5313. -
  5314. -
  5315. -// Map old_index to new_index as needed. scratch_cp is only needed
  5316. -// for RC_TRACE() calls.
  5317. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  5318. - int old_index, int new_index) {
  5319. - if (find_new_index(old_index) != 0) {
  5320. - // old_index is already mapped
  5321. - return;
  5322. - }
  5323. -
  5324. - if (old_index == new_index) {
  5325. - // no mapping is needed
  5326. - return;
  5327. - }
  5328. -
  5329. - _index_map_p->at_put(old_index, new_index);
  5330. - _index_map_count++;
  5331. -
  5332. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  5333. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  5334. -} // end map_index()
  5335. -
  5336. -
  5337. -// Merge old_cp and scratch_cp and return the results of the merge via
  5338. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  5339. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  5340. -// in *merge_cp_p. Also creates a map of indices from entries in
  5341. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  5342. -// entries are only created for entries in scratch_cp that occupy a
  5343. -// different location in *merged_cp_p.
  5344. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  5345. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  5346. - int *merge_cp_length_p, TRAPS) {
  5347. -
  5348. - if (merge_cp_p == NULL) {
  5349. - assert(false, "caller must provide scatch constantPool");
  5350. - return false; // robustness
  5351. - }
  5352. - if (merge_cp_length_p == NULL) {
  5353. - assert(false, "caller must provide scatch CP length");
  5354. - return false; // robustness
  5355. - }
  5356. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  5357. - // but the caller might be smart so make sure we have at least
  5358. - // the minimum.
  5359. - if ((*merge_cp_p)->length() < old_cp->length()) {
  5360. - assert(false, "merge area too small");
  5361. - return false; // robustness
  5362. - }
  5363. -
  5364. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5365. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  5366. - scratch_cp->length()));
  5367. -
  5368. - {
  5369. - // Pass 0:
  5370. - // The old_cp is copied to *merge_cp_p; this means that any code
  5371. - // using old_cp does not have to change. This work looks like a
  5372. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  5373. - // handle one special case:
  5374. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  5375. - // This will make verification happy.
  5376. -
  5377. - int old_i; // index into old_cp
  5378. -
  5379. - // index zero (0) is not used in constantPools
  5380. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  5381. - // leave debugging crumb
  5382. - jbyte old_tag = old_cp->tag_at(old_i).value();
  5383. - switch (old_tag) {
  5384. - case JVM_CONSTANT_Class:
  5385. - case JVM_CONSTANT_UnresolvedClass:
  5386. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5387. - // May be resolving while calling this so do the same for
  5388. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  5389. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  5390. - old_cp->klass_name_at(old_i));
  5391. - break;
  5392. -
  5393. - case JVM_CONSTANT_Double:
  5394. - case JVM_CONSTANT_Long:
  5395. - // just copy the entry to *merge_cp_p, but double and long take
  5396. - // two constant pool entries
  5397. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5398. - old_i++;
  5399. - break;
  5400. -
  5401. - default:
  5402. - // just copy the entry to *merge_cp_p
  5403. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  5404. - break;
  5405. - }
  5406. - } // end for each old_cp entry
  5407. -
  5408. - // We don't need to sanity check that *merge_cp_length_p is within
  5409. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  5410. - (*merge_cp_length_p) = old_i;
  5411. - }
  5412. -
  5413. - // merge_cp_len should be the same as old_cp->length() at this point
  5414. - // so this trace message is really a "warm-and-breathing" message.
  5415. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5416. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  5417. -
  5418. - int scratch_i; // index into scratch_cp
  5419. - {
  5420. - // Pass 1a:
  5421. - // Compare scratch_cp entries to the old_cp entries that we have
  5422. - // already copied to *merge_cp_p. In this pass, we are eliminating
  5423. - // exact duplicates (matching entry at same index) so we only
  5424. - // compare entries in the common indice range.
  5425. - int increment = 1;
  5426. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  5427. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  5428. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5429. - case JVM_CONSTANT_Double:
  5430. - case JVM_CONSTANT_Long:
  5431. - // double and long take two constant pool entries
  5432. - increment = 2;
  5433. - break;
  5434. -
  5435. - default:
  5436. - increment = 1;
  5437. - break;
  5438. - }
  5439. -
  5440. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  5441. - scratch_i, CHECK_0);
  5442. - if (match) {
  5443. - // found a match at the same index so nothing more to do
  5444. - continue;
  5445. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  5446. - *merge_cp_p, scratch_i)) {
  5447. - // The mismatch in compare_entry_to() above is because of a
  5448. - // resolved versus unresolved class entry at the same index
  5449. - // with the same string value. Since Pass 0 reverted any
  5450. - // class entries to unresolved class entries in *merge_cp_p,
  5451. - // we go with the unresolved class entry.
  5452. - continue;
  5453. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  5454. - *merge_cp_p, scratch_i)) {
  5455. - // The mismatch in compare_entry_to() above is because of a
  5456. - // resolved versus unresolved string entry at the same index
  5457. - // with the same string value. We can live with whichever
  5458. - // happens to be at scratch_i in *merge_cp_p.
  5459. - continue;
  5460. - }
  5461. -
  5462. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  5463. - CHECK_0);
  5464. - if (found_i != 0) {
  5465. - guarantee(found_i != scratch_i,
  5466. - "compare_entry_to() and find_matching_entry() do not agree");
  5467. -
  5468. - // Found a matching entry somewhere else in *merge_cp_p so
  5469. - // just need a mapping entry.
  5470. - map_index(scratch_cp, scratch_i, found_i);
  5471. - continue;
  5472. - }
  5473. -
  5474. - // The find_matching_entry() call above could fail to find a match
  5475. - // due to a resolved versus unresolved class or string entry situation
  5476. - // like we solved above with the is_unresolved_*_mismatch() calls.
  5477. - // However, we would have to call is_unresolved_*_mismatch() over
  5478. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  5479. - // worth the time.
  5480. -
  5481. - // No match found so we have to append this entry and any unique
  5482. - // referenced entries to *merge_cp_p.
  5483. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5484. - CHECK_0);
  5485. - }
  5486. - }
  5487. -
  5488. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5489. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5490. - *merge_cp_length_p, scratch_i, _index_map_count));
  5491. -
  5492. - if (scratch_i < scratch_cp->length()) {
  5493. - // Pass 1b:
  5494. - // old_cp is smaller than scratch_cp so there are entries in
  5495. - // scratch_cp that we have not yet processed. We take care of
  5496. - // those now.
  5497. - int increment = 1;
  5498. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  5499. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5500. - case JVM_CONSTANT_Double:
  5501. - case JVM_CONSTANT_Long:
  5502. - // double and long take two constant pool entries
  5503. - increment = 2;
  5504. - break;
  5505. -
  5506. - default:
  5507. - increment = 1;
  5508. - break;
  5509. - }
  5510. -
  5511. - int found_i =
  5512. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  5513. - if (found_i != 0) {
  5514. - // Found a matching entry somewhere else in *merge_cp_p so
  5515. - // just need a mapping entry.
  5516. - map_index(scratch_cp, scratch_i, found_i);
  5517. - continue;
  5518. - }
  5519. -
  5520. - // No match found so we have to append this entry and any unique
  5521. - // referenced entries to *merge_cp_p.
  5522. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  5523. - CHECK_0);
  5524. - }
  5525. -
  5526. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  5527. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  5528. - *merge_cp_length_p, scratch_i, _index_map_count));
  5529. - }
  5530. -
  5531. - return true;
  5532. -} // end merge_constant_pools()
  5533. -
  5534. -
  5535. -// Merge constant pools between the_class and scratch_class and
  5536. -// potentially rewrite bytecodes in scratch_class to use the merged
  5537. -// constant pool.
  5538. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  5539. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  5540. - TRAPS) {
  5541. - // worst case merged constant pool length is old and new combined
  5542. - int merge_cp_length = the_class->constants()->length()
  5543. - + scratch_class->constants()->length();
  5544. -
  5545. - constantPoolHandle old_cp(THREAD, the_class->constants());
  5546. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  5547. -
  5548. - // Constant pools are not easily reused so we allocate a new one
  5549. - // each time.
  5550. - // merge_cp is created unsafe for concurrent GC processing. It
  5551. - // should be marked safe before discarding it. Even though
  5552. - // garbage, if it crosses a card boundary, it may be scanned
  5553. - // in order to find the start of the first complete object on the card.
  5554. - constantPoolHandle merge_cp(THREAD,
  5555. - oopFactory::new_constantPool(merge_cp_length,
  5556. - oopDesc::IsUnsafeConc,
  5557. - THREAD));
  5558. - int orig_length = old_cp->orig_length();
  5559. - if (orig_length == 0) {
  5560. - // This old_cp is an actual original constant pool. We save
  5561. - // the original length in the merged constant pool so that
  5562. - // merge_constant_pools() can be more efficient. If a constant
  5563. - // pool has a non-zero orig_length() value, then that constant
  5564. - // pool was created by a merge operation in RedefineClasses.
  5565. - merge_cp->set_orig_length(old_cp->length());
  5566. - } else {
  5567. - // This old_cp is a merged constant pool from a previous
  5568. - // RedefineClasses() calls so just copy the orig_length()
  5569. - // value.
  5570. - merge_cp->set_orig_length(old_cp->orig_length());
  5571. - }
  5572. -
  5573. - ResourceMark rm(THREAD);
  5574. - _index_map_count = 0;
  5575. - _index_map_p = new intArray(scratch_cp->length(), -1);
  5576. -
  5577. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  5578. - &merge_cp_length, THREAD);
  5579. - if (!result) {
  5580. - // The merge can fail due to memory allocation failure or due
  5581. - // to robustness checks.
  5582. - return JVMTI_ERROR_INTERNAL;
  5583. - }
  5584. -
  5585. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  5586. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  5587. -
  5588. - if (_index_map_count == 0) {
  5589. - // there is nothing to map between the new and merged constant pools
  5590. -
  5591. - if (old_cp->length() == scratch_cp->length()) {
  5592. - // The old and new constant pools are the same length and the
  5593. - // index map is empty. This means that the three constant pools
  5594. - // are equivalent (but not the same). Unfortunately, the new
  5595. - // constant pool has not gone through link resolution nor have
  5596. - // the new class bytecodes gone through constant pool cache
  5597. - // rewriting so we can't use the old constant pool with the new
  5598. - // class.
  5599. -
  5600. - merge_cp()->set_is_conc_safe(true);
  5601. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5602. - } else if (old_cp->length() < scratch_cp->length()) {
  5603. - // The old constant pool has fewer entries than the new constant
  5604. - // pool and the index map is empty. This means the new constant
  5605. - // pool is a superset of the old constant pool. However, the old
  5606. - // class bytecodes have already gone through constant pool cache
  5607. - // rewriting so we can't use the new constant pool with the old
  5608. - // class.
  5609. -
  5610. - merge_cp()->set_is_conc_safe(true);
  5611. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  5612. - } else {
  5613. - // The old constant pool has more entries than the new constant
  5614. - // pool and the index map is empty. This means that both the old
  5615. - // and merged constant pools are supersets of the new constant
  5616. - // pool.
  5617. -
  5618. - // Replace the new constant pool with a shrunken copy of the
  5619. - // merged constant pool; the previous new constant pool will
  5620. - // get GCed.
  5621. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  5622. - THREAD);
  5623. - // drop local ref to the merged constant pool
  5624. - merge_cp()->set_is_conc_safe(true);
  5625. - merge_cp = constantPoolHandle();
  5626. - }
  5627. - } else {
  5628. - if (RC_TRACE_ENABLED(0x00040000)) {
  5629. - // don't want to loop unless we are tracing
  5630. - int count = 0;
  5631. - for (int i = 1; i < _index_map_p->length(); i++) {
  5632. - int value = _index_map_p->at(i);
  5633. -
  5634. - if (value != -1) {
  5635. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5636. - ("index_map[%d]: old=%d new=%d", count, i, value));
  5637. - count++;
  5638. - }
  5639. - }
  5640. - }
  5641. -
  5642. - // We have entries mapped between the new and merged constant pools
  5643. - // so we have to rewrite some constant pool references.
  5644. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  5645. - return JVMTI_ERROR_INTERNAL;
  5646. - }
  5647. -
  5648. - // Replace the new constant pool with a shrunken copy of the
  5649. - // merged constant pool so now the rewritten bytecodes have
  5650. - // valid references; the previous new constant pool will get
  5651. - // GCed.
  5652. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  5653. - THREAD);
  5654. - merge_cp()->set_is_conc_safe(true);
  5655. - }
  5656. - assert(old_cp()->is_conc_safe(), "Just checking");
  5657. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  5658. -
  5659. - return JVMTI_ERROR_NONE;
  5660. -} // end merge_cp_and_rewrite()
  5661. -
  5662. -
  5663. -// Rewrite constant pool references in klass scratch_class.
  5664. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  5665. - TRAPS) {
  5666. -
  5667. - // rewrite constant pool references in the methods:
  5668. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  5669. - // propagate failure back to caller
  5670. - return false;
  5671. - }
  5672. -
  5673. - // rewrite constant pool references in the class_annotations:
  5674. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  5675. - // propagate failure back to caller
  5676. - return false;
  5677. - }
  5678. -
  5679. - // rewrite constant pool references in the fields_annotations:
  5680. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  5681. - // propagate failure back to caller
  5682. - return false;
  5683. - }
  5684. -
  5685. - // rewrite constant pool references in the methods_annotations:
  5686. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  5687. - // propagate failure back to caller
  5688. - return false;
  5689. - }
  5690. -
  5691. - // rewrite constant pool references in the methods_parameter_annotations:
  5692. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  5693. - THREAD)) {
  5694. - // propagate failure back to caller
  5695. - return false;
  5696. - }
  5697. -
  5698. - // rewrite constant pool references in the methods_default_annotations:
  5699. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  5700. - THREAD)) {
  5701. - // propagate failure back to caller
  5702. - return false;
  5703. - }
  5704. -
  5705. - return true;
  5706. -} // end rewrite_cp_refs()
  5707. -
  5708. -
  5709. -// Rewrite constant pool references in the methods.
  5710. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  5711. - instanceKlassHandle scratch_class, TRAPS) {
  5712. -
  5713. - objArrayHandle methods(THREAD, scratch_class->methods());
  5714. -
  5715. - if (methods.is_null() || methods->length() == 0) {
  5716. - // no methods so nothing to do
  5717. - return true;
  5718. - }
  5719. -
  5720. - // rewrite constant pool references in the methods:
  5721. - for (int i = methods->length() - 1; i >= 0; i--) {
  5722. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  5723. - methodHandle new_method;
  5724. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  5725. - if (!new_method.is_null()) {
  5726. - // the method has been replaced so save the new method version
  5727. - methods->obj_at_put(i, new_method());
  5728. - }
  5729. - }
  5730. -
  5731. - return true;
  5732. -}
  5733. -
  5734. -
  5735. -// Rewrite constant pool references in the specific method. This code
  5736. -// was adapted from Rewriter::rewrite_method().
  5737. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  5738. - methodHandle *new_method_p, TRAPS) {
  5739. -
  5740. - *new_method_p = methodHandle(); // default is no new method
  5741. -
  5742. - // We cache a pointer to the bytecodes here in code_base. If GC
  5743. - // moves the methodOop, then the bytecodes will also move which
  5744. - // will likely cause a crash. We create a No_Safepoint_Verifier
  5745. - // object to detect whether we pass a possible safepoint in this
  5746. - // code block.
  5747. - No_Safepoint_Verifier nsv;
  5748. -
  5749. - // Bytecodes and their length
  5750. - address code_base = method->code_base();
  5751. - int code_length = method->code_size();
  5752. -
  5753. - int bc_length;
  5754. - for (int bci = 0; bci < code_length; bci += bc_length) {
  5755. - address bcp = code_base + bci;
  5756. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  5757. -
  5758. - bc_length = Bytecodes::length_for(c);
  5759. - if (bc_length == 0) {
  5760. - // More complicated bytecodes report a length of zero so
  5761. - // we have to try again a slightly different way.
  5762. - bc_length = Bytecodes::length_at(method(), bcp);
  5763. - }
  5764. -
  5765. - assert(bc_length != 0, "impossible bytecode length");
  5766. -
  5767. - switch (c) {
  5768. - case Bytecodes::_ldc:
  5769. - {
  5770. - int cp_index = *(bcp + 1);
  5771. - int new_index = find_new_index(cp_index);
  5772. -
  5773. - if (StressLdcRewrite && new_index == 0) {
  5774. - // If we are stressing ldc -> ldc_w rewriting, then we
  5775. - // always need a new_index value.
  5776. - new_index = cp_index;
  5777. - }
  5778. - if (new_index != 0) {
  5779. - // the original index is mapped so we have more work to do
  5780. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  5781. - // The new value can still use ldc instead of ldc_w
  5782. - // unless we are trying to stress ldc -> ldc_w rewriting
  5783. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5784. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  5785. - bcp, cp_index, new_index));
  5786. - *(bcp + 1) = new_index;
  5787. - } else {
  5788. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5789. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  5790. - Bytecodes::name(c), bcp, cp_index, new_index));
  5791. - // the new value needs ldc_w instead of ldc
  5792. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  5793. - bcp = (address)inst_buffer;
  5794. - // construct new instruction sequence
  5795. - *bcp = Bytecodes::_ldc_w;
  5796. - bcp++;
  5797. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  5798. - // See comment below for difference between put_Java_u2()
  5799. - // and put_native_u2().
  5800. - Bytes::put_Java_u2(bcp, new_index);
  5801. -
  5802. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  5803. - methodHandle m;
  5804. - {
  5805. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  5806. -
  5807. - // ldc is 2 bytes and ldc_w is 3 bytes
  5808. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  5809. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  5810. - guarantee(false, "insert_space_at() failed");
  5811. - }
  5812. - }
  5813. -
  5814. - // return the new method so that the caller can update
  5815. - // the containing class
  5816. - *new_method_p = method = m;
  5817. - // switch our bytecode processing loop from the old method
  5818. - // to the new method
  5819. - code_base = method->code_base();
  5820. - code_length = method->code_size();
  5821. - bcp = code_base + bci;
  5822. - c = (Bytecodes::Code)(*bcp);
  5823. - bc_length = Bytecodes::length_for(c);
  5824. - assert(bc_length != 0, "sanity check");
  5825. - } // end we need ldc_w instead of ldc
  5826. - } // end if there is a mapped index
  5827. - } break;
  5828. -
  5829. - // these bytecodes have a two-byte constant pool index
  5830. - case Bytecodes::_anewarray : // fall through
  5831. - case Bytecodes::_checkcast : // fall through
  5832. - case Bytecodes::_getfield : // fall through
  5833. - case Bytecodes::_getstatic : // fall through
  5834. - case Bytecodes::_instanceof : // fall through
  5835. - case Bytecodes::_invokeinterface: // fall through
  5836. - case Bytecodes::_invokespecial : // fall through
  5837. - case Bytecodes::_invokestatic : // fall through
  5838. - case Bytecodes::_invokevirtual : // fall through
  5839. - case Bytecodes::_ldc_w : // fall through
  5840. - case Bytecodes::_ldc2_w : // fall through
  5841. - case Bytecodes::_multianewarray : // fall through
  5842. - case Bytecodes::_new : // fall through
  5843. - case Bytecodes::_putfield : // fall through
  5844. - case Bytecodes::_putstatic :
  5845. - {
  5846. - address p = bcp + 1;
  5847. - int cp_index = Bytes::get_Java_u2(p);
  5848. - int new_index = find_new_index(cp_index);
  5849. - if (new_index != 0) {
  5850. - // the original index is mapped so update w/ new value
  5851. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  5852. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  5853. - bcp, cp_index, new_index));
  5854. - // Rewriter::rewrite_method() uses put_native_u2() in this
  5855. - // situation because it is reusing the constant pool index
  5856. - // location for a native index into the constantPoolCache.
  5857. - // Since we are updating the constant pool index prior to
  5858. - // verification and constantPoolCache initialization, we
  5859. - // need to keep the new index in Java byte order.
  5860. - Bytes::put_Java_u2(p, new_index);
  5861. - }
  5862. - } break;
  5863. + u2 num = the_class->next_method_idnum();
  5864. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5865. + // cannot add any more methods
  5866. + result = result | Klass::ModifyClass;
  5867. + }
  5868. + u2 new_num = k_new_method->method_idnum();
  5869. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5870. + if (idnum_owner != NULL) {
  5871. + // There is already a method assigned this idnum -- switch them
  5872. + idnum_owner->set_method_idnum(new_num);
  5873. + }
  5874. + k_new_method->set_method_idnum(num);
  5875. + swap_all_method_annotations(new_num, num, new_class);
  5876. }
  5877. - } // end for each bytecode
  5878. -} // end rewrite_cp_refs_in_method()
  5879. -
  5880. -
  5881. -// Rewrite constant pool references in the class_annotations field.
  5882. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  5883. - instanceKlassHandle scratch_class, TRAPS) {
  5884. + TRACE_RC1("Method added: new: %s [%d]",
  5885. + k_new_method->name_and_sig_as_C_string(), ni);
  5886. + ++ni; // advance to next new method
  5887. + break;
  5888. + case deleted:
  5889. + // method deleted, see if it is OK
  5890. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5891. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5892. + // hack: private should be treated as final, but alas
  5893. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5894. + ) {
  5895. + // deleted methods must be private
  5896. + result = result | Klass::ModifyClass;
  5897. + }
  5898. + TRACE_RC1("Method deleted: old: %s [%d]",
  5899. + k_old_method->name_and_sig_as_C_string(), oi);
  5900. + ++oi; // advance to next old method
  5901. + break;
  5902. + default:
  5903. + ShouldNotReachHere();
  5904. + }
  5905. + }
  5906. - typeArrayHandle class_annotations(THREAD,
  5907. - scratch_class->class_annotations());
  5908. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  5909. - // no class_annotations so nothing to do
  5910. - return true;
  5911. + if (new_class()->size() != new_class->old_version()->size()) {
  5912. + result |= Klass::ModifyClassSize;
  5913. }
  5914. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5915. - ("class_annotations length=%d", class_annotations->length()));
  5916. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  5917. + result |= Klass::ModifyInstanceSize;
  5918. + }
  5919. - int byte_i = 0; // byte index into class_annotations
  5920. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  5921. - THREAD);
  5922. + // (tw) Check method bodies to be able to return NoChange?
  5923. + return result;
  5924. }
  5925. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  5926. -// Rewrite constant pool references in an annotations typeArray. This
  5927. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  5928. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  5929. -//
  5930. -// annotations_typeArray {
  5931. -// u2 num_annotations;
  5932. -// annotation annotations[num_annotations];
  5933. -// }
  5934. -//
  5935. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  5936. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  5937. -
  5938. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  5939. - // not enough room for num_annotations field
  5940. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5941. - ("length() is too small for num_annotations field"));
  5942. - return false;
  5943. - }
  5944. + class CalculateFieldUpdates : public FieldClosure {
  5945. - u2 num_annotations = Bytes::get_Java_u2((address)
  5946. - annotations_typeArray->byte_at_addr(byte_i_ref));
  5947. - byte_i_ref += 2;
  5948. + private:
  5949. + instanceKlass* _old_ik;
  5950. + GrowableArray<int> _update_info;
  5951. + int _position;
  5952. + bool _copy_backwards;
  5953. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5954. - ("num_annotations=%d", num_annotations));
  5955. + public:
  5956. - int calc_num_annotations = 0;
  5957. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  5958. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  5959. - byte_i_ref, THREAD)) {
  5960. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5961. - ("bad annotation_struct at %d", calc_num_annotations));
  5962. - // propagate failure back to caller
  5963. - return false;
  5964. + bool does_copy_backwards() {
  5965. + return _copy_backwards;
  5966. }
  5967. - }
  5968. - assert(num_annotations == calc_num_annotations, "sanity check");
  5969. - return true;
  5970. -} // end rewrite_cp_refs_in_annotations_typeArray()
  5971. + CalculateFieldUpdates(instanceKlass* old_ik) :
  5972. + _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
  5973. + _update_info.append(_position);
  5974. + _update_info.append(0);
  5975. + }
  5976. + GrowableArray<int> &finish() {
  5977. + _update_info.append(0);
  5978. + return _update_info;
  5979. + }
  5980. -// Rewrite constant pool references in the annotation struct portion of
  5981. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  5982. -// the 2nd-edition of the VM spec:
  5983. -//
  5984. -// struct annotation {
  5985. -// u2 type_index;
  5986. -// u2 num_element_value_pairs;
  5987. -// {
  5988. -// u2 element_name_index;
  5989. -// element_value value;
  5990. -// } element_value_pairs[num_element_value_pairs];
  5991. -// }
  5992. -//
  5993. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  5994. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  5995. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  5996. - // not enough room for smallest annotation_struct
  5997. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  5998. - ("length() is too small for annotation_struct"));
  5999. - return false;
  6000. - }
  6001. + void do_field(fieldDescriptor* fd) {
  6002. + int alignment = fd->offset() - _position;
  6003. + if (alignment > 0) {
  6004. + // This field was aligned, so we need to make sure that we fill the gap
  6005. + fill(alignment);
  6006. + }
  6007. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  6008. - byte_i_ref, "mapped old type_index=%d", THREAD);
  6009. + assert(_position == fd->offset(), "must be correct offset!");
  6010. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  6011. - annotations_typeArray->byte_at_addr(
  6012. - byte_i_ref));
  6013. - byte_i_ref += 2;
  6014. + fieldDescriptor old_fd;
  6015. + if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
  6016. + // Found field in the old class, copy
  6017. + copy(old_fd.offset(), type2aelembytes(fd->field_type()));
  6018. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6019. - ("type_index=%d num_element_value_pairs=%d", type_index,
  6020. - num_element_value_pairs));
  6021. + if (old_fd.offset() < fd->offset()) {
  6022. + _copy_backwards = true;
  6023. + }
  6024. - int calc_num_element_value_pairs = 0;
  6025. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  6026. - calc_num_element_value_pairs++) {
  6027. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6028. - // not enough room for another element_name_index, let alone
  6029. - // the rest of another component
  6030. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6031. - ("length() is too small for element_name_index"));
  6032. - return false;
  6033. + // Transfer special flags
  6034. + fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
  6035. + fd->set_is_field_access_watched(old_fd.is_field_access_watched());
  6036. + } else {
  6037. + // New field, fill
  6038. + fill(type2aelembytes(fd->field_type()));
  6039. + }
  6040. }
  6041. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  6042. - annotations_typeArray, byte_i_ref,
  6043. - "mapped old element_name_index=%d", THREAD);
  6044. + private:
  6045. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6046. - ("element_name_index=%d", element_name_index));
  6047. -
  6048. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  6049. - byte_i_ref, THREAD)) {
  6050. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6051. - ("bad element_value at %d", calc_num_element_value_pairs));
  6052. - // propagate failure back to caller
  6053. - return false;
  6054. + void fill(int size) {
  6055. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
  6056. + (*_update_info.adr_at(_update_info.length() - 1)) -= size;
  6057. + } else {
  6058. + _update_info.append(-size);
  6059. + }
  6060. + _position += size;
  6061. }
  6062. - } // end for each component
  6063. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  6064. - "sanity check");
  6065. -
  6066. - return true;
  6067. -} // end rewrite_cp_refs_in_annotation_struct()
  6068. -
  6069. -
  6070. -// Rewrite a constant pool reference at the current position in
  6071. -// annotations_typeArray if needed. Returns the original constant
  6072. -// pool reference if a rewrite was not needed or the new constant
  6073. -// pool reference if a rewrite was needed.
  6074. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  6075. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  6076. - const char * trace_mesg, TRAPS) {
  6077. -
  6078. - address cp_index_addr = (address)
  6079. - annotations_typeArray->byte_at_addr(byte_i_ref);
  6080. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  6081. - u2 new_cp_index = find_new_index(old_cp_index);
  6082. - if (new_cp_index != 0) {
  6083. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  6084. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  6085. - old_cp_index = new_cp_index;
  6086. - }
  6087. - byte_i_ref += 2;
  6088. - return old_cp_index;
  6089. -}
  6090. -
  6091. -
  6092. -// Rewrite constant pool references in the element_value portion of an
  6093. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  6094. -// the 2nd-edition of the VM spec:
  6095. -//
  6096. -// struct element_value {
  6097. -// u1 tag;
  6098. -// union {
  6099. -// u2 const_value_index;
  6100. -// {
  6101. -// u2 type_name_index;
  6102. -// u2 const_name_index;
  6103. -// } enum_const_value;
  6104. -// u2 class_info_index;
  6105. -// annotation annotation_value;
  6106. -// struct {
  6107. -// u2 num_values;
  6108. -// element_value values[num_values];
  6109. -// } array_value;
  6110. -// } value;
  6111. -// }
  6112. -//
  6113. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  6114. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  6115. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  6116. - // not enough room for a tag let alone the rest of an element_value
  6117. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6118. - ("length() is too small for a tag"));
  6119. - return false;
  6120. - }
  6121. + void copy(int offset, int size) {
  6122. + int prev_end = -1;
  6123. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
  6124. + prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
  6125. + }
  6126. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  6127. - byte_i_ref++;
  6128. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  6129. -
  6130. - switch (tag) {
  6131. - // These BaseType tag values are from Table 4.2 in VM spec:
  6132. - case 'B': // byte
  6133. - case 'C': // char
  6134. - case 'D': // double
  6135. - case 'F': // float
  6136. - case 'I': // int
  6137. - case 'J': // long
  6138. - case 'S': // short
  6139. - case 'Z': // boolean
  6140. -
  6141. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  6142. - // the VM spec:
  6143. - case 's':
  6144. - {
  6145. - // For the above tag values (including the BaseType values),
  6146. - // value.const_value_index is right union field.
  6147. -
  6148. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6149. - // not enough room for a const_value_index
  6150. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6151. - ("length() is too small for a const_value_index"));
  6152. - return false;
  6153. + if (prev_end == offset) {
  6154. + (*_update_info.adr_at(_update_info.length() - 2)) += size;
  6155. + } else {
  6156. + _update_info.append(size);
  6157. + _update_info.append(offset);
  6158. }
  6159. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  6160. - annotations_typeArray, byte_i_ref,
  6161. - "mapped old const_value_index=%d", THREAD);
  6162. + _position += size;
  6163. + }
  6164. + };
  6165. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6166. - ("const_value_index=%d", const_value_index));
  6167. - } break;
  6168. + instanceKlass* ik = instanceKlass::cast(new_version);
  6169. + instanceKlass* old_ik = instanceKlass::cast(new_version->klass_part()->old_version());
  6170. + CalculateFieldUpdates cl(old_ik);
  6171. + ik->do_nonstatic_fields(&cl);
  6172. - case 'e':
  6173. - {
  6174. - // for the above tag value, value.enum_const_value is right union field
  6175. + GrowableArray<int> result = cl.finish();
  6176. + ik->store_update_information(result);
  6177. + ik->set_copying_backwards(cl.does_copy_backwards());
  6178. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  6179. - // not enough room for a enum_const_value
  6180. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6181. - ("length() is too small for a enum_const_value"));
  6182. - return false;
  6183. + IF_TRACE_RC2 {
  6184. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  6185. + if (cl.does_copy_backwards()) {
  6186. + TRACE_RC2("\tDoes copy backwards!");
  6187. + }
  6188. + for (int i=0; i<result.length(); i++) {
  6189. + int curNum = result.at(i);
  6190. + if (curNum < 0) {
  6191. + TRACE_RC2("\t%d CLEAN", curNum);
  6192. + } else if (curNum > 0) {
  6193. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  6194. + i++;
  6195. + } else {
  6196. + TRACE_RC2("\tEND");
  6197. }
  6198. + }
  6199. + }
  6200. +}
  6201. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  6202. - annotations_typeArray, byte_i_ref,
  6203. - "mapped old type_name_index=%d", THREAD);
  6204. -
  6205. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  6206. - annotations_typeArray, byte_i_ref,
  6207. - "mapped old const_name_index=%d", THREAD);
  6208. +void VM_RedefineClasses::rollback() {
  6209. + TRACE_RC1("Rolling back redefinition!");
  6210. + SystemDictionary::rollback_redefinition();
  6211. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6212. - ("type_name_index=%d const_name_index=%d", type_name_index,
  6213. - const_name_index));
  6214. - } break;
  6215. + TRACE_RC1("After rolling back system dictionary!");
  6216. + for (int i=0; i<_new_classes->length(); i++) {
  6217. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  6218. + }
  6219. - case 'c':
  6220. - {
  6221. - // for the above tag value, value.class_info_index is right union field
  6222. + for (int i=0; i<_new_classes->length(); i++) {
  6223. + instanceKlassHandle new_class = _new_classes->at(i);
  6224. + new_class->set_redefining(false);
  6225. + new_class->old_version()->klass_part()->set_new_version(NULL);
  6226. + new_class->set_old_version(NULL);
  6227. + }
  6228. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6229. - // not enough room for a class_info_index
  6230. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6231. - ("length() is too small for a class_info_index"));
  6232. - return false;
  6233. - }
  6234. +}
  6235. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  6236. - annotations_typeArray, byte_i_ref,
  6237. - "mapped old class_info_index=%d", THREAD);
  6238. -
  6239. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6240. - ("class_info_index=%d", class_info_index));
  6241. - } break;
  6242. -
  6243. - case '@':
  6244. - // For the above tag value, value.attr_value is the right union
  6245. - // field. This is a nested annotation.
  6246. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  6247. - byte_i_ref, THREAD)) {
  6248. - // propagate failure back to caller
  6249. - return false;
  6250. - }
  6251. - break;
  6252. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  6253. + markOop first_mark = first->mark();
  6254. + markOop second_mark = second->mark();
  6255. + first->set_mark(second_mark);
  6256. + second->set_mark(first_mark);
  6257. +}
  6258. - case '[':
  6259. - {
  6260. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  6261. - // not enough room for a num_values field
  6262. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6263. - ("length() is too small for a num_values field"));
  6264. - return false;
  6265. - }
  6266. - // For the above tag value, value.array_value is the right union
  6267. - // field. This is an array of nested element_value.
  6268. - u2 num_values = Bytes::get_Java_u2((address)
  6269. - annotations_typeArray->byte_at_addr(byte_i_ref));
  6270. - byte_i_ref += 2;
  6271. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  6272. -
  6273. - int calc_num_values = 0;
  6274. - for (; calc_num_values < num_values; calc_num_values++) {
  6275. - if (!rewrite_cp_refs_in_element_value(
  6276. - annotations_typeArray, byte_i_ref, THREAD)) {
  6277. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6278. - ("bad nested element_value at %d", calc_num_values));
  6279. - // propagate failure back to caller
  6280. - return false;
  6281. +class FieldCopier : public FieldClosure {
  6282. + public:
  6283. + void do_field(fieldDescriptor* fd) {
  6284. + instanceKlass* cur = instanceKlass::cast(fd->field_holder());
  6285. + oop cur_oop = cur->java_mirror();
  6286. +
  6287. + instanceKlass* old = instanceKlass::cast(cur->old_version());
  6288. + oop old_oop = old->java_mirror();
  6289. +
  6290. + fieldDescriptor result;
  6291. + bool found = old->find_local_field(fd->name(), fd->signature(), &result);
  6292. + if (found && result.is_static()) {
  6293. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d",
  6294. + fd->name()->as_C_string(), result.offset(), fd->offset());
  6295. + memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
  6296. + old_oop->obj_field_addr<HeapWord>(result.offset()),
  6297. + type2aelembytes(fd->field_type()));
  6298. +
  6299. + // Static fields may have references to java.lang.Class
  6300. + if (fd->field_type() == T_OBJECT) {
  6301. + oop oop = cur_oop->obj_field(fd->offset());
  6302. + if (oop != NULL && oop->is_instanceMirror()) {
  6303. + klassOop klass = java_lang_Class::as_klassOop(oop);
  6304. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  6305. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  6306. + if (klass->klass_part()->new_version() != NULL) {
  6307. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  6308. +
  6309. + cur_oop->obj_field_put(fd->offset(), oop);
  6310. + }
  6311. + }
  6312. }
  6313. }
  6314. - assert(num_values == calc_num_values, "sanity check");
  6315. - } break;
  6316. -
  6317. - default:
  6318. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  6319. - return false;
  6320. - } // end decode tag field
  6321. -
  6322. - return true;
  6323. -} // end rewrite_cp_refs_in_element_value()
  6324. -
  6325. -
  6326. -// Rewrite constant pool references in a fields_annotations field.
  6327. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  6328. - instanceKlassHandle scratch_class, TRAPS) {
  6329. -
  6330. - objArrayHandle fields_annotations(THREAD,
  6331. - scratch_class->fields_annotations());
  6332. + }
  6333. + }
  6334. +};
  6335. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  6336. - // no fields_annotations so nothing to do
  6337. - return true;
  6338. +void VM_RedefineClasses::mark_as_scavengable(nmethod* nm) {
  6339. + if (!nm->on_scavenge_root_list()) {
  6340. + CodeCache::add_scavenge_root_nmethod(nm);
  6341. }
  6342. +}
  6343. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6344. - ("fields_annotations length=%d", fields_annotations->length()));
  6345. +struct StoreBarrier {
  6346. + template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
  6347. +};
  6348. - for (int i = 0; i < fields_annotations->length(); i++) {
  6349. - typeArrayHandle field_annotations(THREAD,
  6350. - (typeArrayOop)fields_annotations->obj_at(i));
  6351. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  6352. - // this field does not have any annotations so skip it
  6353. - continue;
  6354. - }
  6355. +struct StoreNoBarrier {
  6356. + template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
  6357. +};
  6358. - int byte_i = 0; // byte index into field_annotations
  6359. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  6360. - THREAD)) {
  6361. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6362. - ("bad field_annotations at %d", i));
  6363. - // propagate failure back to caller
  6364. - return false;
  6365. +template <class S>
  6366. +class ChangePointersOopClosure : public OopClosureNoHeader {
  6367. + // Forward pointers to instanceKlass and mirror class to new versions
  6368. + template <class T>
  6369. + inline void do_oop_work(T* p) {
  6370. + oop oop = oopDesc::load_decode_heap_oop(p);
  6371. + if (oop == NULL) {
  6372. + return;
  6373. + }
  6374. + if (oop->is_instanceKlass()) {
  6375. + klassOop klass = (klassOop) oop;
  6376. + if (klass->klass_part()->new_version() != NULL) {
  6377. + oop = klass->klass_part()->new_version();
  6378. + S::oop_store(p, oop);
  6379. + }
  6380. + } else if (oop->is_instanceMirror()) {
  6381. + klassOop klass = java_lang_Class::as_klassOop(oop);
  6382. + if (klass != NULL && klass->klass_part()->oop_is_instance()) {
  6383. + assert(oop == instanceKlass::cast(klass)->java_mirror(), "just checking");
  6384. + if (klass->klass_part()->new_version() != NULL) {
  6385. + oop = instanceKlass::cast(klass->klass_part()->new_version())->java_mirror();
  6386. + S::oop_store(p, oop);
  6387. + }
  6388. + }
  6389. }
  6390. }
  6391. - return true;
  6392. -} // end rewrite_cp_refs_in_fields_annotations()
  6393. -
  6394. -
  6395. -// Rewrite constant pool references in a methods_annotations field.
  6396. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  6397. - instanceKlassHandle scratch_class, TRAPS) {
  6398. -
  6399. - objArrayHandle methods_annotations(THREAD,
  6400. - scratch_class->methods_annotations());
  6401. + virtual void do_oop(oop* o) {
  6402. + do_oop_work(o);
  6403. + }
  6404. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  6405. - // no methods_annotations so nothing to do
  6406. - return true;
  6407. + virtual void do_oop(narrowOop* o) {
  6408. + do_oop_work(o);
  6409. }
  6410. +};
  6411. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6412. - ("methods_annotations length=%d", methods_annotations->length()));
  6413. +void VM_RedefineClasses::doit() {
  6414. + Thread *thread = Thread::current();
  6415. +
  6416. + TRACE_RC1("Entering doit!");
  6417. - for (int i = 0; i < methods_annotations->length(); i++) {
  6418. - typeArrayHandle method_annotations(THREAD,
  6419. - (typeArrayOop)methods_annotations->obj_at(i));
  6420. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  6421. - // this method does not have any annotations so skip it
  6422. - continue;
  6423. - }
  6424. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  6425. - int byte_i = 0; // byte index into method_annotations
  6426. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  6427. - THREAD)) {
  6428. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6429. - ("bad method_annotations at %d", i));
  6430. - // propagate failure back to caller
  6431. - return false;
  6432. + if (UseSharedSpaces) {
  6433. + // Sharing is enabled so we remap the shared readonly space to
  6434. + // shared readwrite, private just in case we need to redefine
  6435. + // a shared class. We do the remap during the doit() phase of
  6436. + // the safepoint to be safer.
  6437. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  6438. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  6439. + _result = JVMTI_ERROR_INTERNAL;
  6440. + return;
  6441. }
  6442. }
  6443. +
  6444. + RC_TIMER_START(_timer_prepare_redefinition);
  6445. + for (int i = 0; i < _new_classes->length(); i++) {
  6446. + redefine_single_class(_new_classes->at(i), thread);
  6447. + }
  6448. +
  6449. + // Deoptimize all compiled code that depends on this class
  6450. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  6451. - return true;
  6452. -} // end rewrite_cp_refs_in_methods_annotations()
  6453. + // Adjust constantpool caches and vtables for all classes
  6454. + // that reference methods of the evolved class.
  6455. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  6456. + RC_TIMER_STOP(_timer_prepare_redefinition);
  6457. + RC_TIMER_START(_timer_heap_iteration);
  6458. -// Rewrite constant pool references in a methods_parameter_annotations
  6459. -// field. This "structure" is adapted from the
  6460. -// RuntimeVisibleParameterAnnotations_attribute described in section
  6461. -// 4.8.17 of the 2nd-edition of the VM spec:
  6462. -//
  6463. -// methods_parameter_annotations_typeArray {
  6464. -// u1 num_parameters;
  6465. -// {
  6466. -// u2 num_annotations;
  6467. -// annotation annotations[num_annotations];
  6468. -// } parameter_annotations[num_parameters];
  6469. -// }
  6470. -//
  6471. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  6472. - instanceKlassHandle scratch_class, TRAPS) {
  6473. + class ChangePointersObjectClosure : public ObjectClosure {
  6474. - objArrayHandle methods_parameter_annotations(THREAD,
  6475. - scratch_class->methods_parameter_annotations());
  6476. + private:
  6477. - if (methods_parameter_annotations.is_null()
  6478. - || methods_parameter_annotations->length() == 0) {
  6479. - // no methods_parameter_annotations so nothing to do
  6480. - return true;
  6481. - }
  6482. + OopClosureNoHeader *_closure;
  6483. + bool _needs_instance_update;
  6484. + oop _tmp_obj;
  6485. + int _tmp_obj_size;
  6486. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6487. - ("methods_parameter_annotations length=%d",
  6488. - methods_parameter_annotations->length()));
  6489. + public:
  6490. + ChangePointersObjectClosure(OopClosureNoHeader *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
  6491. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  6492. - typeArrayHandle method_parameter_annotations(THREAD,
  6493. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  6494. - if (method_parameter_annotations.is_null()
  6495. - || method_parameter_annotations->length() == 0) {
  6496. - // this method does not have any parameter annotations so skip it
  6497. - continue;
  6498. - }
  6499. + bool needs_instance_update() {
  6500. + return _needs_instance_update;
  6501. + }
  6502. - if (method_parameter_annotations->length() < 1) {
  6503. - // not enough room for a num_parameters field
  6504. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6505. - ("length() is too small for a num_parameters field at %d", i));
  6506. - return false;
  6507. - }
  6508. + void copy_to_tmp(oop o) {
  6509. + int size = o->size();
  6510. + if (_tmp_obj_size < size) {
  6511. + _tmp_obj_size = size;
  6512. + _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  6513. + }
  6514. + Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
  6515. + }
  6516. - int byte_i = 0; // byte index into method_parameter_annotations
  6517. + virtual void do_object(oop obj) {
  6518. + if (obj->is_instanceKlass()) return;
  6519. + if (obj->is_instanceMirror()) {
  6520. + // static fields may have references to old java.lang.Class instances, update them
  6521. + // at the same time, we don't want to update other oops in the java.lang.Class
  6522. + // Causes SIGSEGV?
  6523. + //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
  6524. + } else {
  6525. + obj->oop_iterate(_closure);
  6526. + }
  6527. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  6528. - byte_i++;
  6529. + if (obj->blueprint()->new_version() != NULL) {
  6530. + Klass* new_klass = obj->blueprint()->new_version()->klass_part();
  6531. + if (obj->is_perm()) {
  6532. + _needs_instance_update = true;
  6533. + } else if(new_klass->update_information() != NULL) {
  6534. + int size_diff = obj->size() - obj->size_given_klass(new_klass);
  6535. +
  6536. + // Either new size is bigger or gap is to small to be filled
  6537. + if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
  6538. + // We need an instance update => set back to old klass
  6539. + _needs_instance_update = true;
  6540. + } else {
  6541. + oop src = obj;
  6542. + if (new_klass->is_copying_backwards()) {
  6543. + copy_to_tmp(obj);
  6544. + src = _tmp_obj;
  6545. + }
  6546. + src->set_klass_no_check(obj->blueprint()->new_version());
  6547. + MarkSweep::update_fields(obj, src, new_klass->update_information());
  6548. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6549. - ("num_parameters=%d", num_parameters));
  6550. + if (size_diff > 0) {
  6551. + HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
  6552. + CollectedHeap::fill_with_object(dead_space, size_diff);
  6553. + }
  6554. + }
  6555. + } else {
  6556. + obj->set_klass_no_check(obj->blueprint()->new_version());
  6557. + }
  6558. + }
  6559. + }
  6560. + };
  6561. +
  6562. + ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
  6563. + ChangePointersOopClosure<StoreBarrier> oopClosure;
  6564. + ChangePointersObjectClosure objectClosure(&oopClosure);
  6565. - int calc_num_parameters = 0;
  6566. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  6567. - if (!rewrite_cp_refs_in_annotations_typeArray(
  6568. - method_parameter_annotations, byte_i, THREAD)) {
  6569. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6570. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  6571. - // propagate failure back to caller
  6572. - return false;
  6573. + {
  6574. + // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
  6575. + // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
  6576. + // mark such nmethod's as "scavengable".
  6577. + // For now, mark all nmethod's as scavengable that are not scavengable already
  6578. + if (ScavengeRootsInCode) {
  6579. + CodeCache::nmethods_do(mark_as_scavengable);
  6580. }
  6581. +
  6582. + SharedHeap::heap()->gc_prologue(true);
  6583. + Universe::heap()->object_iterate(&objectClosure);
  6584. + Universe::root_oops_do(&oopClosureNoBarrier);
  6585. + SharedHeap::heap()->gc_epilogue(false);
  6586. }
  6587. - assert(num_parameters == calc_num_parameters, "sanity check");
  6588. - }
  6589. - return true;
  6590. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  6591. + for (int i=0; i<_new_classes->length(); i++) {
  6592. + klassOop cur_oop = _new_classes->at(i)();
  6593. + instanceKlass* cur = instanceKlass::cast(cur_oop);
  6594. + klassOop old_oop = cur->old_version();
  6595. + instanceKlass* old = instanceKlass::cast(old_oop);
  6596. -// Rewrite constant pool references in a methods_default_annotations
  6597. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  6598. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  6599. -//
  6600. -// methods_default_annotations_typeArray {
  6601. -// element_value default_value;
  6602. -// }
  6603. -//
  6604. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  6605. - instanceKlassHandle scratch_class, TRAPS) {
  6606. + // Swap marks to have same hashcodes
  6607. + swap_marks(cur_oop, old_oop);
  6608. + swap_marks(cur->java_mirror(), old->java_mirror());
  6609. - objArrayHandle methods_default_annotations(THREAD,
  6610. - scratch_class->methods_default_annotations());
  6611. + // Revert pool holder for old version of klass (it was updated by one of ours closure!)
  6612. + old->constants()->set_pool_holder(old_oop);
  6613. - if (methods_default_annotations.is_null()
  6614. - || methods_default_annotations->length() == 0) {
  6615. - // no methods_default_annotations so nothing to do
  6616. - return true;
  6617. - }
  6618. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6619. - ("methods_default_annotations length=%d",
  6620. - methods_default_annotations->length()));
  6621. + if (old->array_klasses() != NULL) {
  6622. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  6623. + assert(cur->array_klasses() == NULL, "just checking");
  6624. + cur->set_array_klasses(old->array_klasses());
  6625. + }
  6626. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  6627. - typeArrayHandle method_default_annotations(THREAD,
  6628. - (typeArrayOop)methods_default_annotations->obj_at(i));
  6629. - if (method_default_annotations.is_null()
  6630. - || method_default_annotations->length() == 0) {
  6631. - // this method does not have any default annotations so skip it
  6632. - continue;
  6633. + // Initialize the new class! Special static initialization that does not execute the
  6634. + // static constructor but copies static field values from the old class if name
  6635. + // and signature of a static field match.
  6636. + FieldCopier copier;
  6637. + cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
  6638. + old->set_java_mirror(cur->java_mirror());
  6639. +
  6640. + // Transfer init state
  6641. + instanceKlass::ClassState state = old->init_state();
  6642. + if (state > instanceKlass::linked) {
  6643. + cur->set_init_state(state);
  6644. + }
  6645. }
  6646. - int byte_i = 0; // byte index into method_default_annotations
  6647. + RC_TIMER_STOP(_timer_heap_iteration);
  6648. + RC_TIMER_START(_timer_redefinition);
  6649. + if (objectClosure.needs_instance_update()){
  6650. - if (!rewrite_cp_refs_in_element_value(
  6651. - method_default_annotations, byte_i, THREAD)) {
  6652. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  6653. - ("bad default element_value at %d", i));
  6654. - // propagate failure back to caller
  6655. - return false;
  6656. - }
  6657. + // Do a full garbage collection to update the instance sizes accordingly
  6658. + TRACE_RC1("Before performing full GC!");
  6659. + Universe::set_redefining_gc_run(true);
  6660. + notify_gc_begin(true);
  6661. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  6662. + notify_gc_end();
  6663. + Universe::set_redefining_gc_run(false);
  6664. + TRACE_RC1("GC done!");
  6665. }
  6666. - return true;
  6667. -} // end rewrite_cp_refs_in_methods_default_annotations()
  6668. + // Unmark klassOops as "redefining"
  6669. + for (int i=0; i<_new_classes->length(); i++) {
  6670. + klassOop cur_klass = _new_classes->at(i)();
  6671. + instanceKlass* cur = (instanceKlass*)cur_klass->klass_part();
  6672. + cur->set_redefining(false);
  6673. + cur->clear_update_information();
  6674. + }
  6675. + // Disable any dependent concurrent compilations
  6676. + SystemDictionary::notice_modification();
  6677. -// Rewrite constant pool references in the method's stackmap table.
  6678. -// These "structures" are adapted from the StackMapTable_attribute that
  6679. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  6680. -// (dated 2005.10.26):
  6681. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6682. -//
  6683. -// stack_map {
  6684. -// u2 number_of_entries;
  6685. -// stack_map_frame entries[number_of_entries];
  6686. -// }
  6687. -//
  6688. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  6689. - methodHandle method, TRAPS) {
  6690. + // Set flag indicating that some invariants are no longer true.
  6691. + // See jvmtiExport.hpp for detailed explanation.
  6692. + JvmtiExport::set_has_redefined_a_class();
  6693. - if (!method->has_stackmap_table()) {
  6694. - return;
  6695. - }
  6696. + // Clean up caches in the compiler interface and compiler threads
  6697. + ciObjectFactory::resort_shared_ci_objects();
  6698. - typeArrayOop stackmap_data = method->stackmap_data();
  6699. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  6700. - address stackmap_end = stackmap_p + stackmap_data->length();
  6701. -
  6702. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  6703. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  6704. - stackmap_p += 2;
  6705. -
  6706. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6707. - ("number_of_entries=%u", number_of_entries));
  6708. -
  6709. - // walk through each stack_map_frame
  6710. - u2 calc_number_of_entries = 0;
  6711. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  6712. - // The stack_map_frame structure is a u1 frame_type followed by
  6713. - // 0 or more bytes of data:
  6714. - //
  6715. - // union stack_map_frame {
  6716. - // same_frame;
  6717. - // same_locals_1_stack_item_frame;
  6718. - // same_locals_1_stack_item_frame_extended;
  6719. - // chop_frame;
  6720. - // same_frame_extended;
  6721. - // append_frame;
  6722. - // full_frame;
  6723. - // }
  6724. -
  6725. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  6726. - // The Linux compiler does not like frame_type to be u1 or u2. It
  6727. - // issues the following warning for the first if-statement below:
  6728. - //
  6729. - // "warning: comparison is always true due to limited range of data type"
  6730. - //
  6731. - u4 frame_type = *stackmap_p;
  6732. - stackmap_p++;
  6733. -
  6734. - // same_frame {
  6735. - // u1 frame_type = SAME; /* 0-63 */
  6736. - // }
  6737. - if (frame_type >= 0 && frame_type <= 63) {
  6738. - // nothing more to do for same_frame
  6739. - }
  6740. -
  6741. - // same_locals_1_stack_item_frame {
  6742. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  6743. - // verification_type_info stack[1];
  6744. - // }
  6745. - else if (frame_type >= 64 && frame_type <= 127) {
  6746. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6747. - calc_number_of_entries, frame_type, THREAD);
  6748. - }
  6749. -
  6750. - // reserved for future use
  6751. - else if (frame_type >= 128 && frame_type <= 246) {
  6752. - // nothing more to do for reserved frame_types
  6753. - }
  6754. -
  6755. - // same_locals_1_stack_item_frame_extended {
  6756. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  6757. - // u2 offset_delta;
  6758. - // verification_type_info stack[1];
  6759. - // }
  6760. - else if (frame_type == 247) {
  6761. - stackmap_p += 2;
  6762. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6763. - calc_number_of_entries, frame_type, THREAD);
  6764. - }
  6765. -
  6766. - // chop_frame {
  6767. - // u1 frame_type = CHOP; /* 248-250 */
  6768. - // u2 offset_delta;
  6769. - // }
  6770. - else if (frame_type >= 248 && frame_type <= 250) {
  6771. - stackmap_p += 2;
  6772. - }
  6773. -
  6774. - // same_frame_extended {
  6775. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  6776. - // u2 offset_delta;
  6777. - // }
  6778. - else if (frame_type == 251) {
  6779. - stackmap_p += 2;
  6780. - }
  6781. -
  6782. - // append_frame {
  6783. - // u1 frame_type = APPEND; /* 252-254 */
  6784. - // u2 offset_delta;
  6785. - // verification_type_info locals[frame_type - 251];
  6786. - // }
  6787. - else if (frame_type >= 252 && frame_type <= 254) {
  6788. - assert(stackmap_p + 2 <= stackmap_end,
  6789. - "no room for offset_delta");
  6790. - stackmap_p += 2;
  6791. - u1 len = frame_type - 251;
  6792. - for (u1 i = 0; i < len; i++) {
  6793. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6794. - calc_number_of_entries, frame_type, THREAD);
  6795. - }
  6796. - }
  6797. +#ifdef ASSERT
  6798. - // full_frame {
  6799. - // u1 frame_type = FULL_FRAME; /* 255 */
  6800. - // u2 offset_delta;
  6801. - // u2 number_of_locals;
  6802. - // verification_type_info locals[number_of_locals];
  6803. - // u2 number_of_stack_items;
  6804. - // verification_type_info stack[number_of_stack_items];
  6805. - // }
  6806. - else if (frame_type == 255) {
  6807. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  6808. - "no room for smallest full_frame");
  6809. - stackmap_p += 2;
  6810. -
  6811. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  6812. - stackmap_p += 2;
  6813. -
  6814. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  6815. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6816. - calc_number_of_entries, frame_type, THREAD);
  6817. - }
  6818. + // Universe::verify();
  6819. + // JNIHandles::verify();
  6820. - // Use the largest size for the number_of_stack_items, but only get
  6821. - // the right number of bytes.
  6822. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  6823. - stackmap_p += 2;
  6824. + SystemDictionary::classes_do(check_class, thread);
  6825. +#endif
  6826. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  6827. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  6828. - calc_number_of_entries, frame_type, THREAD);
  6829. - }
  6830. - }
  6831. - } // end while there is a stack_map_frame
  6832. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  6833. -} // end rewrite_cp_refs_in_stack_map_table()
  6834. + RC_TIMER_STOP(_timer_redefinition);
  6835. + if (TraceRedefineClasses > 0) {
  6836. + tty->flush();
  6837. + }
  6838. +}
  6839. -// Rewrite constant pool references in the verification type info
  6840. -// portion of the method's stackmap table. These "structures" are
  6841. -// adapted from the StackMapTable_attribute that is described in
  6842. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  6843. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  6844. -//
  6845. -// The verification_type_info structure is a u1 tag followed by 0 or
  6846. -// more bytes of data:
  6847. -//
  6848. -// union verification_type_info {
  6849. -// Top_variable_info;
  6850. -// Integer_variable_info;
  6851. -// Float_variable_info;
  6852. -// Long_variable_info;
  6853. -// Double_variable_info;
  6854. -// Null_variable_info;
  6855. -// UninitializedThis_variable_info;
  6856. -// Object_variable_info;
  6857. -// Uninitialized_variable_info;
  6858. -// }
  6859. -//
  6860. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  6861. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  6862. - u1 frame_type, TRAPS) {
  6863. -
  6864. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  6865. - u1 tag = *stackmap_p_ref;
  6866. - stackmap_p_ref++;
  6867. -
  6868. - switch (tag) {
  6869. - // Top_variable_info {
  6870. - // u1 tag = ITEM_Top; /* 0 */
  6871. - // }
  6872. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  6873. - case 0: // fall through
  6874. -
  6875. - // Integer_variable_info {
  6876. - // u1 tag = ITEM_Integer; /* 1 */
  6877. - // }
  6878. - case ITEM_Integer: // fall through
  6879. -
  6880. - // Float_variable_info {
  6881. - // u1 tag = ITEM_Float; /* 2 */
  6882. - // }
  6883. - case ITEM_Float: // fall through
  6884. -
  6885. - // Double_variable_info {
  6886. - // u1 tag = ITEM_Double; /* 3 */
  6887. - // }
  6888. - case ITEM_Double: // fall through
  6889. -
  6890. - // Long_variable_info {
  6891. - // u1 tag = ITEM_Long; /* 4 */
  6892. - // }
  6893. - case ITEM_Long: // fall through
  6894. -
  6895. - // Null_variable_info {
  6896. - // u1 tag = ITEM_Null; /* 5 */
  6897. - // }
  6898. - case ITEM_Null: // fall through
  6899. -
  6900. - // UninitializedThis_variable_info {
  6901. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  6902. - // }
  6903. - case ITEM_UninitializedThis:
  6904. - // nothing more to do for the above tag types
  6905. - break;
  6906. +void VM_RedefineClasses::doit_epilogue() {
  6907. - // Object_variable_info {
  6908. - // u1 tag = ITEM_Object; /* 7 */
  6909. - // u2 cpool_index;
  6910. - // }
  6911. - case ITEM_Object:
  6912. - {
  6913. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  6914. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  6915. - u2 new_cp_index = find_new_index(cpool_index);
  6916. - if (new_cp_index != 0) {
  6917. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6918. - ("mapped old cpool_index=%d", cpool_index));
  6919. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  6920. - cpool_index = new_cp_index;
  6921. - }
  6922. - stackmap_p_ref += 2;
  6923. -
  6924. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6925. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  6926. - frame_type, cpool_index));
  6927. - } break;
  6928. -
  6929. - // Uninitialized_variable_info {
  6930. - // u1 tag = ITEM_Uninitialized; /* 8 */
  6931. - // u2 offset;
  6932. - // }
  6933. - case ITEM_Uninitialized:
  6934. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  6935. - stackmap_p_ref += 2;
  6936. - break;
  6937. + RC_TIMER_START(_timer_vm_op_epilogue);
  6938. - default:
  6939. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  6940. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  6941. - ShouldNotReachHere();
  6942. - break;
  6943. - } // end switch (tag)
  6944. -} // end rewrite_cp_refs_in_verification_type_info()
  6945. -
  6946. -
  6947. -// Change the constant pool associated with klass scratch_class to
  6948. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  6949. -// are copied from scratch_cp to a smaller constant pool and the
  6950. -// smaller constant pool is associated with scratch_class.
  6951. -void VM_RedefineClasses::set_new_constant_pool(
  6952. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  6953. - int scratch_cp_length, bool shrink, TRAPS) {
  6954. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  6955. -
  6956. - if (shrink) {
  6957. - // scratch_cp is a merged constant pool and has enough space for a
  6958. - // worst case merge situation. We want to associate the minimum
  6959. - // sized constant pool with the klass to save space.
  6960. - constantPoolHandle smaller_cp(THREAD,
  6961. - oopFactory::new_constantPool(scratch_cp_length,
  6962. - oopDesc::IsUnsafeConc,
  6963. - THREAD));
  6964. - // preserve orig_length() value in the smaller copy
  6965. - int orig_length = scratch_cp->orig_length();
  6966. - assert(orig_length != 0, "sanity check");
  6967. - smaller_cp->set_orig_length(orig_length);
  6968. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  6969. - scratch_cp = smaller_cp;
  6970. - smaller_cp()->set_is_conc_safe(true);
  6971. - }
  6972. -
  6973. - // attach new constant pool to klass
  6974. - scratch_cp->set_pool_holder(scratch_class());
  6975. -
  6976. - // attach klass to new constant pool
  6977. - scratch_class->set_constants(scratch_cp());
  6978. -
  6979. - int i; // for portability
  6980. -
  6981. - // update each field in klass to use new constant pool indices as needed
  6982. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  6983. - jshort cur_index = fs.name_index();
  6984. - jshort new_index = find_new_index(cur_index);
  6985. - if (new_index != 0) {
  6986. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6987. - ("field-name_index change: %d to %d", cur_index, new_index));
  6988. - fs.set_name_index(new_index);
  6989. - }
  6990. - cur_index = fs.signature_index();
  6991. - new_index = find_new_index(cur_index);
  6992. - if (new_index != 0) {
  6993. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6994. - ("field-signature_index change: %d to %d", cur_index, new_index));
  6995. - fs.set_signature_index(new_index);
  6996. - }
  6997. - cur_index = fs.initval_index();
  6998. - new_index = find_new_index(cur_index);
  6999. - if (new_index != 0) {
  7000. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7001. - ("field-initval_index change: %d to %d", cur_index, new_index));
  7002. - fs.set_initval_index(new_index);
  7003. - }
  7004. - cur_index = fs.generic_signature_index();
  7005. - new_index = find_new_index(cur_index);
  7006. - if (new_index != 0) {
  7007. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7008. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  7009. - fs.set_generic_signature_index(new_index);
  7010. - }
  7011. - } // end for each field
  7012. -
  7013. - // Update constant pool indices in the inner classes info to use
  7014. - // new constant indices as needed. The inner classes info is a
  7015. - // quadruple:
  7016. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  7017. - InnerClassesIterator iter(scratch_class);
  7018. - for (; !iter.done(); iter.next()) {
  7019. - int cur_index = iter.inner_class_info_index();
  7020. - if (cur_index == 0) {
  7021. - continue; // JVM spec. allows null inner class refs so skip it
  7022. - }
  7023. - int new_index = find_new_index(cur_index);
  7024. - if (new_index != 0) {
  7025. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7026. - ("inner_class_info change: %d to %d", cur_index, new_index));
  7027. - iter.set_inner_class_info_index(new_index);
  7028. - }
  7029. - cur_index = iter.outer_class_info_index();
  7030. - new_index = find_new_index(cur_index);
  7031. - if (new_index != 0) {
  7032. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7033. - ("outer_class_info change: %d to %d", cur_index, new_index));
  7034. - iter.set_outer_class_info_index(new_index);
  7035. - }
  7036. - cur_index = iter.inner_name_index();
  7037. - new_index = find_new_index(cur_index);
  7038. - if (new_index != 0) {
  7039. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7040. - ("inner_name change: %d to %d", cur_index, new_index));
  7041. - iter.set_inner_name_index(new_index);
  7042. - }
  7043. - } // end for each inner class
  7044. -
  7045. - // Attach each method in klass to the new constant pool and update
  7046. - // to use new constant pool indices as needed:
  7047. - objArrayHandle methods(THREAD, scratch_class->methods());
  7048. - for (i = methods->length() - 1; i >= 0; i--) {
  7049. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7050. - method->set_constants(scratch_cp());
  7051. -
  7052. - int new_index = find_new_index(method->name_index());
  7053. - if (new_index != 0) {
  7054. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7055. - ("method-name_index change: %d to %d", method->name_index(),
  7056. - new_index));
  7057. - method->set_name_index(new_index);
  7058. - }
  7059. - new_index = find_new_index(method->signature_index());
  7060. - if (new_index != 0) {
  7061. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7062. - ("method-signature_index change: %d to %d",
  7063. - method->signature_index(), new_index));
  7064. - method->set_signature_index(new_index);
  7065. - }
  7066. - new_index = find_new_index(method->generic_signature_index());
  7067. - if (new_index != 0) {
  7068. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7069. - ("method-generic_signature_index change: %d to %d",
  7070. - method->generic_signature_index(), new_index));
  7071. - method->set_generic_signature_index(new_index);
  7072. - }
  7073. -
  7074. - // Update constant pool indices in the method's checked exception
  7075. - // table to use new constant indices as needed.
  7076. - int cext_length = method->checked_exceptions_length();
  7077. - if (cext_length > 0) {
  7078. - CheckedExceptionElement * cext_table =
  7079. - method->checked_exceptions_start();
  7080. - for (int j = 0; j < cext_length; j++) {
  7081. - int cur_index = cext_table[j].class_cp_index;
  7082. - int new_index = find_new_index(cur_index);
  7083. - if (new_index != 0) {
  7084. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7085. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  7086. - cext_table[j].class_cp_index = (u2)new_index;
  7087. - }
  7088. - } // end for each checked exception table entry
  7089. - } // end if there are checked exception table entries
  7090. -
  7091. - // Update each catch type index in the method's exception table
  7092. - // to use new constant pool indices as needed. The exception table
  7093. - // holds quadruple entries of the form:
  7094. - // (beg_bci, end_bci, handler_bci, klass_index)
  7095. -
  7096. - ExceptionTable ex_table(method());
  7097. - int ext_length = ex_table.length();
  7098. -
  7099. - for (int j = 0; j < ext_length; j ++) {
  7100. - int cur_index = ex_table.catch_type_index(j);
  7101. - int new_index = find_new_index(cur_index);
  7102. - if (new_index != 0) {
  7103. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7104. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  7105. - ex_table.set_catch_type_index(j, new_index);
  7106. - }
  7107. - } // end for each exception table entry
  7108. -
  7109. - // Update constant pool indices in the method's local variable
  7110. - // table to use new constant indices as needed. The local variable
  7111. - // table hold sextuple entries of the form:
  7112. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  7113. - int lvt_length = method->localvariable_table_length();
  7114. - if (lvt_length > 0) {
  7115. - LocalVariableTableElement * lv_table =
  7116. - method->localvariable_table_start();
  7117. - for (int j = 0; j < lvt_length; j++) {
  7118. - int cur_index = lv_table[j].name_cp_index;
  7119. - int new_index = find_new_index(cur_index);
  7120. - if (new_index != 0) {
  7121. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7122. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  7123. - lv_table[j].name_cp_index = (u2)new_index;
  7124. - }
  7125. - cur_index = lv_table[j].descriptor_cp_index;
  7126. - new_index = find_new_index(cur_index);
  7127. - if (new_index != 0) {
  7128. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7129. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  7130. - new_index));
  7131. - lv_table[j].descriptor_cp_index = (u2)new_index;
  7132. - }
  7133. - cur_index = lv_table[j].signature_cp_index;
  7134. - new_index = find_new_index(cur_index);
  7135. - if (new_index != 0) {
  7136. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7137. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  7138. - lv_table[j].signature_cp_index = (u2)new_index;
  7139. - }
  7140. - } // end for each local variable table entry
  7141. - } // end if there are local variable table entries
  7142. + //unlock_threads();
  7143. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  7144. - } // end for each method
  7145. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7146. -} // end set_new_constant_pool()
  7147. + ResourceMark mark;
  7148. + VM_GC_Operation::doit_epilogue();
  7149. + TRACE_RC1("GC Operation epilogue finished! ");
  7150. -// Unevolving classes may point to methods of the_class directly
  7151. -// from their constant pool caches, itables, and/or vtables. We
  7152. -// use the SystemDictionary::classes_do() facility and this helper
  7153. -// to fix up these pointers.
  7154. -//
  7155. -// Note: We currently don't support updating the vtable in
  7156. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7157. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  7158. - oop initiating_loader, TRAPS) {
  7159. - Klass *k = k_oop->klass_part();
  7160. - if (k->oop_is_instance()) {
  7161. - HandleMark hm(THREAD);
  7162. - instanceKlass *ik = (instanceKlass *) k;
  7163. + // Free the array of scratch classes
  7164. + delete _new_classes;
  7165. + _new_classes = NULL;
  7166. - // HotSpot specific optimization! HotSpot does not currently
  7167. - // support delegation from the bootstrap class loader to a
  7168. - // user-defined class loader. This means that if the bootstrap
  7169. - // class loader is the initiating class loader, then it will also
  7170. - // be the defining class loader. This also means that classes
  7171. - // loaded by the bootstrap class loader cannot refer to classes
  7172. - // loaded by a user-defined class loader. Note: a user-defined
  7173. - // class loader can delegate to the bootstrap class loader.
  7174. - //
  7175. - // If the current class being redefined has a user-defined class
  7176. - // loader as its defining class loader, then we can skip all
  7177. - // classes loaded by the bootstrap class loader.
  7178. - bool is_user_defined =
  7179. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  7180. - if (is_user_defined && ik->class_loader() == NULL) {
  7181. - return;
  7182. - }
  7183. + // Free the array of affected classes
  7184. + delete _affected_klasses;
  7185. + _affected_klasses = NULL;
  7186. - // This is a very busy routine. We don't want too much tracing
  7187. - // printed out.
  7188. - bool trace_name_printed = false;
  7189. -
  7190. - // Very noisy: only enable this call if you are trying to determine
  7191. - // that a specific class gets found by this routine.
  7192. - // RC_TRACE macro has an embedded ResourceMark
  7193. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  7194. - // ("adjust check: name=%s", ik->external_name()));
  7195. - // trace_name_printed = true;
  7196. -
  7197. - // Fix the vtable embedded in the_class and subclasses of the_class,
  7198. - // if one exists. We discard scratch_class and we don't keep an
  7199. - // instanceKlass around to hold obsolete methods so we don't have
  7200. - // any other instanceKlass embedded vtables to update. The vtable
  7201. - // holds the methodOops for virtual (but not final) methods.
  7202. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  7203. - // ik->vtable() creates a wrapper object; rm cleans it up
  7204. - ResourceMark rm(THREAD);
  7205. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  7206. - _matching_new_methods,
  7207. - _matching_methods_length,
  7208. - &trace_name_printed);
  7209. - }
  7210. -
  7211. - // If the current class has an itable and we are either redefining an
  7212. - // interface or if the current class is a subclass of the_class, then
  7213. - // we potentially have to fix the itable. If we are redefining an
  7214. - // interface, then we have to call adjust_method_entries() for
  7215. - // every instanceKlass that has an itable since there isn't a
  7216. - // subclass relationship between an interface and an instanceKlass.
  7217. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  7218. - || ik->is_subclass_of(_the_class_oop))) {
  7219. - // ik->itable() creates a wrapper object; rm cleans it up
  7220. - ResourceMark rm(THREAD);
  7221. - ik->itable()->adjust_method_entries(_matching_old_methods,
  7222. - _matching_new_methods,
  7223. - _matching_methods_length,
  7224. - &trace_name_printed);
  7225. - }
  7226. -
  7227. - // The constant pools in other classes (other_cp) can refer to
  7228. - // methods in the_class. We have to update method information in
  7229. - // other_cp's cache. If other_cp has a previous version, then we
  7230. - // have to repeat the process for each previous version. The
  7231. - // constant pool cache holds the methodOops for non-virtual
  7232. - // methods and for virtual, final methods.
  7233. - //
  7234. - // Special case: if the current class is the_class, then new_cp
  7235. - // has already been attached to the_class and old_cp has already
  7236. - // been added as a previous version. The new_cp doesn't have any
  7237. - // cached references to old methods so it doesn't need to be
  7238. - // updated. We can simply start with the previous version(s) in
  7239. - // that case.
  7240. - constantPoolHandle other_cp;
  7241. - constantPoolCacheOop cp_cache;
  7242. -
  7243. - if (k_oop != _the_class_oop) {
  7244. - // this klass' constant pool cache may need adjustment
  7245. - other_cp = constantPoolHandle(ik->constants());
  7246. - cp_cache = other_cp->cache();
  7247. - if (cp_cache != NULL) {
  7248. - cp_cache->adjust_method_entries(_matching_old_methods,
  7249. - _matching_new_methods,
  7250. - _matching_methods_length,
  7251. - &trace_name_printed);
  7252. - }
  7253. - }
  7254. - {
  7255. - ResourceMark rm(THREAD);
  7256. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  7257. - // contain a GrowableArray of handles. We have to clean up the
  7258. - // GrowableArray _after_ the PreviousVersionWalker destructor
  7259. - // has destroyed the handles.
  7260. - {
  7261. - // the previous versions' constant pool caches may need adjustment
  7262. - PreviousVersionWalker pvw(ik);
  7263. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  7264. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  7265. - other_cp = pv_info->prev_constant_pool_handle();
  7266. - cp_cache = other_cp->cache();
  7267. - if (cp_cache != NULL) {
  7268. - cp_cache->adjust_method_entries(_matching_old_methods,
  7269. - _matching_new_methods,
  7270. - _matching_methods_length,
  7271. - &trace_name_printed);
  7272. - }
  7273. - }
  7274. - } // pvw is cleaned up
  7275. - } // rm is cleaned up
  7276. - }
  7277. -}
  7278. + TRACE_RC1("Redefinition finished!");
  7279. -void VM_RedefineClasses::update_jmethod_ids() {
  7280. - for (int j = 0; j < _matching_methods_length; ++j) {
  7281. - methodOop old_method = _matching_old_methods[j];
  7282. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  7283. - if (jmid != NULL) {
  7284. - // There is a jmethodID, change it to point to the new method
  7285. - methodHandle new_method_h(_matching_new_methods[j]);
  7286. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7287. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  7288. - "should be replaced");
  7289. - }
  7290. - }
  7291. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  7292. }
  7293. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  7294. - BitMap *emcp_methods, int * emcp_method_count_p) {
  7295. - *emcp_method_count_p = 0;
  7296. - int obsolete_count = 0;
  7297. - int old_index = 0;
  7298. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  7299. - methodOop old_method = _matching_old_methods[j];
  7300. - methodOop new_method = _matching_new_methods[j];
  7301. - methodOop old_array_method;
  7302. -
  7303. - // Maintain an old_index into the _old_methods array by skipping
  7304. - // deleted methods
  7305. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  7306. - != old_method) {
  7307. - ++old_index;
  7308. - }
  7309. -
  7310. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  7311. - // The EMCP definition from JSR-163 requires the bytecodes to be
  7312. - // the same with the exception of constant pool indices which may
  7313. - // differ. However, the constants referred to by those indices
  7314. - // must be the same.
  7315. - //
  7316. - // We use methods_EMCP() for comparison since constant pool
  7317. - // merging can remove duplicate constant pool entries that were
  7318. - // present in the old method and removed from the rewritten new
  7319. - // method. A faster binary comparison function would consider the
  7320. - // old and new methods to be different when they are actually
  7321. - // EMCP.
  7322. - //
  7323. - // The old and new methods are EMCP and you would think that we
  7324. - // could get rid of one of them here and now and save some space.
  7325. - // However, the concept of EMCP only considers the bytecodes and
  7326. - // the constant pool entries in the comparison. Other things,
  7327. - // e.g., the line number table (LNT) or the local variable table
  7328. - // (LVT) don't count in the comparison. So the new (and EMCP)
  7329. - // method can have a new LNT that we need so we can't just
  7330. - // overwrite the new method with the old method.
  7331. - //
  7332. - // When this routine is called, we have already attached the new
  7333. - // methods to the_class so the old methods are effectively
  7334. - // overwritten. However, if an old method is still executing,
  7335. - // then the old method cannot be collected until sometime after
  7336. - // the old method call has returned. So the overwriting of old
  7337. - // methods by new methods will save us space except for those
  7338. - // (hopefully few) old methods that are still executing.
  7339. - //
  7340. - // A method refers to a constMethodOop and this presents another
  7341. - // possible avenue to space savings. The constMethodOop in the
  7342. - // new method contains possibly new attributes (LNT, LVT, etc).
  7343. - // At first glance, it seems possible to save space by replacing
  7344. - // the constMethodOop in the old method with the constMethodOop
  7345. - // from the new method. The old and new methods would share the
  7346. - // same constMethodOop and we would save the space occupied by
  7347. - // the old constMethodOop. However, the constMethodOop contains
  7348. - // a back reference to the containing method. Sharing the
  7349. - // constMethodOop between two methods could lead to confusion in
  7350. - // the code that uses the back reference. This would lead to
  7351. - // brittle code that could be broken in non-obvious ways now or
  7352. - // in the future.
  7353. - //
  7354. - // Another possibility is to copy the constMethodOop from the new
  7355. - // method to the old method and then overwrite the new method with
  7356. - // the old method. Since the constMethodOop contains the bytecodes
  7357. - // for the method embedded in the oop, this option would change
  7358. - // the bytecodes out from under any threads executing the old
  7359. - // method and make the thread's bcp invalid. Since EMCP requires
  7360. - // that the bytecodes be the same modulo constant pool indices, it
  7361. - // is straight forward to compute the correct new bcp in the new
  7362. - // constMethodOop from the old bcp in the old constMethodOop. The
  7363. - // time consuming part would be searching all the frames in all
  7364. - // of the threads to find all of the calls to the old method.
  7365. - //
  7366. - // It looks like we will have to live with the limited savings
  7367. - // that we get from effectively overwriting the old methods
  7368. - // when the new methods are attached to the_class.
  7369. -
  7370. - // track which methods are EMCP for add_previous_version() call
  7371. - emcp_methods->set_bit(old_index);
  7372. - (*emcp_method_count_p)++;
  7373. -
  7374. - // An EMCP method is _not_ obsolete. An obsolete method has a
  7375. - // different jmethodID than the current method. An EMCP method
  7376. - // has the same jmethodID as the current method. Having the
  7377. - // same jmethodID for all EMCP versions of a method allows for
  7378. - // a consistent view of the EMCP methods regardless of which
  7379. - // EMCP method you happen to have in hand. For example, a
  7380. - // breakpoint set in one EMCP method will work for all EMCP
  7381. - // versions of the method including the current one.
  7382. - } else {
  7383. - // mark obsolete methods as such
  7384. - old_method->set_is_obsolete();
  7385. - obsolete_count++;
  7386. -
  7387. - // obsolete methods need a unique idnum
  7388. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  7389. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  7390. -// u2 old_num = old_method->method_idnum();
  7391. - old_method->set_method_idnum(num);
  7392. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  7393. - }
  7394. - // With tracing we try not to "yack" too much. The position of
  7395. - // this trace assumes there are fewer obsolete methods than
  7396. - // EMCP methods.
  7397. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  7398. - old_method->name()->as_C_string(),
  7399. - old_method->signature()->as_C_string()));
  7400. - }
  7401. - old_method->set_is_old();
  7402. - }
  7403. - for (int i = 0; i < _deleted_methods_length; ++i) {
  7404. - methodOop old_method = _deleted_methods[i];
  7405. -
  7406. - assert(old_method->vtable_index() < 0,
  7407. - "cannot delete methods with vtable entries");;
  7408. -
  7409. - // Mark all deleted methods as old and obsolete
  7410. - old_method->set_is_old();
  7411. - old_method->set_is_obsolete();
  7412. - ++obsolete_count;
  7413. - // With tracing we try not to "yack" too much. The position of
  7414. - // this trace assumes there are fewer obsolete methods than
  7415. - // EMCP methods.
  7416. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  7417. - old_method->name()->as_C_string(),
  7418. - old_method->signature()->as_C_string()));
  7419. - }
  7420. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  7421. - "sanity check");
  7422. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  7423. - obsolete_count));
  7424. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  7425. + // classes for primitives cannot be redefined
  7426. + if (java_lang_Class::is_primitive(klass_mirror)) {
  7427. + return false;
  7428. + }
  7429. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  7430. + // classes for arrays cannot be redefined
  7431. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  7432. + return false;
  7433. + }
  7434. + return true;
  7435. }
  7436. -// This internal class transfers the native function registration from old methods
  7437. -// to new methods. It is designed to handle both the simple case of unchanged
  7438. -// native methods and the complex cases of native method prefixes being added and/or
  7439. -// removed.
  7440. -// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  7441. -//
  7442. -// This class is used after the new methods have been installed in "the_class".
  7443. -//
  7444. -// So, for example, the following must be handled. Where 'm' is a method and
  7445. -// a number followed by an underscore is a prefix.
  7446. -//
  7447. -// Old Name New Name
  7448. -// Simple transfer to new method m -> m
  7449. -// Add prefix m -> 1_m
  7450. -// Remove prefix 1_m -> m
  7451. -// Simultaneous add of prefixes m -> 3_2_1_m
  7452. -// Simultaneous removal of prefixes 3_2_1_m -> m
  7453. -// Simultaneous add and remove 1_m -> 2_m
  7454. -// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  7455. -//
  7456. -class TransferNativeFunctionRegistration {
  7457. - private:
  7458. - instanceKlassHandle the_class;
  7459. - int prefix_count;
  7460. - char** prefixes;
  7461. -
  7462. - // Recursively search the binary tree of possibly prefixed method names.
  7463. - // Iteration could be used if all agents were well behaved. Full tree walk is
  7464. - // more resilent to agents not cleaning up intermediate methods.
  7465. - // Branch at each depth in the binary tree is:
  7466. - // (1) without the prefix.
  7467. - // (2) with the prefix.
  7468. - // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  7469. - methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  7470. - Symbol* signature) {
  7471. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  7472. - if (name_symbol != NULL) {
  7473. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  7474. - if (method != NULL) {
  7475. - // Even if prefixed, intermediate methods must exist.
  7476. - if (method->is_native()) {
  7477. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  7478. - return method;
  7479. - }
  7480. - if (depth < prefix_count) {
  7481. - // Try applying further prefixes (other than this one).
  7482. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  7483. - if (method != NULL) {
  7484. - return method; // found
  7485. - }
  7486. -
  7487. - // Try adding this prefix to the method name and see if it matches
  7488. - // another method name.
  7489. - char* prefix = prefixes[depth];
  7490. - size_t prefix_len = strlen(prefix);
  7491. - size_t trial_len = name_len + prefix_len;
  7492. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  7493. - strcpy(trial_name_str, prefix);
  7494. - strcat(trial_name_str, name_str);
  7495. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  7496. - signature);
  7497. - if (method != NULL) {
  7498. - // If found along this branch, it was prefixed, mark as such
  7499. - method->set_is_prefixed_native();
  7500. - return method; // found
  7501. - }
  7502. - }
  7503. - }
  7504. - }
  7505. - return NULL; // This whole branch bore nothing
  7506. +#ifdef ASSERT
  7507. +
  7508. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7509. + klassOop k_oop = k_oop_latest;
  7510. + while (k_oop != NULL) {
  7511. +
  7512. + instanceKlassHandle k_handle(THREAD, k_oop);
  7513. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  7514. + k_oop = k_oop->klass_part()->old_version();
  7515. }
  7516. +}
  7517. - // Return the method name with old prefixes stripped away.
  7518. - char* method_name_without_prefixes(methodOop method) {
  7519. - Symbol* name = method->name();
  7520. - char* name_str = name->as_utf8();
  7521. +#endif
  7522. - // Old prefixing may be defunct, strip prefixes, if any.
  7523. - for (int i = prefix_count-1; i >= 0; i--) {
  7524. - char* prefix = prefixes[i];
  7525. - size_t prefix_len = strlen(prefix);
  7526. - if (strncmp(prefix, name_str, prefix_len) == 0) {
  7527. - name_str += prefix_len;
  7528. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  7529. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  7530. +// do that, they assume that cache entry is resolved already.
  7531. +void VM_RedefineClasses::unpatch_bytecode(methodOop method) {
  7532. + RawBytecodeStream bcs(method);
  7533. + Bytecodes::Code code;
  7534. + Bytecodes::Code java_code;
  7535. + while (!bcs.is_last_bytecode()) {
  7536. + code = bcs.raw_next();
  7537. + address bcp = bcs.bcp();
  7538. +
  7539. + if (code == Bytecodes::_breakpoint) {
  7540. + int bci = method->bci_from(bcp);
  7541. + code = method->orig_bytecode_at(bci);
  7542. + java_code = Bytecodes::java_code(code);
  7543. + if (code != java_code &&
  7544. + (java_code == Bytecodes::_getfield ||
  7545. + java_code == Bytecodes::_putfield ||
  7546. + java_code == Bytecodes::_aload_0)) {
  7547. + // Let breakpoint table handling unpatch bytecode
  7548. + method->set_orig_bytecode_at(bci, java_code);
  7549. + }
  7550. + } else {
  7551. + java_code = Bytecodes::java_code(code);
  7552. + if (code != java_code &&
  7553. + (java_code == Bytecodes::_getfield ||
  7554. + java_code == Bytecodes::_putfield ||
  7555. + java_code == Bytecodes::_aload_0)) {
  7556. + *bcp = java_code;
  7557. }
  7558. }
  7559. - return name_str;
  7560. - }
  7561. - // Strip any prefixes off the old native method, then try to find a
  7562. - // (possibly prefixed) new native that matches it.
  7563. - methodOop strip_and_search_for_new_native(methodOop method) {
  7564. - ResourceMark rm;
  7565. - char* name_str = method_name_without_prefixes(method);
  7566. - return search_prefix_name_space(0, name_str, strlen(name_str),
  7567. - method->signature());
  7568. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  7569. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  7570. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  7571. + assert(code2 == Bytecodes::_fast_igetfield ||
  7572. + code2 == Bytecodes::_fast_agetfield ||
  7573. + code2 == Bytecodes::_fast_fgetfield, "");
  7574. + *(bcp + 1) = Bytecodes::java_code(code2);
  7575. + }
  7576. }
  7577. +}
  7578. - public:
  7579. +// Unevolving classes may point to old methods directly
  7580. +// from their constant pool caches, itables, and/or vtables. We
  7581. +// use the SystemDictionary::classes_do() facility and this helper
  7582. +// to fix up these pointers. Additional field offsets and vtable indices
  7583. +// in the constant pool cache entries are fixed.
  7584. +//
  7585. +// Note: We currently don't support updating the vtable in
  7586. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  7587. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7588. + klassOop k_oop = k_oop_latest;
  7589. + while (k_oop != NULL) {
  7590. + Klass *k = k_oop->klass_part();
  7591. + if (k->oop_is_instance()) {
  7592. + HandleMark hm(THREAD);
  7593. + instanceKlass *ik = (instanceKlass *) k;
  7594. - // Construct a native method transfer processor for this class.
  7595. - TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  7596. - assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  7597. + constantPoolHandle other_cp;
  7598. + constantPoolCacheOop cp_cache;
  7599. - the_class = _the_class;
  7600. - prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  7601. - }
  7602. + other_cp = constantPoolHandle(ik->constants());
  7603. - // Attempt to transfer any of the old or deleted methods that are native
  7604. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  7605. - for (int j = 0; j < methods_length; j++) {
  7606. - methodOop old_method = old_methods[j];
  7607. + for (int i=0; i<other_cp->length(); i++) {
  7608. + if (other_cp->tag_at(i).is_klass()) {
  7609. + klassOop klass = other_cp->klass_at(i, THREAD);
  7610. + if (klass->klass_part()->new_version() != NULL) {
  7611. - if (old_method->is_native() && old_method->has_native_function()) {
  7612. - methodOop new_method = strip_and_search_for_new_native(old_method);
  7613. - if (new_method != NULL) {
  7614. - // Actually set the native function in the new method.
  7615. - // Redefine does not send events (except CFLH), certainly not this
  7616. - // behind the scenes re-registration.
  7617. - new_method->set_native_function(old_method->native_function(),
  7618. - !methodOopDesc::native_bind_event_is_interesting);
  7619. + // (tw) TODO: check why/if this is necessary
  7620. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  7621. + }
  7622. + klass = other_cp->klass_at(i, THREAD);
  7623. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  7624. }
  7625. }
  7626. +
  7627. + cp_cache = other_cp->cache();
  7628. +
  7629. + if (cp_cache != NULL) {
  7630. + cp_cache->adjust_entries();
  7631. + }
  7632. +
  7633. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
  7634. + if (RewriteBytecodes) {
  7635. + ik->methods_do(unpatch_bytecode);
  7636. + }
  7637. }
  7638. + k_oop = k_oop->klass_part()->old_version();
  7639. }
  7640. -};
  7641. +}
  7642. -// Don't lose the association between a native method and its JNI function.
  7643. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  7644. - TransferNativeFunctionRegistration transfer(the_class);
  7645. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  7646. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  7647. +void VM_RedefineClasses::update_jmethod_ids() {
  7648. + for (int j = 0; j < _matching_methods_length; ++j) {
  7649. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  7650. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  7651. +
  7652. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  7653. + if (old_method->new_version() != NULL && jmid == NULL) {
  7654. + // (tw) Have to create jmethodID in this case
  7655. + jmid = old_method->jmethod_id();
  7656. + }
  7657. +
  7658. + if (jmid != NULL) {
  7659. + // There is a jmethodID, change it to point to the new method
  7660. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  7661. + if (old_method->new_version() == NULL) {
  7662. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  7663. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  7664. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  7665. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  7666. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7667. + } else {
  7668. + jmethodID mid = new_method_h->jmethod_id();
  7669. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  7670. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  7671. + }
  7672. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  7673. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  7674. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  7675. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  7676. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  7677. +
  7678. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  7679. + }
  7680. + }
  7681. }
  7682. +
  7683. // Deoptimize all compiled code that depends on this class.
  7684. //
  7685. // If the can_redefine_classes capability is obtained in the onload
  7686. @@ -2964,7 +1835,10 @@ void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  7687. // All dependencies have been recorded from startup or this is a second or
  7688. // subsequent use of RedefineClasses
  7689. - if (JvmtiExport::all_dependencies_are_recorded()) {
  7690. +
  7691. + // For now deopt all
  7692. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  7693. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  7694. Universe::flush_evol_dependents_on(k_h);
  7695. } else {
  7696. CodeCache::mark_all_nmethods_for_deoptimization();
  7697. @@ -2987,10 +1861,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7698. methodOop old_method;
  7699. methodOop new_method;
  7700. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7701. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7702. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  7703. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  7704. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7705. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7706. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  7707. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  7708. _matching_methods_length = 0;
  7709. _deleted_methods_length = 0;
  7710. @@ -3005,36 +1879,36 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7711. }
  7712. // New method at the end
  7713. new_method = (methodOop) _new_methods->obj_at(nj);
  7714. - _added_methods[_added_methods_length++] = new_method;
  7715. + _added_methods[_added_methods_length++] = nj;
  7716. ++nj;
  7717. } else if (nj >= _new_methods->length()) {
  7718. // Old method, at the end, is deleted
  7719. old_method = (methodOop) _old_methods->obj_at(oj);
  7720. - _deleted_methods[_deleted_methods_length++] = old_method;
  7721. + _deleted_methods[_deleted_methods_length++] = oj;
  7722. ++oj;
  7723. } else {
  7724. old_method = (methodOop) _old_methods->obj_at(oj);
  7725. new_method = (methodOop) _new_methods->obj_at(nj);
  7726. if (old_method->name() == new_method->name()) {
  7727. if (old_method->signature() == new_method->signature()) {
  7728. - _matching_old_methods[_matching_methods_length ] = old_method;
  7729. - _matching_new_methods[_matching_methods_length++] = new_method;
  7730. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  7731. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  7732. ++nj;
  7733. ++oj;
  7734. } else {
  7735. // added overloaded have already been moved to the end,
  7736. // so this is a deleted overloaded method
  7737. - _deleted_methods[_deleted_methods_length++] = old_method;
  7738. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7739. ++oj;
  7740. }
  7741. } else { // names don't match
  7742. if (old_method->name()->fast_compare(new_method->name()) > 0) {
  7743. // new method
  7744. - _added_methods[_added_methods_length++] = new_method;
  7745. + _added_methods[_added_methods_length++] = nj;//new_method;
  7746. ++nj;
  7747. } else {
  7748. // deleted method
  7749. - _deleted_methods[_deleted_methods_length++] = old_method;
  7750. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  7751. ++oj;
  7752. }
  7753. }
  7754. @@ -3042,6 +1916,7 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7755. }
  7756. assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  7757. assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  7758. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  7759. }
  7760. @@ -3049,287 +1924,176 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  7761. // Install the redefinition of a class:
  7762. // - house keeping (flushing breakpoints and caches, deoptimizing
  7763. // dependent compiled code)
  7764. -// - replacing parts in the_class with parts from scratch_class
  7765. -// - adding a weak reference to track the obsolete but interesting
  7766. -// parts of the_class
  7767. // - adjusting constant pool caches and vtables in other classes
  7768. -// that refer to methods in the_class. These adjustments use the
  7769. -// SystemDictionary::classes_do() facility which only allows
  7770. -// a helper method to be specified. The interesting parameters
  7771. -// that we would like to pass to the helper method are saved in
  7772. -// static global fields in the VM operation.
  7773. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  7774. - instanceKlassHandle scratch_class, TRAPS) {
  7775. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  7776. +
  7777. + ResourceMark rm(THREAD);
  7778. - RC_TIMER_START(_timer_rsc_phase1);
  7779. + assert(the_new_class->old_version() != NULL, "Must not be null");
  7780. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  7781. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  7782. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  7783. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  7784. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  7785. +#ifndef JVMTI_KERNEL
  7786. // Remove all breakpoints in methods of this class
  7787. JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  7788. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  7789. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  7790. +#endif // !JVMTI_KERNEL
  7791. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  7792. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  7793. // We are redefining java.lang.reflect.Method. Method.invoke() is
  7794. // cached and users of the cache care about each active version of
  7795. // the method so we have to track this previous version.
  7796. // Do this before methods get switched
  7797. Universe::reflect_invoke_cache()->add_previous_version(
  7798. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7799. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  7800. }
  7801. - // Deoptimize all compiled code that depends on this class
  7802. - flush_dependent_code(the_class, THREAD);
  7803. -
  7804. - _old_methods = the_class->methods();
  7805. - _new_methods = scratch_class->methods();
  7806. - _the_class_oop = the_class_oop;
  7807. + _old_methods = the_old_class->methods();
  7808. + _new_methods = the_new_class->methods();
  7809. compute_added_deleted_matching_methods();
  7810. - update_jmethod_ids();
  7811. -
  7812. - // Attach new constant pool to the original klass. The original
  7813. - // klass still refers to the old constant pool (for now).
  7814. - scratch_class->constants()->set_pool_holder(the_class());
  7815. -
  7816. -#if 0
  7817. - // In theory, with constant pool merging in place we should be able
  7818. - // to save space by using the new, merged constant pool in place of
  7819. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  7820. - // the klass version we are replacing now and any constant pool(s) in
  7821. - // previous versions of klass. Nice theory, doesn't work in practice.
  7822. - // When this code is enabled, even simple programs throw NullPointer
  7823. - // exceptions. I'm guessing that this is caused by some constant pool
  7824. - // cache difference between the new, merged constant pool and the
  7825. - // constant pool that was just being used by the klass. I'm keeping
  7826. - // this code around to archive the idea, but the code has to remain
  7827. - // disabled for now.
  7828. -
  7829. - // Attach each old method to the new constant pool. This can be
  7830. - // done here since we are past the bytecode verification and
  7831. - // constant pool optimization phases.
  7832. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  7833. - methodOop method = (methodOop)_old_methods->obj_at(i);
  7834. - method->set_constants(scratch_class->constants());
  7835. - }
  7836. -
  7837. - {
  7838. - // walk all previous versions of the klass
  7839. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  7840. - PreviousVersionWalker pvw(ik);
  7841. - instanceKlassHandle ikh;
  7842. - do {
  7843. - ikh = pvw.next_previous_version();
  7844. - if (!ikh.is_null()) {
  7845. - ik = ikh();
  7846. -
  7847. - // attach previous version of klass to the new constant pool
  7848. - ik->set_constants(scratch_class->constants());
  7849. -
  7850. - // Attach each method in the previous version of klass to the
  7851. - // new constant pool
  7852. - objArrayOop prev_methods = ik->methods();
  7853. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  7854. - methodOop method = (methodOop)prev_methods->obj_at(i);
  7855. - method->set_constants(scratch_class->constants());
  7856. - }
  7857. - }
  7858. - } while (!ikh.is_null());
  7859. - }
  7860. -#endif
  7861. -
  7862. - // Replace methods and constantpool
  7863. - the_class->set_methods(_new_methods);
  7864. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  7865. - // and to be able to undo operation easily.
  7866. -
  7867. - constantPoolOop old_constants = the_class->constants();
  7868. - the_class->set_constants(scratch_class->constants());
  7869. - scratch_class->set_constants(old_constants); // See the previous comment.
  7870. -#if 0
  7871. - // We are swapping the guts of "the new class" with the guts of "the
  7872. - // class". Since the old constant pool has just been attached to "the
  7873. - // new class", it seems logical to set the pool holder in the old
  7874. - // constant pool also. However, doing this will change the observable
  7875. - // class hierarchy for any old methods that are still executing. A
  7876. - // method can query the identity of its "holder" and this query uses
  7877. - // the method's constant pool link to find the holder. The change in
  7878. - // holding class from "the class" to "the new class" can confuse
  7879. - // things.
  7880. - //
  7881. - // Setting the old constant pool's holder will also cause
  7882. - // verification done during vtable initialization below to fail.
  7883. - // During vtable initialization, the vtable's class is verified to be
  7884. - // a subtype of the method's holder. The vtable's class is "the
  7885. - // class" and the method's holder is gotten from the constant pool
  7886. - // link in the method itself. For "the class"'s directly implemented
  7887. - // methods, the method holder is "the class" itself (as gotten from
  7888. - // the new constant pool). The check works fine in this case. The
  7889. - // check also works fine for methods inherited from super classes.
  7890. - //
  7891. - // Miranda methods are a little more complicated. A miranda method is
  7892. - // provided by an interface when the class implementing the interface
  7893. - // does not provide its own method. These interfaces are implemented
  7894. - // internally as an instanceKlass. These special instanceKlasses
  7895. - // share the constant pool of the class that "implements" the
  7896. - // interface. By sharing the constant pool, the method holder of a
  7897. - // miranda method is the class that "implements" the interface. In a
  7898. - // non-redefine situation, the subtype check works fine. However, if
  7899. - // the old constant pool's pool holder is modified, then the check
  7900. - // fails because there is no class hierarchy relationship between the
  7901. - // vtable's class and "the new class".
  7902. -
  7903. - old_constants->set_pool_holder(scratch_class());
  7904. -#endif
  7905. // track which methods are EMCP for add_previous_version() call below
  7906. - BitMap emcp_methods(_old_methods->length());
  7907. +
  7908. + // (tw) TODO: Check if we need the concept of EMCP?
  7909. + BitMap emcp_methods(_old_methods->length());
  7910. int emcp_method_count = 0;
  7911. emcp_methods.clear(); // clears 0..(length() - 1)
  7912. +
  7913. + // We need to mark methods as old!!
  7914. check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  7915. - transfer_old_native_function_registrations(the_class);
  7916. -
  7917. - // The class file bytes from before any retransformable agents mucked
  7918. - // with them was cached on the scratch class, move to the_class.
  7919. - // Note: we still want to do this if nothing needed caching since it
  7920. - // should get cleared in the_class too.
  7921. - if (the_class->get_cached_class_file_bytes() == 0) {
  7922. - // the_class doesn't have a cache yet so copy it
  7923. - the_class->set_cached_class_file(
  7924. - scratch_class->get_cached_class_file_bytes(),
  7925. - scratch_class->get_cached_class_file_len());
  7926. - }
  7927. -#ifndef PRODUCT
  7928. - else {
  7929. - assert(the_class->get_cached_class_file_bytes() ==
  7930. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  7931. - assert(the_class->get_cached_class_file_len() ==
  7932. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  7933. - }
  7934. -#endif
  7935. + update_jmethod_ids();
  7936. - // Replace inner_classes
  7937. - typeArrayOop old_inner_classes = the_class->inner_classes();
  7938. - the_class->set_inner_classes(scratch_class->inner_classes());
  7939. - scratch_class->set_inner_classes(old_inner_classes);
  7940. + // TODO:
  7941. + transfer_old_native_function_registrations(the_old_class);
  7942. - // Initialize the vtable and interface table after
  7943. - // methods have been rewritten
  7944. - {
  7945. - ResourceMark rm(THREAD);
  7946. - // no exception should happen here since we explicitly
  7947. - // do not check loader constraints.
  7948. - // compare_and_normalize_class_versions has already checked:
  7949. - // - classloaders unchanged, signatures unchanged
  7950. - // - all instanceKlasses for redefined classes reused & contents updated
  7951. - the_class->vtable()->initialize_vtable(false, THREAD);
  7952. - the_class->itable()->initialize_itable(false, THREAD);
  7953. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  7954. - }
  7955. -
  7956. - // Leave arrays of jmethodIDs and itable index cache unchanged
  7957. -
  7958. - // Copy the "source file name" attribute from new class version
  7959. - the_class->set_source_file_name(scratch_class->source_file_name());
  7960. -
  7961. - // Copy the "source debug extension" attribute from new class version
  7962. - the_class->set_source_debug_extension(
  7963. - scratch_class->source_debug_extension(),
  7964. - scratch_class->source_debug_extension() == NULL ? 0 :
  7965. - (int)strlen(scratch_class->source_debug_extension()));
  7966. -
  7967. - // Use of javac -g could be different in the old and the new
  7968. - if (scratch_class->access_flags().has_localvariable_table() !=
  7969. - the_class->access_flags().has_localvariable_table()) {
  7970. -
  7971. - AccessFlags flags = the_class->access_flags();
  7972. - if (scratch_class->access_flags().has_localvariable_table()) {
  7973. - flags.set_has_localvariable_table();
  7974. - } else {
  7975. - flags.clear_has_localvariable_table();
  7976. - }
  7977. - the_class->set_access_flags(flags);
  7978. - }
  7979. -
  7980. - // Replace class annotation fields values
  7981. - typeArrayOop old_class_annotations = the_class->class_annotations();
  7982. - the_class->set_class_annotations(scratch_class->class_annotations());
  7983. - scratch_class->set_class_annotations(old_class_annotations);
  7984. -
  7985. - // Replace fields annotation fields values
  7986. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  7987. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  7988. - scratch_class->set_fields_annotations(old_fields_annotations);
  7989. -
  7990. - // Replace methods annotation fields values
  7991. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  7992. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  7993. - scratch_class->set_methods_annotations(old_methods_annotations);
  7994. -
  7995. - // Replace methods parameter annotation fields values
  7996. - objArrayOop old_methods_parameter_annotations =
  7997. - the_class->methods_parameter_annotations();
  7998. - the_class->set_methods_parameter_annotations(
  7999. - scratch_class->methods_parameter_annotations());
  8000. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  8001. -
  8002. - // Replace methods default annotation fields values
  8003. - objArrayOop old_methods_default_annotations =
  8004. - the_class->methods_default_annotations();
  8005. - the_class->set_methods_default_annotations(
  8006. - scratch_class->methods_default_annotations());
  8007. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  8008. -
  8009. - // Replace minor version number of class file
  8010. - u2 old_minor_version = the_class->minor_version();
  8011. - the_class->set_minor_version(scratch_class->minor_version());
  8012. - scratch_class->set_minor_version(old_minor_version);
  8013. -
  8014. - // Replace major version number of class file
  8015. - u2 old_major_version = the_class->major_version();
  8016. - the_class->set_major_version(scratch_class->major_version());
  8017. - scratch_class->set_major_version(old_major_version);
  8018. -
  8019. - // Replace CP indexes for class and name+type of enclosing method
  8020. - u2 old_class_idx = the_class->enclosing_method_class_index();
  8021. - u2 old_method_idx = the_class->enclosing_method_method_index();
  8022. - the_class->set_enclosing_method_indices(
  8023. - scratch_class->enclosing_method_class_index(),
  8024. - scratch_class->enclosing_method_method_index());
  8025. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  8026. -
  8027. - // keep track of previous versions of this class
  8028. - the_class->add_previous_version(scratch_class, &emcp_methods,
  8029. - emcp_method_count);
  8030. -
  8031. - RC_TIMER_STOP(_timer_rsc_phase1);
  8032. - RC_TIMER_START(_timer_rsc_phase2);
  8033. - // Adjust constantpool caches and vtables for all classes
  8034. - // that reference methods of the evolved class.
  8035. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  8036. - if (the_class->oop_map_cache() != NULL) {
  8037. - // Flush references to any obsolete methods from the oop map cache
  8038. - // so that obsolete methods are not pinned.
  8039. - the_class->oop_map_cache()->flush_obsolete_entries();
  8040. +#ifdef ASSERT
  8041. +
  8042. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8043. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  8044. +
  8045. + //JNIHandles::verify();
  8046. +
  8047. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8048. +
  8049. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  8050. + assert(the_new_class->old_version() != NULL, "Must not be null");
  8051. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  8052. +
  8053. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  8054. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  8055. }
  8056. + _old_methods->verify();
  8057. + _new_methods->verify();
  8058. +
  8059. + the_new_class->vtable()->verify(tty);
  8060. + the_old_class->vtable()->verify(tty);
  8061. +
  8062. +#endif
  8063. +
  8064. // increment the classRedefinedCount field in the_class and in any
  8065. // direct and indirect subclasses of the_class
  8066. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  8067. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  8068. +
  8069. +}
  8070. +
  8071. +
  8072. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  8073. + TRACE_RC3("Checking matching methods for EMCP");
  8074. + *emcp_method_count_p = 0;
  8075. + int obsolete_count = 0;
  8076. + int old_index = 0;
  8077. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8078. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  8079. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  8080. + methodOop old_array_method;
  8081. +
  8082. + // Maintain an old_index into the _old_methods array by skipping
  8083. + // deleted methods
  8084. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8085. + != old_method) {
  8086. + ++old_index;
  8087. + }
  8088. - // RC_TRACE macro has an embedded ResourceMark
  8089. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  8090. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  8091. - the_class->external_name(),
  8092. - java_lang_Class::classRedefinedCount(the_class_mirror),
  8093. - os::available_memory() >> 10));
  8094. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8095. + // The EMCP definition from JSR-163 requires the bytecodes to be
  8096. + // the same with the exception of constant pool indices which may
  8097. + // differ. However, the constants referred to by those indices
  8098. + // must be the same.
  8099. + //
  8100. + // We use methods_EMCP() for comparison since constant pool
  8101. + // merging can remove duplicate constant pool entries that were
  8102. + // present in the old method and removed from the rewritten new
  8103. + // method. A faster binary comparison function would consider the
  8104. + // old and new methods to be different when they are actually
  8105. + // EMCP.
  8106. +
  8107. + // track which methods are EMCP for add_previous_version() call
  8108. + emcp_methods->set_bit(old_index);
  8109. + (*emcp_method_count_p)++;
  8110. +
  8111. + // An EMCP method is _not_ obsolete. An obsolete method has a
  8112. + // different jmethodID than the current method. An EMCP method
  8113. + // has the same jmethodID as the current method. Having the
  8114. + // same jmethodID for all EMCP versions of a method allows for
  8115. + // a consistent view of the EMCP methods regardless of which
  8116. + // EMCP method you happen to have in hand. For example, a
  8117. + // breakpoint set in one EMCP method will work for all EMCP
  8118. + // versions of the method including the current one.
  8119. +
  8120. + old_method->set_new_version(new_method);
  8121. + new_method->set_old_version(old_method);
  8122. +
  8123. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  8124. +
  8125. + // Transfer breakpoints
  8126. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  8127. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  8128. + TRACE_RC2("Checking breakpoint");
  8129. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  8130. + if (bp->match(old_method)) {
  8131. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  8132. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  8133. + new_method->set_breakpoint(bp->bci());
  8134. + }
  8135. + }
  8136. + } else {
  8137. + // mark obsolete methods as such
  8138. + old_method->set_is_obsolete();
  8139. + obsolete_count++;
  8140. +
  8141. + // With tracing we try not to "yack" too much. The position of
  8142. + // this trace assumes there are fewer obsolete methods than
  8143. + // EMCP methods.
  8144. + TRACE_RC3("mark %s(%s) as obsolete",
  8145. + old_method->name()->as_C_string(),
  8146. + old_method->signature()->as_C_string());
  8147. + }
  8148. + old_method->set_is_old();
  8149. + }
  8150. + for (int i = 0; i < _deleted_methods_length; ++i) {
  8151. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  8152. - RC_TIMER_STOP(_timer_rsc_phase2);
  8153. -} // end redefine_single_class()
  8154. + //assert(old_method->vtable_index() < 0,
  8155. + // "cannot delete methods with vtable entries");;
  8156. + // Mark all deleted methods as old and obsolete
  8157. + old_method->set_is_old();
  8158. + old_method->set_is_obsolete();
  8159. + ++obsolete_count;
  8160. + // With tracing we try not to "yack" too much. The position of
  8161. + // this trace assumes there are fewer obsolete methods than
  8162. + // EMCP methods.
  8163. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  8164. + old_method->name()->as_C_string(),
  8165. + old_method->signature()->as_C_string());
  8166. + }
  8167. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  8168. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  8169. +}
  8170. // Increment the classRedefinedCount field in the specific instanceKlass
  8171. // and in all direct and indirect subclasses.
  8172. @@ -3338,134 +2102,267 @@ void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  8173. klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  8174. int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  8175. java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  8176. -
  8177. - if (class_oop != _the_class_oop) {
  8178. - // _the_class_oop count is printed at end of redefine_single_class()
  8179. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  8180. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  8181. - }
  8182. -
  8183. - for (Klass *subk = ik->subklass(); subk != NULL;
  8184. - subk = subk->next_sibling()) {
  8185. - if (subk->oop_is_instance()) {
  8186. - // Only update instanceKlasses
  8187. - instanceKlass *subik = (instanceKlass*)subk;
  8188. - // recursively do subclasses of the current subclass
  8189. - increment_class_counter(subik, THREAD);
  8190. - }
  8191. - }
  8192. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  8193. }
  8194. -void VM_RedefineClasses::check_class(klassOop k_oop,
  8195. - oop initiating_loader, TRAPS) {
  8196. +#ifndef PRODUCT
  8197. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  8198. Klass *k = k_oop->klass_part();
  8199. if (k->oop_is_instance()) {
  8200. HandleMark hm(THREAD);
  8201. instanceKlass *ik = (instanceKlass *) k;
  8202. - bool no_old_methods = true; // be optimistic
  8203. - ResourceMark rm(THREAD);
  8204. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  8205. +
  8206. + if (ik->vtable_length() > 0) {
  8207. + ResourceMark rm(THREAD);
  8208. + if (!ik->vtable()->check_no_old_or_obsolete_entries()) {
  8209. + TRACE_RC1("size of class: %d\n", k_oop->size());
  8210. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  8211. + assert(false, "OLD method found");
  8212. + }
  8213. +
  8214. + ik->vtable()->verify(tty, true);
  8215. + }
  8216. + }
  8217. +}
  8218. +
  8219. +#endif
  8220. - // a vtable should never contain old or obsolete methods
  8221. - if (ik->vtable_length() > 0 &&
  8222. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  8223. - if (RC_TRACE_ENABLED(0x00004000)) {
  8224. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8225. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  8226. - " -- OLD or OBSOLETE method found -- class: %s",
  8227. - ik->signature_name()));
  8228. - ik->vtable()->dump_vtable();
  8229. +static bool match_right(void* value, Pair<klassOop, klassOop> elem) {
  8230. + return elem.right() == value;
  8231. +}
  8232. +
  8233. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS)
  8234. +{
  8235. + GrowableArray< Pair<klassOop, klassOop> > links;
  8236. +
  8237. + for (int i=0; i<class_count; i++) {
  8238. +
  8239. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  8240. + instanceKlassHandle the_class(THREAD, java_lang_Class::as_klassOop(mirror));
  8241. + Handle the_class_loader(THREAD, the_class->class_loader());
  8242. + Handle protection_domain(THREAD, the_class->protection_domain());
  8243. +
  8244. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  8245. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  8246. + ClassFileParser cfp(&st);
  8247. +
  8248. + GrowableArray<Symbol*> symbolArr;
  8249. + TempNewSymbol parsed_name;
  8250. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  8251. + cfp.parseClassFile(the_class->name(), the_class_loader, protection_domain, the_class, KlassHandle(), NULL, &symbolArr, parsed_name, false, THREAD);
  8252. +
  8253. + for (int j=0; j<symbolArr.length(); j++) {
  8254. + Symbol* sym = symbolArr.at(j);
  8255. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  8256. + klassOop super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
  8257. + if (super_klass != NULL) {
  8258. + instanceKlassHandle the_super_class(THREAD, super_klass);
  8259. + if (_affected_klasses->contains(the_super_class)) {
  8260. + TRACE_RC2("Found class to link");
  8261. + links.append(Pair<klassOop, klassOop>(super_klass, the_class()));
  8262. + }
  8263. }
  8264. - no_old_methods = false;
  8265. - }
  8266. -
  8267. - // an itable should never contain old or obsolete methods
  8268. - if (ik->itable_length() > 0 &&
  8269. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  8270. - if (RC_TRACE_ENABLED(0x00004000)) {
  8271. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8272. - ("klassItable::check_no_old_or_obsolete_entries failure"
  8273. - " -- OLD or OBSOLETE method found -- class: %s",
  8274. - ik->signature_name()));
  8275. - ik->itable()->dump_itable();
  8276. + }
  8277. +
  8278. + assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
  8279. + the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
  8280. + }
  8281. +
  8282. +
  8283. + TRACE_RC1("Identified links between classes! ");
  8284. +
  8285. + for (int i=0; i < _affected_klasses->length(); i++) {
  8286. + instanceKlassHandle klass = _affected_klasses->at(i);
  8287. +
  8288. + if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
  8289. + klass->clear_redefinition_flag(Klass::MarkedAsAffected);
  8290. + klassOop superKlass = klass->super();
  8291. + if (_affected_klasses->contains(superKlass)) {
  8292. + links.append(Pair<klassOop, klassOop>(superKlass, klass()));
  8293. }
  8294. - no_old_methods = false;
  8295. - }
  8296. -
  8297. - // the constant pool cache should never contain old or obsolete methods
  8298. - if (ik->constants() != NULL &&
  8299. - ik->constants()->cache() != NULL &&
  8300. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  8301. - if (RC_TRACE_ENABLED(0x00004000)) {
  8302. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  8303. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  8304. - " -- OLD or OBSOLETE method found -- class: %s",
  8305. - ik->signature_name()));
  8306. - ik->constants()->cache()->dump_cache();
  8307. +
  8308. + objArrayOop superInterfaces = klass->local_interfaces();
  8309. + for (int j=0; j<superInterfaces->length(); j++) {
  8310. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  8311. + if (_affected_klasses->contains(interfaceKlass)) {
  8312. + links.append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  8313. + }
  8314. }
  8315. - no_old_methods = false;
  8316. + }
  8317. + }
  8318. +
  8319. + IF_TRACE_RC2 {
  8320. + TRACE_RC2("Identified links: ");
  8321. + for (int i=0; i<links.length(); i++) {
  8322. + TRACE_RC2("%s to %s", links.at(i).left()->klass_part()->name()->as_C_string(),
  8323. + links.at(i).right()->klass_part()->name()->as_C_string());
  8324. + }
  8325. + }
  8326. +
  8327. + for (int i = 0; i < _affected_klasses->length(); i++) {
  8328. + int j;
  8329. + for (j = i; j < _affected_klasses->length(); j++) {
  8330. + // Search for node with no incoming edges
  8331. + klassOop oop = _affected_klasses->at(j)();
  8332. + int k = links.find(oop, match_right);
  8333. + if (k == -1) break;
  8334. + }
  8335. + if (j == _affected_klasses->length()) {
  8336. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  8337. }
  8338. - if (!no_old_methods) {
  8339. - if (RC_TRACE_ENABLED(0x00004000)) {
  8340. - dump_methods();
  8341. + // Remove all links from this node
  8342. + klassOop oop = _affected_klasses->at(j)();
  8343. + int k = 0;
  8344. + while (k < links.length()) {
  8345. + if (links.adr_at(k)->left() == oop) {
  8346. + links.delete_at(k);
  8347. } else {
  8348. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  8349. - "to see more info about the following guarantee() failure.");
  8350. + k++;
  8351. }
  8352. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  8353. }
  8354. +
  8355. + // Swap node
  8356. + instanceKlassHandle tmp = _affected_klasses->at(j);
  8357. + _affected_klasses->at_put(j, _affected_klasses->at(i));
  8358. + _affected_klasses->at_put(i, tmp);
  8359. }
  8360. +
  8361. + return JVMTI_ERROR_NONE;
  8362. }
  8363. -void VM_RedefineClasses::dump_methods() {
  8364. - int j;
  8365. - RC_TRACE(0x00004000, ("_old_methods --"));
  8366. - for (j = 0; j < _old_methods->length(); ++j) {
  8367. - methodOop m = (methodOop) _old_methods->obj_at(j);
  8368. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8369. - m->access_flags().print_on(tty);
  8370. - tty->print(" -- ");
  8371. - m->print_name(tty);
  8372. - tty->cr();
  8373. - }
  8374. - RC_TRACE(0x00004000, ("_new_methods --"));
  8375. - for (j = 0; j < _new_methods->length(); ++j) {
  8376. - methodOop m = (methodOop) _new_methods->obj_at(j);
  8377. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8378. - m->access_flags().print_on(tty);
  8379. - tty->print(" -- ");
  8380. - m->print_name(tty);
  8381. - tty->cr();
  8382. - }
  8383. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  8384. - for (j = 0; j < _matching_methods_length; ++j) {
  8385. - methodOop m = _matching_old_methods[j];
  8386. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8387. - m->access_flags().print_on(tty);
  8388. - tty->print(" -- ");
  8389. - m->print_name(tty);
  8390. - tty->cr();
  8391. - m = _matching_new_methods[j];
  8392. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  8393. - m->access_flags().print_on(tty);
  8394. - tty->cr();
  8395. - }
  8396. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  8397. - for (j = 0; j < _deleted_methods_length; ++j) {
  8398. - methodOop m = _deleted_methods[j];
  8399. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8400. - m->access_flags().print_on(tty);
  8401. - tty->print(" -- ");
  8402. - m->print_name(tty);
  8403. - tty->cr();
  8404. - }
  8405. - RC_TRACE(0x00004000, ("_added_methods --"));
  8406. - for (j = 0; j < _added_methods_length; ++j) {
  8407. - methodOop m = _added_methods[j];
  8408. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  8409. - m->access_flags().print_on(tty);
  8410. - tty->print(" -- ");
  8411. - m->print_name(tty);
  8412. - tty->cr();
  8413. +// This internal class transfers the native function registration from old methods
  8414. +// to new methods. It is designed to handle both the simple case of unchanged
  8415. +// native methods and the complex cases of native method prefixes being added and/or
  8416. +// removed.
  8417. +// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  8418. +//
  8419. +// This class is used after the new methods have been installed in "the_class".
  8420. +//
  8421. +// So, for example, the following must be handled. Where 'm' is a method and
  8422. +// a number followed by an underscore is a prefix.
  8423. +//
  8424. +// Old Name New Name
  8425. +// Simple transfer to new method m -> m
  8426. +// Add prefix m -> 1_m
  8427. +// Remove prefix 1_m -> m
  8428. +// Simultaneous add of prefixes m -> 3_2_1_m
  8429. +// Simultaneous removal of prefixes 3_2_1_m -> m
  8430. +// Simultaneous add and remove 1_m -> 2_m
  8431. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8432. +//
  8433. +class TransferNativeFunctionRegistration {
  8434. +private:
  8435. + instanceKlassHandle the_class;
  8436. + int prefix_count;
  8437. + char** prefixes;
  8438. +
  8439. + // Recursively search the binary tree of possibly prefixed method names.
  8440. + // Iteration could be used if all agents were well behaved. Full tree walk is
  8441. + // more resilent to agents not cleaning up intermediate methods.
  8442. + // Branch at each depth in the binary tree is:
  8443. + // (1) without the prefix.
  8444. + // (2) with the prefix.
  8445. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  8446. + methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  8447. + Symbol* signature) {
  8448. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8449. + if (name_symbol != NULL) {
  8450. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  8451. + if (method != NULL) {
  8452. + // Even if prefixed, intermediate methods must exist.
  8453. + if (method->is_native()) {
  8454. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8455. + return method;
  8456. + }
  8457. + if (depth < prefix_count) {
  8458. + // Try applying further prefixes (other than this one).
  8459. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8460. + if (method != NULL) {
  8461. + return method; // found
  8462. + }
  8463. +
  8464. + // Try adding this prefix to the method name and see if it matches
  8465. + // another method name.
  8466. + char* prefix = prefixes[depth];
  8467. + size_t prefix_len = strlen(prefix);
  8468. + size_t trial_len = name_len + prefix_len;
  8469. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8470. + strcpy(trial_name_str, prefix);
  8471. + strcat(trial_name_str, name_str);
  8472. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8473. + signature);
  8474. + if (method != NULL) {
  8475. + // If found along this branch, it was prefixed, mark as such
  8476. + method->set_is_prefixed_native();
  8477. + return method; // found
  8478. + }
  8479. + }
  8480. + }
  8481. + }
  8482. + return NULL; // This whole branch bore nothing
  8483. + }
  8484. +
  8485. + // Return the method name with old prefixes stripped away.
  8486. + char* method_name_without_prefixes(methodOop method) {
  8487. + Symbol* name = method->name();
  8488. + char* name_str = name->as_utf8();
  8489. +
  8490. + // Old prefixing may be defunct, strip prefixes, if any.
  8491. + for (int i = prefix_count-1; i >= 0; i--) {
  8492. + char* prefix = prefixes[i];
  8493. + size_t prefix_len = strlen(prefix);
  8494. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  8495. + name_str += prefix_len;
  8496. + }
  8497. + }
  8498. + return name_str;
  8499. + }
  8500. +
  8501. + // Strip any prefixes off the old native method, then try to find a
  8502. + // (possibly prefixed) new native that matches it.
  8503. + methodOop strip_and_search_for_new_native(methodOop method) {
  8504. + ResourceMark rm;
  8505. + char* name_str = method_name_without_prefixes(method);
  8506. + return search_prefix_name_space(0, name_str, strlen(name_str),
  8507. + method->signature());
  8508. + }
  8509. +
  8510. +public:
  8511. +
  8512. + // Construct a native method transfer processor for this class.
  8513. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  8514. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  8515. +
  8516. + the_class = _the_class;
  8517. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  8518. + }
  8519. +
  8520. + // Attempt to transfer any of the old or deleted methods that are native
  8521. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  8522. + for (int j = 0; j < methods_length; j++) {
  8523. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  8524. +
  8525. + if (old_method->is_native() && old_method->has_native_function()) {
  8526. + methodOop new_method = strip_and_search_for_new_native(old_method);
  8527. + if (new_method != NULL) {
  8528. + // Actually set the native function in the new method.
  8529. + // Redefine does not send events (except CFLH), certainly not this
  8530. + // behind the scenes re-registration.
  8531. + new_method->set_native_function(old_method->native_function(),
  8532. + !methodOopDesc::native_bind_event_is_interesting);
  8533. +
  8534. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  8535. + }
  8536. + }
  8537. + }
  8538. }
  8539. +};
  8540. +
  8541. +// Don't lose the association between a native method and its JNI function.
  8542. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  8543. + TransferNativeFunctionRegistration transfer(old_klass);
  8544. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  8545. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  8546. }
  8547. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8548. index 671f2ae..8333cee 100644
  8549. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8550. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  8551. @@ -1,5 +1,5 @@
  8552. /*
  8553. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  8554. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  8555. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8556. *
  8557. * This code is free software; you can redistribute it and/or modify it
  8558. @@ -30,332 +30,29 @@
  8559. #include "memory/resourceArea.hpp"
  8560. #include "oops/objArrayKlass.hpp"
  8561. #include "oops/objArrayOop.hpp"
  8562. +#include "oops/fieldStreams.hpp"
  8563. #include "prims/jvmtiRedefineClassesTrace.hpp"
  8564. -#include "runtime/vm_operations.hpp"
  8565. -
  8566. -// Introduction:
  8567. -//
  8568. -// The RedefineClasses() API is used to change the definition of one or
  8569. -// more classes. While the API supports redefining more than one class
  8570. -// in a single call, in general, the API is discussed in the context of
  8571. -// changing the definition of a single current class to a single new
  8572. -// class. For clarity, the current class is will always be called
  8573. -// "the_class" and the new class will always be called "scratch_class".
  8574. -//
  8575. -// The name "the_class" is used because there is only one structure
  8576. -// that represents a specific class; redefinition does not replace the
  8577. -// structure, but instead replaces parts of the structure. The name
  8578. -// "scratch_class" is used because the structure that represents the
  8579. -// new definition of a specific class is simply used to carry around
  8580. -// the parts of the new definition until they are used to replace the
  8581. -// appropriate parts in the_class. Once redefinition of a class is
  8582. -// complete, scratch_class is thrown away.
  8583. -//
  8584. -//
  8585. -// Implementation Overview:
  8586. -//
  8587. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  8588. -// does the real work. The work is split in varying degrees between
  8589. -// doit_prologue(), doit() and doit_epilogue().
  8590. -//
  8591. -// 1) doit_prologue() is called by the JavaThread on the way to a
  8592. -// safepoint. It does parameter verification and loads scratch_class
  8593. -// which involves:
  8594. -// - parsing the incoming class definition using the_class' class
  8595. -// loader and security context
  8596. -// - linking scratch_class
  8597. -// - merging constant pools and rewriting bytecodes as needed
  8598. -// for the merged constant pool
  8599. -// - verifying the bytecodes in scratch_class
  8600. -// - setting up the constant pool cache and rewriting bytecodes
  8601. -// as needed to use the cache
  8602. -// - finally, scratch_class is compared to the_class to verify
  8603. -// that it is a valid replacement class
  8604. -// - if everything is good, then scratch_class is saved in an
  8605. -// instance field in the VM operation for the doit() call
  8606. -//
  8607. -// Note: A JavaThread must do the above work.
  8608. -//
  8609. -// 2) doit() is called by the VMThread during a safepoint. It installs
  8610. -// the new class definition(s) which involves:
  8611. -// - retrieving the scratch_class from the instance field in the
  8612. -// VM operation
  8613. -// - house keeping (flushing breakpoints and caches, deoptimizing
  8614. -// dependent compiled code)
  8615. -// - replacing parts in the_class with parts from scratch_class
  8616. -// - adding weak reference(s) to track the obsolete but interesting
  8617. -// parts of the_class
  8618. -// - adjusting constant pool caches and vtables in other classes
  8619. -// that refer to methods in the_class. These adjustments use the
  8620. -// SystemDictionary::classes_do() facility which only allows
  8621. -// a helper method to be specified. The interesting parameters
  8622. -// that we would like to pass to the helper method are saved in
  8623. -// static global fields in the VM operation.
  8624. -// - telling the SystemDictionary to notice our changes
  8625. -//
  8626. -// Note: the above work must be done by the VMThread to be safe.
  8627. -//
  8628. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  8629. -// is finished and the safepoint is done. It simply cleans up
  8630. -// memory allocated in doit_prologue() and used in doit().
  8631. -//
  8632. -//
  8633. -// Constant Pool Details:
  8634. -//
  8635. -// When the_class is redefined, we cannot just replace the constant
  8636. -// pool in the_class with the constant pool from scratch_class because
  8637. -// that could confuse obsolete methods that may still be running.
  8638. -// Instead, the constant pool from the_class, old_cp, is merged with
  8639. -// the constant pool from scratch_class, scratch_cp. The resulting
  8640. -// constant pool, merge_cp, replaces old_cp in the_class.
  8641. -//
  8642. -// The key part of any merging algorithm is the entry comparison
  8643. -// function so we have to know the types of entries in a constant pool
  8644. -// in order to merge two of them together. Constant pools can contain
  8645. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  8646. -// is not presently used so we only have to worry about the other 11
  8647. -// entry types. For the purposes of constant pool merging, it is
  8648. -// helpful to know that the 11 entry types fall into 3 different
  8649. -// subtypes: "direct", "indirect" and "double-indirect".
  8650. -//
  8651. -// Direct CP entries contain data and do not contain references to
  8652. -// other CP entries. The following are direct CP entries:
  8653. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  8654. -//
  8655. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  8656. -// and no other data. The following are indirect CP entries:
  8657. -// JVM_CONSTANT_{Class,NameAndType,String}
  8658. -//
  8659. -// Double-indirect CP entries contain two references to indirect CP
  8660. -// entries and no other data. The following are double-indirect CP
  8661. -// entries:
  8662. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  8663. -//
  8664. -// When comparing entries between two constant pools, the entry types
  8665. -// are compared first and if they match, then further comparisons are
  8666. -// made depending on the entry subtype. Comparing direct CP entries is
  8667. -// simply a matter of comparing the data associated with each entry.
  8668. -// Comparing both indirect and double-indirect CP entries requires
  8669. -// recursion.
  8670. -//
  8671. -// Fortunately, the recursive combinations are limited because indirect
  8672. -// CP entries can only refer to direct CP entries and double-indirect
  8673. -// CP entries can only refer to indirect CP entries. The following is
  8674. -// an example illustration of the deepest set of indirections needed to
  8675. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  8676. -//
  8677. -// JVM_CONSTANT_Fieldref {
  8678. -// class_index => JVM_CONSTANT_Class {
  8679. -// name_index => JVM_CONSTANT_Utf8 {
  8680. -// <data-1>
  8681. -// }
  8682. -// }
  8683. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  8684. -// name_index => JVM_CONSTANT_Utf8 {
  8685. -// <data-2>
  8686. -// }
  8687. -// descriptor_index => JVM_CONSTANT_Utf8 {
  8688. -// <data-3>
  8689. -// }
  8690. -// }
  8691. -// }
  8692. -//
  8693. -// The above illustration is not a data structure definition for any
  8694. -// computer language. The curly braces ('{' and '}') are meant to
  8695. -// delimit the context of the "fields" in the CP entry types shown.
  8696. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  8697. -// "=>", e.g., the class_index is used to indirectly reference a
  8698. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  8699. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  8700. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  8701. -// have to do a total of 5 indirections just to get to the CP entries
  8702. -// that contain the interesting pieces of data and then we have to
  8703. -// fetch the three pieces of data. This means we have to do a total of
  8704. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  8705. -// entries.
  8706. -//
  8707. -// Here is the indirection, data and dereference count for each entry
  8708. -// type:
  8709. -//
  8710. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  8711. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  8712. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  8713. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  8714. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  8715. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  8716. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  8717. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  8718. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  8719. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  8720. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  8721. -//
  8722. -// So different subtypes of CP entries require different amounts of
  8723. -// work for a proper comparison.
  8724. -//
  8725. -// Now that we've talked about the different entry types and how to
  8726. -// compare them we need to get back to merging. This is not a merge in
  8727. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  8728. -// constant pools, we copy all the entries from old_cp to merge_cp,
  8729. -// preserving entry order. Next we append all the unique entries from
  8730. -// scratch_cp to merge_cp and we track the index changes from the
  8731. -// location in scratch_cp to the possibly new location in merge_cp.
  8732. -// When we are done, any obsolete code that is still running that
  8733. -// uses old_cp should not be able to observe any difference if it
  8734. -// were to use merge_cp. As for the new code in scratch_class, it is
  8735. -// modified to use the appropriate index values in merge_cp before it
  8736. -// is used to replace the code in the_class.
  8737. -//
  8738. -// There is one small complication in copying the entries from old_cp
  8739. -// to merge_cp. Two of the CP entry types are special in that they are
  8740. -// lazily resolved. Before explaining the copying complication, we need
  8741. -// to digress into CP entry resolution.
  8742. -//
  8743. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  8744. -// the class file, but are not stored in memory as such until they are
  8745. -// resolved. The entries are not resolved unless they are used because
  8746. -// resolution is expensive. During class file parsing the entries are
  8747. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  8748. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  8749. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  8750. -// have been parsed, but the index values in the entries have not been
  8751. -// validated. After the entire constant pool has been parsed, the index
  8752. -// values can be validated and then the entries are converted into
  8753. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  8754. -// entries. During this conversion process, the UTF8 values that are
  8755. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  8756. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  8757. -// entries are modified to refer to the Symbol*s. This optimization
  8758. -// eliminates one level of indirection for those two CP entry types and
  8759. -// gets the entries ready for verification. During class file parsing
  8760. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  8761. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  8762. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  8763. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  8764. -// entries.
  8765. -//
  8766. -// Now we can get back to the copying complication. When we copy
  8767. -// entries from old_cp to merge_cp, we have to revert any
  8768. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  8769. -// or verification will fail.
  8770. -//
  8771. -// It is important to explicitly state that the merging algorithm
  8772. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  8773. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  8774. -// entries in the merge_cp. This is done both to make verification
  8775. -// happy and to avoid adding more brittleness between RedefineClasses
  8776. -// and the constant pool cache. By allowing the constant pool cache
  8777. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  8778. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  8779. -// about those algorithms in RedefineClasses.
  8780. -//
  8781. -// Appending unique entries from scratch_cp to merge_cp is straight
  8782. -// forward for direct CP entries and most indirect CP entries. For the
  8783. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  8784. -// indirect CP entry types, the presence of more than one piece of
  8785. -// interesting data makes appending the entries more complicated.
  8786. -//
  8787. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  8788. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  8789. -// If the index in scratch_cp is different than the destination index
  8790. -// in merge_cp, then the change in index value is tracked.
  8791. -//
  8792. -// Note: the above discussion for the direct CP entries also applies
  8793. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  8794. -//
  8795. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  8796. -// one data element at the end of the recursion, we know that we have
  8797. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  8798. -// unique then it is appended to merge_cp before the current entry.
  8799. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  8800. -// is updated to refer to the duplicate entry in merge_cp before it is
  8801. -// appended to merge_cp. Again, any changes in index values are tracked
  8802. -// as needed.
  8803. -//
  8804. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  8805. -// types is theoretical. Since those entry types have already been
  8806. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  8807. -// they are handled as direct CP entries.
  8808. -//
  8809. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  8810. -// data elements at the end of the recursions, we know that we have
  8811. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  8812. -// entries are appended to merge_cp before the current entry. For any
  8813. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  8814. -// updated to refer to the duplicate entry in merge_cp before it is
  8815. -// appended to merge_cp. Again, any changes in index values are tracked
  8816. -// as needed.
  8817. -//
  8818. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  8819. -// types, since there are two indirect CP entries and three data
  8820. -// elements at the end of the recursions, we know that we have between
  8821. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  8822. -// above for an example of all six entries. The uniqueness algorithm
  8823. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  8824. -// covered above. Any unique entries are appended to merge_cp before
  8825. -// the current entry. For any entries that are not unique, the current
  8826. -// entry is updated to refer to the duplicate entry in merge_cp before
  8827. -// it is appended to merge_cp. Again, any changes in index values are
  8828. -// tracked as needed.
  8829. -//
  8830. -//
  8831. -// Other Details:
  8832. -//
  8833. -// Details for other parts of RedefineClasses need to be written.
  8834. -// This is a placeholder section.
  8835. -//
  8836. -//
  8837. -// Open Issues (in no particular order):
  8838. -//
  8839. -// - How do we serialize the RedefineClasses() API without deadlocking?
  8840. -//
  8841. -// - SystemDictionary::parse_stream() was called with a NULL protection
  8842. -// domain since the initial version. This has been changed to pass
  8843. -// the_class->protection_domain(). This change has been tested with
  8844. -// all NSK tests and nothing broke, but what will adding it now break
  8845. -// in ways that we don't test?
  8846. -//
  8847. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  8848. -// (indirect) use of the Relocator class that the max instruction
  8849. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  8850. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  8851. -// what it does to the bytecodes. More investigation is needed.
  8852. -//
  8853. -// - java.lang.Object methods can be called on arrays. This is
  8854. -// implemented via the arrayKlassOop vtable which we don't
  8855. -// update. For example, if we redefine java.lang.Object.toString(),
  8856. -// then the new version of the method will not be called for array
  8857. -// objects.
  8858. -//
  8859. -// - How do we know if redefine_single_class() and the guts of
  8860. -// instanceKlass are out of sync? I don't think this can be
  8861. -// automated, but we should probably order the work in
  8862. -// redefine_single_class() to match the order of field
  8863. -// definitions in instanceKlass. We also need to add some
  8864. -// comments about keeping things in sync.
  8865. -//
  8866. -// - set_new_constant_pool() is huge and we should consider refactoring
  8867. -// it into smaller chunks of work.
  8868. -//
  8869. -// - The exception table update code in set_new_constant_pool() defines
  8870. -// const values that are also defined in a local context elsewhere.
  8871. -// The same literal values are also used in elsewhere. We need to
  8872. -// coordinate a cleanup of these constants with Runtime.
  8873. -//
  8874. -
  8875. -class VM_RedefineClasses: public VM_Operation {
  8876. +#include "gc_implementation/shared/vmGCOperations.hpp"
  8877. +
  8878. +// New version that allows arbitrary changes to already loaded classes.
  8879. +class VM_RedefineClasses: public VM_GC_Operation {
  8880. private:
  8881. +
  8882. // These static fields are needed by SystemDictionary::classes_do()
  8883. // facility and the adjust_cpool_cache_and_vtable() helper:
  8884. static objArrayOop _old_methods;
  8885. static objArrayOop _new_methods;
  8886. - static methodOop* _matching_old_methods;
  8887. - static methodOop* _matching_new_methods;
  8888. - static methodOop* _deleted_methods;
  8889. - static methodOop* _added_methods;
  8890. + static int* _matching_old_methods;
  8891. + static int* _matching_new_methods;
  8892. + static int* _deleted_methods;
  8893. + static int* _added_methods;
  8894. static int _matching_methods_length;
  8895. static int _deleted_methods_length;
  8896. static int _added_methods_length;
  8897. - static klassOop _the_class_oop;
  8898. +
  8899. + static int _revision_number;
  8900. +
  8901. + static GrowableArray<instanceKlassHandle>* _affected_klasses;
  8902. // The instance fields are used to pass information from
  8903. // doit_prologue() to doit() and doit_epilogue().
  8904. @@ -366,40 +63,28 @@ class VM_RedefineClasses: public VM_Operation {
  8905. // RetransformClasses. Indicate which.
  8906. JvmtiClassLoadKind _class_load_kind;
  8907. - // _index_map_count is just an optimization for knowing if
  8908. - // _index_map_p contains any entries.
  8909. - int _index_map_count;
  8910. - intArray * _index_map_p;
  8911. - // ptr to _class_count scratch_classes
  8912. - instanceKlassHandle * _scratch_classes;
  8913. - jvmtiError _res;
  8914. + GrowableArray<instanceKlassHandle>* _new_classes;
  8915. + jvmtiError _result;
  8916. + int _max_redefinition_flags;
  8917. // Performance measurement support. These timers do not cover all
  8918. // the work done for JVM/TI RedefineClasses() but they do cover
  8919. // the heavy lifting.
  8920. - elapsedTimer _timer_rsc_phase1;
  8921. - elapsedTimer _timer_rsc_phase2;
  8922. - elapsedTimer _timer_vm_op_prologue;
  8923. -
  8924. - // These routines are roughly in call order unless otherwise noted.
  8925. -
  8926. - // Load the caller's new class definition(s) into _scratch_classes.
  8927. - // Constant pool merging work is done here as needed. Also calls
  8928. - // compare_and_normalize_class_versions() to verify the class
  8929. - // definition(s).
  8930. + elapsedTimer _timer_total;
  8931. + elapsedTimer _timer_prologue;
  8932. + elapsedTimer _timer_class_linking;
  8933. + elapsedTimer _timer_class_loading;
  8934. + elapsedTimer _timer_prepare_redefinition;
  8935. + elapsedTimer _timer_wait_for_locks;
  8936. + elapsedTimer _timer_heap_iteration;
  8937. + elapsedTimer _timer_redefinition;
  8938. + elapsedTimer _timer_vm_op_epilogue;
  8939. +
  8940. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  8941. + jvmtiError find_sorted_affected_classes( );
  8942. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  8943. jvmtiError load_new_class_versions(TRAPS);
  8944. - // Verify that the caller provided class definition(s) that meet
  8945. - // the restrictions of RedefineClasses. Normalize the order of
  8946. - // overloaded methods as needed.
  8947. - jvmtiError compare_and_normalize_class_versions(
  8948. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  8949. -
  8950. - // Swap annotations[i] with annotations[j]
  8951. - // Used by compare_and_normalize_class_versions() when normalizing
  8952. - // overloaded methods or changing idnum as when adding or deleting methods.
  8953. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  8954. -
  8955. // Figure out which new methods match old methods in name and signature,
  8956. // which methods have been added, and which are no longer present
  8957. void compute_added_deleted_matching_methods();
  8958. @@ -407,95 +92,71 @@ class VM_RedefineClasses: public VM_Operation {
  8959. // Change jmethodIDs to point to the new methods
  8960. void update_jmethod_ids();
  8961. - // In addition to marking methods as obsolete, this routine
  8962. - // records which methods are EMCP (Equivalent Module Constant
  8963. - // Pool) in the emcp_methods BitMap and returns the number of
  8964. - // EMCP methods via emcp_method_count_p. This information is
  8965. - // used when information about the previous version of the_class
  8966. - // is squirreled away.
  8967. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  8968. - int * emcp_method_count_p);
  8969. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  8970. + void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  8971. +
  8972. + static void add_affected_klasses( klassOop obj );
  8973. - // Unevolving classes may point to methods of the_class directly
  8974. - // from their constant pool caches, itables, and/or vtables. We
  8975. - // use the SystemDictionary::classes_do() facility and this helper
  8976. - // to fix up these pointers.
  8977. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  8978. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
  8979. // Install the redefinition of a class
  8980. - void redefine_single_class(jclass the_jclass,
  8981. - instanceKlassHandle scratch_class, TRAPS);
  8982. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  8983. // Increment the classRedefinedCount field in the specific instanceKlass
  8984. // and in all direct and indirect subclasses.
  8985. void increment_class_counter(instanceKlass *ik, TRAPS);
  8986. - // Support for constant pool merging (these routines are in alpha
  8987. - // order):
  8988. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  8989. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  8990. - int find_new_index(int old_index);
  8991. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  8992. - constantPoolHandle cp2, int index2);
  8993. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  8994. - constantPoolHandle cp2, int index2);
  8995. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  8996. - bool merge_constant_pools(constantPoolHandle old_cp,
  8997. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  8998. - int *merge_cp_length_p, TRAPS);
  8999. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  9000. - instanceKlassHandle scratch_class, TRAPS);
  9001. - u2 rewrite_cp_ref_in_annotation_data(
  9002. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  9003. - const char * trace_mesg, TRAPS);
  9004. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  9005. - bool rewrite_cp_refs_in_annotation_struct(
  9006. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9007. - bool rewrite_cp_refs_in_annotations_typeArray(
  9008. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  9009. - bool rewrite_cp_refs_in_class_annotations(
  9010. - instanceKlassHandle scratch_class, TRAPS);
  9011. - bool rewrite_cp_refs_in_element_value(
  9012. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  9013. - bool rewrite_cp_refs_in_fields_annotations(
  9014. - instanceKlassHandle scratch_class, TRAPS);
  9015. - void rewrite_cp_refs_in_method(methodHandle method,
  9016. - methodHandle * new_method_p, TRAPS);
  9017. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  9018. - bool rewrite_cp_refs_in_methods_annotations(
  9019. - instanceKlassHandle scratch_class, TRAPS);
  9020. - bool rewrite_cp_refs_in_methods_default_annotations(
  9021. - instanceKlassHandle scratch_class, TRAPS);
  9022. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  9023. - instanceKlassHandle scratch_class, TRAPS);
  9024. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  9025. - void rewrite_cp_refs_in_verification_type_info(
  9026. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  9027. - u1 frame_size, TRAPS);
  9028. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  9029. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  9030. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  9031. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  9032. - static void dump_methods();
  9033. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  9034. +
  9035. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  9036. +
  9037. + static void unpatch_bytecode(methodOop method);
  9038. +
  9039. +#ifdef ASSERT
  9040. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  9041. +#endif
  9042. +
  9043. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  9044. + void calculate_instance_update_information(klassOop new_version);
  9045. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  9046. + static void mark_as_scavengable(nmethod* nm);
  9047. +
  9048. + bool check_arguments();
  9049. + jvmtiError check_arguments_error();
  9050. public:
  9051. - VM_RedefineClasses(jint class_count,
  9052. - const jvmtiClassDefinition *class_defs,
  9053. - JvmtiClassLoadKind class_load_kind);
  9054. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  9055. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  9056. + virtual ~VM_RedefineClasses();
  9057. +
  9058. bool doit_prologue();
  9059. void doit();
  9060. void doit_epilogue();
  9061. + void rollback();
  9062. - bool allow_nested_vm_operations() const { return true; }
  9063. - jvmtiError check_error() { return _res; }
  9064. + jvmtiError check_exception() const;
  9065. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  9066. + bool skip_operation() const { return false; }
  9067. + bool allow_nested_vm_operations() const { return true; }
  9068. + jvmtiError check_error() { return _result; }
  9069. // Modifiable test must be shared between IsModifiableClass query
  9070. // and redefine implementation
  9071. static bool is_modifiable_class(oop klass_mirror);
  9072. +
  9073. + // Utility methods for transfering field access flags
  9074. +
  9075. + static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
  9076. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  9077. +
  9078. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  9079. +
  9080. + void lock_threads();
  9081. + void unlock_threads();
  9082. +
  9083. + static void swap_marks(oop first, oop second);
  9084. +
  9085. };
  9086. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  9087. diff --git a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9088. index 878d300..9dbe748 100644
  9089. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9090. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  9091. @@ -1,5 +1,5 @@
  9092. /*
  9093. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  9094. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  9095. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9096. *
  9097. * This code is free software; you can redistribute it and/or modify it
  9098. @@ -22,114 +22,26 @@
  9099. *
  9100. */
  9101. -#ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9102. -#define SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9103. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  9104. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  9105. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  9106. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  9107. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  9108. -// RedefineClasses tracing support via the TraceRedefineClasses
  9109. -// option. A bit is assigned to each group of trace messages.
  9110. -// Groups of messages are individually selectable. We have to use
  9111. -// decimal values on the command line since the command option
  9112. -// parsing logic doesn't like non-decimal numerics. The HEX values
  9113. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  9114. -// the old cumulative behavior, pick the level after the one in
  9115. -// which you are interested and subtract one, e.g., 33554431 will
  9116. -// print every tracing message.
  9117. -//
  9118. -// 0x00000000 | 0 - default; no tracing messages
  9119. -// 0x00000001 | 1 - name each target class before loading, after
  9120. -// loading and after redefinition is completed
  9121. -// 0x00000002 | 2 - print info if parsing, linking or
  9122. -// verification throws an exception
  9123. -// 0x00000004 | 4 - print timer info for the VM operation
  9124. -// 0x00000008 | 8 - print subclass counter updates
  9125. -// 0x00000010 | 16 - unused
  9126. -// 0x00000020 | 32 - unused
  9127. -// 0x00000040 | 64 - unused
  9128. -// 0x00000080 | 128 - unused
  9129. -// 0x00000100 | 256 - previous class weak reference addition
  9130. -// 0x00000200 | 512 - previous class weak reference mgmt during
  9131. -// class unloading checks (GC)
  9132. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  9133. -// add previous ops (GC)
  9134. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  9135. -// 0x00001000 | 4096 - detect calls to obsolete methods
  9136. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  9137. -// 0x00004000 | 16384 - detect old/obsolete methods in metadata
  9138. -// 0x00008000 | 32768 - old/new method matching/add/delete
  9139. -// 0x00010000 | 65536 - impl details: CP size info
  9140. -// 0x00020000 | 131072 - impl details: CP merge pass info
  9141. -// 0x00040000 | 262144 - impl details: CP index maps
  9142. -// 0x00080000 | 524288 - impl details: modified CP index values
  9143. -// 0x00100000 | 1048576 - impl details: vtable updates
  9144. -// 0x00200000 | 2097152 - impl details: itable updates
  9145. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  9146. -// 0x00800000 | 8388608 - impl details: methodComparator info
  9147. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  9148. -// 0x02000000 | 33554432 - impl details: annotation updates
  9149. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  9150. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  9151. -// 0x10000000 | 268435456 - unused
  9152. -// 0x20000000 | 536870912 - unused
  9153. -// 0x40000000 | 1073741824 - unused
  9154. -// 0x80000000 | 2147483648 - unused
  9155. -//
  9156. -// Note: The ResourceMark is to cleanup resource allocated args.
  9157. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  9158. -#define RC_TRACE(level, args) \
  9159. - if ((TraceRedefineClasses & level) != 0) { \
  9160. - ResourceMark rm; \
  9161. - tty->print("RedefineClasses-0x%x: ", level); \
  9162. - tty->print_cr args; \
  9163. - } while (0)
  9164. -
  9165. -#define RC_TRACE_NO_CR(level, args) \
  9166. - if ((TraceRedefineClasses & level) != 0) { \
  9167. - ResourceMark rm; \
  9168. - tty->print("RedefineClasses-0x%x: ", level); \
  9169. - tty->print args; \
  9170. - } while (0)
  9171. -
  9172. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  9173. - if ((TraceRedefineClasses & level) != 0) { \
  9174. - ResourceMark rm(thread); \
  9175. - tty->print("RedefineClasses-0x%x: ", level); \
  9176. - tty->print_cr args; \
  9177. - } while (0)
  9178. -
  9179. -#define RC_TRACE_MESG(args) \
  9180. - { \
  9181. - ResourceMark rm; \
  9182. - tty->print("RedefineClasses: "); \
  9183. - tty->print_cr args; \
  9184. - } while (0)
  9185. -
  9186. -// Macro for checking if TraceRedefineClasses has a specific bit
  9187. -// enabled. Returns true if the bit specified by level is set.
  9188. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  9189. -
  9190. -// Macro for checking if TraceRedefineClasses has one or more bits
  9191. -// set in a range of bit values. Returns true if one or more bits
  9192. -// is set in the range from low..high inclusive. Assumes that low
  9193. -// and high are single bit values.
  9194. -//
  9195. -// ((high << 1) - 1)
  9196. -// Yields a mask that removes bits greater than the high bit value.
  9197. -// This algorithm doesn't work with highest bit.
  9198. -// ~(low - 1)
  9199. -// Yields a mask that removes bits lower than the low bit value.
  9200. -#define RC_TRACE_IN_RANGE(low, high) \
  9201. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  9202. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  9203. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  9204. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  9205. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  9206. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  9207. // Timer support macros. Only do timer operations if timer tracing
  9208. // is enabled. The "while (0)" is so we can use semi-colon at end of
  9209. // the macro.
  9210. #define RC_TIMER_START(t) \
  9211. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9212. + if (TimeRedefineClasses) { \
  9213. t.start(); \
  9214. } while (0)
  9215. #define RC_TIMER_STOP(t) \
  9216. - if (RC_TRACE_ENABLED(0x00000004)) { \
  9217. + if (TimeRedefineClasses) { \
  9218. t.stop(); \
  9219. } while (0)
  9220. -
  9221. -#endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP
  9222. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  9223. index 60eaf97..785dc24 100644
  9224. --- a/src/share/vm/prims/methodComparator.cpp
  9225. +++ b/src/share/vm/prims/methodComparator.cpp
  9226. @@ -42,10 +42,9 @@ bool MethodComparator::methods_EMCP(methodOop old_method, methodOop new_method)
  9227. if (old_method->code_size() != new_method->code_size())
  9228. return false;
  9229. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  9230. - // RC_TRACE macro has an embedded ResourceMark
  9231. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  9232. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  9233. old_method->name()->as_C_string(),
  9234. - check_stack_and_locals_size(old_method, new_method)));
  9235. + check_stack_and_locals_size(old_method, new_method));
  9236. return false;
  9237. }
  9238. @@ -114,10 +113,9 @@ bool MethodComparator::methods_switchable(methodOop old_method, methodOop new_me
  9239. // Now we can test all forward jumps
  9240. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  9241. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  9242. - RC_TRACE(0x00800000,
  9243. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9244. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  9245. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  9246. - fwd_jmps.at(i*2+1)));
  9247. + fwd_jmps.at(i*2+1));
  9248. return false;
  9249. }
  9250. }
  9251. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  9252. index 22d450b..bac1ae6 100644
  9253. --- a/src/share/vm/runtime/arguments.cpp
  9254. +++ b/src/share/vm/runtime/arguments.cpp
  9255. @@ -54,8 +54,8 @@
  9256. #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  9257. #endif
  9258. -// Note: This is a special bug reporting site for the JVM
  9259. -#define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  9260. +// (tw) The DCE VM has its own JIRA bug tracking system.
  9261. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  9262. #define DEFAULT_JAVA_LAUNCHER "generic"
  9263. char** Arguments::_jvm_flags_array = NULL;
  9264. @@ -1792,6 +1792,16 @@ bool Arguments::check_gc_consistency() {
  9265. status = false;
  9266. }
  9267. + // (tw) Must use serial GC. This limitation applies because the instance size changing GC modifications
  9268. + // are only built into the mark and compact algorithm.
  9269. + if (!UseSerialGC && i >= 1) {
  9270. + //jio_fprintf(defaultStream::error_stream(),
  9271. + // "Must use the serial GC in the Dynamic Code Evolution VM\n");
  9272. + //status = false;
  9273. + } else {
  9274. + UseSerialGC = true;
  9275. + }
  9276. +
  9277. return status;
  9278. }
  9279. @@ -3208,7 +3218,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
  9280. // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  9281. set_aggressive_opts_flags();
  9282. -
  9283. +#ifndef COMPILER2
  9284. // Turn off biased locking for locking debug mode flags,
  9285. // which are subtlely different from each other but neither works with
  9286. // biased locking.
  9287. @@ -3225,6 +3235,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
  9288. }
  9289. UseBiasedLocking = false;
  9290. }
  9291. +#endif
  9292. #ifdef CC_INTERP
  9293. // Clear flags not supported by the C++ interpreter
  9294. diff --git a/src/share/vm/runtime/fieldDescriptor.cpp b/src/share/vm/runtime/fieldDescriptor.cpp
  9295. index 3d5213f..9cc701b 100644
  9296. --- a/src/share/vm/runtime/fieldDescriptor.cpp
  9297. +++ b/src/share/vm/runtime/fieldDescriptor.cpp
  9298. @@ -92,7 +92,8 @@ void fieldDescriptor::initialize(klassOop k, int index) {
  9299. instanceKlass* ik = instanceKlass::cast(k);
  9300. _cp = ik->constants();
  9301. FieldInfo* f = ik->field(index);
  9302. - assert(!f->is_internal(), "regular Java fields only");
  9303. + // (tw) do we need this?
  9304. +// assert(!f->is_internal(), "regular Java fields only");
  9305. _access_flags = accessFlags_from(f->access_flags());
  9306. guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
  9307. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  9308. index 8df7220..341b399 100644
  9309. --- a/src/share/vm/runtime/globals.hpp
  9310. +++ b/src/share/vm/runtime/globals.hpp
  9311. @@ -1230,6 +1230,11 @@ class CommandLineFlags {
  9312. product(intx, TraceRedefineClasses, 0, \
  9313. "Trace level for JVMTI RedefineClasses") \
  9314. \
  9315. + product(bool, TimeRedefineClasses, false, \
  9316. + "Measure timing for JVMTI RedefineClasses") \
  9317. + \
  9318. + product(bool, AllowAdvancedClassRedefinition, true, \
  9319. + "Allow advanced class redefinition beyond swapping method bodies")\
  9320. develop(bool, StressMethodComparator, false, \
  9321. "run the MethodComparator on all loaded methods") \
  9322. \
  9323. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  9324. index 2875ee0..61fd8fe 100644
  9325. --- a/src/share/vm/runtime/interfaceSupport.hpp
  9326. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  9327. @@ -296,7 +296,7 @@ class ThreadToNativeFromVM : public ThreadStateTransition {
  9328. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  9329. // We are leaving the VM at this point and going directly to native code.
  9330. // Block, if we are in the middle of a safepoint synchronization.
  9331. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9332. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9333. thread->frame_anchor()->make_walkable(thread);
  9334. trans_and_fence(_thread_in_vm, _thread_in_native);
  9335. // Check for pending. async. exceptions or suspends.
  9336. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  9337. index edbba98..4a27925 100644
  9338. --- a/src/share/vm/runtime/javaCalls.cpp
  9339. +++ b/src/share/vm/runtime/javaCalls.cpp
  9340. @@ -60,7 +60,7 @@ JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, Ja
  9341. bool clear_pending_exception = true;
  9342. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  9343. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  9344. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  9345. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  9346. _result = result;
  9347. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  9348. index 3cbcaca..30839d7 100644
  9349. --- a/src/share/vm/runtime/jniHandles.cpp
  9350. +++ b/src/share/vm/runtime/jniHandles.cpp
  9351. @@ -112,6 +112,10 @@ jobject JNIHandles::make_weak_global(Handle obj) {
  9352. }
  9353. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  9354. + if (mh->newest_version() != mh()) {
  9355. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  9356. + return (jmethodID) make_weak_global(mh_new);
  9357. + }
  9358. return (jmethodID) make_weak_global(mh);
  9359. }
  9360. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  9361. index 2095237..c541434 100644
  9362. --- a/src/share/vm/runtime/mutex.cpp
  9363. +++ b/src/share/vm/runtime/mutex.cpp
  9364. @@ -1227,7 +1227,7 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
  9365. // in increasing rank order (modulo any native ranks)
  9366. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9367. if (tmp->next() != NULL) {
  9368. - assert(tmp->rank() == Mutex::native ||
  9369. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9370. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9371. }
  9372. }
  9373. @@ -1247,7 +1247,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
  9374. // in increasing rank order (modulo any native ranks)
  9375. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  9376. if (tmp->next() != NULL) {
  9377. - assert(tmp->rank() == Mutex::native ||
  9378. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  9379. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  9380. }
  9381. }
  9382. @@ -1310,6 +1310,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
  9383. // already hold Terminator_lock - may happen because of periodic safepoints
  9384. if (this->rank() != Mutex::native &&
  9385. this->rank() != Mutex::suspend_resume &&
  9386. + this->rank() != Mutex::redefine_classes &&
  9387. locks != NULL && locks->rank() <= this->rank() &&
  9388. !SafepointSynchronize::is_at_safepoint() &&
  9389. this != Interrupt_lock &&
  9390. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  9391. index 7d2cd82..11eb32e 100644
  9392. --- a/src/share/vm/runtime/mutex.hpp
  9393. +++ b/src/share/vm/runtime/mutex.hpp
  9394. @@ -109,7 +109,8 @@ class Monitor : public CHeapObj<mtInternal> {
  9395. barrier = safepoint + 1,
  9396. nonleaf = barrier + 1,
  9397. max_nonleaf = nonleaf + 900,
  9398. - native = max_nonleaf + 1
  9399. + native = max_nonleaf + 1,
  9400. + redefine_classes = native + 1
  9401. };
  9402. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  9403. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  9404. index d9184c7..cfd1f3a 100644
  9405. --- a/src/share/vm/runtime/mutexLocker.cpp
  9406. +++ b/src/share/vm/runtime/mutexLocker.cpp
  9407. @@ -49,6 +49,7 @@
  9408. // Consider using GCC's __read_mostly.
  9409. Mutex* Patching_lock = NULL;
  9410. +Mutex* RedefineClasses_lock = NULL;
  9411. Monitor* SystemDictionary_lock = NULL;
  9412. Mutex* PackageTable_lock = NULL;
  9413. Mutex* CompiledIC_lock = NULL;
  9414. @@ -281,6 +282,7 @@ void mutex_init() {
  9415. def(Debug3_lock , Mutex , nonleaf+4, true );
  9416. def(CompileThread_lock , Monitor, nonleaf+5, false);
  9417. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  9418. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  9419. #ifdef INCLUDE_TRACE
  9420. def(JfrMsg_lock , Monitor, leaf, true);
  9421. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  9422. index 90011d8..d6b0c54 100644
  9423. --- a/src/share/vm/runtime/mutexLocker.hpp
  9424. +++ b/src/share/vm/runtime/mutexLocker.hpp
  9425. @@ -43,6 +43,7 @@
  9426. // Mutexes used in the VM.
  9427. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  9428. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  9429. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  9430. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  9431. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  9432. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  9433. index 1665d93..6baabba 100644
  9434. --- a/src/share/vm/runtime/reflection.cpp
  9435. +++ b/src/share/vm/runtime/reflection.cpp
  9436. @@ -468,7 +468,8 @@ bool Reflection::verify_class_access(klassOop current_class, klassOop new_class,
  9437. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9438. if ( JDK_Version::is_gte_jdk14x_version()
  9439. && UseNewReflection
  9440. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9441. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9442. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9443. return true;
  9444. }
  9445. @@ -519,6 +520,12 @@ bool Reflection::verify_field_access(klassOop current_class,
  9446. AccessFlags access,
  9447. bool classloader_only,
  9448. bool protected_restriction) {
  9449. +
  9450. + // (tw) Decide accessibility based on active version
  9451. + if (current_class != NULL) {
  9452. + current_class = current_class->klass_part()->active_version();
  9453. + }
  9454. +
  9455. // Verify that current_class can access a field of field_class, where that
  9456. // field's access bits are "access". We assume that we've already verified
  9457. // that current_class can access field_class.
  9458. @@ -560,7 +567,8 @@ bool Reflection::verify_field_access(klassOop current_class,
  9459. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  9460. if ( JDK_Version::is_gte_jdk14x_version()
  9461. && UseNewReflection
  9462. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  9463. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  9464. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  9465. return true;
  9466. }
  9467. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  9468. index 709d783..689b9a2 100644
  9469. --- a/src/share/vm/runtime/sharedRuntime.cpp
  9470. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  9471. @@ -603,21 +603,13 @@ void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Symbol* n
  9472. //
  9473. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  9474. JavaThread* thread, methodOopDesc* method))
  9475. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  9476. + assert(TraceRedefineClasses >= 4, "wrong call");
  9477. if (method->is_obsolete()) {
  9478. // We are calling an obsolete method, but this is not necessarily
  9479. // an error. Our method could have been redefined just after we
  9480. // fetched the methodOop from the constant pool.
  9481. -
  9482. - // RC_TRACE macro has an embedded ResourceMark
  9483. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  9484. - ("calling obsolete method '%s'",
  9485. - method->name_and_sig_as_C_string()));
  9486. - if (RC_TRACE_ENABLED(0x00002000)) {
  9487. - // this option is provided to debug calls to obsolete methods
  9488. - guarantee(false, "faulting at call to an obsolete method.");
  9489. - }
  9490. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  9491. }
  9492. return 0;
  9493. JRT_END
  9494. @@ -1137,7 +1129,20 @@ methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
  9495. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  9496. int retry_count = 0;
  9497. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  9498. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  9499. + callee_method->method_holder()->klass_part()->super() != NULL) {
  9500. +
  9501. + // (tw) If we are executing an old method, this is OK!
  9502. + {
  9503. + ResourceMark rm(thread);
  9504. + RegisterMap cbl_map(thread, false);
  9505. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  9506. +
  9507. + CodeBlob* caller_cb = caller_frame.cb();
  9508. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  9509. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  9510. + if (caller_nm->method()->is_old()) break;
  9511. + }
  9512. +
  9513. // If has a pending exception then there is no need to re-try to
  9514. // resolve this method.
  9515. // If the method has been redefined, we need to try again.
  9516. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  9517. index ae28b65..bb0681e 100644
  9518. --- a/src/share/vm/runtime/thread.cpp
  9519. +++ b/src/share/vm/runtime/thread.cpp
  9520. @@ -216,6 +216,8 @@ Thread::Thread() {
  9521. set_self_raw_id(0);
  9522. set_lgrp_id(-1);
  9523. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  9524. +
  9525. // allocated data structures
  9526. set_osthread(NULL);
  9527. set_resource_area(new (mtThread)ResourceArea());
  9528. @@ -249,6 +251,7 @@ Thread::Thread() {
  9529. omFreeProvision = 32 ;
  9530. omInUseList = NULL ;
  9531. omInUseCount = 0 ;
  9532. + _pretend_new_universe = false;
  9533. #ifdef ASSERT
  9534. _visited_for_critical_count = false;
  9535. @@ -884,6 +887,15 @@ bool Thread::owns_locks_but_compiled_lock() const {
  9536. return false;
  9537. }
  9538. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  9539. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  9540. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  9541. + return true;
  9542. + }
  9543. + }
  9544. + return false;
  9545. +}
  9546. +
  9547. #endif
  9548. @@ -1637,7 +1649,7 @@ void JavaThread::run() {
  9549. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  9550. assert(JavaThread::current() == this, "sanity check");
  9551. - assert(!Thread::current()->owns_locks(), "sanity check");
  9552. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  9553. DTRACE_THREAD_PROBE(start, this);
  9554. @@ -3193,7 +3205,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  9555. // Create a CompilerThread
  9556. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9557. -: JavaThread(&compiler_thread_entry) {
  9558. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  9559. _env = NULL;
  9560. _log = NULL;
  9561. _task = NULL;
  9562. @@ -3201,6 +3213,7 @@ CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  9563. _counters = counters;
  9564. _buffer_blob = NULL;
  9565. _scanned_nmethod = NULL;
  9566. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  9567. #ifndef PRODUCT
  9568. _ideal_graph_printer = NULL;
  9569. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  9570. index 774bd27..4620820 100644
  9571. --- a/src/share/vm/runtime/thread.hpp
  9572. +++ b/src/share/vm/runtime/thread.hpp
  9573. @@ -202,12 +202,15 @@ class Thread: public ThreadShadow {
  9574. public:
  9575. void enter_signal_handler() { _num_nested_signal++; }
  9576. void leave_signal_handler() { _num_nested_signal--; }
  9577. - bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9578. + bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  9579. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  9580. private:
  9581. // Debug tracing
  9582. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  9583. + Mutex* _redefine_classes_mutex;
  9584. +
  9585. // Active_handles points to a block of handles
  9586. JNIHandleBlock* _active_handles;
  9587. @@ -530,10 +533,15 @@ public:
  9588. uintptr_t _self_raw_id; // used by get_thread (mutable)
  9589. int _lgrp_id;
  9590. +
  9591. + bool _pretend_new_universe;
  9592. +
  9593. public:
  9594. // Stack overflow support
  9595. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  9596. + 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; } }
  9597. + bool pretend_new_universe() { return _pretend_new_universe; }
  9598. void set_stack_base(address base) { _stack_base = base; }
  9599. size_t stack_size() const { return _stack_size; }
  9600. void set_stack_size(size_t size) { _stack_size = size; }
  9601. @@ -570,6 +578,7 @@ public:
  9602. void print_owned_locks() const { print_owned_locks_on(tty); }
  9603. Monitor* owned_locks() const { return _owned_locks; }
  9604. bool owns_locks() const { return owned_locks() != NULL; }
  9605. + bool owns_locks_but_redefine_classes_lock() const;
  9606. bool owns_locks_but_compiled_lock() const;
  9607. // Deadlock detection
  9608. @@ -1793,6 +1802,8 @@ class CompilerThread : public JavaThread {
  9609. CompileTask* _task;
  9610. CompileQueue* _queue;
  9611. BufferBlob* _buffer_blob;
  9612. + bool _should_bailout;
  9613. + Mutex* _compilation_mutex;
  9614. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  9615. @@ -1802,12 +1813,16 @@ class CompilerThread : public JavaThread {
  9616. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  9617. + bool should_bailout() const { return _should_bailout; }
  9618. + void set_should_bailout(bool b) { _should_bailout = false; }
  9619. +
  9620. bool is_Compiler_thread() const { return true; }
  9621. // Hide this compiler thread from external view.
  9622. bool is_hidden_from_external_view() const { return true; }
  9623. CompileQueue* queue() { return _queue; }
  9624. CompilerCounters* counters() { return _counters; }
  9625. + Mutex *compilation_mutex() { return _compilation_mutex; }
  9626. // Get/set the thread's compilation environment.
  9627. ciEnv* env() { return _env; }
  9628. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  9629. index 7643670..0d3cd70 100644
  9630. --- a/src/share/vm/runtime/vmThread.cpp
  9631. +++ b/src/share/vm/runtime/vmThread.cpp
  9632. @@ -691,6 +691,9 @@ void VMThread::execute(VM_Operation* op) {
  9633. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  9634. Thread::oops_do(f, cf);
  9635. _vm_queue->oops_do(f);
  9636. + if (_cur_vm_operation != NULL) {
  9637. + _cur_vm_operation->oops_do(f);
  9638. + }
  9639. }
  9640. //------------------------------------------------------------------------------------------------------------------
  9641. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  9642. index 03f254d..18e324b 100644
  9643. --- a/src/share/vm/utilities/exceptions.cpp
  9644. +++ b/src/share/vm/utilities/exceptions.cpp
  9645. @@ -254,6 +254,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  9646. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  9647. assert(!thread->has_pending_exception(), "already has exception");
  9648. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  9649. + Thread::current()->set_pretend_new_universe(false);
  9650. Handle h_exception;
  9651. // Resolve exception klass
  9652. @@ -285,6 +287,7 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  9653. h_exception = Handle(thread, thread->pending_exception());
  9654. thread->clear_pending_exception();
  9655. }
  9656. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  9657. return h_exception;
  9658. }
  9659. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  9660. index 2a6d6b8..4b6927f 100644
  9661. --- a/src/share/vm/utilities/growableArray.hpp
  9662. +++ b/src/share/vm/utilities/growableArray.hpp
  9663. @@ -145,6 +145,33 @@ class GenericGrowableArray : public ResourceObj {
  9664. assert(on_stack(), "fast ResourceObj path only");
  9665. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  9666. }
  9667. +
  9668. +};
  9669. +
  9670. +template<class E, class F> class Pair : public StackObj
  9671. +{
  9672. +private:
  9673. + E _left;
  9674. + F _right;
  9675. +
  9676. +public:
  9677. +
  9678. + Pair() {
  9679. +
  9680. + }
  9681. +
  9682. + Pair(E left, F right) {
  9683. + this->_left = left;
  9684. + this->_right = right;
  9685. + }
  9686. +
  9687. + E left() {
  9688. + return _left;
  9689. + }
  9690. +
  9691. + F right() {
  9692. + return _right;
  9693. + }
  9694. };
  9695. template<class E> class GrowableArray : public GenericGrowableArray {