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.

full-jdk7u85-b02.patch 504KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376
  1. diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make
  2. index 3de1dea..8bf7f94 100644
  3. --- a/make/bsd/makefiles/gcc.make
  4. +++ b/make/bsd/makefiles/gcc.make
  5. @@ -117,7 +117,10 @@
  6. CFLAGS += -fno-rtti
  7. CFLAGS += -fno-exceptions
  8. CFLAGS += -pthread
  9. -CFLAGS += -fcheck-new
  10. +## well, strictly speaking we should check for clang not Darwin
  11. +ifneq ($(OS_VENDOR), Darwin)
  12. + CFLAGS += -fcheck-new
  13. +endif
  14. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  15. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  16. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  17. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  18. index fc19edc..d2cddd3 100644
  19. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  20. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  21. @@ -2109,6 +2109,22 @@
  22. // resolve first time through
  23. address entry;
  24. switch (bytecode()) {
  25. + case Bytecodes::_fast_agetfield : // fall through
  26. + case Bytecodes::_fast_bgetfield : // fall through
  27. + case Bytecodes::_fast_cgetfield : // fall through
  28. + case Bytecodes::_fast_dgetfield : // fall through
  29. + case Bytecodes::_fast_fgetfield : // fall through
  30. + case Bytecodes::_fast_igetfield : // fall through
  31. + case Bytecodes::_fast_lgetfield : // fall through
  32. + case Bytecodes::_fast_sgetfield : // fall through
  33. + case Bytecodes::_fast_aputfield : // fall through
  34. + case Bytecodes::_fast_bputfield : // fall through
  35. + case Bytecodes::_fast_cputfield : // fall through
  36. + case Bytecodes::_fast_dputfield : // fall through
  37. + case Bytecodes::_fast_fputfield : // fall through
  38. + case Bytecodes::_fast_iputfield : // fall through
  39. + case Bytecodes::_fast_lputfield : // fall through
  40. + case Bytecodes::_fast_sputfield : // fall through
  41. case Bytecodes::_getstatic : // fall through
  42. case Bytecodes::_putstatic : // fall through
  43. case Bytecodes::_getfield : // fall through
  44. @@ -2211,6 +2227,7 @@
  45. // Correct values of the cache and index registers are preserved.
  46. void TemplateTable::jvmti_post_field_access(Register cache,
  47. Register index,
  48. + int byte_no,
  49. bool is_static,
  50. bool has_tos) {
  51. if (JvmtiExport::can_post_field_access()) {
  52. @@ -2237,7 +2254,11 @@
  53. // cache: cache entry pointer
  54. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  55. rax, cache);
  56. - __ get_cache_and_index_at_bcp(cache, index, 1);
  57. +
  58. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  59. + __ restore_bcp();
  60. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  61. +
  62. __ bind(L1);
  63. }
  64. }
  65. @@ -2258,7 +2279,7 @@
  66. const Register flags = rax;
  67. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  68. - jvmti_post_field_access(cache, index, is_static, false);
  69. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  70. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  71. if (!is_static) pop_and_check_object(obj);
  72. @@ -2393,7 +2414,7 @@
  73. // The registers cache and index expected to be set before call.
  74. // The function may destroy various registers, just not the cache and index registers.
  75. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  76. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  77. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  78. @@ -2451,7 +2472,11 @@
  79. // rcx: jvalue object on the stack
  80. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  81. rbx, rax, rcx);
  82. - __ get_cache_and_index_at_bcp(cache, index, 1);
  83. +
  84. + // (tw) Redefinition might have occured => reresolve the cp entry.
  85. + __ restore_bcp();
  86. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  87. +
  88. __ bind(L1);
  89. }
  90. }
  91. @@ -2467,7 +2492,7 @@
  92. const Register flags = rax;
  93. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  94. - jvmti_post_field_mod(cache, index, is_static);
  95. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  96. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  97. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  98. @@ -2818,6 +2843,11 @@
  99. // rcx: cache entry pointer
  100. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  101. __ pop_ptr(rax); // restore object pointer
  102. +
  103. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  104. + __ restore_bcp();
  105. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  106. +
  107. __ bind(L1);
  108. }
  109. @@ -3008,6 +3038,26 @@
  110. __ bind(notFinal);
  111. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  112. + Label notOld;
  113. + __ movl(rax, flags);
  114. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  115. + __ jcc(Assembler::zero, notOld);
  116. +
  117. + // Need a null check here!
  118. + __ null_check(recv);
  119. +
  120. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  121. + // DCEVM: TODO: Check if we can improve performance by inlining.
  122. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  123. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  124. +
  125. + // profile this call
  126. + __ profile_final_call(rax);
  127. + __ jump_from_interpreted(method, rdx);
  128. +
  129. + __ bind(notOld);
  130. +
  131. // get receiver klass
  132. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  133. __ load_klass(rax, recv);
  134. @@ -3093,6 +3143,31 @@
  135. invokevirtual_helper(rbx, rcx, rdx);
  136. __ bind(notMethod);
  137. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  138. + //__ movl(rax, rdx);
  139. + Label notOld;
  140. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  141. + __ jcc(Assembler::zero, notOld);
  142. +
  143. + // Get receiver klass into rdx - also a null check
  144. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  145. + __ verify_oop(rdx);
  146. +
  147. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  148. + // DCEVM: TODO: Check if we can improve performance by inlining.
  149. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  150. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  151. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  152. +
  153. + // DCEVM: TODO: Check if resolved method could be null.
  154. +
  155. + // profile this call
  156. + __ profile_virtual_call(rdx, rsi, rdi);
  157. +
  158. + __ jump_from_interpreted(rbx, rdx);
  159. +
  160. + __ bind(notOld);
  161. +
  162. // Get receiver klass into rdx - also a null check
  163. __ restore_locals(); // restore rdi
  164. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  165. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  166. index 932ee97..67bb710 100644
  167. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  168. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  169. @@ -2151,6 +2151,22 @@
  170. // resolve first time through
  171. address entry;
  172. switch (bytecode()) {
  173. + case Bytecodes::_fast_agetfield : // fall through
  174. + case Bytecodes::_fast_bgetfield : // fall through
  175. + case Bytecodes::_fast_cgetfield : // fall through
  176. + case Bytecodes::_fast_dgetfield : // fall through
  177. + case Bytecodes::_fast_fgetfield : // fall through
  178. + case Bytecodes::_fast_igetfield : // fall through
  179. + case Bytecodes::_fast_lgetfield : // fall through
  180. + case Bytecodes::_fast_sgetfield : // fall through
  181. + case Bytecodes::_fast_aputfield : // fall through
  182. + case Bytecodes::_fast_bputfield : // fall through
  183. + case Bytecodes::_fast_cputfield : // fall through
  184. + case Bytecodes::_fast_dputfield : // fall through
  185. + case Bytecodes::_fast_fputfield : // fall through
  186. + case Bytecodes::_fast_iputfield : // fall through
  187. + case Bytecodes::_fast_lputfield : // fall through
  188. + case Bytecodes::_fast_sputfield : // fall through
  189. case Bytecodes::_getstatic:
  190. case Bytecodes::_putstatic:
  191. case Bytecodes::_getfield:
  192. @@ -2267,7 +2283,7 @@
  193. // The registers cache and index expected to be set before call.
  194. // Correct values of the cache and index registers are preserved.
  195. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  196. - bool is_static, bool has_tos) {
  197. + int byte_no, bool is_static, bool has_tos) {
  198. // do the JVMTI work here to avoid disturbing the register state below
  199. // We use c_rarg registers here because we want to use the register used in
  200. // the call to the VM
  201. @@ -2298,7 +2314,11 @@
  202. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  203. InterpreterRuntime::post_field_access),
  204. c_rarg1, c_rarg2, c_rarg3);
  205. - __ get_cache_and_index_at_bcp(cache, index, 1);
  206. +
  207. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  208. + __ restore_bcp();
  209. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  210. +
  211. __ bind(L1);
  212. }
  213. }
  214. @@ -2320,7 +2340,7 @@
  215. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  216. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  217. - jvmti_post_field_access(cache, index, is_static, false);
  218. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  219. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  220. if (!is_static) {
  221. @@ -2455,7 +2475,7 @@
  222. // The registers cache and index expected to be set before call.
  223. // The function may destroy various registers, just not the cache and index registers.
  224. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  225. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  226. transition(vtos, vtos);
  227. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  228. @@ -2507,7 +2527,11 @@
  229. CAST_FROM_FN_PTR(address,
  230. InterpreterRuntime::post_field_modification),
  231. c_rarg1, c_rarg2, c_rarg3);
  232. - __ get_cache_and_index_at_bcp(cache, index, 1);
  233. +
  234. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  235. + __ restore_bcp();
  236. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  237. +
  238. __ bind(L1);
  239. }
  240. }
  241. @@ -2523,7 +2547,7 @@
  242. const Register bc = c_rarg3;
  243. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  244. - jvmti_post_field_mod(cache, index, is_static);
  245. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  246. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  247. // [jk] not needed currently
  248. @@ -2837,6 +2861,11 @@
  249. InterpreterRuntime::post_field_access),
  250. c_rarg1, c_rarg2);
  251. __ pop_ptr(rax); // restore object pointer
  252. +
  253. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  254. + __ restore_bcp();
  255. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  256. +
  257. __ bind(L1);
  258. }
  259. @@ -3073,6 +3102,26 @@
  260. __ bind(notFinal);
  261. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  262. + Label notOld;
  263. + __ movl(rax, flags);
  264. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  265. + __ jcc(Assembler::zero, notOld);
  266. +
  267. + // Need a null check here!
  268. + __ null_check(recv);
  269. +
  270. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  271. + // DCEVM: TODO: Check if we can improve performance by inlining.
  272. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  273. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  274. +
  275. + // profile this call
  276. + __ profile_final_call(rax);
  277. + __ jump_from_interpreted(method, rdx);
  278. +
  279. + __ bind(notOld);
  280. +
  281. // get receiver klass
  282. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  283. __ load_klass(rax, recv);
  284. @@ -3156,6 +3205,35 @@
  285. invokevirtual_helper(rbx, rcx, rdx);
  286. __ bind(notMethod);
  287. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  288. + Label notOld;
  289. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  290. + __ jcc(Assembler::zero, notOld);
  291. +
  292. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  293. + // DCEVM: TODO: Check if we can improve performance by inlining.
  294. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  295. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  296. + // DCEVM: FIXME: What exactly should we store here?
  297. + __ push(rcx); // destroyed by Linux arguments passing conventions
  298. + __ movptr(r14, rcx);
  299. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  300. + __ pop(rcx);
  301. +
  302. + // Get receiver klass into rdx - also a null check
  303. + __ restore_locals(); // restore r14
  304. + __ load_klass(rdx, rcx);
  305. + __ verify_oop(rdx);
  306. +
  307. + // DCEVM: TODO: Check if resolved method could be null.
  308. +
  309. + // profile this call
  310. + __ profile_virtual_call(rdx, r13, r14);
  311. +
  312. + __ jump_from_interpreted(rbx, rdx);
  313. +
  314. + __ bind(notOld);
  315. +
  316. // Get receiver klass into rdx - also a null check
  317. __ restore_locals(); // restore r14
  318. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  319. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  320. index 9a8ca61..196ab25 100644
  321. --- a/src/share/vm/c1/c1_Compilation.hpp
  322. +++ b/src/share/vm/c1/c1_Compilation.hpp
  323. @@ -242,8 +242,8 @@
  324. #define BAILOUT(msg) { bailout(msg); return; }
  325. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  326. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  327. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  328. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  329. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  330. class InstructionMark: public StackObj {
  331. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  332. index e20db5d..57f37db 100644
  333. --- a/src/share/vm/ci/ciEnv.cpp
  334. +++ b/src/share/vm/ci/ciEnv.cpp
  335. @@ -1172,3 +1172,11 @@
  336. // If memory is low, we stop compiling methods.
  337. record_method_not_compilable("out of memory");
  338. }
  339. +
  340. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  341. +void ciEnv::cleanup_after_redefinition() {
  342. +
  343. + if (_factory != NULL) {
  344. + _factory->cleanup_after_redefinition();
  345. + }
  346. +}
  347. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  348. index 103e532..abe2e37 100644
  349. --- a/src/share/vm/ci/ciEnv.hpp
  350. +++ b/src/share/vm/ci/ciEnv.hpp
  351. @@ -417,6 +417,8 @@
  352. void record_failure(const char* reason);
  353. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  354. void record_out_of_memory_failure();
  355. +
  356. + void cleanup_after_redefinition();
  357. };
  358. #endif // SHARE_VM_CI_CIENV_HPP
  359. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  360. index e0ab96b..36efef4 100644
  361. --- a/src/share/vm/ci/ciObjectFactory.cpp
  362. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  363. @@ -296,6 +296,11 @@
  364. // into the table. We need to recompute our index.
  365. index = find(keyHandle(), _ci_objects);
  366. }
  367. +
  368. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  369. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  370. + return _ci_objects->at(index);
  371. + }
  372. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  373. insert(index, new_object, _ci_objects);
  374. return new_object;
  375. @@ -764,3 +769,50 @@
  376. _unloaded_instances->length(),
  377. _unloaded_klasses->length());
  378. }
  379. +
  380. +// DCEVM: Resoring the ciObject arrays after class redefinition
  381. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  382. +
  383. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  384. + oop last = NULL;
  385. + for (int j = 0; j< objects->length(); j++) {
  386. + oop o = objects->at(j)->get_oop();
  387. + if (last >= o) {
  388. + int cur_last_index = j - 1;
  389. + oop cur_last = last;
  390. + while (cur_last >= o) {
  391. +
  392. + // Swap the two objects to guarantee ordering
  393. + ciObject *tmp = objects->at(cur_last_index);
  394. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  395. + objects->at_put(cur_last_index + 1, tmp);
  396. +
  397. + // Decrement index to move one step to the left
  398. + cur_last_index--;
  399. + if (cur_last_index < 0) {
  400. + break;
  401. + }
  402. + cur_last = objects->at(cur_last_index)->get_oop();
  403. + }
  404. + } else {
  405. + assert(last < o, "out of order");
  406. + last = o;
  407. + }
  408. + }
  409. +
  410. +#ifdef ASSERT
  411. + if (CIObjectFactoryVerify) {
  412. + oop last = NULL;
  413. + for (int j = 0; j< objects->length(); j++) {
  414. + oop o = objects->at(j)->get_oop();
  415. + assert(last < o, "out of order");
  416. + last = o;
  417. + }
  418. + }
  419. +#endif // ASSERT
  420. +}
  421. +
  422. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  423. +void ciObjectFactory::cleanup_after_redefinition() {
  424. + sort_ci_objects(_ci_objects);
  425. +}
  426. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  427. index 26cc2c3..855a4ac 100644
  428. --- a/src/share/vm/ci/ciObjectFactory.hpp
  429. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  430. @@ -38,6 +38,7 @@
  431. class ciObjectFactory : public ResourceObj {
  432. friend class VMStructs;
  433. friend class ciEnv;
  434. + friend class CompileBroker;
  435. private:
  436. static volatile bool _initialized;
  437. @@ -137,6 +138,11 @@
  438. void print_contents();
  439. void print();
  440. +
  441. +private:
  442. +
  443. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  444. + void cleanup_after_redefinition();
  445. };
  446. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  447. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  448. index 847cbd2..3e0ce54 100644
  449. --- a/src/share/vm/classfile/classFileParser.cpp
  450. +++ b/src/share/vm/classfile/classFileParser.cpp
  451. @@ -795,6 +795,7 @@
  452. Handle class_loader,
  453. Handle protection_domain,
  454. Symbol* class_name,
  455. + KlassHandle old_klass,
  456. TRAPS) {
  457. ClassFileStream* cfs = stream();
  458. assert(length > 0, "only called for length>0");
  459. @@ -813,6 +814,9 @@
  460. interface_index, CHECK_(nullHandle));
  461. if (cp->tag_at(interface_index).is_klass()) {
  462. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  463. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  464. + interf = KlassHandle(THREAD, interf->newest_version());
  465. + }
  466. } else {
  467. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  468. @@ -825,6 +829,9 @@
  469. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  470. unresolved_klass, class_loader, protection_domain,
  471. false, CHECK_(nullHandle));
  472. + if (!old_klass.is_null()) {
  473. + k = k->klass_part()->newest_version();
  474. + }
  475. interf = KlassHandle(THREAD, k);
  476. }
  477. @@ -1923,6 +1930,8 @@
  478. int runtime_invisible_parameter_annotations_length = 0;
  479. u1* annotation_default = NULL;
  480. int annotation_default_length = 0;
  481. + u2 code_section_table_length;
  482. + typeArrayHandle code_section_table;
  483. // Parse code and exceptions attribute
  484. u2 method_attributes_count = cfs->get_u2_fast();
  485. @@ -2092,6 +2101,24 @@
  486. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  487. stackmap_data = typeArrayHandle(THREAD, sm);
  488. parsed_stackmap_attribute = true;
  489. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  490. + int length = code_attribute_length;
  491. + int value_count = length / sizeof(u2);
  492. + int line_count = length / 3;
  493. + if (TraceRedefineClasses >= 3) {
  494. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  495. + }
  496. + code_section_table_length = value_count;
  497. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  498. + code_section_table->set_length(value_count);
  499. +
  500. + for (int i = 0; i < value_count; ++i) {
  501. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  502. + code_section_table->short_at_put(i, value);
  503. + if (TraceRedefineClasses >= 4) {
  504. + tty->print_cr("Code section table at %d: %d", i, value);
  505. + }
  506. + }
  507. } else {
  508. // Skip unknown attributes
  509. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  510. @@ -2216,6 +2243,18 @@
  511. }
  512. #endif
  513. + // DCEVM: TODO: Get a different solution for the problem of method forward
  514. + // points and variable sized interpreter frames.
  515. + if (UseMethodForwardPoints) {
  516. + if (max_stack > MethodForwardPointsMaxStack) {
  517. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  518. + }
  519. + if (max_locals > MethodForwardPointsMaxLocals) {
  520. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  521. + }
  522. + max_stack = MethodForwardPointsMaxStack;
  523. + max_locals = MethodForwardPointsMaxLocals;
  524. + }
  525. // Fill in code attribute information
  526. m->set_max_stack(max_stack);
  527. m->set_max_locals(max_locals);
  528. @@ -2228,6 +2267,8 @@
  529. * sure that the oops can pass verification when this field is set.
  530. */
  531. m->constMethod()->set_stackmap_data(stackmap_data());
  532. +
  533. + m->constMethod()->set_code_section_table(code_section_table());
  534. // Copy byte codes
  535. m->set_code(code_start);
  536. @@ -2825,6 +2866,15 @@
  537. "Invalid Deprecated classfile attribute length %u in class file %s",
  538. attribute_length, CHECK);
  539. }
  540. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  541. + // DCEVM: Check for deleted field attribute
  542. + _field_redefinition_policy = cfs->get_u1_fast();
  543. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  544. + // DCEVM: Check for deleted static field attribute
  545. + _static_field_redefinition_policy = cfs->get_u1_fast();
  546. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  547. + // DCEVM: Check for deleted method attribute
  548. + _method_redefinition_policy = cfs->get_u1_fast();
  549. } else if (_major_version >= JAVA_1_5_VERSION) {
  550. if (tag == vmSymbols::tag_signature()) {
  551. if (attribute_length != 2) {
  552. @@ -2929,6 +2979,17 @@
  553. }
  554. k->set_inner_classes(_inner_classes());
  555. k->set_class_annotations(_annotations());
  556. +
  557. +
  558. + if (_field_redefinition_policy != 0xff) {
  559. + k->set_field_redefinition_policy(_field_redefinition_policy);
  560. + }
  561. + if (_static_field_redefinition_policy != 0xff) {
  562. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  563. + }
  564. + if (_method_redefinition_policy != 0xff) {
  565. + k->set_method_redefinition_policy(_method_redefinition_policy);
  566. + }
  567. }
  568. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  569. @@ -2952,9 +3013,126 @@
  570. }
  571. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  572. +// them in a growable array.
  573. +void ClassFileParser::findSuperSymbols(Symbol* name,
  574. + Handle class_loader,
  575. + Handle protection_domain,
  576. + KlassHandle old_klass,
  577. + GrowableArray<Symbol*> &handles,
  578. + TRAPS) {
  579. +
  580. + _cp_patches = NULL;
  581. + // So that JVMTI can cache class file in the state before retransformable agents
  582. + // have modified it
  583. + unsigned char *cached_class_file_bytes = NULL;
  584. +
  585. + ClassFileStream* cfs = stream();
  586. +
  587. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  588. +
  589. + instanceKlassHandle nullHandle;
  590. +
  591. + // Save the class file name for easier error message printing.
  592. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  593. +
  594. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  595. + // Magic value
  596. + u4 magic = cfs->get_u4_fast();
  597. + if (magic != JAVA_CLASSFILE_MAGIC) {
  598. + // Invalid class file!
  599. + return;
  600. + }
  601. +
  602. + // Version numbers
  603. + u2 minor_version = cfs->get_u2_fast();
  604. + u2 major_version = cfs->get_u2_fast();
  605. +
  606. + // Check version numbers - we check this even with verifier off
  607. + if (!is_supported_version(major_version, minor_version)) {
  608. +
  609. + // Unsupported version!
  610. + return;
  611. + }
  612. +
  613. + _major_version = major_version;
  614. + _minor_version = minor_version;
  615. +
  616. +
  617. + // Check if verification needs to be relaxed for this class file
  618. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  619. + _relax_verify = Verifier::relax_verify_for(class_loader());
  620. + _need_verify = false;
  621. +
  622. + // Constant pool
  623. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  624. + int cp_size = cp->length();
  625. +
  626. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  627. +
  628. + // Access flags
  629. + AccessFlags access_flags;
  630. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  631. +
  632. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  633. + // Set abstract bit for old class files for backward compatibility
  634. + flags |= JVM_ACC_ABSTRACT;
  635. + }
  636. + access_flags.set_flags(flags);
  637. +
  638. + // This class and superclass
  639. + instanceKlassHandle super_klass;
  640. + u2 this_class_index = cfs->get_u2_fast();
  641. + check_property(
  642. + valid_cp_range(this_class_index, cp_size) &&
  643. + cp->tag_at(this_class_index).is_unresolved_klass(),
  644. + "Invalid this class index %u in constant pool in class file %s",
  645. + this_class_index, CHECK);
  646. +
  647. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  648. + assert(class_name != NULL, "class_name can't be null");
  649. +
  650. + // Update _class_name which could be null previously to be class_name
  651. + _class_name = class_name;
  652. +
  653. + // DCEVM: DO NOT release all handles when parsing is done
  654. + {// HandleMark hm(THREAD);
  655. +
  656. + // Checks if name in class file matches requested name
  657. + if (name != NULL && class_name != name) {
  658. + return;
  659. + }
  660. +
  661. + u2 super_class_index = cfs->get_u2_fast();
  662. +
  663. + if (super_class_index != 0) {
  664. + Symbol* super_class = cp->klass_name_at(super_class_index);
  665. + handles.append(super_class);
  666. + } else {
  667. + // DCEVM: This redefinition must be for the Object class.
  668. + }
  669. +
  670. + // Interfaces
  671. + u2 itfs_len = cfs->get_u2_fast();
  672. + objArrayHandle local_interfaces;
  673. + if (itfs_len == 0) {
  674. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  675. + } else {
  676. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  677. + }
  678. +
  679. + for (int i=0; i<local_interfaces->length(); i++) {
  680. + oop o = local_interfaces->obj_at(i);
  681. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  682. + handles.append(interface_handle);
  683. + }
  684. + }
  685. +}
  686. +
  687. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  688. Handle class_loader,
  689. Handle protection_domain,
  690. + KlassHandle old_klass,
  691. KlassHandle host_klass,
  692. GrowableArray<Handle>* cp_patches,
  693. TempNewSymbol& parsed_name,
  694. @@ -3005,10 +3183,13 @@
  695. unsigned char* ptr = cfs->buffer();
  696. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  697. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  698. + Thread::current()->set_pretend_new_universe(false);
  699. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  700. &ptr, &end_ptr,
  701. &cached_class_file_bytes,
  702. &cached_class_file_length);
  703. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  704. if (ptr != cfs->buffer()) {
  705. // JVMTI agent has modified class file data.
  706. @@ -3164,7 +3345,11 @@
  707. // However, make sure it is not an array type.
  708. bool is_array = false;
  709. if (cp->tag_at(super_class_index).is_klass()) {
  710. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  711. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  712. + if (!old_klass.is_null()) {
  713. + resolved_klass = resolved_klass->klass_part()->newest_version();
  714. + }
  715. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  716. if (_need_verify)
  717. is_array = super_klass->oop_is_array();
  718. } else if (_need_verify) {
  719. @@ -3182,7 +3367,7 @@
  720. if (itfs_len == 0) {
  721. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  722. } else {
  723. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  724. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  725. }
  726. u2 java_fields_count = 0;
  727. @@ -3237,7 +3422,9 @@
  728. protection_domain,
  729. true,
  730. CHECK_(nullHandle));
  731. -
  732. + if (!old_klass.is_null()) {
  733. + k = k->klass_part()->newest_version();
  734. + }
  735. KlassHandle kh (THREAD, k);
  736. super_klass = instanceKlassHandle(THREAD, kh());
  737. }
  738. @@ -3626,6 +3813,19 @@
  739. rt = REF_NONE;
  740. } else {
  741. rt = super_klass->reference_type();
  742. +
  743. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  744. + if (name == vmSymbols::java_lang_ref_Reference()) {
  745. + rt = REF_OTHER;
  746. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  747. + rt = REF_SOFT;
  748. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  749. + rt = REF_WEAK;
  750. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  751. + rt = REF_FINAL;
  752. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  753. + rt = REF_PHANTOM;
  754. + }
  755. }
  756. // We can now create the basic klassOop for this klass
  757. @@ -3726,7 +3926,7 @@
  758. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  759. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  760. - set_precomputed_flags(this_klass);
  761. + set_precomputed_flags(this_klass, old_klass);
  762. // reinitialize modifiers, using the InnerClasses attribute
  763. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  764. @@ -3748,6 +3948,10 @@
  765. // Allocate mirror and initialize static fields
  766. java_lang_Class::create_mirror(this_klass, class_loader, CHECK_(nullHandle));
  767. +
  768. + if (rt == REF_OTHER) {
  769. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  770. + }
  771. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  772. false /* not shared class */);
  773. @@ -3891,7 +4095,7 @@
  774. }
  775. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  776. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  777. klassOop super = k->super();
  778. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  779. @@ -3899,7 +4103,9 @@
  780. if (!_has_empty_finalizer) {
  781. if (_has_finalizer ||
  782. (super != NULL && super->klass_part()->has_finalizer())) {
  783. - k->set_has_finalizer();
  784. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  785. + k->set_has_finalizer();
  786. + }
  787. }
  788. }
  789. @@ -3915,7 +4121,7 @@
  790. // Check if this klass supports the java.lang.Cloneable interface
  791. if (SystemDictionary::Cloneable_klass_loaded()) {
  792. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  793. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  794. k->set_is_cloneable();
  795. }
  796. }
  797. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  798. index a95a784..ac217fc 100644
  799. --- a/src/share/vm/classfile/classFileParser.hpp
  800. +++ b/src/share/vm/classfile/classFileParser.hpp
  801. @@ -64,6 +64,9 @@
  802. int _sde_length;
  803. typeArrayHandle _inner_classes;
  804. typeArrayHandle _annotations;
  805. + u1 _field_redefinition_policy;
  806. + u1 _static_field_redefinition_policy;
  807. + u1 _method_redefinition_policy;
  808. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  809. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  810. @@ -151,6 +154,7 @@
  811. Handle class_loader,
  812. Handle protection_domain,
  813. Symbol* class_name,
  814. + KlassHandle old_klass,
  815. TRAPS);
  816. // Field parsing
  817. @@ -239,7 +243,7 @@
  818. unsigned int nonstatic_oop_map_count,
  819. int* nonstatic_oop_offsets,
  820. unsigned int* nonstatic_oop_counts);
  821. - void set_precomputed_flags(instanceKlassHandle k);
  822. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  823. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  824. objArrayHandle local_ifs, TRAPS);
  825. @@ -345,7 +349,12 @@
  826. public:
  827. // Constructor
  828. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  829. + ClassFileParser(ClassFileStream* st) {
  830. + set_stream(st);
  831. + _field_redefinition_policy = 0xff;
  832. + _static_field_redefinition_policy = 0xff;
  833. + _method_redefinition_policy = 0xff;
  834. + }
  835. // Parse .class file and return new klassOop. The klassOop is not hooked up
  836. // to the system dictionary or any other structures, so a .class file can
  837. @@ -357,21 +366,33 @@
  838. instanceKlassHandle parseClassFile(Symbol* name,
  839. Handle class_loader,
  840. Handle protection_domain,
  841. + KlassHandle old_klass,
  842. TempNewSymbol& parsed_name,
  843. bool verify,
  844. TRAPS) {
  845. KlassHandle no_host_klass;
  846. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  847. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  848. }
  849. instanceKlassHandle parseClassFile(Symbol* name,
  850. Handle class_loader,
  851. Handle protection_domain,
  852. + KlassHandle old_klass,
  853. KlassHandle host_klass,
  854. GrowableArray<Handle>* cp_patches,
  855. TempNewSymbol& parsed_name,
  856. bool verify,
  857. TRAPS);
  858. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  859. +
  860. + // DCEVM: Creates symbol handles for the super class and the interfaces
  861. + void findSuperSymbols(Symbol* name,
  862. + Handle class_loader,
  863. + Handle protection_domain,
  864. + KlassHandle old_klass,
  865. + GrowableArray<Symbol*> &handles,
  866. + TRAPS);
  867. +
  868. // Verifier checks
  869. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  870. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  871. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  872. index aa670a4..584c168 100644
  873. --- a/src/share/vm/classfile/classLoader.cpp
  874. +++ b/src/share/vm/classfile/classLoader.cpp
  875. @@ -924,6 +924,7 @@
  876. instanceKlassHandle result = parser.parseClassFile(h_name,
  877. class_loader,
  878. protection_domain,
  879. + KlassHandle(),
  880. parsed_name,
  881. false,
  882. CHECK_(h));
  883. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  884. index 78e76cc..ee21f3a 100644
  885. --- a/src/share/vm/classfile/dictionary.cpp
  886. +++ b/src/share/vm/classfile/dictionary.cpp
  887. @@ -326,6 +326,21 @@
  888. }
  889. }
  890. +
  891. +// DCEVM: Just the classes from defining class loaders
  892. +void Dictionary::classes_do(ObjectClosure *closure) {
  893. + for (int index = 0; index < table_size(); index++) {
  894. + for (DictionaryEntry* probe = bucket(index);
  895. + probe != NULL;
  896. + probe = probe->next()) {
  897. + klassOop k = probe->klass();
  898. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  899. + closure->do_object(k);
  900. + }
  901. + }
  902. + }
  903. +}
  904. +
  905. // Added for initialize_itable_for_klass to handle exceptions
  906. // Just the classes from defining class loaders
  907. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  908. @@ -433,6 +448,33 @@
  909. add_entry(index, entry);
  910. }
  911. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  912. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  913. +
  914. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  915. + bool found = false;
  916. + for (int index = 0; index < table_size(); index++) {
  917. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  918. + if (entry->klass() == old_class()) {
  919. + entry->set_literal(k());
  920. + found = true;
  921. + }
  922. + }
  923. + }
  924. +
  925. + return found;
  926. +}
  927. +
  928. +// DCEVM: Undo previous updates to the system dictionary
  929. +void Dictionary::rollback_redefinition() {
  930. + for (int index = 0; index < table_size(); index++) {
  931. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  932. + if (entry->klass()->klass_part()->is_redefining()) {
  933. + entry->set_literal(entry->klass()->klass_part()->old_version());
  934. + }
  935. + }
  936. + }
  937. +}
  938. // This routine does not lock the system dictionary.
  939. //
  940. @@ -459,12 +501,22 @@
  941. return NULL;
  942. }
  943. +// DCEVM: return old version if we are not in the new universe?
  944. +klassOop Dictionary::intercept_for_version(klassOop k) {
  945. + if (k == NULL) return k;
  946. +
  947. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  948. + return k->klass_part()->old_version();
  949. + }
  950. +
  951. + return k;
  952. +}
  953. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  954. Handle loader, Handle protection_domain, TRAPS) {
  955. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  956. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  957. - return entry->klass();
  958. + return intercept_for_version(entry->klass());
  959. } else {
  960. return NULL;
  961. }
  962. @@ -477,7 +529,7 @@
  963. assert (index == index_for(name, loader), "incorrect index?");
  964. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  965. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  966. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  967. }
  968. @@ -489,7 +541,7 @@
  969. assert (index == index_for(name, Handle()), "incorrect index?");
  970. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  971. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  972. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  973. }
  974. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  975. index bd33760..186d0eb 100644
  976. --- a/src/share/vm/classfile/dictionary.hpp
  977. +++ b/src/share/vm/classfile/dictionary.hpp
  978. @@ -73,6 +73,10 @@
  979. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  980. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  981. +
  982. + void rollback_redefinition();
  983. +
  984. klassOop find_class(int index, unsigned int hash,
  985. Symbol* name, Handle loader);
  986. @@ -89,6 +93,7 @@
  987. void classes_do(void f(klassOop, TRAPS), TRAPS);
  988. void classes_do(void f(klassOop, oop));
  989. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  990. + void classes_do(ObjectClosure *closure);
  991. void methods_do(void f(methodOop));
  992. @@ -105,6 +110,7 @@
  993. bool do_unloading(BoolObjectClosure* is_alive);
  994. // Protection domains
  995. + static klassOop intercept_for_version(klassOop k);
  996. klassOop find(int index, unsigned int hash, Symbol* name,
  997. Handle loader, Handle protection_domain, TRAPS);
  998. bool is_valid_protection_domain(int index, unsigned int hash,
  999. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  1000. index 78176f1..992697d 100644
  1001. --- a/src/share/vm/classfile/javaClasses.cpp
  1002. +++ b/src/share/vm/classfile/javaClasses.cpp
  1003. @@ -1820,7 +1820,7 @@
  1004. klassOop klass = SystemDictionary::reflect_Method_klass();
  1005. // This class is eagerly initialized during VM initialization, since we keep a refence
  1006. // to one of the methods
  1007. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1008. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1009. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1010. }
  1011. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1012. index 7f02ca2..a99ccab 100644
  1013. --- a/src/share/vm/classfile/javaClasses.hpp
  1014. +++ b/src/share/vm/classfile/javaClasses.hpp
  1015. @@ -214,7 +214,6 @@
  1016. class java_lang_Class : AllStatic {
  1017. friend class VMStructs;
  1018. -
  1019. private:
  1020. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1021. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1022. index 8650cd9..965cce2 100644
  1023. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1024. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1025. @@ -449,7 +449,7 @@
  1026. if (k != NULL) {
  1027. // We found the class in the system dictionary, so we should
  1028. // make sure that the klassOop matches what we already have.
  1029. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1030. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1031. } else {
  1032. // If we don't find the class in the system dictionary, it
  1033. // has to be in the placeholders table.
  1034. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1035. index d01b2c4..1ad80f7 100644
  1036. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1037. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1038. @@ -106,7 +106,7 @@
  1039. klassOop klass() { return literal(); }
  1040. klassOop* klass_addr() { return literal_addr(); }
  1041. - void set_klass(klassOop k) { set_literal(k); }
  1042. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1043. LoaderConstraintEntry* next() {
  1044. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1045. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1046. index 7901263..224938e 100644
  1047. --- a/src/share/vm/classfile/systemDictionary.cpp
  1048. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1049. @@ -157,6 +157,7 @@
  1050. // can return a null klass
  1051. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1052. }
  1053. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1054. return klass;
  1055. }
  1056. @@ -199,7 +200,8 @@
  1057. // Forwards to resolve_instance_class_or_null
  1058. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1059. - assert(!THREAD->is_Compiler_thread(),
  1060. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1061. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1062. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1063. class_name->as_C_string(),
  1064. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1065. @@ -961,6 +963,7 @@
  1066. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1067. class_loader,
  1068. protection_domain,
  1069. + KlassHandle(),
  1070. host_klass,
  1071. cp_patches,
  1072. parsed_name,
  1073. @@ -1022,7 +1025,14 @@
  1074. Handle protection_domain,
  1075. ClassFileStream* st,
  1076. bool verify,
  1077. + KlassHandle old_class,
  1078. TRAPS) {
  1079. + bool redefine_classes_locked = false;
  1080. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1081. + Thread::current()->redefine_classes_mutex()->lock();
  1082. + redefine_classes_locked = true;
  1083. + }
  1084. +
  1085. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1086. // or all classloaders with UnsyncloadClass do not acquire lock here
  1087. bool DoObjectLock = true;
  1088. @@ -1050,9 +1060,14 @@
  1089. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1090. class_loader,
  1091. protection_domain,
  1092. + old_class,
  1093. parsed_name,
  1094. verify,
  1095. THREAD);
  1096. + if (!old_class.is_null() && !k.is_null()) {
  1097. + k->set_redefining(true);
  1098. + k->set_old_version(old_class());
  1099. + }
  1100. const char* pkg = "java/";
  1101. if (!HAS_PENDING_EXCEPTION &&
  1102. @@ -1087,11 +1102,16 @@
  1103. // Add class just loaded
  1104. // If a class loader supports parallel classloading handle parallel define requests
  1105. // find_or_define_instance_class may return a different instanceKlass
  1106. - if (is_parallelCapable(class_loader)) {
  1107. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1108. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1109. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1110. } else {
  1111. - define_instance_class(k, THREAD);
  1112. + define_instance_class(k, old_class, THREAD);
  1113. }
  1114. + }
  1115. +
  1116. + if (redefine_classes_locked) {
  1117. + Thread::current()->redefine_classes_mutex()->unlock();
  1118. }
  1119. // If parsing the class file or define_instance_class failed, we
  1120. @@ -1122,7 +1142,7 @@
  1121. MutexLocker mu(SystemDictionary_lock, THREAD);
  1122. klassOop check = find_class(parsed_name, class_loader);
  1123. - assert(check == k(), "should be present in the dictionary");
  1124. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1125. klassOop check2 = find_class(h_name, h_loader);
  1126. assert(check == check2, "name inconsistancy in SystemDictionary");
  1127. @@ -1349,7 +1369,11 @@
  1128. }
  1129. }
  1130. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1131. +void SystemDictionary::rollback_redefinition() {
  1132. + dictionary()->rollback_redefinition();
  1133. +}
  1134. +
  1135. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1136. Handle class_loader_h(THREAD, k->class_loader());
  1137. @@ -1376,13 +1400,23 @@
  1138. Symbol* name_h = k->name();
  1139. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1140. int d_index = dictionary()->hash_to_index(d_hash);
  1141. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1142. +
  1143. + // DCEVM: Update version of the klassOop in the system dictionary
  1144. + // TODO: Check for thread safety!
  1145. + if (!old_class.is_null()) {
  1146. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1147. + assert (ok, "must have found old class and updated!");
  1148. + }
  1149. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1150. +
  1151. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1152. // Register class just loaded with class loader (placed in Vector)
  1153. // Note we do this before updating the dictionary, as this can
  1154. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1155. // class in the dictionary and will not update the class hierarchy).
  1156. - if (k->class_loader() != NULL) {
  1157. + // (tw) Only register if not redefining a class.
  1158. + if (k->class_loader() != NULL && old_class.is_null()) {
  1159. methodHandle m(THREAD, Universe::loader_addClass_method());
  1160. JavaValue result(T_VOID);
  1161. JavaCallArguments args(class_loader_h);
  1162. @@ -1408,8 +1442,9 @@
  1163. }
  1164. k->eager_initialize(THREAD);
  1165. + // (tw) Only notify jvmti if not redefining a class.
  1166. // notify jvmti
  1167. - if (JvmtiExport::should_post_class_load()) {
  1168. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1169. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1170. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1171. @@ -1482,7 +1517,7 @@
  1172. }
  1173. }
  1174. - define_instance_class(k, THREAD);
  1175. + define_instance_class(k, KlassHandle(), THREAD);
  1176. Handle linkage_exception = Handle(); // null handle
  1177. @@ -1613,6 +1648,14 @@
  1178. Universe::flush_dependents_on(k);
  1179. }
  1180. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1181. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1182. + assert(k.not_null(), "just checking");
  1183. +
  1184. + k->remove_from_sibling_list();
  1185. +
  1186. + // TODO: Remove from interfaces.
  1187. +}
  1188. // ----------------------------------------------------------------------------
  1189. // GC support
  1190. @@ -1702,6 +1745,24 @@
  1191. }
  1192. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1193. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1194. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1195. + f->do_oop((oop*) &_well_known_klasses[k]);
  1196. + }
  1197. +
  1198. + {
  1199. + for (int i = 0; i < T_VOID+1; i++) {
  1200. + if (_box_klasses[i] != NULL) {
  1201. + assert(i >= T_BOOLEAN, "checking");
  1202. + f->do_oop((oop*) &_box_klasses[i]);
  1203. + }
  1204. + }
  1205. + }
  1206. +
  1207. + // TODO: Check if we need to call FilterFieldsMap
  1208. +}
  1209. +
  1210. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1211. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1212. f->do_oop((oop*) &_well_known_klasses[k]);
  1213. @@ -1732,6 +1793,11 @@
  1214. // Don't iterate over placeholders
  1215. void SystemDictionary::classes_do(void f(klassOop)) {
  1216. dictionary()->classes_do(f);
  1217. +}
  1218. +
  1219. +// (tw) Iterate over all classes in the dictionary.
  1220. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1221. + dictionary()->classes_do(closure);
  1222. }
  1223. // Added for initialize_itable_for_klass
  1224. @@ -1870,7 +1936,9 @@
  1225. // Preload ref klasses and set reference types
  1226. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1227. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1228. +
  1229. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1230. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1231. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
  1232. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1233. @@ -1957,7 +2025,11 @@
  1234. // also holds array classes
  1235. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1236. - if ((defining == true) || (k() != check)) {
  1237. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1238. + ResourceMark rm(Thread::current());
  1239. + tty->print_cr("(%d / %d) (%s/%s)", k->revision_number(), check->klass_part()->revision_number(), k->name()->as_C_string(), check->klass_part()->name()->as_C_string());
  1240. + k()->print();
  1241. + check->print();
  1242. linkage_error = "loader (instance of %s): attempted duplicate class "
  1243. "definition for name: \"%s\"";
  1244. } else {
  1245. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1246. index 85474c5..2dabd95 100644
  1247. --- a/src/share/vm/classfile/systemDictionary.hpp
  1248. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1249. @@ -270,7 +270,7 @@
  1250. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1251. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1252. Handle protection_domain,
  1253. - ClassFileStream* st, bool verify, TRAPS);
  1254. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1255. // Lookup an already loaded class. If not found NULL is returned.
  1256. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1257. @@ -311,6 +311,8 @@
  1258. // Iterate over all klasses in dictionary
  1259. // Just the classes from defining class loaders
  1260. static void classes_do(void f(klassOop));
  1261. + static void classes_do(ObjectClosure *closure);
  1262. + static void preloaded_classes_do(OopClosure *closure);
  1263. // Added for initialize_itable_for_klass to handle exceptions
  1264. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1265. // All classes, and their class loaders
  1266. @@ -416,6 +418,8 @@
  1267. int limit = (int)end_id + 1;
  1268. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1269. }
  1270. +
  1271. + static void rollback_redefinition();
  1272. public:
  1273. #define WK_KLASS_DECLARE(name, symbol, option) \
  1274. @@ -598,11 +602,11 @@
  1275. // after waiting, but before reentering SystemDictionary_lock
  1276. // to preserve lock order semantics.
  1277. static void double_lock_wait(Handle lockObject, TRAPS);
  1278. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1279. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1280. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1281. Handle class_loader,
  1282. instanceKlassHandle k, TRAPS);
  1283. - static instanceKlassHandle load_shared_class(Symbol* class_name,
  1284. + static instanceKlassHandle load_shared_class(Symbol* class_name, // after waiting, but before reentering SystemDictionary_lock,
  1285. Handle class_loader, TRAPS);
  1286. static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
  1287. Handle class_loader, TRAPS);
  1288. @@ -617,12 +621,16 @@
  1289. // Setup link to hierarchy
  1290. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1291. +public:
  1292. + // Remove link to hierarchy
  1293. + static void remove_from_hierarchy(instanceKlassHandle k);
  1294. +
  1295. +private:
  1296. // event based tracing
  1297. static void post_class_load_event(const Ticks& start_time, instanceKlassHandle k,
  1298. Handle initiating_loader);
  1299. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1300. -private:
  1301. // We pass in the hashtable index so we can calculate it outside of
  1302. // the SystemDictionary_lock.
  1303. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1304. index 49c4b2c..74d7614 100644
  1305. --- a/src/share/vm/classfile/verifier.cpp
  1306. +++ b/src/share/vm/classfile/verifier.cpp
  1307. @@ -106,7 +106,7 @@
  1308. return !need_verify;
  1309. }
  1310. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1311. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1312. HandleMark hm;
  1313. ResourceMark rm(THREAD);
  1314. @@ -117,7 +117,8 @@
  1315. const char* klassName = klass->external_name();
  1316. bool can_failover = FailOverToOldVerifier &&
  1317. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1318. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1319. + may_use_old_verifier;
  1320. // If the class should be verified, first see if we can use the split
  1321. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1322. @@ -138,6 +139,7 @@
  1323. tty->print_cr(
  1324. "Fail over class verification to old verifier for: %s", klassName);
  1325. }
  1326. + assert(may_use_old_verifier, "");
  1327. exception_name = inference_verify(
  1328. klass, message_buffer, message_buffer_len, THREAD);
  1329. }
  1330. @@ -145,6 +147,7 @@
  1331. exception_message = split_verifier.exception_message();
  1332. }
  1333. } else {
  1334. + assert(may_use_old_verifier, "");
  1335. exception_name = inference_verify(
  1336. klass, message_buffer, message_buffer_len, THREAD);
  1337. }
  1338. @@ -159,6 +162,9 @@
  1339. }
  1340. tty->print_cr("End class verification for: %s", klassName);
  1341. }
  1342. + } else if (TraceClassInitialization) {
  1343. + // (tw) Output not verified classes
  1344. + tty->print_cr("Class %s was not verified", klassName);
  1345. }
  1346. if (HAS_PENDING_EXCEPTION) {
  1347. @@ -210,7 +216,7 @@
  1348. // NOTE: this is called too early in the bootstrapping process to be
  1349. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1350. (refl_magic_klass == NULL ||
  1351. - !klass->is_subtype_of(refl_magic_klass) ||
  1352. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1353. VerifyReflectionBytecodes)
  1354. );
  1355. }
  1356. @@ -517,7 +523,7 @@
  1357. ClassVerifier::ClassVerifier(
  1358. instanceKlassHandle klass, TRAPS)
  1359. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1360. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1361. _this_type = VerificationType::reference_type(klass->name());
  1362. // Create list to hold symbols in reference area.
  1363. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1364. @@ -547,7 +553,7 @@
  1365. _klass->external_name());
  1366. }
  1367. - objArrayHandle methods(THREAD, _klass->methods());
  1368. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1369. int num_methods = methods->length();
  1370. for (int index = 0; index < num_methods; index++) {
  1371. @@ -2668,7 +2674,10 @@
  1372. VerificationType stack_object_type =
  1373. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1374. if (current_type() != stack_object_type) {
  1375. - assert(cp->cache() == NULL, "not rewritten yet");
  1376. +
  1377. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1378. + //assert(cp->cache() == NULL, "not rewritten yet");
  1379. +
  1380. Symbol* ref_class_name =
  1381. cp->klass_name_at(cp->klass_ref_index_at(index));
  1382. // See the comments in verify_field_instructions() for
  1383. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1384. index 92c4fd2..5e8e0da 100644
  1385. --- a/src/share/vm/classfile/verifier.hpp
  1386. +++ b/src/share/vm/classfile/verifier.hpp
  1387. @@ -48,7 +48,7 @@
  1388. * Otherwise, no exception is thrown and the return indicates the
  1389. * error.
  1390. */
  1391. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1392. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1393. // Return false if the class is loaded by the bootstrap loader,
  1394. // or if defineClass was called requesting skipping verification
  1395. @@ -257,7 +257,10 @@
  1396. ErrorContext _error_context; // contains information about an error
  1397. +public:
  1398. void verify_method(methodHandle method, TRAPS);
  1399. +
  1400. +private:
  1401. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1402. void verify_exception_handler_table(u4 code_length, char* code_data,
  1403. int& min, int& max, TRAPS);
  1404. @@ -341,6 +344,7 @@
  1405. VerificationType object_type() const;
  1406. + instanceKlassHandle _klass_to_verify;
  1407. instanceKlassHandle _klass; // the class being verified
  1408. methodHandle _method; // current method being verified
  1409. VerificationType _this_type; // the verification type of the current class
  1410. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1411. index c881d1e..53c6d4d 100644
  1412. --- a/src/share/vm/classfile/vmSymbols.hpp
  1413. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1414. @@ -139,6 +139,10 @@
  1415. template(tag_annotation_default, "AnnotationDefault") \
  1416. template(tag_enclosing_method, "EnclosingMethod") \
  1417. template(tag_bootstrap_methods, "BootstrapMethods") \
  1418. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1419. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1420. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1421. + template(tag_code_sections, "CodeSections") \
  1422. \
  1423. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1424. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1425. @@ -380,6 +384,10 @@
  1426. template(oop_size_name, "oop_size") \
  1427. template(static_oop_field_count_name, "static_oop_field_count") \
  1428. \
  1429. + /* mutator in case of class redefinition */ \
  1430. + template(static_transformer_name, "$staticTransformer") \
  1431. + template(transformer_name, "$transformer") \
  1432. + \
  1433. /* non-intrinsic name/signature pairs: */ \
  1434. template(register_method_name, "register") \
  1435. do_alias(register_method_signature, object_void_signature) \
  1436. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1437. index c07d997..1a17d5a 100644
  1438. --- a/src/share/vm/compiler/compileBroker.cpp
  1439. +++ b/src/share/vm/compiler/compileBroker.cpp
  1440. @@ -1181,6 +1181,14 @@
  1441. int comp_level,
  1442. methodHandle hot_method, int hot_count,
  1443. const char* comment, Thread* THREAD) {
  1444. + JavaThread* thread = JavaThread::current();
  1445. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1446. + return NULL; // FIXME: DCEVM: should we do something else?
  1447. + }
  1448. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1449. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1450. + }
  1451. +
  1452. // make sure arguments make sense
  1453. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1454. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1455. @@ -1260,6 +1268,7 @@
  1456. }
  1457. // RedefineClasses() has replaced this method; just return
  1458. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1459. if (method->is_old()) {
  1460. return NULL;
  1461. }
  1462. @@ -1592,6 +1601,8 @@
  1463. // Never compile a method if breakpoints are present in it
  1464. if (method()->number_of_breakpoints() == 0) {
  1465. + thread->compilation_mutex()->lock();
  1466. + thread->set_should_bailout(false);
  1467. // Compile the method.
  1468. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1469. invoke_compiler_on_method(task);
  1470. @@ -1599,6 +1610,7 @@
  1471. // After compilation is disabled, remove remaining methods from queue
  1472. method->clear_queued_for_compilation();
  1473. }
  1474. + thread->compilation_mutex()->unlock();
  1475. }
  1476. }
  1477. }
  1478. @@ -2149,3 +2161,15 @@
  1479. st->cr();
  1480. #endif
  1481. }
  1482. +
  1483. +// (tw) Clean up compiler interface after a class redefinition step
  1484. +void CompileBroker::cleanup_after_redefinition() {
  1485. + int num_threads = _method_threads->length();
  1486. +
  1487. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1488. + for (int i=0; i<num_threads; i++) {
  1489. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1490. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1491. + }
  1492. + }
  1493. +}
  1494. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1495. index 29f2b22..37989d1 100644
  1496. --- a/src/share/vm/compiler/compileBroker.hpp
  1497. +++ b/src/share/vm/compiler/compileBroker.hpp
  1498. @@ -408,6 +408,7 @@
  1499. static void print_compiler_threads_on(outputStream* st);
  1500. + static void cleanup_after_redefinition();
  1501. static int get_total_compile_count() { return _total_compile_count; }
  1502. static int get_total_bailout_count() { return _total_bailout_count; }
  1503. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1504. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1505. index a3abd66..b45f9e1 100644
  1506. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1507. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1508. @@ -162,6 +162,13 @@
  1509. }
  1510. }
  1511. +
  1512. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1513. + CompactPoint* cp, HeapWord* compact_top) {
  1514. + ShouldNotReachHere();
  1515. + return NULL;
  1516. +}
  1517. +
  1518. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1519. // update the block offset table. Removed initialize_threshold call because
  1520. // CFLS does not use a block offset array for contiguous spaces.
  1521. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1522. index 24509b6..6670b73 100644
  1523. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1524. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1525. @@ -149,6 +149,7 @@
  1526. // Support for compacting cms
  1527. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1528. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1529. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1530. // Initialization helpers.
  1531. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1532. index 29841d8..a13a35d 100644
  1533. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1534. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1535. @@ -32,6 +32,8 @@
  1536. #include "oops/objArrayKlass.inline.hpp"
  1537. #include "oops/oop.inline.hpp"
  1538. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1539. +
  1540. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1541. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1542. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1543. @@ -357,3 +359,86 @@
  1544. }
  1545. #endif
  1546. +
  1547. +// (tw) Copy the rescued objects to their destination address after compaction.
  1548. +void MarkSweep::copy_rescued_objects_back() {
  1549. +
  1550. + if (_rescued_oops != NULL) {
  1551. +
  1552. + for (int i=0; i<_rescued_oops->length(); i++) {
  1553. + oop rescued_obj = _rescued_oops->at(i);
  1554. +
  1555. + int size = rescued_obj->size();
  1556. + oop new_obj = rescued_obj->forwardee();
  1557. +
  1558. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1559. + MarkSweep::update_fields(rescued_obj, new_obj);
  1560. + } else {
  1561. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1562. + }
  1563. +
  1564. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1565. +
  1566. + new_obj->init_mark();
  1567. + assert(new_obj->is_oop(), "must be a valid oop");
  1568. + }
  1569. + _rescued_oops->clear();
  1570. + _rescued_oops = NULL;
  1571. + }
  1572. +}
  1573. +
  1574. +// (tw) Update instances of a class whose fields changed.
  1575. +void MarkSweep::update_fields(oop q, oop new_location) {
  1576. +
  1577. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1578. +
  1579. + klassOop old_klass_oop = q->klass();
  1580. + klassOop new_klass_oop = q->blueprint()->new_version();
  1581. +
  1582. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1583. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1584. +
  1585. + int size = q->size_given_klass(old_klass);
  1586. + int new_size = q->size_given_klass(new_klass);
  1587. +
  1588. + oop tmp_obj = q;
  1589. +
  1590. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1591. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1592. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1593. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1594. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1595. + }
  1596. + }
  1597. +
  1598. + int *cur = new_klass_oop->klass_part()->update_information();
  1599. +
  1600. + tmp_obj->set_klass_no_check(new_klass_oop);
  1601. +
  1602. + if (cur == NULL) {
  1603. + assert(size == new_size, "just checking");
  1604. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1605. + } else {
  1606. + int destOffset = 0;
  1607. + while (*cur != 0) {
  1608. + if (*cur > 0) {
  1609. + int size = *cur;
  1610. + cur++;
  1611. + int offset = *cur;
  1612. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1613. + destOffset += size;
  1614. + cur++;
  1615. + } else {
  1616. + assert(*cur < 0, "");
  1617. + int skip = -*cur;
  1618. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1619. + destOffset += skip;
  1620. + cur++;
  1621. + }
  1622. + }
  1623. + }
  1624. +
  1625. + if (tmp_obj != q) {
  1626. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1627. + }
  1628. +}
  1629. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1630. index eb8252c..b96a677 100644
  1631. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1632. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1633. @@ -117,7 +117,11 @@
  1634. friend class AdjustPointerClosure;
  1635. friend class KeepAliveClosure;
  1636. friend class VM_MarkSweep;
  1637. + friend class GenMarkSweep;
  1638. friend void marksweep_init();
  1639. +
  1640. +public:
  1641. + static GrowableArray<oop>* _rescued_oops;
  1642. //
  1643. // Vars
  1644. @@ -208,6 +212,8 @@
  1645. template <class T> static inline void mark_and_push(T* p);
  1646. static inline void push_objarray(oop obj, size_t index);
  1647. + static void copy_rescued_objects_back();
  1648. + static void update_fields(oop q, oop new_location);
  1649. static void follow_stack(); // Empty marking stack.
  1650. static void preserve_mark(oop p, markOop mark);
  1651. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1652. index 1a1af1b..94972f0 100644
  1653. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1654. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1655. @@ -402,7 +402,7 @@
  1656. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1657. assert(h_exception->is_oop(), "just checking");
  1658. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1659. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1660. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1661. if (ExitVMOnVerifyError) vm_exit(-1);
  1662. ShouldNotReachHere();
  1663. }
  1664. @@ -656,6 +656,82 @@
  1665. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1666. IRT_END
  1667. +// (tw) Correctly resolve method when running old code.
  1668. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1669. + {
  1670. + MonitorLockerEx ml(RedefinitionSync_lock);
  1671. + while (Threads::wait_at_instrumentation_entry()) {
  1672. + ml.wait();
  1673. + }
  1674. + }
  1675. + frame f = last_frame(thread);
  1676. + methodOop m = f.interpreter_frame_method();
  1677. + methodOop forward_method = m->forward_method();
  1678. + if (forward_method != NULL) {
  1679. + int bci = f.interpreter_frame_bci();
  1680. +
  1681. + if (TraceRedefineClasses >= 3) {
  1682. + tty->print_cr("Executing NOP in method %s at bci %d %d", m->name()->as_C_string(), bci, m->is_in_code_section(bci + 1));
  1683. + }
  1684. +
  1685. + int next_bci = bci - 1;
  1686. + // First try bci before NOP.
  1687. + if (!m->is_in_code_section(next_bci)) {
  1688. + // Try bci after NOP.
  1689. + next_bci = bci + 1;
  1690. + if (!m->is_in_code_section(next_bci)) return;
  1691. + }
  1692. +
  1693. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1694. + if (TraceRedefineClasses >= 2) {
  1695. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1696. + }
  1697. + RegisterMap reg_map(thread);
  1698. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1699. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1700. + iframe->set_method(forward_method, new_bci - 1);
  1701. + }
  1702. +IRT_END
  1703. +
  1704. +// (tw) Correctly resolve method when running old code.
  1705. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1706. + // extract receiver from the outgoing argument list if necessary
  1707. + Handle receiver(thread, receiverOop);
  1708. +
  1709. + // TODO: Check for invokeinterface!
  1710. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1711. +
  1712. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1713. + klassOop klass = receiverOop->klass();
  1714. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1715. + klass = klass->klass_part()->old_version();
  1716. + }
  1717. +
  1718. + // TODO: Check for correctness if different vtable indices in different versions?
  1719. +
  1720. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1721. + thread->set_vm_result(method);
  1722. +IRT_END
  1723. +
  1724. +// Correctly resolve interface method when running old code.
  1725. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1726. +
  1727. + // extract receiver from the outgoing argument list if necessary
  1728. + Handle receiver(thread, receiverOop);
  1729. +
  1730. + // TODO: Check for invokeinterface!
  1731. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1732. +
  1733. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1734. + klassOop klass = receiverOop->klass();
  1735. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1736. + klass = klass->klass_part()->old_version();
  1737. + }
  1738. +
  1739. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1740. + thread->set_vm_result(method);
  1741. +IRT_END
  1742. +
  1743. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1744. // extract receiver from the outgoing argument list if necessary
  1745. Handle receiver(thread, NULL);
  1746. @@ -684,6 +760,10 @@
  1747. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1748. int retry_count = 0;
  1749. while (info.resolved_method()->is_old()) {
  1750. + // (tw) If we are executing an old method, this is OK!
  1751. + if (method(thread)->is_old()) {
  1752. + break;
  1753. + }
  1754. // It is very unlikely that method is redefined more than 100 times
  1755. // in the middle of resolve. If it is looping here more than 100 times
  1756. // means then there could be a bug here.
  1757. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1758. index 6d5f13a..50fa219 100644
  1759. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1760. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1761. @@ -141,6 +141,9 @@
  1762. static void post_method_entry(JavaThread *thread);
  1763. static void post_method_exit (JavaThread *thread);
  1764. static int interpreter_contains(address pc);
  1765. + static void forward_method(JavaThread *thread);
  1766. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1767. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1768. // Native signature handlers
  1769. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1770. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1771. index 1676add..ccd5241 100644
  1772. --- a/src/share/vm/interpreter/linkResolver.cpp
  1773. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1774. @@ -153,8 +153,8 @@
  1775. // Klass resolution
  1776. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1777. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1778. - sel_klass->as_klassOop(),
  1779. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1780. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1781. true)) {
  1782. ResourceMark rm(THREAD);
  1783. Exceptions::fthrow(
  1784. @@ -346,7 +346,7 @@
  1785. // We'll check for the method name first, as that's most likely
  1786. // to be false (so we'll short-circuit out of these tests).
  1787. if (sel_method->name() == vmSymbols::clone_name() &&
  1788. - sel_klass() == SystemDictionary::Object_klass() &&
  1789. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1790. resolved_klass->oop_is_array()) {
  1791. // We need to change "protected" to "public".
  1792. assert(flags.is_protected(), "clone not protected?");
  1793. @@ -412,6 +412,154 @@
  1794. }
  1795. }
  1796. +
  1797. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1798. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1799. +
  1800. + // Interface method lookup?
  1801. + if (is_interface) {
  1802. +
  1803. + // lookup method in this interface or its super, java.lang.Object
  1804. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1805. +
  1806. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1807. + // lookup method in all the super-interfaces
  1808. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1809. + }
  1810. +
  1811. + // Other methods
  1812. + } else {
  1813. + Handle nested_exception;
  1814. +
  1815. + // 2. lookup method in resolved klass and its super klasses
  1816. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1817. +
  1818. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1819. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1820. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1821. +
  1822. + if (resolved_method.is_null()) {
  1823. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1824. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1825. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1826. + if (HAS_PENDING_EXCEPTION) {
  1827. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1828. + CLEAR_PENDING_EXCEPTION;
  1829. + }
  1830. + }
  1831. + }
  1832. + }
  1833. +}
  1834. +
  1835. +void LinkResolver::lookup_correct_field(fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static) {
  1836. +
  1837. + // First attempt unversioned
  1838. + sel_klass = KlassHandle(Thread::current(), resolved_klass->find_field(field_name, field_sig, &fd));
  1839. +
  1840. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1841. +
  1842. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  1843. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1844. + if (is_static) {
  1845. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1846. + }
  1847. +
  1848. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1849. +
  1850. + if (redefinition_policy != Klass::DynamicCheck) {
  1851. +
  1852. + if (redefinition_policy == Klass::AccessOldMembers) {
  1853. + // Forget looked up fields
  1854. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1855. + }
  1856. +
  1857. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1858. +
  1859. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1860. +
  1861. + // Select correct version for resolved klass.
  1862. + find_correct_resolved_klass(resolved_klass, current_klass);
  1863. +
  1864. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1865. +
  1866. + // FIXME: idubrov
  1867. + //if (sel_klass.is_null()) {
  1868. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1869. + //} else {
  1870. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1871. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1872. + //}
  1873. + }
  1874. + }
  1875. + }
  1876. +}
  1877. +
  1878. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1879. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1880. +
  1881. + // First attempt unversioned
  1882. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1883. +
  1884. + // (tw) Are we in an old method that wants to see a different view on the world?
  1885. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1886. +
  1887. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  1888. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1889. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1890. +
  1891. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1892. +
  1893. + // We do not throw the exception
  1894. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1895. + // Forget any new member lookup
  1896. + resolved_method = methodHandle(THREAD, NULL);
  1897. + }
  1898. +
  1899. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1900. +
  1901. + if (resolved_method.is_null()) {
  1902. +
  1903. + // Select correct version for resolved klass.
  1904. + find_correct_resolved_klass(resolved_klass, current_klass);
  1905. +
  1906. + // Now do the lookup in a second attempt with a different resolved klass.
  1907. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1908. +
  1909. + // FIXME: idubrov
  1910. + //IF_TRACE_RC2 {
  1911. + // ResourceMark rm(THREAD);
  1912. + // if (resolved_method.is_null()) {
  1913. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1914. + // } else {
  1915. + // assert(resolved_method->is_old(), "must be old method!");
  1916. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1917. + // }
  1918. + //}
  1919. + }
  1920. + }
  1921. + }
  1922. +
  1923. + if (resolved_method.is_null()) {
  1924. + // no method found
  1925. + ResourceMark rm(THREAD);
  1926. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1927. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1928. + method_name,
  1929. + method_signature));
  1930. + }
  1931. +}
  1932. +
  1933. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1934. + int current_klass_revision = current_klass->revision_number();
  1935. + int resolved_klass_revision = resolved_klass->revision_number();
  1936. + // FIXME: idubrov
  1937. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1938. +
  1939. + while (resolved_klass->revision_number() > current_klass_revision) {
  1940. + assert(resolved_klass->old_version(), "must have old version");
  1941. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1942. + }
  1943. +}
  1944. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1945. Symbol* method_name, Symbol* method_signature,
  1946. KlassHandle current_klass, bool check_access, TRAPS) {
  1947. @@ -424,35 +572,8 @@
  1948. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1949. }
  1950. - Handle nested_exception;
  1951. -
  1952. - // 2. lookup method in resolved klass and its super klasses
  1953. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1954. -
  1955. - if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1956. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1957. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1958. -
  1959. - if (resolved_method.is_null()) {
  1960. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1961. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1962. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1963. - if (HAS_PENDING_EXCEPTION) {
  1964. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1965. - CLEAR_PENDING_EXCEPTION;
  1966. - }
  1967. - }
  1968. - }
  1969. -
  1970. - if (resolved_method.is_null()) {
  1971. - // 4. method lookup failed
  1972. - ResourceMark rm(THREAD);
  1973. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1974. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1975. - method_name,
  1976. - method_signature),
  1977. - nested_exception);
  1978. - }
  1979. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1980. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1981. // 5. check if method is concrete
  1982. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1983. @@ -520,7 +641,10 @@
  1984. }
  1985. // lookup method in this interface or its super, java.lang.Object
  1986. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1987. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1988. +
  1989. +
  1990. +
  1991. if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1992. // lookup method in all the super-interfaces
  1993. @@ -621,9 +745,14 @@
  1994. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1995. }
  1996. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  1997. +
  1998. // Resolve instance field
  1999. fieldDescriptor fd; // find_field initializes fd if found
  2000. - KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
  2001. +
  2002. + KlassHandle sel_klass;
  2003. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  2004. +
  2005. // check if field exists; i.e., if a klass containing the field def has been selected
  2006. if (sel_klass.is_null()){
  2007. ResourceMark rm(THREAD);
  2008. @@ -631,7 +760,6 @@
  2009. }
  2010. // check access
  2011. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  2012. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  2013. // check for errors
  2014. @@ -643,7 +771,7 @@
  2015. }
  2016. // Final fields can only be accessed from its own class.
  2017. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  2018. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2019. THROW(vmSymbols::java_lang_IllegalAccessError());
  2020. }
  2021. @@ -848,7 +976,7 @@
  2022. bool check_access, bool check_null_and_abstract, TRAPS) {
  2023. methodHandle resolved_method;
  2024. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2025. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2026. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2027. }
  2028. // throws linktime exceptions
  2029. @@ -878,6 +1006,7 @@
  2030. KlassHandle resolved_klass,
  2031. Handle recv,
  2032. KlassHandle recv_klass,
  2033. + KlassHandle current_klass,
  2034. bool check_null_and_abstract,
  2035. TRAPS) {
  2036. @@ -926,10 +1055,44 @@
  2037. // recv_klass might be an arrayKlassOop but all vtables start at
  2038. // the same place. The cast is to avoid virtual call and assertion.
  2039. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2040. - selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2041. +
  2042. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2043. + // have anything in common, as the receiver type could've been hotswapped.
  2044. + // Does not always work (method could be resolved with correct dynamic type and later
  2045. + // be called at the same place with a wrong dynamic type).
  2046. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2047. +
  2048. + // The vTable must be based on the view of the world of the resolved method
  2049. + klassOop method_holder = resolved_method->method_holder();
  2050. +
  2051. + if (method_holder->klass_part()->new_version() != NULL) {
  2052. + // We are executing in old code
  2053. + // FIXME: idubrov
  2054. + //TRACE_RC2("Calling a method in old code");
  2055. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2056. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2057. + }
  2058. + }
  2059. +
  2060. + if (inst->is_subtype_of(method_holder)) {
  2061. + selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2062. + } else {
  2063. +
  2064. + tty->print_cr("Failure:");
  2065. + inst->as_klassOop()->print();
  2066. + inst->super()->print();
  2067. + juint off = inst->super_check_offset();
  2068. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2069. + sup->print();
  2070. + method_holder->print();
  2071. +
  2072. + bool b = inst->is_subtype_of(method_holder);
  2073. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), "(tw) A virtual method was called, but the type of the receiver is not related with the type of the class of the called method!");
  2074. + }
  2075. }
  2076. }
  2077. +
  2078. // check if method exists
  2079. if (selected_method.is_null()) {
  2080. ResourceMark rm(THREAD);
  2081. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2082. index dfd74f9..cf6e44a 100644
  2083. --- a/src/share/vm/interpreter/linkResolver.hpp
  2084. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2085. @@ -110,7 +110,11 @@
  2086. // It does all necessary link-time checks & throws exceptions if necessary.
  2087. class LinkResolver: AllStatic {
  2088. - private:
  2089. +private:
  2090. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2091. + static void lookup_correct_field (fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static);
  2092. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2093. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2094. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2095. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2096. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2097. @@ -133,7 +137,7 @@
  2098. 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);
  2099. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2100. - 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);
  2101. + 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);
  2102. 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);
  2103. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2104. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2105. index 17e9f26..e77500f 100644
  2106. --- a/src/share/vm/interpreter/templateTable.hpp
  2107. +++ b/src/share/vm/interpreter/templateTable.hpp
  2108. @@ -329,8 +329,8 @@
  2109. static void shouldnotreachhere();
  2110. // jvmti support
  2111. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2112. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2113. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2114. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2115. static void jvmti_post_fast_field_mod();
  2116. // debugging of TemplateGenerator
  2117. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2118. index 76e18d8..6af7c14 100644
  2119. --- a/src/share/vm/memory/genMarkSweep.cpp
  2120. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2121. @@ -421,6 +421,7 @@
  2122. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2123. // here (perm_gen first rather than last), so we tell the validate code
  2124. // to use a higher index (saved from phase2) when verifying perm_gen.
  2125. + assert(_rescued_oops == NULL, "must be empty before processing");
  2126. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2127. Generation* pg = gch->perm_gen();
  2128. @@ -433,10 +434,14 @@
  2129. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2130. + MarkSweep::copy_rescued_objects_back();
  2131. +
  2132. GenCompactClosure blk;
  2133. gch->generation_iterate(&blk, true);
  2134. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2135. + MarkSweep::copy_rescued_objects_back();
  2136. +
  2137. pg->post_compact(); // Shared spaces verification.
  2138. }
  2139. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2140. index 350f583..59faad1 100644
  2141. --- a/src/share/vm/memory/permGen.cpp
  2142. +++ b/src/share/vm/memory/permGen.cpp
  2143. @@ -57,7 +57,12 @@
  2144. for (;;) {
  2145. {
  2146. - MutexLocker ml(Heap_lock);
  2147. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2148. + Monitor *lock = Heap_lock;
  2149. + if (SafepointSynchronize::is_at_safepoint()) {
  2150. + lock = NULL;
  2151. + }
  2152. + MutexLockerEx ml(lock);
  2153. if ((obj = gen->allocate(size, false)) != NULL) {
  2154. return obj;
  2155. }
  2156. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2157. index f97bc34..9b20d08 100644
  2158. --- a/src/share/vm/memory/space.cpp
  2159. +++ b/src/share/vm/memory/space.cpp
  2160. @@ -378,6 +378,31 @@
  2161. _compaction_top = bottom();
  2162. }
  2163. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2164. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2165. +CompactPoint* cp, HeapWord* compact_top) {
  2166. + // First check if we should switch compaction space
  2167. + assert(this == cp->space, "'this' should be current compaction space.");
  2168. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2169. + while (size > compaction_max_size) {
  2170. + // switch to next compaction space
  2171. + cp->space->set_compaction_top(compact_top);
  2172. + cp->space = cp->space->next_compaction_space();
  2173. + if (cp->space == NULL) {
  2174. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2175. + assert(cp->gen != NULL, "compaction must succeed");
  2176. + cp->space = cp->gen->first_compaction_space();
  2177. + assert(cp->space != NULL, "generation must have a first compaction space");
  2178. + }
  2179. + compact_top = cp->space->bottom();
  2180. + cp->space->set_compaction_top(compact_top);
  2181. + cp->threshold = cp->space->initialize_threshold();
  2182. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2183. + }
  2184. +
  2185. + return compact_top;
  2186. +}
  2187. +
  2188. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2189. CompactPoint* cp, HeapWord* compact_top) {
  2190. // q is alive
  2191. @@ -401,7 +426,7 @@
  2192. }
  2193. // store the forwarding pointer into the mark word
  2194. - if ((HeapWord*)q != compact_top) {
  2195. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2196. q->forward_to(oop(compact_top));
  2197. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2198. } else {
  2199. @@ -449,7 +474,208 @@
  2200. // Faster object search.
  2201. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2202. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2203. + if (!Universe::is_redefining_gc_run()) {
  2204. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2205. + return;
  2206. + }
  2207. +
  2208. + /* Compute the new addresses for the live objects and store it in the mark
  2209. + * Used by universe::mark_sweep_phase2()
  2210. + */
  2211. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2212. +
  2213. + /* We're sure to be here before any objects are compacted into this
  2214. + * space, so this is a good time to initialize this:
  2215. + */
  2216. + set_compaction_top(bottom());
  2217. +
  2218. + if (cp->space == NULL) {
  2219. + assert(cp->gen != NULL, "need a generation");
  2220. + assert(cp->threshold == NULL, "just checking");
  2221. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2222. + cp->space = cp->gen->first_compaction_space();
  2223. + compact_top = cp->space->bottom();
  2224. + cp->space->set_compaction_top(compact_top);
  2225. + cp->threshold = cp->space->initialize_threshold();
  2226. + } else {
  2227. + compact_top = cp->space->compaction_top();
  2228. + }
  2229. +
  2230. + /* We allow some amount of garbage towards the bottom of the space, so
  2231. + * we don't start compacting before there is a significant gain to be made.
  2232. + * Occasionally, we want to ensure a full compaction, which is determined
  2233. + * by the MarkSweepAlwaysCompactCount parameter.
  2234. + */
  2235. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2236. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2237. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2238. +
  2239. + size_t allowed_deadspace = 0;
  2240. + if (skip_dead) {
  2241. + int ratio = (int)allowed_dead_ratio();
  2242. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2243. + }
  2244. +
  2245. + HeapWord* q = bottom();
  2246. + HeapWord* t = end();
  2247. +
  2248. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2249. + live object. */
  2250. + HeapWord* first_dead = end();/* The first dead object. */
  2251. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2252. + first header of preceding free area. */
  2253. + _first_dead = first_dead;
  2254. +
  2255. + const intx interval = PrefetchScanIntervalInBytes;
  2256. +
  2257. + while (q < t) {
  2258. + assert(!block_is_obj(q) ||
  2259. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2260. + oop(q)->mark()->has_bias_pattern(),
  2261. + "these are the only valid states during a mark sweep");
  2262. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2263. + /* prefetch beyond q */
  2264. + Prefetch::write(q, interval);
  2265. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2266. + size_t size = block_size(q);
  2267. +
  2268. + // DCEVM: begin
  2269. + //////////////////////////////////////////////////////////////////////////
  2270. + size_t forward_size = size;
  2271. +
  2272. + // Compute the forward sizes and leave out objects whose position could
  2273. + // possibly overlap other objects.
  2274. +
  2275. + // DCEVM: There is a new version of the class of q => different size
  2276. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2277. +
  2278. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2279. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2280. + forward_size = new_size;
  2281. + }
  2282. +
  2283. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2284. +
  2285. + bool rescueing = false;
  2286. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2287. + if (MarkSweep::_rescued_oops == NULL) {
  2288. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2289. + }
  2290. + // FIXME: idubrov
  2291. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2292. + MarkSweep::_rescued_oops->append(oop(q));
  2293. + } else {
  2294. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2295. + }
  2296. +
  2297. + if ((size != forward_size || rescueing) && q < first_dead) {
  2298. + // (tw) This object moves => first_dead must be set to here!
  2299. + first_dead = q;
  2300. + }
  2301. + //////////////////////////////////////////////////////////////////////////
  2302. + q += size;
  2303. + end_of_live = q;
  2304. + } else {
  2305. + /* run over all the contiguous dead objects */
  2306. + HeapWord* end = q;
  2307. + do {
  2308. + /* prefetch beyond end */
  2309. + Prefetch::write(end, interval);
  2310. + end += block_size(end);
  2311. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2312. +
  2313. + /* see if we might want to pretend this object is alive so that
  2314. + * we don't have to compact quite as often.
  2315. + */
  2316. + if (allowed_deadspace > 0 && q == compact_top) {
  2317. + size_t sz = pointer_delta(end, q);
  2318. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2319. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2320. + q = end;
  2321. + end_of_live = end;
  2322. + continue;
  2323. + }
  2324. + }
  2325. +
  2326. + /* otherwise, it really is a free region. */
  2327. +
  2328. + /* for the previous LiveRange, record the end of the live objects. */
  2329. + if (liveRange) {
  2330. + liveRange->set_end(q);
  2331. + }
  2332. +
  2333. + /* record the current LiveRange object.
  2334. + * liveRange->start() is overlaid on the mark word.
  2335. + */
  2336. + liveRange = (LiveRange*)q;
  2337. + liveRange->set_start(end);
  2338. + liveRange->set_end(end);
  2339. +
  2340. + /* see if this is the first dead region. */
  2341. + if (q < first_dead) {
  2342. + first_dead = q;
  2343. + }
  2344. +
  2345. + /* move on to the next object */
  2346. + q = end;
  2347. + }
  2348. + }
  2349. +
  2350. + //////////////////////////////////////////////////////////////////////////
  2351. + // Compute the forwarding addresses for the objects that need to be
  2352. + // rescued.
  2353. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2354. + if (MarkSweep::_rescued_oops != NULL) {
  2355. + // FIXME: idubrov
  2356. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2357. +
  2358. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2359. + oop q = MarkSweep::_rescued_oops->at(i);
  2360. +
  2361. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2362. + size_t size = block_size((HeapWord*)q);
  2363. +
  2364. + size_t forward_size = size;
  2365. +
  2366. + // (tw) There is a new version of the class of q => different size
  2367. + if (oop(q)->blueprint()->new_version() != NULL) {
  2368. +
  2369. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2370. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2371. + forward_size = new_size;
  2372. + }
  2373. +
  2374. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2375. + assert(compact_top <= t, "must not write over end of space!");
  2376. + }
  2377. + MarkSweep::_rescued_oops->clear();
  2378. + MarkSweep::_rescued_oops = NULL;
  2379. + }
  2380. + //////////////////////////////////////////////////////////////////////////
  2381. +
  2382. + assert(q == t, "just checking");
  2383. + if (liveRange != NULL) {
  2384. + liveRange->set_end(q);
  2385. + }
  2386. + _end_of_live = end_of_live;
  2387. + if (end_of_live < first_dead) {
  2388. + first_dead = end_of_live;
  2389. + }
  2390. + _first_dead = first_dead;
  2391. +
  2392. +// FIXME: idubrov
  2393. +// if (_first_dead > top()) {
  2394. +// _first_dead = top();
  2395. +// }
  2396. +//
  2397. +// if (_end_of_live > top()) {
  2398. +// _end_of_live = top();
  2399. +// }
  2400. + assert(_first_dead <= top(), "Must be smaller equal");
  2401. + assert(_end_of_live <= top(), "Must be smaller equal");
  2402. +
  2403. + /* save the compaction_top of the compaction space. */
  2404. + cp->space->set_compaction_top(compact_top);
  2405. }
  2406. void Space::adjust_pointers() {
  2407. @@ -490,17 +716,313 @@
  2408. assert(q == t, "just checking");
  2409. }
  2410. +
  2411. +#ifdef ASSERT
  2412. +
  2413. +int CompactibleSpace::space_index(oop obj) {
  2414. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2415. +
  2416. + if (heap->is_in_permanent(obj)) {
  2417. + return -1;
  2418. + }
  2419. +
  2420. + int index = 0;
  2421. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2422. + Generation* gen = heap->get_gen(i);
  2423. + CompactibleSpace* space = gen->first_compaction_space();
  2424. + while (space != NULL) {
  2425. + if (space->is_in_reserved(obj)) {
  2426. + return index;
  2427. + }
  2428. + space = space->next_compaction_space();
  2429. + index++;
  2430. + }
  2431. + }
  2432. +
  2433. + tty->print_cr("could not compute space_index for %08xh", obj);
  2434. + index = 0;
  2435. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2436. + Generation* gen = heap->get_gen(i);
  2437. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2438. +
  2439. + CompactibleSpace* space = gen->first_compaction_space();
  2440. + while (space != NULL) {
  2441. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2442. + space = space->next_compaction_space();
  2443. + index++;
  2444. + }
  2445. + }
  2446. +
  2447. + ShouldNotReachHere();
  2448. + return 0;
  2449. +}
  2450. +#endif
  2451. +
  2452. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2453. +
  2454. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2455. +
  2456. + if (old_obj->is_perm()) {
  2457. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2458. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2459. + return true;
  2460. + }
  2461. + }
  2462. +
  2463. + int size = old_obj->size();
  2464. + int original_size = size;
  2465. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2466. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2467. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2468. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2469. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2470. + }
  2471. +
  2472. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2473. +
  2474. + if (is_in_reserved(new_obj)) {
  2475. + // Old and new address are in same space, so just compare the address.
  2476. + // Must rescue if object moves towards the top of the space.
  2477. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2478. + return normalComparison;
  2479. +
  2480. + } else {
  2481. +
  2482. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2483. +
  2484. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2485. + if (tenured_gen->is_in_reserved(new_obj)) {
  2486. + // Must never rescue when moving from the new into the old generation.
  2487. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2488. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2489. + return false;
  2490. +
  2491. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2492. + // Must always rescue when moving from the old into the new generation.
  2493. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2494. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2495. + return true;
  2496. +
  2497. + } else {
  2498. + // In the new generation, eden is located before the from space, so a
  2499. + // simple pointer comparison is sufficient.
  2500. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2501. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2502. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2503. + return normalComparison;
  2504. + }
  2505. + }
  2506. +}
  2507. +
  2508. +oop CompactibleSpace::rescue(oop old_obj) {
  2509. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2510. +
  2511. + int size = old_obj->size();
  2512. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2513. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2514. +
  2515. + if (MarkSweep::_rescued_oops == NULL) {
  2516. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2517. + }
  2518. +
  2519. + MarkSweep::_rescued_oops->append(rescued_obj);
  2520. + return rescued_obj;
  2521. +}
  2522. +
  2523. void CompactibleSpace::adjust_pointers() {
  2524. // Check first is there is any work to do.
  2525. if (used() == 0) {
  2526. return; // Nothing to do.
  2527. }
  2528. + /* adjust all the interior pointers to point at the new locations of objects
  2529. + * Used by MarkSweep::mark_sweep_phase3() */
  2530. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2531. + HeapWord* q = bottom();
  2532. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2533. +
  2534. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2535. +
  2536. + debug_only(HeapWord* prev_q = NULL);
  2537. + debug_only(HeapWord* prev_prev_q = NULL);
  2538. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2539. + if (q < t && _first_dead > q &&
  2540. + !oop(q)->is_gc_marked()) {
  2541. + /* we have a chunk of the space which hasn't moved and we've
  2542. + * reinitialized the mark word during the previous pass, so we can't
  2543. + * use is_gc_marked for the traversal. */
  2544. + HeapWord* end = _first_dead;
  2545. +
  2546. + while (q < end) {
  2547. + /* I originally tried to conjoin "block_start(q) == q" to the
  2548. + * assertion below, but that doesn't work, because you can't
  2549. + * accurately traverse previous objects to get to the current one
  2550. + * after their pointers (including pointers into permGen) have been
  2551. + * updated, until the actual compaction is done. dld, 4/00 */
  2552. + assert(block_is_obj(q),
  2553. + "should be at block boundaries, and should be looking at objs");
  2554. +
  2555. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2556. +
  2557. + /* point all the oops to the new location */
  2558. + size_t size = oop(q)->adjust_pointers();
  2559. + size = adjust_obj_size(size);
  2560. +
  2561. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2562. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2563. +
  2564. + debug_only(prev_prev_prev_q = prev_prev_q);
  2565. + debug_only(prev_prev_q = prev_q);
  2566. + debug_only(prev_q = q);
  2567. + q += size;
  2568. + }
  2569. +
  2570. + // (tw) first_dead can be live object!
  2571. + q = _first_dead;
  2572. +
  2573. +// if (_first_dead == t) {
  2574. +// q = t;
  2575. +// } else {
  2576. +// /* $$$ This is funky. Using this to read the previously written
  2577. +// * LiveRange. See also use below. */
  2578. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2579. +// }
  2580. + }
  2581. +
  2582. + const intx interval = PrefetchScanIntervalInBytes;
  2583. +
  2584. + debug_only(prev_q = NULL);
  2585. + debug_only(prev_prev_q = NULL);
  2586. + debug_only(prev_prev_prev_q = NULL);
  2587. + while (q < t) {
  2588. + /* prefetch beyond q */
  2589. + Prefetch::write(q, interval);
  2590. + if (oop(q)->is_gc_marked()) {
  2591. + /* q is alive */
  2592. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2593. + /* point all the oops to the new location */
  2594. + size_t size = oop(q)->adjust_pointers();
  2595. + size = adjust_obj_size(size);
  2596. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2597. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2598. + debug_only(prev_prev_prev_q = prev_prev_q);
  2599. + debug_only(prev_prev_q = prev_q);
  2600. + debug_only(prev_q = q);
  2601. + q += size;
  2602. + } else {
  2603. + /* q is not a live object, so its mark should point at the next
  2604. + * live object */
  2605. + debug_only(prev_prev_prev_q = prev_prev_q);
  2606. + debug_only(prev_prev_q = prev_q);
  2607. + debug_only(prev_q = q);
  2608. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2609. + assert(q > prev_q, "we should be moving forward through memory");
  2610. + }
  2611. + }
  2612. +
  2613. + assert(q == t, "just checking");
  2614. }
  2615. void CompactibleSpace::compact() {
  2616. - SCAN_AND_COMPACT(obj_size);
  2617. +
  2618. + if(!Universe::is_redefining_gc_run()) {
  2619. + SCAN_AND_COMPACT(obj_size);
  2620. + return;
  2621. + }
  2622. +
  2623. + /* Copy all live objects to their new location
  2624. + * Used by MarkSweep::mark_sweep_phase4() */
  2625. +
  2626. + HeapWord* q = bottom();
  2627. + HeapWord* const t = _end_of_live;
  2628. + debug_only(HeapWord* prev_q = NULL);
  2629. +
  2630. + if (q < t && _first_dead > q &&
  2631. + !oop(q)->is_gc_marked()) {
  2632. + debug_only(
  2633. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2634. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2635. + * the traversal. */
  2636. + HeapWord* const end = _first_dead;
  2637. +
  2638. + while (q < end) {
  2639. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2640. + assert(!oop(q)->is_gc_marked(),
  2641. + "should be unmarked (special dense prefix handling)");
  2642. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2643. + debug_only(prev_q = q);
  2644. + q += size;
  2645. + }
  2646. + ) /* debug_only */
  2647. + // (tw) first_dead can be live object!
  2648. + q = _first_dead;
  2649. +
  2650. + //if (_first_dead == t) {
  2651. + // q = t;
  2652. + //} else {
  2653. + ///* $$$ Funky */
  2654. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2655. + //}
  2656. + }
  2657. +
  2658. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2659. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2660. + while (q < t) {
  2661. + if (!oop(q)->is_gc_marked()) {
  2662. + /* mark is pointer to next marked oop */
  2663. + debug_only(prev_q = q);
  2664. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2665. + assert(q > prev_q, "we should be moving forward through memory");
  2666. + } else {
  2667. + /* prefetch beyond q */
  2668. + Prefetch::read(q, scan_interval);
  2669. +
  2670. + /* size and destination */
  2671. + size_t size = obj_size(q);
  2672. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2673. +
  2674. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2675. + oop dest_obj = rescue(oop(q));
  2676. + debug_only(Copy::fill_to_words(q, size, 0));
  2677. + } else {
  2678. +
  2679. + /* prefetch beyond compaction_top */
  2680. + Prefetch::write(compaction_top, copy_interval);
  2681. +
  2682. + /* copy object and reinit its mark */
  2683. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2684. + compaction_top));
  2685. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2686. +
  2687. + if (oop(q)->blueprint()->new_version() != NULL) {
  2688. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2689. + } else {
  2690. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2691. + }
  2692. + oop(compaction_top)->init_mark();
  2693. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2694. + }
  2695. +
  2696. + debug_only(prev_q = q);
  2697. + q += size;
  2698. + }
  2699. + }
  2700. +
  2701. + /* Let's remember if we were empty before we did the compaction. */
  2702. + bool was_empty = used_region().is_empty();
  2703. + /* Reset space after compaction is complete */
  2704. + reset_after_compaction();
  2705. + /* We do this clear, below, since it has overloaded meanings for some */
  2706. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2707. + /* compacted into will have had their offset table thresholds updated */
  2708. + /* continuously, but those that weren't need to have their thresholds */
  2709. + /* re-initialized. Also mangles unused area for debugging. */
  2710. + if (used_region().is_empty()) {
  2711. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2712. + } else {
  2713. + if (ZapUnusedHeapArea) mangle_unused_area();
  2714. + }
  2715. +
  2716. + //SCAN_AND_COMPACT(obj_size);
  2717. }
  2718. void Space::print_short() const { print_short_on(tty); }
  2719. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2720. index ef2f2c6..b54d470 100644
  2721. --- a/src/share/vm/memory/space.hpp
  2722. +++ b/src/share/vm/memory/space.hpp
  2723. @@ -445,6 +445,9 @@
  2724. // indicates when the next such action should be taken.
  2725. virtual void prepare_for_compaction(CompactPoint* cp);
  2726. // MarkSweep support phase3
  2727. + DEBUG_ONLY(int space_index(oop obj));
  2728. + bool must_rescue(oop old_obj, oop new_obj);
  2729. + oop rescue(oop old_obj);
  2730. virtual void adjust_pointers();
  2731. // MarkSweep support phase4
  2732. virtual void compact();
  2733. @@ -475,6 +478,10 @@
  2734. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2735. HeapWord* compact_top);
  2736. + // (tw)
  2737. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2738. + HeapWord* compact_top);
  2739. +
  2740. // Return a size with adjusments as required of the space.
  2741. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2742. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2743. index 4030d9d..da9a186 100644
  2744. --- a/src/share/vm/memory/universe.cpp
  2745. +++ b/src/share/vm/memory/universe.cpp
  2746. @@ -100,6 +100,8 @@
  2747. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2748. #endif
  2749. +bool Universe::_is_redefining_gc_run = false;
  2750. +
  2751. // Known objects
  2752. klassOop Universe::_boolArrayKlassObj = NULL;
  2753. klassOop Universe::_byteArrayKlassObj = NULL;
  2754. @@ -204,6 +206,38 @@
  2755. f(systemObjArrayKlassObj());
  2756. }
  2757. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2758. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2759. +
  2760. + class AlwaysTrueClosure: public BoolObjectClosure {
  2761. + public:
  2762. + void do_object(oop p) { ShouldNotReachHere(); }
  2763. + bool do_object_b(oop p) { return true; }
  2764. + };
  2765. + AlwaysTrueClosure always_true;
  2766. +
  2767. + // General strong roots
  2768. + Universe::oops_do(oopClosure);
  2769. + JNIHandles::oops_do(oopClosure);
  2770. + Threads::oops_do(oopClosure, NULL);
  2771. + ObjectSynchronizer::oops_do(oopClosure);
  2772. + FlatProfiler::oops_do(oopClosure);
  2773. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2774. + JvmtiExport::oops_do(oopClosure);
  2775. + // SO_AllClasses
  2776. + SystemDictionary::oops_do(oopClosure);
  2777. +
  2778. + // Now adjust pointers in remaining weak roots. (All of which should
  2779. + // have been cleared if they pointed to non-surviving objects.)
  2780. + // Global (weak) JNI handles
  2781. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2782. +
  2783. + CodeCache::oops_do(oopClosure);
  2784. + StringTable::oops_do(oopClosure);
  2785. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2786. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2787. +}
  2788. +
  2789. void Universe::oops_do(OopClosure* f, bool do_all) {
  2790. f->do_oop((oop*) &_int_mirror);
  2791. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2792. index 50fcb62..afb6b33 100644
  2793. --- a/src/share/vm/memory/universe.hpp
  2794. +++ b/src/share/vm/memory/universe.hpp
  2795. @@ -127,6 +127,8 @@
  2796. friend class SystemDictionary;
  2797. friend class VMStructs;
  2798. friend class CompactingPermGenGen;
  2799. + friend class Space;
  2800. + friend class ContiguousSpace;
  2801. friend class VM_PopulateDumpSharedSpace;
  2802. friend jint universe_init();
  2803. @@ -258,7 +260,18 @@
  2804. static void compute_verify_oop_data();
  2805. + static bool _is_redefining_gc_run;
  2806. +
  2807. public:
  2808. +
  2809. + static bool is_redefining_gc_run() {
  2810. + return _is_redefining_gc_run;
  2811. + }
  2812. +
  2813. + static void set_redefining_gc_run(bool b) {
  2814. + _is_redefining_gc_run = b;
  2815. + }
  2816. +
  2817. // Known classes in the VM
  2818. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2819. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2820. @@ -403,6 +416,8 @@
  2821. // Iteration
  2822. + static void root_oops_do(OopClosure *f);
  2823. +
  2824. // Apply "f" to the addresses of all the direct heap pointers maintained
  2825. // as static fields of "Universe".
  2826. static void oops_do(OopClosure* f, bool do_all = false);
  2827. @@ -419,6 +434,7 @@
  2828. // Debugging
  2829. static bool verify_in_progress() { return _verify_in_progress; }
  2830. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2831. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  2832. static void verify(const char* prefix, bool silent = VerifySilently) {
  2833. verify(VerifyOption_Default, prefix, silent);
  2834. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2835. index bc9e1b5..cff296a 100644
  2836. --- a/src/share/vm/oops/arrayKlass.cpp
  2837. +++ b/src/share/vm/oops/arrayKlass.cpp
  2838. @@ -136,9 +136,9 @@
  2839. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2840. // An array is a subtype of Serializable, Clonable, and Object
  2841. - return k == SystemDictionary::Object_klass()
  2842. - || k == SystemDictionary::Cloneable_klass()
  2843. - || k == SystemDictionary::Serializable_klass();
  2844. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2845. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2846. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2847. }
  2848. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2849. index e74811f..be3fe7d 100644
  2850. --- a/src/share/vm/oops/constMethodKlass.cpp
  2851. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2852. @@ -102,6 +102,7 @@
  2853. constMethodOop cm = constMethodOop(obj);
  2854. MarkSweep::mark_and_push(cm->adr_constants());
  2855. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2856. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2857. // Performance tweak: We skip iterating over the klass pointer since we
  2858. // know that Universe::constMethodKlassObj never moves.
  2859. }
  2860. @@ -113,6 +114,7 @@
  2861. constMethodOop cm_oop = constMethodOop(obj);
  2862. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2863. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2864. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2865. // Performance tweak: We skip iterating over the klass pointer since we
  2866. // know that Universe::constMethodKlassObj never moves.
  2867. }
  2868. @@ -123,6 +125,7 @@
  2869. constMethodOop cm = constMethodOop(obj);
  2870. blk->do_oop(cm->adr_constants());
  2871. blk->do_oop(cm->adr_stackmap_data());
  2872. + blk->do_oop(cm->adr_code_section_table());
  2873. // Get size before changing pointers.
  2874. // Don't call size() or oop_size() since that is a virtual call.
  2875. int size = cm->object_size();
  2876. @@ -138,6 +141,8 @@
  2877. if (mr.contains(adr)) blk->do_oop(adr);
  2878. adr = cm->adr_stackmap_data();
  2879. if (mr.contains(adr)) blk->do_oop(adr);
  2880. + adr = cm->adr_code_section_table();
  2881. + if (mr.contains(adr)) blk->do_oop(adr);
  2882. // Get size before changing pointers.
  2883. // Don't call size() or oop_size() since that is a virtual call.
  2884. int size = cm->object_size();
  2885. @@ -152,6 +157,7 @@
  2886. constMethodOop cm = constMethodOop(obj);
  2887. MarkSweep::adjust_pointer(cm->adr_constants());
  2888. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2889. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2890. // Get size before changing pointers.
  2891. // Don't call size() or oop_size() since that is a virtual call.
  2892. int size = cm->object_size();
  2893. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2894. index 549192b..5cea5c4 100644
  2895. --- a/src/share/vm/oops/constMethodOop.hpp
  2896. +++ b/src/share/vm/oops/constMethodOop.hpp
  2897. @@ -129,7 +129,7 @@
  2898. public:
  2899. oop* oop_block_beg() const { return adr_constants(); }
  2900. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2901. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2902. private:
  2903. //
  2904. @@ -140,6 +140,9 @@
  2905. // Raw stackmap data for the method
  2906. typeArrayOop _stackmap_data;
  2907. +
  2908. + // (tw) Table mapping code sections for method forward points.
  2909. + typeArrayOop _code_section_table;
  2910. //
  2911. // End of the oop block.
  2912. @@ -194,6 +197,28 @@
  2913. oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
  2914. }
  2915. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2916. +
  2917. + // code section table
  2918. + typeArrayOop code_section_table() const { return _code_section_table; }
  2919. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2920. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2921. + static const int ValuesPerCodeSectionEntry = 3;
  2922. + int code_section_entries() const {
  2923. + if (!has_code_section_table()) return 0;
  2924. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2925. + }
  2926. +
  2927. + int code_section_new_index_at(int index) const {
  2928. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2929. + }
  2930. +
  2931. + int code_section_original_index_at(int index) const {
  2932. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2933. + }
  2934. +
  2935. + int code_section_length_at(int index) const {
  2936. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2937. + }
  2938. void init_fingerprint() {
  2939. const uint64_t initval = CONST64(0x8000000000000000);
  2940. @@ -301,6 +326,7 @@
  2941. // Garbage collection support
  2942. oop* adr_constants() const { return (oop*)&_constants; }
  2943. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2944. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2945. bool is_conc_safe() { return _is_conc_safe; }
  2946. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2947. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2948. index b8d6f83..e8b189d 100644
  2949. --- a/src/share/vm/oops/cpCacheOop.cpp
  2950. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2951. @@ -37,9 +37,15 @@
  2952. // Implememtation of ConstantPoolCacheEntry
  2953. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2954. + _flags = other->_flags; // flags
  2955. +}
  2956. +
  2957. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2958. assert(0 < index && index < 0x10000, "sanity check");
  2959. _indices = index;
  2960. + _f1 = NULL;
  2961. + _f2 = 0;
  2962. assert(constant_pool_index() == index, "");
  2963. }
  2964. @@ -162,7 +168,8 @@
  2965. int vtable_index) {
  2966. assert(!is_secondary_entry(), "");
  2967. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2968. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2969. + // (tw) No longer valid assert
  2970. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2971. int byte_no = -1;
  2972. bool change_to_virtual = false;
  2973. @@ -183,6 +190,7 @@
  2974. set_method_flags(as_TosState(method->result_type()),
  2975. ( 1 << is_vfinal_shift) |
  2976. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2977. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2978. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2979. method()->size_of_parameters());
  2980. set_f2_as_vfinal_method(method());
  2981. @@ -190,9 +198,13 @@
  2982. assert(vtable_index >= 0, "valid index");
  2983. assert(!method->is_final_method(), "sanity");
  2984. set_method_flags(as_TosState(method->result_type()),
  2985. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2986. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2987. method()->size_of_parameters());
  2988. set_f2(vtable_index);
  2989. +
  2990. + // (tw) save method holder in f1 for virtual calls
  2991. + set_f1(method());
  2992. }
  2993. byte_no = 2;
  2994. break;
  2995. @@ -206,7 +218,8 @@
  2996. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  2997. set_method_flags(as_TosState(method->result_type()),
  2998. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  2999. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  3000. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3001. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3002. method()->size_of_parameters());
  3003. set_f1(method());
  3004. byte_no = 1;
  3005. @@ -259,7 +272,7 @@
  3006. set_f1(interf);
  3007. set_f2(index);
  3008. set_method_flags(as_TosState(method->result_type()),
  3009. - 0, // no option bits
  3010. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3011. method()->size_of_parameters());
  3012. set_bytecode_1(Bytecodes::_invokeinterface);
  3013. }
  3014. @@ -520,27 +533,12 @@
  3015. // If this constantPoolCacheEntry refers to old_method then update it
  3016. // to refer to new_method.
  3017. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3018. - methodOop new_method, bool * trace_name_printed) {
  3019. + methodOop new_method) {
  3020. if (is_vfinal()) {
  3021. - // virtual and final so _f2 contains method ptr instead of vtable index
  3022. - if (f2_as_vfinal_method() == old_method) {
  3023. - // match old_method so need an update
  3024. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3025. - _f2 = (intptr_t)new_method;
  3026. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3027. - if (!(*trace_name_printed)) {
  3028. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3029. - RC_TRACE_MESG(("adjust: name=%s",
  3030. - Klass::cast(old_method->method_holder())->external_name()));
  3031. - *trace_name_printed = true;
  3032. - }
  3033. - // RC_TRACE macro has an embedded ResourceMark
  3034. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3035. - new_method->name()->as_C_string(),
  3036. - new_method->signature()->as_C_string()));
  3037. - }
  3038. -
  3039. + // virtual and final so f2() contains method ptr instead of vtable index
  3040. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3041. + initialize_entry(constant_pool_index());
  3042. return true;
  3043. }
  3044. @@ -548,84 +546,26 @@
  3045. return false;
  3046. }
  3047. - if ((oop)_f1 == NULL) {
  3048. - // NULL f1() means this is a virtual entry so bail out
  3049. - // We are assuming that the vtable index does not need change.
  3050. + // (tw) check how to update interface methods!
  3051. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3052. +
  3053. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3054. + initialize_entry(constant_pool_index());
  3055. + return true;
  3056. + }
  3057. +
  3058. return false;
  3059. }
  3060. if ((oop)_f1 == old_method) {
  3061. _f1 = new_method;
  3062. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3063. - if (!(*trace_name_printed)) {
  3064. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3065. - RC_TRACE_MESG(("adjust: name=%s",
  3066. - Klass::cast(old_method->method_holder())->external_name()));
  3067. - *trace_name_printed = true;
  3068. - }
  3069. - // RC_TRACE macro has an embedded ResourceMark
  3070. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3071. - new_method->name()->as_C_string(),
  3072. - new_method->signature()->as_C_string()));
  3073. - }
  3074. return true;
  3075. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3076. + initialize_entry(constant_pool_index());
  3077. }
  3078. return false;
  3079. -}
  3080. -
  3081. -// a constant pool cache entry should never contain old or obsolete methods
  3082. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3083. - if (is_vfinal()) {
  3084. - // virtual and final so _f2 contains method ptr instead of vtable index
  3085. - methodOop m = (methodOop)_f2;
  3086. - // Return false if _f2 refers to an old or an obsolete method.
  3087. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3088. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3089. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3090. - // _f1 == NULL || !_f1->is_method() are OK here
  3091. - return true;
  3092. - }
  3093. -
  3094. - methodOop m = (methodOop)_f1;
  3095. - // return false if _f1 refers to an old or an obsolete method
  3096. - return (!m->is_old() && !m->is_obsolete());
  3097. -}
  3098. -
  3099. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3100. - if (!is_method_entry()) {
  3101. - // not a method entry so not interesting by default
  3102. - return false;
  3103. - }
  3104. -
  3105. - methodOop m = NULL;
  3106. - if (is_vfinal()) {
  3107. - // virtual and final so _f2 contains method ptr instead of vtable index
  3108. - m = f2_as_vfinal_method();
  3109. - } else if (is_f1_null()) {
  3110. - // NULL _f1 means this is a virtual entry so also not interesting
  3111. - return false;
  3112. - } else {
  3113. - oop f1 = _f1; // _f1 is volatile
  3114. - if (!f1->is_method()) {
  3115. - // _f1 can also contain a klassOop for an interface
  3116. - return false;
  3117. - }
  3118. - m = f1_as_method();
  3119. - }
  3120. -
  3121. - // Secondary entry can have vfinal flag and a NULL _f2, giving m==NULL here:
  3122. - assert(is_secondary_entry() || (m != NULL && m->is_method()), "sanity check");
  3123. -
  3124. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3125. - // robustness for above sanity checks or method is not in
  3126. - // the interesting class
  3127. - return false;
  3128. - }
  3129. -
  3130. - // the method is in the interesting class so the entry is interesting
  3131. - return true;
  3132. }
  3133. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3134. @@ -665,60 +605,18 @@
  3135. }
  3136. }
  3137. -// RedefineClasses() API support:
  3138. -// If any entry of this constantPoolCache points to any of
  3139. -// old_methods, replace it with the corresponding new_method.
  3140. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3141. - int methods_length, bool * trace_name_printed) {
  3142. -
  3143. - if (methods_length == 0) {
  3144. - // nothing to do if there are no methods
  3145. - return;
  3146. - }
  3147. -
  3148. - // get shorthand for the interesting class
  3149. - klassOop old_holder = old_methods[0]->method_holder();
  3150. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3151. + int methods_length) {
  3152. for (int i = 0; i < length(); i++) {
  3153. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3154. - // skip uninteresting methods
  3155. - continue;
  3156. - }
  3157. -
  3158. - // The constantPoolCache contains entries for several different
  3159. - // things, but we only care about methods. In fact, we only care
  3160. - // about methods in the same class as the one that contains the
  3161. - // old_methods. At this point, we have an interesting entry.
  3162. -
  3163. - for (int j = 0; j < methods_length; j++) {
  3164. - methodOop old_method = old_methods[j];
  3165. - methodOop new_method = new_methods[j];
  3166. -
  3167. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3168. - trace_name_printed)) {
  3169. - // current old_method matched this entry and we updated it so
  3170. - // break out and get to the next interesting entry if there one
  3171. - break;
  3172. - }
  3173. + if (entry_at(i)->is_field_entry()) {
  3174. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3175. + // point to changed fields
  3176. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3177. + } else if(entry_at(i)->is_method_entry() && !entry_at(i)->is_secondary_entry()) {
  3178. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3179. }
  3180. }
  3181. }
  3182. -// the constant pool cache should never contain old or obsolete methods
  3183. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3184. - for (int i = 1; i < length(); i++) {
  3185. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3186. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3187. - return false;
  3188. - }
  3189. - }
  3190. - return true;
  3191. -}
  3192. -void constantPoolCacheOopDesc::dump_cache() {
  3193. - for (int i = 1; i < length(); i++) {
  3194. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3195. - entry_at(i)->print(tty, i);
  3196. - }
  3197. - }
  3198. -}
  3199. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3200. index b9107cd..653ab13 100644
  3201. --- a/src/share/vm/oops/cpCacheOop.hpp
  3202. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3203. @@ -136,7 +136,8 @@
  3204. void set_bytecode_2(Bytecodes::Code code);
  3205. void set_f1(oop f1) {
  3206. oop existing_f1 = _f1; // read once
  3207. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3208. + // (tw) need to relax assertion for redefinition
  3209. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3210. oop_store(&_f1, f1);
  3211. }
  3212. void release_set_f1(oop f1);
  3213. @@ -174,6 +175,7 @@
  3214. tos_state_mask = right_n_bits(tos_state_bits),
  3215. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3216. // misc. option bits; can be any bit position in [16..27]
  3217. + is_old_method_shift = 19,
  3218. is_vfinal_shift = 20,
  3219. is_volatile_shift = 21,
  3220. is_final_shift = 22,
  3221. @@ -206,6 +208,8 @@
  3222. // Initialization
  3223. void initialize_entry(int original_index); // initialize primary entry
  3224. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3225. +
  3226. + void copy_from(ConstantPoolCacheEntry *other);
  3227. void set_field( // sets entry to resolved field state
  3228. Bytecodes::Code get_code, // the bytecode used for reading the field
  3229. @@ -368,10 +372,7 @@
  3230. // trace_name_printed is set to true if the current call has
  3231. // printed the klass name so that other routines in the adjust_*
  3232. // group don't print the klass name.
  3233. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3234. - bool * trace_name_printed);
  3235. - bool check_no_old_or_obsolete_entries();
  3236. - bool is_interesting_method_entry(klassOop k);
  3237. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3238. // Debugging & Printing
  3239. void print (outputStream* st, int index) const;
  3240. @@ -492,16 +493,9 @@
  3241. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3242. }
  3243. - // RedefineClasses() API support:
  3244. - // If any entry of this constantPoolCache points to any of
  3245. - // old_methods, replace it with the corresponding new_method.
  3246. - // trace_name_printed is set to true if the current call has
  3247. - // printed the klass name so that other routines in the adjust_*
  3248. - // group don't print the klass name.
  3249. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3250. - int methods_length, bool * trace_name_printed);
  3251. - bool check_no_old_or_obsolete_entries();
  3252. - void dump_cache();
  3253. + // (tw) Update method and field references
  3254. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3255. + int methods_length);
  3256. };
  3257. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3258. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3259. index 2ddc80a..65d8f62 100644
  3260. --- a/src/share/vm/oops/instanceKlass.cpp
  3261. +++ b/src/share/vm/oops/instanceKlass.cpp
  3262. @@ -250,12 +250,118 @@
  3263. }
  3264. +void instanceKlass::initialize_redefined_class() {
  3265. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3266. + name()->as_C_string()));
  3267. +
  3268. + assert(!is_initialized(), "");
  3269. + assert(this->old_version() != NULL, "");
  3270. + assert(is_linked(), "must be linked before");
  3271. +
  3272. +
  3273. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3274. + class UpdateStaticFieldClosure : public FieldClosure {
  3275. +
  3276. + private:
  3277. + instanceKlassHandle this_oop;
  3278. +
  3279. + public:
  3280. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3281. + this->this_oop = this_oop;
  3282. + }
  3283. +
  3284. + virtual void do_field(fieldDescriptor* fd) {
  3285. + fieldDescriptor result;
  3286. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3287. +
  3288. + if (found && result.is_static()) {
  3289. + int old_offset = result.offset();
  3290. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3291. +
  3292. + oop new_location = this_oop()->java_mirror();
  3293. + oop old_location = this_oop->old_version()->java_mirror();
  3294. + int offset = fd->offset();
  3295. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3296. + fd->name()->as_C_string(), old_offset, offset));
  3297. +
  3298. + oop cur_oop;
  3299. +
  3300. + switch(result.field_type()) {
  3301. +
  3302. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3303. +
  3304. + case T_BOOLEAN:
  3305. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3306. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3307. + break;
  3308. +
  3309. + case T_CHAR:
  3310. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3311. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3312. + break;
  3313. +
  3314. + case T_FLOAT:
  3315. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3316. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3317. + break;
  3318. +
  3319. + case T_DOUBLE:
  3320. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3321. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3322. + break;
  3323. +
  3324. + case T_BYTE:
  3325. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3326. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3327. + break;
  3328. +
  3329. + case T_SHORT:
  3330. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3331. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3332. + break;
  3333. +
  3334. + case T_INT:
  3335. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3336. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3337. + break;
  3338. +
  3339. + case T_LONG:
  3340. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3341. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3342. + break;
  3343. +
  3344. + case T_OBJECT:
  3345. + case T_ARRAY:
  3346. + cur_oop = old_location->obj_field(old_offset);
  3347. + new_location->obj_field_put_raw(offset, cur_oop);
  3348. + old_location->obj_field_put_raw(old_offset, NULL);
  3349. + break;
  3350. +
  3351. + default:
  3352. + ShouldNotReachHere();
  3353. + }
  3354. + } else {
  3355. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3356. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3357. + // field not found
  3358. + // (tw) TODO: Probably this call is not necessary here!
  3359. + // FIXME: idubrov
  3360. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3361. + }
  3362. + }
  3363. + };
  3364. +
  3365. + UpdateStaticFieldClosure cl(this_oop);
  3366. + this->do_local_static_fields(&cl);
  3367. +}
  3368. +
  3369. +
  3370. bool instanceKlass::verify_code(
  3371. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3372. // 1) Verify the bytecodes
  3373. Verifier::Mode mode =
  3374. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3375. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3376. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3377. }
  3378. @@ -362,7 +468,13 @@
  3379. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3380. jt->get_thread_stat()->perf_timers_addr(),
  3381. PerfClassTraceTime::CLASS_VERIFY);
  3382. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3383. + if (this_oop->is_redefining()) {
  3384. + Thread::current()->set_pretend_new_universe(true);
  3385. + }
  3386. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3387. + if (this_oop->is_redefining()) {
  3388. + Thread::current()->set_pretend_new_universe(false);
  3389. + }
  3390. if (!verify_ok) {
  3391. return false;
  3392. }
  3393. @@ -400,7 +512,8 @@
  3394. }
  3395. #endif
  3396. this_oop->set_init_state(linked);
  3397. - if (JvmtiExport::should_post_class_prepare()) {
  3398. + // (tw) Must check for old version in order to prevent infinite loops.
  3399. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3400. Thread *thread = THREAD;
  3401. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3402. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3403. @@ -673,6 +786,18 @@
  3404. return false;
  3405. }
  3406. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3407. + k = k->klass_part()->newest_version();
  3408. + if (this->newest_version() == k) return true;
  3409. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3410. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3411. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3412. + return true;
  3413. + }
  3414. + }
  3415. + return false;
  3416. +}
  3417. +
  3418. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3419. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3420. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3421. @@ -801,7 +926,25 @@
  3422. }
  3423. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3424. +
  3425. + ResourceMark rm(THREAD);
  3426. methodHandle h_method(THREAD, this_oop->class_initializer());
  3427. +
  3428. + if (this_oop->revision_number() != -1){
  3429. + methodOop m = NULL;
  3430. + if (AllowAdvancedClassRedefinition) {
  3431. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3432. + }
  3433. + methodHandle method(m);
  3434. + if (method() != NULL && method()->is_static()) {
  3435. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3436. + h_method = method;
  3437. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3438. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3439. + return;
  3440. + }
  3441. + }
  3442. +
  3443. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3444. if (TraceClassInitialization) {
  3445. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3446. @@ -949,6 +1092,137 @@
  3447. }
  3448. }
  3449. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3450. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3451. + for (int i=0; i<values.length(); i++) {
  3452. + arr[i] = values.at(i);
  3453. + }
  3454. + set_update_information(arr);
  3455. +}
  3456. +
  3457. +void instanceKlass::clear_update_information() {
  3458. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3459. + set_update_information(NULL);
  3460. +}
  3461. +
  3462. +typedef Pair<int, klassOop> typeInfoPair;
  3463. +
  3464. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3465. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3466. + for (int i=0; i<values.length(); i++) {
  3467. + arr[i] = values.at(i);
  3468. + }
  3469. + set_type_check_information(arr);
  3470. +}
  3471. +
  3472. +void instanceKlass::clear_type_check_information() {
  3473. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3474. + set_type_check_information(NULL);
  3475. +}
  3476. +
  3477. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3478. +
  3479. + assert (old_version() != NULL, "must have old version!");
  3480. +
  3481. + klassOop old_klass_oop = old_version();
  3482. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3483. + instanceKlass *new_klass = this;
  3484. +
  3485. + fieldDescriptor fd;
  3486. + fieldDescriptor old_fd;
  3487. +
  3488. + instanceKlass *cur_new_klass = new_klass;
  3489. + klassOop cur_new_klass_oop = this->as_klassOop();
  3490. +
  3491. + if (_fields_not_changed) {
  3492. +
  3493. + class MyFieldClosure : public FieldClosure {
  3494. +
  3495. + FieldEvolutionClosure *_cl;
  3496. + public:
  3497. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3498. + virtual void do_field(fieldDescriptor* fd) {
  3499. + _cl->do_changed_field(fd, fd);
  3500. + }
  3501. + };
  3502. +
  3503. + MyFieldClosure mfc(cl);
  3504. + do_nonstatic_fields(&mfc);
  3505. + } else {
  3506. +
  3507. + _fields_not_changed = true;
  3508. + GrowableArray<fieldDescriptor> fds;
  3509. + while (true) {
  3510. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3511. + fd.initialize(cur_new_klass_oop, fs.index());
  3512. + if (fd.is_static()) {
  3513. + continue;
  3514. + }
  3515. + fds.append(fd);
  3516. + }
  3517. +
  3518. + if (cur_new_klass->super() != NULL) {
  3519. + cur_new_klass_oop = cur_new_klass->super();
  3520. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3521. + } else {
  3522. + break;
  3523. + }
  3524. + }
  3525. +
  3526. + GrowableArray<fieldDescriptor> sortedFds;
  3527. + while (fds.length() > 0) {
  3528. + int minOffset = 0x7fffffff;
  3529. + int minIndex = -1;
  3530. + for (int i=0; i<fds.length(); i++) {
  3531. + int curOffset = fds.adr_at(i)->offset();
  3532. + if (curOffset < minOffset) {
  3533. + minOffset = curOffset;
  3534. + minIndex = i;
  3535. + }
  3536. + }
  3537. +
  3538. + sortedFds.append(fds.at(minIndex));
  3539. + fds.remove_at(minIndex);
  3540. + }
  3541. +
  3542. +
  3543. + for (int i=0; i<sortedFds.length(); i++) {
  3544. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3545. +
  3546. + char found = 0;
  3547. + instanceKlass *cur_old_klass = old_klass;
  3548. + klassOop cur_old_klass_oop = old_klass_oop;
  3549. + while (true) {
  3550. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3551. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3552. + if (old_fd.is_static()) {
  3553. + continue;
  3554. + }
  3555. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3556. + found = 1;
  3557. + break;
  3558. + }
  3559. + }
  3560. + if (!found && cur_old_klass->super()) {
  3561. + cur_old_klass_oop = cur_old_klass->super();
  3562. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3563. + } else {
  3564. + break;
  3565. + }
  3566. + }
  3567. +
  3568. + if (found) {
  3569. + if (old_fd.offset() != fd.offset()) {
  3570. + _fields_not_changed = false;
  3571. + }
  3572. + cl->do_changed_field(&old_fd, &fd);
  3573. + } else {
  3574. + _fields_not_changed = false;
  3575. + cl->do_new_field(&fd);
  3576. + }
  3577. + }
  3578. + }
  3579. +}
  3580. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3581. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3582. @@ -1368,6 +1642,20 @@
  3583. return id;
  3584. }
  3585. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3586. + size_t idnum = (size_t)method->method_idnum();
  3587. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3588. + size_t length; // length assigned as debugging crumb
  3589. + jmethodID id = NULL;
  3590. + if (jmeths != NULL && // If there is a cache
  3591. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3592. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3593. + return true;
  3594. + }
  3595. +
  3596. + return false;
  3597. +}
  3598. +
  3599. // Cache an itable index
  3600. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3601. @@ -1527,6 +1815,13 @@
  3602. last = b;
  3603. b = b->next();
  3604. }
  3605. +
  3606. + // (tw) Hack as dependencies get wrong version of klassOop
  3607. + if(this->old_version() != NULL) {
  3608. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3609. + return;
  3610. + }
  3611. +
  3612. #ifdef ASSERT
  3613. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3614. nm->print();
  3615. @@ -2416,6 +2711,9 @@
  3616. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3617. st->print(BULLET"fake entry for mirror: ");
  3618. mirrored_klass->print_value_on(st);
  3619. + if (mirrored_klass != NULL) {
  3620. + st->print_cr("revision: %d (oldest=%d, newest=%d)", mirrored_klass->klass_part()->revision_number(), mirrored_klass->klass_part()->oldest_version()->klass_part()->revision_number(), mirrored_klass->klass_part()->newest_version()->klass_part()->revision_number());
  3621. + }
  3622. st->cr();
  3623. st->print(BULLET"fake entry resolved_constructor: ");
  3624. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3625. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3626. index f718837..b77a8ca 100644
  3627. --- a/src/share/vm/oops/instanceKlass.hpp
  3628. +++ b/src/share/vm/oops/instanceKlass.hpp
  3629. @@ -102,6 +102,22 @@
  3630. virtual void do_field(fieldDescriptor* fd) = 0;
  3631. };
  3632. +// (tw) Iterates over the fields of the old and new class
  3633. +class FieldEvolutionClosure : public StackObj {
  3634. +public:
  3635. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3636. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3637. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3638. +};
  3639. +
  3640. +// (tw) Iterates over the methods of the old and new class
  3641. +class MethodEvolutionClosure : public StackObj {
  3642. +public:
  3643. + virtual void do_new_method(methodOop oop) = 0;
  3644. + virtual void do_old_method(methodOop oop) = 0;
  3645. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3646. +};
  3647. +
  3648. #ifndef PRODUCT
  3649. // Print fields.
  3650. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3651. @@ -287,6 +303,11 @@
  3652. // _idnum_allocated_count.
  3653. u1 _init_state; // state of class
  3654. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3655. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3656. + // information is cached.
  3657. + bool _fields_not_changed;
  3658. +
  3659. u1 _reference_type; // reference type
  3660. // embedded Java vtable follows here
  3661. @@ -454,6 +475,7 @@
  3662. // initialization (virtuals from Klass)
  3663. bool should_be_initialized() const; // means that initialize should be called
  3664. void initialize(TRAPS);
  3665. + void initialize_redefined_class();
  3666. void link_class(TRAPS);
  3667. bool link_class_or_fail(TRAPS); // returns false on failure
  3668. void unlink_class();
  3669. @@ -631,6 +653,7 @@
  3670. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3671. size_t *length_p, jmethodID* id_p);
  3672. jmethodID jmethod_id_or_null(methodOop method);
  3673. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3674. // cached itable index support
  3675. void set_cached_itable_index(size_t idnum, int index);
  3676. @@ -713,6 +736,7 @@
  3677. // subclass/subinterface checks
  3678. bool implements_interface(klassOop k) const;
  3679. + bool implements_interface_any_version(klassOop k) const;
  3680. // Access to the implementor of an interface.
  3681. klassOop implementor() const
  3682. @@ -762,6 +786,12 @@
  3683. void do_local_static_fields(FieldClosure* cl);
  3684. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3685. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3686. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3687. + void store_update_information(GrowableArray<int> &values);
  3688. + void clear_update_information();
  3689. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3690. + void clear_type_check_information();
  3691. +
  3692. void methods_do(void f(methodOop method));
  3693. void array_klasses_do(void f(klassOop k));
  3694. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3695. index 8e7dc12..63d6dc4 100644
  3696. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3697. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3698. @@ -480,6 +480,28 @@
  3699. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3700. klassKlass::oop_print_on(obj, st);
  3701. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3702. +
  3703. + st->print(BULLET"revision: %d", ik->revision_number());
  3704. +
  3705. + if (ik->new_version() != NULL) {
  3706. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3707. + }
  3708. +
  3709. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3710. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3711. + }
  3712. +
  3713. + if (ik->old_version() != NULL) {
  3714. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3715. + }
  3716. +
  3717. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3718. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3719. + }
  3720. +
  3721. + st->cr();
  3722. +
  3723. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3724. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3725. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3726. @@ -663,7 +685,7 @@
  3727. }
  3728. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3729. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3730. - guarantee(sib->super() == super, "siblings should have same superklass");
  3731. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3732. sib = sib->next_sibling();
  3733. }
  3734. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3735. index 7db4f03..1171487 100644
  3736. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3737. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3738. @@ -455,10 +455,13 @@
  3739. instanceKlass* ik = instanceKlass::cast(k);
  3740. // Check that we have the right class
  3741. - debug_only(static bool first_time = true);
  3742. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3743. - "Invalid update of maps");
  3744. - debug_only(first_time = false);
  3745. +
  3746. + // (tw) Asserts no longer valid for class redefinition
  3747. + // debug_only(static bool first_time = true);
  3748. +
  3749. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3750. + // "Invalid update of maps");
  3751. + //debug_only(first_time = false);
  3752. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3753. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3754. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3755. index ff33181..28537e2 100644
  3756. --- a/src/share/vm/oops/klass.cpp
  3757. +++ b/src/share/vm/oops/klass.cpp
  3758. @@ -55,6 +55,26 @@
  3759. return false;
  3760. }
  3761. +void Klass::update_supers_to_newest_version() {
  3762. +
  3763. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3764. +
  3765. + for (uint i=0; i<primary_super_limit(); i++) {
  3766. + klassOop cur = _primary_supers[i];
  3767. + if (cur != NULL) {
  3768. + _primary_supers[i] = cur->klass_part()->newest_version();
  3769. + }
  3770. + }
  3771. +
  3772. + // Scan the array-of-objects
  3773. + int cnt = secondary_supers()->length();
  3774. + for (int i = 0; i < cnt; i++) {
  3775. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3776. + if (cur != NULL) {
  3777. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3778. + }
  3779. + }
  3780. +}
  3781. bool Klass::search_secondary_supers(klassOop k) const {
  3782. // Put some extra logic here out-of-line, before the search proper.
  3783. // This cuts down the size of the inline method.
  3784. @@ -170,6 +190,16 @@
  3785. kl->set_alloc_size(0);
  3786. TRACE_INIT_ID(kl);
  3787. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3788. + kl->set_redefining(false);
  3789. + kl->set_new_version(NULL);
  3790. + kl->set_old_version(NULL);
  3791. + kl->set_redefinition_index(-1);
  3792. + kl->set_revision_number(-1);
  3793. + kl->set_field_redefinition_policy(DynamicCheck);
  3794. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3795. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3796. +
  3797. kl->set_prototype_header(markOopDesc::prototype());
  3798. kl->set_biased_lock_revocation_count(0);
  3799. kl->set_last_biased_lock_bulk_revocation_time(0);
  3800. @@ -241,7 +271,7 @@
  3801. set_super(NULL);
  3802. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3803. assert(super_depth() == 0, "Object must already be initialized properly");
  3804. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3805. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3806. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3807. "initialize this only once to a non-trivial value");
  3808. set_super(k);
  3809. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3810. index a449e87..52364ba 100644
  3811. --- a/src/share/vm/oops/klass.hpp
  3812. +++ b/src/share/vm/oops/klass.hpp
  3813. @@ -171,6 +171,7 @@
  3814. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3815. };
  3816. +template<class L, class R> class Pair;
  3817. class Klass : public Klass_vtbl {
  3818. friend class VMStructs;
  3819. @@ -223,6 +224,39 @@
  3820. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3821. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3822. + // (tw) Different class redefinition flags of code evolution.
  3823. + enum RedefinitionFlags {
  3824. +
  3825. + // This class is not redefined at all!
  3826. + NoRedefinition,
  3827. +
  3828. + // There are changes to the class meta data.
  3829. + ModifyClass = 1,
  3830. +
  3831. + // The size of the class meta data changes.
  3832. + ModifyClassSize = ModifyClass << 1,
  3833. +
  3834. + // There are change to the instance format.
  3835. + ModifyInstances = ModifyClassSize << 1,
  3836. +
  3837. + // The size of instances changes.
  3838. + ModifyInstanceSize = ModifyInstances << 1,
  3839. +
  3840. + // A super type of this class is removed.
  3841. + RemoveSuperType = ModifyInstanceSize << 1,
  3842. +
  3843. + // This class (or one of its super classes) has an instance transformer method.
  3844. + HasInstanceTransformer = RemoveSuperType << 1,
  3845. + };
  3846. +
  3847. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3848. + enum RedefinitionPolicy {
  3849. + StaticCheck,
  3850. + DynamicCheck,
  3851. + AccessDeletedMembers,
  3852. + AccessOldMembers
  3853. + };
  3854. +
  3855. protected:
  3856. //
  3857. // The oop block. All oop fields must be declared here and only oop fields
  3858. @@ -242,6 +276,10 @@
  3859. oop _java_mirror;
  3860. // Superclass
  3861. klassOop _super;
  3862. + // Old class
  3863. + klassOop _old_version;
  3864. + // New class
  3865. + klassOop _new_version;
  3866. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3867. klassOop _subklass;
  3868. // Sibling link (or NULL); links all subklasses of a klass
  3869. @@ -253,6 +291,19 @@
  3870. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3871. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3872. +
  3873. + // (tw) Non-oop fields for enhanced class redefinition
  3874. + jint _revision_number; // The revision number for redefined classes
  3875. + jint _redefinition_index; // Index of this class when performing the redefinition
  3876. + bool _subtype_changed;
  3877. + int _redefinition_flags; // Level of class redefinition
  3878. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3879. + int * _update_information; // Update information
  3880. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3881. + char _method_redefinition_policy;
  3882. + char _field_redefinition_policy;
  3883. + char _static_field_redefinition_policy;
  3884. + bool _is_redefining;
  3885. #ifndef PRODUCT
  3886. int _verify_count; // to avoid redundant verifies
  3887. @@ -301,6 +352,99 @@
  3888. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3889. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3890. +
  3891. + // BEGIN class redefinition utilities
  3892. +
  3893. + // double links between new and old version of a class
  3894. + klassOop old_version() const { return _old_version; }
  3895. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3896. + klassOop new_version() const { return _new_version; }
  3897. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3898. +
  3899. + // A subtype of this class is no longer a subtype
  3900. + bool has_subtype_changed() const { return _subtype_changed; }
  3901. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3902. + _subtype_changed = b; }
  3903. + // state of being redefined
  3904. + int redefinition_index() const { return _redefinition_index; }
  3905. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3906. + void set_redefining(bool b) { _is_redefining = b; }
  3907. + bool is_redefining() const { return _is_redefining; }
  3908. + int redefinition_flags() const { return _redefinition_flags; }
  3909. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3910. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3911. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3912. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3913. +
  3914. + // update information
  3915. + int *update_information() const { return _update_information; }
  3916. + void set_update_information(int *info) { _update_information = info; }
  3917. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3918. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3919. +
  3920. + bool is_same_or_older_version(klassOop klass) const {
  3921. + if (Klass::cast(klass) == this) { return true; }
  3922. + else if (_old_version == NULL) { return false; }
  3923. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3924. + }
  3925. +
  3926. + // Revision number for redefined classes, -1 for originally loaded classes
  3927. + jint revision_number() const {
  3928. + return _revision_number;
  3929. + }
  3930. +
  3931. + bool was_redefined() const {
  3932. + return _revision_number != -1;
  3933. + }
  3934. +
  3935. + void set_revision_number(jint number) {
  3936. + _revision_number = number;
  3937. + }
  3938. +
  3939. + char method_redefinition_policy() {
  3940. + return _method_redefinition_policy;
  3941. + }
  3942. +
  3943. + void set_method_redefinition_policy(char v) {
  3944. + _method_redefinition_policy = v;
  3945. + }
  3946. +
  3947. + char field_redefinition_policy() {
  3948. + return _field_redefinition_policy;
  3949. + }
  3950. +
  3951. + void set_field_redefinition_policy(char v) {
  3952. + _field_redefinition_policy = v;
  3953. + }
  3954. +
  3955. + char static_field_redefinition_policy() {
  3956. + return _static_field_redefinition_policy;
  3957. + }
  3958. +
  3959. + void set_static_field_redefinition_policy(char v) {
  3960. + _static_field_redefinition_policy = v;
  3961. + }
  3962. +
  3963. + klassOop oldest_version() const {
  3964. + if (_old_version == NULL) { return this->as_klassOop(); }
  3965. + else { return _old_version->klass_part()->oldest_version(); };
  3966. + }
  3967. +
  3968. + klassOop newest_version() const {
  3969. + if (_new_version == NULL) { return this->as_klassOop(); }
  3970. + else { return _new_version->klass_part()->newest_version(); };
  3971. + }
  3972. +
  3973. + klassOop active_version() const {
  3974. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3975. + else { return _new_version->klass_part()->active_version(); };
  3976. + }
  3977. +
  3978. + bool is_newest_version() const {
  3979. + return _new_version == NULL;
  3980. + }
  3981. +
  3982. + // END class redefinition utilities
  3983. objArrayOop secondary_supers() const { return _secondary_supers; }
  3984. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3985. @@ -362,6 +506,8 @@
  3986. void set_next_sibling(klassOop s);
  3987. oop* adr_super() const { return (oop*)&_super; }
  3988. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3989. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3990. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3991. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3992. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3993. @@ -491,6 +637,7 @@
  3994. return search_secondary_supers(k);
  3995. }
  3996. }
  3997. + void update_supers_to_newest_version();
  3998. bool search_secondary_supers(klassOop k) const;
  3999. // Find LCA in class hierarchy
  4000. @@ -818,6 +965,8 @@
  4001. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  4002. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  4003. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  4004. #endif // SHARE_VM_OOPS_KLASS_HPP
  4005. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  4006. index 06809d5..9c08f32 100644
  4007. --- a/src/share/vm/oops/klassKlass.cpp
  4008. +++ b/src/share/vm/oops/klassKlass.cpp
  4009. @@ -68,6 +68,8 @@
  4010. Klass* k = Klass::cast(klassOop(obj));
  4011. // If we are alive it is valid to keep our superclass and subtype caches alive
  4012. MarkSweep::mark_and_push(k->adr_super());
  4013. + MarkSweep::mark_and_push(k->adr_old_version());
  4014. + MarkSweep::mark_and_push(k->adr_new_version());
  4015. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4016. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  4017. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4018. @@ -87,6 +89,8 @@
  4019. Klass* k = Klass::cast(klassOop(obj));
  4020. // If we are alive it is valid to keep our superclass and subtype caches alive
  4021. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4022. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4023. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4024. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4025. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4026. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4027. @@ -106,6 +110,8 @@
  4028. int size = oop_size(obj);
  4029. Klass* k = Klass::cast(klassOop(obj));
  4030. blk->do_oop(k->adr_super());
  4031. + blk->do_oop(k->adr_old_version());
  4032. + blk->do_oop(k->adr_new_version());
  4033. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4034. blk->do_oop(k->adr_primary_supers()+i);
  4035. blk->do_oop(k->adr_secondary_super_cache());
  4036. @@ -134,6 +140,10 @@
  4037. oop* adr;
  4038. adr = k->adr_super();
  4039. if (mr.contains(adr)) blk->do_oop(adr);
  4040. + adr = k->adr_old_version();
  4041. + if (mr.contains(adr)) blk->do_oop(adr);
  4042. + adr = k->adr_new_version();
  4043. + if (mr.contains(adr)) blk->do_oop(adr);
  4044. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4045. adr = k->adr_primary_supers()+i;
  4046. if (mr.contains(adr)) blk->do_oop(adr);
  4047. @@ -147,6 +157,8 @@
  4048. // The following are "weak links" in the perm gen and are
  4049. // treated specially in a later phase of a perm gen collection.
  4050. assert(oop(k)->is_perm(), "should be in perm");
  4051. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4052. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4053. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4054. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4055. if (blk->should_remember_klasses()
  4056. @@ -167,6 +179,8 @@
  4057. Klass* k = Klass::cast(klassOop(obj));
  4058. MarkSweep::adjust_pointer(k->adr_super());
  4059. + MarkSweep::adjust_pointer(k->adr_new_version());
  4060. + MarkSweep::adjust_pointer(k->adr_old_version());
  4061. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4062. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4063. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4064. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4065. index f212fc5..9731a9c 100644
  4066. --- a/src/share/vm/oops/klassOop.hpp
  4067. +++ b/src/share/vm/oops/klassOop.hpp
  4068. @@ -41,8 +41,10 @@
  4069. // returns the Klass part containing dispatching behavior
  4070. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4071. - // Convenience wrapper
  4072. + // Convenience wrappers
  4073. inline oop java_mirror() const;
  4074. + inline klassOop old_version() const;
  4075. + inline klassOop new_version() const;
  4076. private:
  4077. // These have no implementation since klassOop should never be accessed in this fashion
  4078. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4079. index ff22444..8d39611 100644
  4080. --- a/src/share/vm/oops/klassVtable.cpp
  4081. +++ b/src/share/vm/oops/klassVtable.cpp
  4082. @@ -97,7 +97,8 @@
  4083. vtable_length = Universe::base_vtable_size();
  4084. }
  4085. - if (super == NULL && !Universe::is_bootstrapping() &&
  4086. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4087. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4088. vtable_length != Universe::base_vtable_size()) {
  4089. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4090. // only way this should happen is from
  4091. @@ -107,9 +108,9 @@
  4092. vtable_length = Universe::base_vtable_size();
  4093. }
  4094. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4095. - "bad vtable size for class Object");
  4096. + "bad vtable size for class Object");*/
  4097. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4098. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4099. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4100. }
  4101. int klassVtable::index_of(methodOop m, int len) const {
  4102. @@ -676,20 +677,6 @@
  4103. }
  4104. }
  4105. return true;
  4106. -}
  4107. -
  4108. -void klassVtable::dump_vtable() {
  4109. - tty->print_cr("vtable dump --");
  4110. - for (int i = 0; i < length(); i++) {
  4111. - methodOop m = unchecked_method_at(i);
  4112. - if (m != NULL) {
  4113. - tty->print(" (%5d) ", i);
  4114. - m->access_flags().print_on(tty);
  4115. - tty->print(" -- ");
  4116. - m->print_name(tty);
  4117. - tty->cr();
  4118. - }
  4119. - }
  4120. }
  4121. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4122. @@ -1262,6 +1249,7 @@
  4123. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4124. vtableEntry* vte = &vt->table()[index];
  4125. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4126. if (vte->method()->name() != table()[index].method()->name() ||
  4127. vte->method()->signature() != table()[index].method()->signature()) {
  4128. fatal("mismatched name/signature of vtable entries");
  4129. @@ -1281,6 +1269,8 @@
  4130. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4131. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4132. + // (tw) TODO: Check: Does not hold?
  4133. + if (method() != NULL) {
  4134. assert(method() != NULL, "must have set method");
  4135. method()->verify();
  4136. // we sub_type, because it could be a miranda method
  4137. @@ -1288,7 +1278,13 @@
  4138. #ifndef PRODUCT
  4139. print();
  4140. #endif
  4141. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4142. + klassOop first_klass = vt->klass()();
  4143. + klassOop second_klass = method()->method_holder();
  4144. + // (tw) the following fatal does not work for old versions of classes
  4145. + if (first_klass->klass_part()->is_newest_version()) {
  4146. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4147. + }
  4148. + }
  4149. }
  4150. }
  4151. @@ -1296,7 +1292,7 @@
  4152. void vtableEntry::print() {
  4153. ResourceMark rm;
  4154. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4155. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4156. if (Verbose) {
  4157. tty->print("m %#lx ", (address)method());
  4158. }
  4159. @@ -1363,6 +1359,33 @@
  4160. tty->print_cr("%6d bytes total", total);
  4161. }
  4162. +bool klassVtable::check_no_old_entries() {
  4163. + // Check that there really is no entry
  4164. + for (int i = 0; i < length(); i++) {
  4165. + methodOop m = unchecked_method_at(i);
  4166. + if (m != NULL) {
  4167. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4168. + return false;
  4169. + }
  4170. + }
  4171. + }
  4172. + return true;
  4173. +}
  4174. +
  4175. +void klassVtable::dump_vtable() {
  4176. + tty->print_cr("vtable dump --");
  4177. + for (int i = 0; i < length(); i++) {
  4178. + methodOop m = unchecked_method_at(i);
  4179. + if (m != NULL) {
  4180. + tty->print(" (%5d) ", i);
  4181. + m->access_flags().print_on(tty);
  4182. + tty->print(" -- ");
  4183. + m->print_name(tty);
  4184. + tty->cr();
  4185. + }
  4186. + }
  4187. +}
  4188. +
  4189. int klassItable::_total_classes; // Total no. of classes with itables
  4190. long klassItable::_total_size; // Total no. of bytes used for itables
  4191. diff --git a/src/share/vm/oops/klassVtable.hpp b/src/share/vm/oops/klassVtable.hpp
  4192. index 405b0c7..0c8d2f7 100644
  4193. --- a/src/share/vm/oops/klassVtable.hpp
  4194. +++ b/src/share/vm/oops/klassVtable.hpp
  4195. @@ -100,6 +100,7 @@
  4196. int methods_length, bool * trace_name_printed);
  4197. bool check_no_old_or_obsolete_entries();
  4198. void dump_vtable();
  4199. + bool check_no_old_entries();
  4200. // Garbage collection
  4201. void oop_follow_contents();
  4202. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4203. index 75d0b09..f1b7d2f 100644
  4204. --- a/src/share/vm/oops/methodKlass.cpp
  4205. +++ b/src/share/vm/oops/methodKlass.cpp
  4206. @@ -93,6 +93,10 @@
  4207. m->set_adapter_entry(NULL);
  4208. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4209. + m->set_forward_method(NULL);
  4210. + m->set_new_version(NULL);
  4211. + m->set_old_version(NULL);
  4212. +
  4213. if (access_flags.is_native()) {
  4214. m->clear_native_function();
  4215. m->set_signature_handler(NULL);
  4216. @@ -122,6 +126,9 @@
  4217. // Performance tweak: We skip iterating over the klass pointer since we
  4218. // know that Universe::methodKlassObj never moves.
  4219. MarkSweep::mark_and_push(m->adr_constMethod());
  4220. + MarkSweep::mark_and_push(m->adr_forward_method());
  4221. + MarkSweep::mark_and_push(m->adr_new_version());
  4222. + MarkSweep::mark_and_push(m->adr_old_version());
  4223. if (m->method_data() != NULL) {
  4224. MarkSweep::mark_and_push(m->adr_method_data());
  4225. }
  4226. @@ -135,6 +142,9 @@
  4227. // Performance tweak: We skip iterating over the klass pointer since we
  4228. // know that Universe::methodKlassObj never moves.
  4229. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4230. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4231. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4232. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4233. #ifdef COMPILER2
  4234. if (m->method_data() != NULL) {
  4235. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4236. @@ -152,6 +162,9 @@
  4237. // Performance tweak: We skip iterating over the klass pointer since we
  4238. // know that Universe::methodKlassObj never moves
  4239. blk->do_oop(m->adr_constMethod());
  4240. + blk->do_oop(m->adr_forward_method());
  4241. + blk->do_oop(m->adr_new_version());
  4242. + blk->do_oop(m->adr_old_version());
  4243. if (m->method_data() != NULL) {
  4244. blk->do_oop(m->adr_method_data());
  4245. }
  4246. @@ -170,6 +183,12 @@
  4247. oop* adr;
  4248. adr = m->adr_constMethod();
  4249. if (mr.contains(adr)) blk->do_oop(adr);
  4250. + adr = m->adr_new_version();
  4251. + if (mr.contains(adr)) blk->do_oop(adr);
  4252. + adr = m->adr_forward_method();
  4253. + if (mr.contains(adr)) blk->do_oop(adr);
  4254. + adr = m->adr_old_version();
  4255. + if (mr.contains(adr)) blk->do_oop(adr);
  4256. if (m->method_data() != NULL) {
  4257. adr = m->adr_method_data();
  4258. if (mr.contains(adr)) blk->do_oop(adr);
  4259. @@ -187,6 +206,9 @@
  4260. // Performance tweak: We skip iterating over the klass pointer since we
  4261. // know that Universe::methodKlassObj never moves.
  4262. MarkSweep::adjust_pointer(m->adr_constMethod());
  4263. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4264. + MarkSweep::adjust_pointer(m->adr_new_version());
  4265. + MarkSweep::adjust_pointer(m->adr_old_version());
  4266. if (m->method_data() != NULL) {
  4267. MarkSweep::adjust_pointer(m->adr_method_data());
  4268. }
  4269. @@ -202,6 +224,9 @@
  4270. assert(obj->is_method(), "should be method");
  4271. methodOop m = methodOop(obj);
  4272. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4273. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4274. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4275. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4276. #ifdef COMPILER2
  4277. if (m->method_data() != NULL) {
  4278. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4279. @@ -222,7 +247,18 @@
  4280. methodOop m = methodOop(obj);
  4281. // get the effect of PrintOopAddress, always, for methods:
  4282. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4283. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4284. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4285. +
  4286. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4287. + st->print(" (old)");
  4288. + }
  4289. + st->cr();
  4290. +
  4291. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4292. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4293. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4294. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4295. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4296. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4297. m->constants()->print_value_on(st); st->cr();
  4298. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4299. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4300. index 4f59d3a..5cdf147 100644
  4301. --- a/src/share/vm/oops/methodOop.cpp
  4302. +++ b/src/share/vm/oops/methodOop.cpp
  4303. @@ -328,6 +328,70 @@
  4304. }
  4305. +bool methodOopDesc::is_in_code_section(int bci) {
  4306. + // There is no table => every bci is in the code section table.
  4307. + if (!constMethod()->has_code_section_table()) return true;
  4308. +
  4309. + constMethodOop m = constMethod();
  4310. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4311. + u2 new_index = m->code_section_new_index_at(i);
  4312. + u2 length = m->code_section_length_at(i);
  4313. + if (bci >= new_index && bci < new_index + length) {
  4314. + // We are in a specified code section.
  4315. + return true;
  4316. + }
  4317. + }
  4318. +
  4319. + return false;
  4320. +}
  4321. +
  4322. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4323. + int original_bci = -1;
  4324. + if (constMethod()->has_code_section_table()) {
  4325. + assert(is_in_code_section(bci), "can only forward in section");
  4326. + // First calculate back to original bci.
  4327. + constMethodOop m = constMethod();
  4328. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4329. + u2 new_index = m->code_section_new_index_at(i);
  4330. + u2 original_index = m->code_section_original_index_at(i);
  4331. + u2 length = m->code_section_length_at(i);
  4332. + if (bci >= new_index && bci < new_index + length) {
  4333. + // We are in a specified code section.
  4334. + original_bci = bci - new_index + original_index;
  4335. + break;
  4336. + }
  4337. + }
  4338. + assert (original_bci != -1, "must have been in code section");
  4339. + } else {
  4340. + // No code sections specified => we are in an original method.
  4341. + original_bci = bci;
  4342. + }
  4343. +
  4344. + // We know the original bci => match to new method.
  4345. + int new_bci = -1;
  4346. + if (new_method->constMethod()->has_code_section_table()) {
  4347. + // Map to new bci.
  4348. + constMethodOop m = new_method->constMethod();
  4349. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4350. + u2 new_index = m->code_section_new_index_at(i);
  4351. + u2 original_index = m->code_section_original_index_at(i);
  4352. + u2 length = m->code_section_length_at(i);
  4353. + if (original_bci >= original_index && original_bci < original_index + length) {
  4354. + new_bci = original_bci - original_index + new_index;
  4355. + break;
  4356. + }
  4357. + }
  4358. + assert (new_bci != -1, "must have found new code section");
  4359. +
  4360. + } else {
  4361. + // We are in an original method.
  4362. + new_bci = original_bci;
  4363. + }
  4364. +
  4365. + return new_bci;
  4366. +}
  4367. +
  4368. +
  4369. int methodOopDesc::extra_stack_words() {
  4370. // not an inline function, to avoid a header dependency on Interpreter
  4371. return extra_stack_entries() * Interpreter::stackElementSize;
  4372. @@ -1061,6 +1125,9 @@
  4373. // Reset correct method/const method, method size, and parameter info
  4374. newm->set_constMethod(newcm);
  4375. + newm->set_forward_method(newm->forward_method());
  4376. + newm->set_new_version(newm->new_version());
  4377. + newm->set_old_version(newm->old_version());
  4378. newm->constMethod()->set_code_size(new_code_length);
  4379. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4380. newm->set_method_size(new_method_size);
  4381. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4382. index 486e106..11e52bb 100644
  4383. --- a/src/share/vm/oops/methodOop.hpp
  4384. +++ b/src/share/vm/oops/methodOop.hpp
  4385. @@ -114,6 +114,11 @@
  4386. AccessFlags _access_flags; // Access flags
  4387. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4388. // note: can have vtables with >2**16 elements (because of inheritance)
  4389. + // (tw) Newer version of method available?
  4390. + methodOop _forward_method;
  4391. + methodOop _new_version;
  4392. + methodOop _old_version;
  4393. +
  4394. #ifdef CC_INTERP
  4395. int _result_index; // C++ interpreter needs for converting results to/from stack
  4396. #endif
  4397. @@ -174,6 +179,32 @@
  4398. Symbol* name() const { return constants()->symbol_at(name_index()); }
  4399. int name_index() const { return constMethod()->name_index(); }
  4400. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4401. +
  4402. + methodOop forward_method() const {return _forward_method; }
  4403. + void set_forward_method(methodOop m) { _forward_method = m; }
  4404. + bool has_forward_method() const { return forward_method() != NULL; }
  4405. + methodOop new_version() const {return _new_version; }
  4406. + void set_new_version(methodOop m) { _new_version = m; }
  4407. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4408. +
  4409. + methodOop old_version() const {return _old_version; };
  4410. + void set_old_version(methodOop m) {
  4411. + if (m == NULL) {
  4412. + _old_version = NULL;
  4413. + return;
  4414. + }
  4415. +
  4416. + assert(_old_version == NULL, "may only be set once");
  4417. + assert(this->code_size() == m->code_size(), "must have same code length");
  4418. + _old_version = m;
  4419. + }
  4420. +
  4421. + methodOop oldest_version() const {
  4422. + if(_old_version == NULL) return (methodOop)this;
  4423. + else {
  4424. + return old_version()->oldest_version();
  4425. + }
  4426. + }
  4427. // signature
  4428. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4429. @@ -670,6 +701,10 @@
  4430. // Inline cache support
  4431. void cleanup_inline_caches();
  4432. + // (tw) Method forwarding support.
  4433. + bool is_in_code_section(int bci);
  4434. + int calculate_forward_bci(int bci, methodOop new_method);
  4435. +
  4436. // Find if klass for method is loaded
  4437. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4438. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4439. @@ -734,6 +769,9 @@
  4440. // Garbage collection support
  4441. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4442. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4443. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4444. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4445. oop* adr_method_data() const { return (oop*)&_method_data; }
  4446. };
  4447. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4448. index 5982c88..4873fca 100644
  4449. --- a/src/share/vm/oops/oop.hpp
  4450. +++ b/src/share/vm/oops/oop.hpp
  4451. @@ -95,6 +95,7 @@
  4452. narrowOop* compressed_klass_addr();
  4453. void set_klass(klassOop k);
  4454. + void set_klass_no_check(klassOop k);
  4455. // For klass field compression
  4456. int klass_gap() const;
  4457. @@ -135,6 +136,7 @@
  4458. bool is_array() const;
  4459. bool is_objArray() const;
  4460. bool is_klass() const;
  4461. + bool is_instanceKlass() const;
  4462. bool is_thread() const;
  4463. bool is_method() const;
  4464. bool is_constMethod() const;
  4465. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4466. index f4eb2f7..0acb346 100644
  4467. --- a/src/share/vm/oops/oop.inline.hpp
  4468. +++ b/src/share/vm/oops/oop.inline.hpp
  4469. @@ -123,6 +123,14 @@
  4470. }
  4471. }
  4472. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4473. + if (UseCompressedOops) {
  4474. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4475. + } else {
  4476. + oop_store_without_check(klass_addr(), (oop) k);
  4477. + }
  4478. +}
  4479. +
  4480. inline int oopDesc::klass_gap() const {
  4481. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4482. }
  4483. @@ -156,6 +164,7 @@
  4484. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4485. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4486. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4487. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4488. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4489. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4490. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4491. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4492. index 50e1263..701ed74 100644
  4493. --- a/src/share/vm/prims/jni.cpp
  4494. +++ b/src/share/vm/prims/jni.cpp
  4495. @@ -406,7 +406,7 @@
  4496. }
  4497. }
  4498. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4499. - Handle(), &st, true,
  4500. + Handle(), &st, true, KlassHandle(),
  4501. CHECK_NULL);
  4502. if (TraceClassResolution && k != NULL) {
  4503. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4504. index c87af13..bb4b5d8 100644
  4505. --- a/src/share/vm/prims/jvm.cpp
  4506. +++ b/src/share/vm/prims/jvm.cpp
  4507. @@ -947,7 +947,7 @@
  4508. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4509. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4510. protection_domain, &st,
  4511. - verify != 0,
  4512. + verify != 0, KlassHandle(),
  4513. CHECK_NULL);
  4514. if (TraceClassResolution && k != NULL) {
  4515. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4516. index 4ac6b82..30b8e84 100644
  4517. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4518. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4519. @@ -290,7 +290,10 @@
  4520. class_definitions[index].klass = jcls;
  4521. }
  4522. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4523. - VMThread::execute(&op);
  4524. + {
  4525. + MutexLocker sd_mutex(RedefineClasses_lock);
  4526. + VMThread::execute(&op);
  4527. + }
  4528. return (op.check_error());
  4529. } /* end RetransformClasses */
  4530. @@ -299,9 +302,12 @@
  4531. // class_definitions - pre-checked for NULL
  4532. jvmtiError
  4533. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4534. -//TODO: add locking
  4535. +
  4536. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4537. - VMThread::execute(&op);
  4538. + {
  4539. + MutexLocker sd_mutex(RedefineClasses_lock);
  4540. + VMThread::execute(&op);
  4541. + }
  4542. return (op.check_error());
  4543. } /* end RedefineClasses */
  4544. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4545. index ec8ede3..2bd5983 100644
  4546. --- a/src/share/vm/prims/jvmtiExport.cpp
  4547. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4548. @@ -2296,7 +2296,7 @@
  4549. // iterate over any code blob descriptors collected and post a
  4550. // DYNAMIC_CODE_GENERATED event to the profiler.
  4551. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4552. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4553. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4554. // iterate over any code blob descriptors that we collected
  4555. if (_code_blobs != NULL) {
  4556. for (int i=0; i<_code_blobs->length(); i++) {
  4557. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4558. index d3fa140..f4f8b57 100644
  4559. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4560. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4561. @@ -286,6 +286,8 @@
  4562. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4563. ((methodOopDesc*)_method->*meth_act)(_bci);
  4564. + // DCEVM: TODO: Check how we can implement this differently here!
  4565. +
  4566. // add/remove breakpoint to/from versions of the method that
  4567. // are EMCP. Directly or transitively obsolete methods are
  4568. // not saved in the PreviousVersionInfo.
  4569. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4570. index 606be1c..ef4f380 100644
  4571. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4572. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4573. @@ -1,5 +1,5 @@
  4574. /*
  4575. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  4576. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4577. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4578. *
  4579. * This code is free software; you can redistribute it and/or modify it
  4580. @@ -30,581 +30,637 @@
  4581. #include "interpreter/rewriter.hpp"
  4582. #include "memory/gcLocker.hpp"
  4583. #include "memory/universe.inline.hpp"
  4584. -#include "oops/fieldStreams.hpp"
  4585. +#include "memory/cardTableRS.hpp"
  4586. #include "oops/klassVtable.hpp"
  4587. +#include "oops/fieldStreams.hpp"
  4588. #include "prims/jvmtiImpl.hpp"
  4589. #include "prims/jvmtiRedefineClasses.hpp"
  4590. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4591. #include "prims/methodComparator.hpp"
  4592. -#include "prims/methodHandles.hpp"
  4593. #include "runtime/deoptimization.hpp"
  4594. #include "runtime/relocator.hpp"
  4595. #include "utilities/bitMap.inline.hpp"
  4596. +#include "compiler/compileBroker.hpp"
  4597. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4598. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4599. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4600. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4601. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4602. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4603. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4604. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4605. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4606. +int* VM_RedefineClasses::_added_methods = NULL;
  4607. int VM_RedefineClasses::_matching_methods_length = 0;
  4608. int VM_RedefineClasses::_deleted_methods_length = 0;
  4609. int VM_RedefineClasses::_added_methods_length = 0;
  4610. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4611. +// Holds the revision number of the current class redefinition
  4612. +int VM_RedefineClasses::_revision_number = -1;
  4613. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4614. - const jvmtiClassDefinition *class_defs,
  4615. - JvmtiClassLoadKind class_load_kind) {
  4616. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4617. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4618. + RC_TIMER_START(_timer_total);
  4619. _class_count = class_count;
  4620. _class_defs = class_defs;
  4621. _class_load_kind = class_load_kind;
  4622. - _res = JVMTI_ERROR_NONE;
  4623. + _updated_oops = NULL;
  4624. + _result = JVMTI_ERROR_NONE;
  4625. }
  4626. -bool VM_RedefineClasses::doit_prologue() {
  4627. - if (_class_count == 0) {
  4628. - _res = JVMTI_ERROR_NONE;
  4629. - return false;
  4630. +VM_RedefineClasses::~VM_RedefineClasses() {
  4631. + {
  4632. + MonitorLockerEx ml(RedefinitionSync_lock);
  4633. + Threads::set_wait_at_instrumentation_entry(false);
  4634. + ml.notify_all();
  4635. }
  4636. - if (_class_defs == NULL) {
  4637. - _res = JVMTI_ERROR_NULL_POINTER;
  4638. - return false;
  4639. +
  4640. + unlock_threads();
  4641. + RC_TIMER_STOP(_timer_total);
  4642. +
  4643. + if (TimeRedefineClasses) {
  4644. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4645. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4646. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4647. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4648. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4649. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4650. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4651. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4652. + tty->print_cr("------------------------------------------------------------------");
  4653. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4654. }
  4655. - for (int i = 0; i < _class_count; i++) {
  4656. - if (_class_defs[i].klass == NULL) {
  4657. - _res = JVMTI_ERROR_INVALID_CLASS;
  4658. - return false;
  4659. - }
  4660. - if (_class_defs[i].class_byte_count == 0) {
  4661. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4662. - return false;
  4663. - }
  4664. - if (_class_defs[i].class_bytes == NULL) {
  4665. - _res = JVMTI_ERROR_NULL_POINTER;
  4666. - return false;
  4667. +}
  4668. +
  4669. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4670. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4671. +
  4672. + // Create array with all classes for which the redefine command was given
  4673. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4674. + for (int i=0; i<_class_count; i++) {
  4675. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4676. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4677. + klasses_to_redefine.append(klass_handle);
  4678. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4679. + }
  4680. +
  4681. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4682. + GrowableArray<instanceKlassHandle> affected_classes;
  4683. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4684. +
  4685. + // Trace affected classes
  4686. + if (RC_TRACE_ENABLED(0x00000001)) {
  4687. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4688. + affected_classes.length()));
  4689. + for (int i=0; i<affected_classes.length(); i++) {
  4690. + RC_TRACE(0x00000001, ("%s",
  4691. + affected_classes.at(i)->name()->as_C_string()));
  4692. }
  4693. }
  4694. - // Start timer after all the sanity checks; not quite accurate, but
  4695. - // better than adding a bunch of stop() calls.
  4696. - RC_TIMER_START(_timer_vm_op_prologue);
  4697. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4698. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4699. + all_affected_klasses->appendAll(&affected_classes);
  4700. +
  4701. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4702. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4703. + if (RC_TRACE_ENABLED(0x00000001)) {
  4704. + RC_TRACE(0x00000001, ("Redefine order: "));
  4705. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4706. + RC_TRACE(0x00000001, ("%s",
  4707. + all_affected_klasses->at(i)->name()->as_C_string()));
  4708. + }
  4709. + }
  4710. +
  4711. + return result;
  4712. +}
  4713. +
  4714. +// Searches for the class bytes of the given class and returns them as a byte array.
  4715. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4716. +
  4717. + *not_changed = false;
  4718. +
  4719. + // Search for the index in the redefinition array that corresponds to the current class
  4720. + int j;
  4721. + for (j=0; j<_class_count; j++) {
  4722. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4723. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4724. + if (the_class_oop == the_class()) {
  4725. + break;
  4726. + }
  4727. + }
  4728. +
  4729. + if (j == _class_count) {
  4730. +
  4731. + *not_changed = true;
  4732. +
  4733. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4734. + // so the user did not specify a different bytecode for that class.
  4735. +
  4736. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4737. + // not cached, we need to reconstitute the class file from VM representation
  4738. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4739. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4740. +
  4741. + JvmtiClassFileReconstituter reconstituter(the_class);
  4742. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4743. + return reconstituter.get_error();
  4744. + }
  4745. +
  4746. + *class_byte_count = (jint)reconstituter.class_file_size();
  4747. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4748. +
  4749. + } else {
  4750. +
  4751. + // it is cached, get it from the cache
  4752. + *class_byte_count = the_class->get_cached_class_file_len();
  4753. + *class_bytes = the_class->get_cached_class_file_bytes();
  4754. + }
  4755. +
  4756. + } else {
  4757. +
  4758. + // Redefine with bytecodes at index j
  4759. + *class_bytes = _class_defs[j].class_bytes;
  4760. + *class_byte_count = _class_defs[j].class_byte_count;
  4761. + }
  4762. +
  4763. + return JVMTI_ERROR_NONE;
  4764. +}
  4765. +
  4766. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4767. +bool VM_RedefineClasses::doit_prologue() {
  4768. +
  4769. + _revision_number++;
  4770. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4771. +
  4772. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4773. + RC_TIMER_START(_timer_prologue);
  4774. +
  4775. + if (!check_arguments()) {
  4776. + RC_TIMER_STOP(_timer_prologue);
  4777. + return false;
  4778. + }
  4779. // We first load new class versions in the prologue, because somewhere down the
  4780. // call chain it is required that the current thread is a Java thread.
  4781. - _res = load_new_class_versions(Thread::current());
  4782. - if (_res != JVMTI_ERROR_NONE) {
  4783. - // Free os::malloc allocated memory in load_new_class_version.
  4784. - os::free(_scratch_classes);
  4785. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4786. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4787. + _result = load_new_class_versions(Thread::current());
  4788. +
  4789. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4790. + if (_result != JVMTI_ERROR_NONE) {
  4791. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4792. + delete _new_classes;
  4793. + _new_classes = NULL;
  4794. + RC_TIMER_STOP(_timer_prologue);
  4795. return false;
  4796. }
  4797. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4798. + RC_TRACE(0x00000001, ("nearly finished"));
  4799. + VM_GC_Operation::doit_prologue();
  4800. + RC_TIMER_STOP(_timer_prologue);
  4801. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4802. return true;
  4803. }
  4804. -void VM_RedefineClasses::doit() {
  4805. - Thread *thread = Thread::current();
  4806. +// Checks basic properties of the arguments of the redefinition command.
  4807. +bool VM_RedefineClasses::check_arguments() {
  4808. - if (UseSharedSpaces) {
  4809. - // Sharing is enabled so we remap the shared readonly space to
  4810. - // shared readwrite, private just in case we need to redefine
  4811. - // a shared class. We do the remap during the doit() phase of
  4812. - // the safepoint to be safer.
  4813. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4814. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4815. - ("failed to remap shared readonly space to readwrite, private"));
  4816. - _res = JVMTI_ERROR_INTERNAL;
  4817. - return;
  4818. - }
  4819. - }
  4820. -
  4821. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4822. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4823. for (int i = 0; i < _class_count; i++) {
  4824. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4825. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4826. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4827. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4828. }
  4829. - // Disable any dependent concurrent compilations
  4830. - SystemDictionary::notice_modification();
  4831. - // Set flag indicating that some invariants are no longer true.
  4832. - // See jvmtiExport.hpp for detailed explanation.
  4833. - JvmtiExport::set_has_redefined_a_class();
  4834. -
  4835. -// check_class() is optionally called for product bits, but is
  4836. -// always called for non-product bits.
  4837. -#ifdef PRODUCT
  4838. - if (RC_TRACE_ENABLED(0x00004000)) {
  4839. -#endif
  4840. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4841. - SystemDictionary::classes_do(check_class, thread);
  4842. -#ifdef PRODUCT
  4843. - }
  4844. -#endif
  4845. -}
  4846. -
  4847. -void VM_RedefineClasses::doit_epilogue() {
  4848. - // Free os::malloc allocated memory.
  4849. - // The memory allocated in redefine will be free'ed in next VM operation.
  4850. - os::free(_scratch_classes);
  4851. -
  4852. - if (RC_TRACE_ENABLED(0x00000004)) {
  4853. - // Used to have separate timers for "doit" and "all", but the timer
  4854. - // overhead skewed the measurements.
  4855. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4856. - _timer_rsc_phase2.milliseconds();
  4857. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4858. -
  4859. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4860. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4861. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4862. - RC_TRACE(0x00000004,
  4863. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4864. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4865. - }
  4866. -}
  4867. -
  4868. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4869. - // classes for primitives cannot be redefined
  4870. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4871. - return false;
  4872. - }
  4873. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4874. - // classes for arrays cannot be redefined
  4875. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4876. - return false;
  4877. - }
  4878. return true;
  4879. }
  4880. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4881. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4882. -// direct CP entries, there is just the current entry to append. For
  4883. -// indirect and double-indirect CP entries, there are zero or more
  4884. -// referenced CP entries along with the current entry to append.
  4885. -// Indirect and double-indirect CP entries are handled by recursive
  4886. -// calls to append_entry() as needed. The referenced CP entries are
  4887. -// always appended to *merge_cp_p before the referee CP entry. These
  4888. -// referenced CP entries may already exist in *merge_cp_p in which case
  4889. -// there is nothing extra to append and only the current entry is
  4890. -// appended.
  4891. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4892. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4893. - TRAPS) {
  4894. +jvmtiError VM_RedefineClasses::check_exception() const {
  4895. + Thread* THREAD = Thread::current();
  4896. + if (HAS_PENDING_EXCEPTION) {
  4897. - // append is different depending on entry tag type
  4898. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4899. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4900. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4901. + ex_name->as_C_string()));
  4902. + if (TraceRedefineClasses >= 1) {
  4903. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4904. + tty->print_cr("");
  4905. + }
  4906. + CLEAR_PENDING_EXCEPTION;
  4907. - // The old verifier is implemented outside the VM. It loads classes,
  4908. - // but does not resolve constant pool entries directly so we never
  4909. - // see Class entries here with the old verifier. Similarly the old
  4910. - // verifier does not like Class entries in the input constant pool.
  4911. - // The split-verifier is implemented in the VM so it can optionally
  4912. - // and directly resolve constant pool entries to load classes. The
  4913. - // split-verifier can accept either Class entries or UnresolvedClass
  4914. - // entries in the input constant pool. We revert the appended copy
  4915. - // back to UnresolvedClass so that either verifier will be happy
  4916. - // with the constant pool entry.
  4917. - case JVM_CONSTANT_Class:
  4918. - {
  4919. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4920. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4921. - scratch_cp->klass_name_at(scratch_i));
  4922. -
  4923. - if (scratch_i != *merge_cp_length_p) {
  4924. - // The new entry in *merge_cp_p is at a different index than
  4925. - // the new entry in scratch_cp so we need to map the index values.
  4926. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4927. - }
  4928. - (*merge_cp_length_p)++;
  4929. - } break;
  4930. -
  4931. - // these are direct CP entries so they can be directly appended,
  4932. - // but double and long take two constant pool entries
  4933. - case JVM_CONSTANT_Double: // fall through
  4934. - case JVM_CONSTANT_Long:
  4935. - {
  4936. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4937. - THREAD);
  4938. -
  4939. - if (scratch_i != *merge_cp_length_p) {
  4940. - // The new entry in *merge_cp_p is at a different index than
  4941. - // the new entry in scratch_cp so we need to map the index values.
  4942. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4943. - }
  4944. - (*merge_cp_length_p) += 2;
  4945. - } break;
  4946. -
  4947. - // these are direct CP entries so they can be directly appended
  4948. - case JVM_CONSTANT_Float: // fall through
  4949. - case JVM_CONSTANT_Integer: // fall through
  4950. - case JVM_CONSTANT_Utf8: // fall through
  4951. -
  4952. - // This was an indirect CP entry, but it has been changed into
  4953. - // an interned string so this entry can be directly appended.
  4954. - case JVM_CONSTANT_String: // fall through
  4955. -
  4956. - // These were indirect CP entries, but they have been changed into
  4957. - // Symbol*s so these entries can be directly appended.
  4958. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4959. - case JVM_CONSTANT_UnresolvedString:
  4960. - {
  4961. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4962. - THREAD);
  4963. -
  4964. - if (scratch_i != *merge_cp_length_p) {
  4965. - // The new entry in *merge_cp_p is at a different index than
  4966. - // the new entry in scratch_cp so we need to map the index values.
  4967. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4968. - }
  4969. - (*merge_cp_length_p)++;
  4970. - } break;
  4971. -
  4972. - // this is an indirect CP entry so it needs special handling
  4973. - case JVM_CONSTANT_NameAndType:
  4974. - {
  4975. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4976. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  4977. - merge_cp_length_p, THREAD);
  4978. -
  4979. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  4980. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  4981. - merge_cp_p, merge_cp_length_p,
  4982. - THREAD);
  4983. -
  4984. - // If the referenced entries already exist in *merge_cp_p, then
  4985. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  4986. - // In that case, all we are appending is the current entry.
  4987. - if (new_name_ref_i != name_ref_i) {
  4988. - RC_TRACE(0x00080000,
  4989. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  4990. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  4991. - }
  4992. - if (new_signature_ref_i != signature_ref_i) {
  4993. - RC_TRACE(0x00080000,
  4994. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  4995. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  4996. - }
  4997. -
  4998. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  4999. - new_name_ref_i, new_signature_ref_i);
  5000. - if (scratch_i != *merge_cp_length_p) {
  5001. - // The new entry in *merge_cp_p is at a different index than
  5002. - // the new entry in scratch_cp so we need to map the index values.
  5003. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5004. - }
  5005. - (*merge_cp_length_p)++;
  5006. - } break;
  5007. -
  5008. - // this is a double-indirect CP entry so it needs special handling
  5009. - case JVM_CONSTANT_Fieldref: // fall through
  5010. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5011. - case JVM_CONSTANT_Methodref:
  5012. - {
  5013. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5014. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  5015. - merge_cp_p, merge_cp_length_p, THREAD);
  5016. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5017. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  5018. - merge_cp_p, merge_cp_length_p, THREAD);
  5019. -
  5020. - const char *entry_name;
  5021. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5022. - case JVM_CONSTANT_Fieldref:
  5023. - entry_name = "Fieldref";
  5024. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5025. - new_name_and_type_ref_i);
  5026. - break;
  5027. - case JVM_CONSTANT_InterfaceMethodref:
  5028. - entry_name = "IFMethodref";
  5029. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5030. - new_klass_ref_i, new_name_and_type_ref_i);
  5031. - break;
  5032. - case JVM_CONSTANT_Methodref:
  5033. - entry_name = "Methodref";
  5034. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5035. - new_name_and_type_ref_i);
  5036. - break;
  5037. - default:
  5038. - guarantee(false, "bad switch");
  5039. - break;
  5040. - }
  5041. -
  5042. - if (klass_ref_i != new_klass_ref_i) {
  5043. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5044. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5045. - }
  5046. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5047. - RC_TRACE(0x00080000,
  5048. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5049. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5050. - new_name_and_type_ref_i));
  5051. - }
  5052. -
  5053. - if (scratch_i != *merge_cp_length_p) {
  5054. - // The new entry in *merge_cp_p is at a different index than
  5055. - // the new entry in scratch_cp so we need to map the index values.
  5056. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5057. - }
  5058. - (*merge_cp_length_p)++;
  5059. - } break;
  5060. -
  5061. - // this is an indirect CP entry so it needs special handling
  5062. - case JVM_CONSTANT_MethodType:
  5063. - {
  5064. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  5065. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5066. - merge_cp_length_p, THREAD);
  5067. - if (new_ref_i != ref_i) {
  5068. - RC_TRACE(0x00080000,
  5069. - ("MethodType entry@%d ref_index change: %d to %d",
  5070. - *merge_cp_length_p, ref_i, new_ref_i));
  5071. - }
  5072. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  5073. - if (scratch_i != *merge_cp_length_p) {
  5074. - // The new entry in *merge_cp_p is at a different index than
  5075. - // the new entry in scratch_cp so we need to map the index values.
  5076. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5077. - }
  5078. - (*merge_cp_length_p)++;
  5079. - } break;
  5080. -
  5081. - // this is an indirect CP entry so it needs special handling
  5082. - case JVM_CONSTANT_MethodHandle:
  5083. - {
  5084. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  5085. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  5086. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5087. - merge_cp_length_p, THREAD);
  5088. - if (new_ref_i != ref_i) {
  5089. - RC_TRACE(0x00080000,
  5090. - ("MethodHandle entry@%d ref_index change: %d to %d",
  5091. - *merge_cp_length_p, ref_i, new_ref_i));
  5092. - }
  5093. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  5094. - if (scratch_i != *merge_cp_length_p) {
  5095. - // The new entry in *merge_cp_p is at a different index than
  5096. - // the new entry in scratch_cp so we need to map the index values.
  5097. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5098. - }
  5099. - (*merge_cp_length_p)++;
  5100. - } break;
  5101. -
  5102. - // this is an indirect CP entry so it needs special handling
  5103. - case JVM_CONSTANT_InvokeDynamic:
  5104. - {
  5105. - // Index of the bootstrap specifier in the operands array
  5106. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  5107. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  5108. - merge_cp_length_p, THREAD);
  5109. - // The bootstrap method NameAndType_info index
  5110. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  5111. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5112. - merge_cp_length_p, THREAD);
  5113. - if (new_bs_i != old_bs_i) {
  5114. - RC_TRACE(0x00080000,
  5115. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  5116. - *merge_cp_length_p, old_bs_i, new_bs_i));
  5117. - }
  5118. - if (new_ref_i != old_ref_i) {
  5119. - RC_TRACE(0x00080000,
  5120. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  5121. - *merge_cp_length_p, old_ref_i, new_ref_i));
  5122. - }
  5123. -
  5124. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  5125. - if (scratch_i != *merge_cp_length_p) {
  5126. - // The new entry in *merge_cp_p is at a different index than
  5127. - // the new entry in scratch_cp so we need to map the index values.
  5128. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5129. - }
  5130. - (*merge_cp_length_p)++;
  5131. - } break;
  5132. -
  5133. - // At this stage, Class or UnresolvedClass could be here, but not
  5134. - // ClassIndex
  5135. - case JVM_CONSTANT_ClassIndex: // fall through
  5136. -
  5137. - // Invalid is used as the tag for the second constant pool entry
  5138. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5139. - // not be seen by itself.
  5140. - case JVM_CONSTANT_Invalid: // fall through
  5141. -
  5142. - // At this stage, String or UnresolvedString could be here, but not
  5143. - // StringIndex
  5144. - case JVM_CONSTANT_StringIndex: // fall through
  5145. -
  5146. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5147. - // here
  5148. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5149. -
  5150. - default:
  5151. - {
  5152. - // leave a breadcrumb
  5153. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5154. - ShouldNotReachHere();
  5155. - } break;
  5156. - } // end switch tag value
  5157. -} // end append_entry()
  5158. -
  5159. -
  5160. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  5161. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5162. -
  5163. - int new_ref_i = ref_i;
  5164. - bool match = (ref_i < *merge_cp_length_p) &&
  5165. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  5166. -
  5167. - if (!match) {
  5168. - // forward reference in *merge_cp_p or not a direct match
  5169. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  5170. - if (found_i != 0) {
  5171. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  5172. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  5173. - new_ref_i = found_i;
  5174. - map_index(scratch_cp, ref_i, found_i);
  5175. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5176. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5177. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5178. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5179. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5180. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5181. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5182. + // The message will be "XXX (wrong name: YYY)"
  5183. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  5184. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5185. + return JVMTI_ERROR_OUT_OF_MEMORY;
  5186. } else {
  5187. - // no match found so we have to append this entry to *merge_cp_p
  5188. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  5189. - // The above call to append_entry() can only append one entry
  5190. - // so the post call query of *merge_cp_length_p is only for
  5191. - // the sake of consistency.
  5192. - new_ref_i = *merge_cp_length_p - 1;
  5193. + // Just in case more exceptions can be thrown..
  5194. + return JVMTI_ERROR_FAILS_VERIFICATION;
  5195. }
  5196. }
  5197. - return new_ref_i;
  5198. -} // end find_or_append_indirect_entry()
  5199. -
  5200. -
  5201. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  5202. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  5203. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  5204. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  5205. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5206. -
  5207. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  5208. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5209. - merge_cp_length_p, THREAD);
  5210. - if (new_ref_i != old_ref_i) {
  5211. - RC_TRACE(0x00080000,
  5212. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  5213. - _operands_cur_length, old_ref_i, new_ref_i));
  5214. - }
  5215. -
  5216. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  5217. - int new_bs_i = _operands_cur_length;
  5218. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  5219. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  5220. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  5221. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  5222. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  5223. -
  5224. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  5225. - merge_ops->short_at_put(new_base++, new_ref_i);
  5226. - merge_ops->short_at_put(new_base++, argc);
  5227. -
  5228. - for (int i = 0; i < argc; i++) {
  5229. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  5230. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  5231. - merge_cp_length_p, THREAD);
  5232. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  5233. - if (new_arg_ref_i != old_arg_ref_i) {
  5234. - RC_TRACE(0x00080000,
  5235. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  5236. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  5237. - }
  5238. - }
  5239. - if (old_bs_i != _operands_cur_length) {
  5240. - // The bootstrap specifier in *merge_cp_p is at a different index than
  5241. - // that in scratch_cp so we need to map the index values.
  5242. - map_operand_index(old_bs_i, new_bs_i);
  5243. - }
  5244. - _operands_cur_length++;
  5245. -} // end append_operand()
  5246. -
  5247. -
  5248. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  5249. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5250. -
  5251. - int new_bs_i = old_bs_i; // bootstrap specifier index
  5252. - bool match = (old_bs_i < _operands_cur_length) &&
  5253. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  5254. -
  5255. - if (!match) {
  5256. - // forward reference in *merge_cp_p or not a direct match
  5257. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  5258. - _operands_cur_length, THREAD);
  5259. - if (found_i != -1) {
  5260. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  5261. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  5262. - new_bs_i = found_i;
  5263. - map_operand_index(old_bs_i, found_i);
  5264. - } else {
  5265. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  5266. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  5267. - new_bs_i = _operands_cur_length - 1;
  5268. - }
  5269. - }
  5270. - return new_bs_i;
  5271. -} // end find_or_append_operand()
  5272. -
  5273. -
  5274. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  5275. - if (merge_cp->operands() == NULL) {
  5276. - return;
  5277. - }
  5278. - // Shrink the merge_cp operands
  5279. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  5280. -
  5281. - if (RC_TRACE_ENABLED(0x00040000)) {
  5282. - // don't want to loop unless we are tracing
  5283. - int count = 0;
  5284. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  5285. - int value = _operands_index_map_p->at(i);
  5286. - if (value != -1) {
  5287. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5288. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  5289. - count++;
  5290. - }
  5291. - }
  5292. - }
  5293. - // Clean-up
  5294. - _operands_index_map_p = NULL;
  5295. - _operands_cur_length = 0;
  5296. - _operands_index_map_count = 0;
  5297. -} // end finalize_operands_merge()
  5298. -
  5299. -
  5300. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5301. - typeArrayOop save;
  5302. -
  5303. - save = scratch_class->get_method_annotations_of(i);
  5304. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5305. - scratch_class->set_method_annotations_of(j, save);
  5306. -
  5307. - save = scratch_class->get_method_parameter_annotations_of(i);
  5308. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5309. - scratch_class->set_method_parameter_annotations_of(j, save);
  5310. -
  5311. - save = scratch_class->get_method_default_annotations_of(i);
  5312. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5313. - scratch_class->set_method_default_annotations_of(j, save);
  5314. + return JVMTI_ERROR_NONE;
  5315. }
  5316. +// Loads all new class versions and stores the instanceKlass handles in an array.
  5317. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5318. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5319. - instanceKlassHandle the_class,
  5320. - instanceKlassHandle scratch_class) {
  5321. + ResourceMark rm(THREAD);
  5322. +
  5323. + RC_TRACE(0x00000001, ("==================================================================="));
  5324. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  5325. + _class_count));
  5326. +
  5327. + // Retrieve an array of all classes that need to be redefined
  5328. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  5329. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  5330. + if (err != JVMTI_ERROR_NONE) {
  5331. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  5332. + (int)err));
  5333. + return err;
  5334. + }
  5335. +
  5336. +
  5337. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5338. +
  5339. + _max_redefinition_flags = Klass::NoRedefinition;
  5340. + jvmtiError result = JVMTI_ERROR_NONE;
  5341. +
  5342. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5343. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  5344. + i+1, all_affected_klasses.length()));
  5345. +
  5346. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5347. + RC_TRACE(0x00000002, ("name=%s",
  5348. + the_class->name()->as_C_string()));
  5349. +
  5350. + the_class->link_class(THREAD);
  5351. + result = check_exception();
  5352. + if (result != JVMTI_ERROR_NONE) break;
  5353. +
  5354. + // Find new class bytes
  5355. + const unsigned char* class_bytes;
  5356. + jint class_byte_count;
  5357. + jvmtiError error;
  5358. + jboolean not_changed;
  5359. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  5360. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  5361. + (int)error));
  5362. + result = error;
  5363. + break;
  5364. + }
  5365. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  5366. +
  5367. +
  5368. + // Set redefined class handle in JvmtiThreadState class.
  5369. + // This redefined class is sent to agent event handler for class file
  5370. + // load hook event.
  5371. + state->set_class_being_redefined(&the_class, _class_load_kind);
  5372. +
  5373. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  5374. +
  5375. + RC_TIMER_STOP(_timer_prologue);
  5376. + RC_TIMER_START(_timer_class_loading);
  5377. +
  5378. +
  5379. + // Parse the stream.
  5380. + Handle the_class_loader(THREAD, the_class->class_loader());
  5381. + Handle protection_domain(THREAD, the_class->protection_domain());
  5382. + Symbol* the_class_sym = the_class->name();
  5383. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  5384. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  5385. + the_class_loader,
  5386. + protection_domain,
  5387. + &st,
  5388. + true,
  5389. + the_class,
  5390. + THREAD));
  5391. +
  5392. + not_changed = false;
  5393. +
  5394. + RC_TIMER_STOP(_timer_class_loading);
  5395. + RC_TIMER_START(_timer_prologue);
  5396. +
  5397. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  5398. + // Clear class_being_redefined just to be sure.
  5399. + state->clear_class_being_redefined();
  5400. +
  5401. + result = check_exception();
  5402. + if (result != JVMTI_ERROR_NONE) break;
  5403. +
  5404. +#ifdef ASSERT
  5405. +
  5406. + assert(new_class() != NULL, "Class could not be loaded!");
  5407. + assert(new_class() != the_class(), "must be different");
  5408. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5409. +
  5410. +
  5411. + objArrayOop k_interfaces = new_class->local_interfaces();
  5412. + for (int j=0; j<k_interfaces->length(); j++) {
  5413. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5414. + }
  5415. +
  5416. + if (!THREAD->is_Compiler_thread()) {
  5417. +
  5418. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5419. + the_class->name()->as_C_string(),
  5420. + (address)(the_class->class_loader()),
  5421. + (address)(the_class->protection_domain())));
  5422. + // If we are on the compiler thread, we must not try to resolve a class.
  5423. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5424. +
  5425. + if (systemLookup != NULL) {
  5426. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5427. +
  5428. +
  5429. + Klass *subklass = new_class()->klass_part()->subklass();
  5430. + while (subklass != NULL) {
  5431. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5432. + subklass = subklass->next_sibling();
  5433. + }
  5434. + } else {
  5435. + // This can happen for reflection generated classes.. ?
  5436. + CLEAR_PENDING_EXCEPTION;
  5437. + }
  5438. + }
  5439. +
  5440. +#endif
  5441. +
  5442. + if (RC_TRACE_ENABLED(0x00000001)) {
  5443. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5444. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5445. + new_class->name()->as_C_string(),
  5446. + new_class->layout_helper(),
  5447. + the_class->layout_helper()));
  5448. + }
  5449. + }
  5450. +
  5451. + // Set the new version of the class
  5452. + new_class->set_revision_number(_revision_number);
  5453. + new_class->set_redefinition_index(i);
  5454. + the_class->set_new_version(new_class());
  5455. + _new_classes->append(new_class);
  5456. +
  5457. + assert(new_class->new_version() == NULL, "");
  5458. +
  5459. + int redefinition_flags = Klass::NoRedefinition;
  5460. +
  5461. + if (not_changed) {
  5462. + redefinition_flags = Klass::NoRedefinition;
  5463. + } else if (AllowAdvancedClassRedefinition) {
  5464. + redefinition_flags = calculate_redefinition_flags(new_class);
  5465. + } else {
  5466. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5467. + if (allowed != JVMTI_ERROR_NONE) {
  5468. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5469. + result = allowed;
  5470. + break;
  5471. + }
  5472. + redefinition_flags = Klass::ModifyClass;
  5473. + }
  5474. +
  5475. + if (new_class->super() != NULL) {
  5476. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5477. + }
  5478. +
  5479. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5480. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5481. + }
  5482. +
  5483. + new_class->set_redefinition_flags(redefinition_flags);
  5484. +
  5485. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5486. +
  5487. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5488. + // TODO: Check if watch access flags of static fields are updated correctly.
  5489. + calculate_instance_update_information(_new_classes->at(i)());
  5490. + } else {
  5491. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5492. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5493. +
  5494. + fieldDescriptor fd_new;
  5495. + fieldDescriptor fd_old;
  5496. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5497. + fd_new.initialize(new_class(), fs.index());
  5498. + fd_old.initialize(new_class->old_version(), fs.index());
  5499. + transfer_special_access_flags(&fd_old, &fd_new);
  5500. + }
  5501. + }
  5502. +
  5503. + if (RC_TRACE_ENABLED(0x00000008)) {
  5504. + if (new_class->super() != NULL) {
  5505. + RC_TRACE(0x00000008, ("Super class is %s",
  5506. + new_class->super()->klass_part()->name()->as_C_string()));
  5507. + }
  5508. + }
  5509. +
  5510. +#ifdef ASSERT
  5511. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5512. +
  5513. + the_class->vtable()->verify(tty);
  5514. + new_class->vtable()->verify(tty);
  5515. +#endif
  5516. +
  5517. + RC_TRACE(0x00000002, ("Verification done!"));
  5518. +
  5519. + if (i == all_affected_klasses.length() - 1) {
  5520. +
  5521. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5522. +
  5523. + RC_TIMER_STOP(_timer_prologue);
  5524. + lock_threads();
  5525. + RC_TIMER_START(_timer_prologue);
  5526. +
  5527. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5528. +
  5529. + klassOop initial_klass = all_affected_klasses.at(j)();
  5530. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5531. + Klass *cur_klass = initial_subklass;
  5532. + while(cur_klass != NULL) {
  5533. +
  5534. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5535. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5536. + if (!all_affected_klasses.contains(handle)) {
  5537. +
  5538. + int k = i + 1;
  5539. + for (; k<all_affected_klasses.length(); k++) {
  5540. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5541. + break;
  5542. + }
  5543. + }
  5544. + all_affected_klasses.insert_before(k, handle);
  5545. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5546. + cur_klass->name()->as_C_string()));
  5547. + }
  5548. + }
  5549. +
  5550. + cur_klass = cur_klass->next_sibling();
  5551. + }
  5552. + }
  5553. +
  5554. + int new_count = all_affected_klasses.length() - 1 - i;
  5555. + if (new_count != 0) {
  5556. +
  5557. + unlock_threads();
  5558. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5559. + new_count));
  5560. + }
  5561. + }
  5562. + }
  5563. +
  5564. + if (result != JVMTI_ERROR_NONE) {
  5565. + rollback();
  5566. + return result;
  5567. + }
  5568. +
  5569. + RC_TIMER_STOP(_timer_prologue);
  5570. + RC_TIMER_START(_timer_class_linking);
  5571. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5572. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5573. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5574. + instanceKlassHandle new_class(the_class->new_version());
  5575. +
  5576. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5577. + i,
  5578. + all_affected_klasses.length(),
  5579. + the_class->name()->as_C_string()));
  5580. + new_class->link_class(THREAD);
  5581. +
  5582. + result = check_exception();
  5583. + if (result != JVMTI_ERROR_NONE) break;
  5584. + }
  5585. + RC_TIMER_STOP(_timer_class_linking);
  5586. + RC_TIMER_START(_timer_prologue);
  5587. +
  5588. + if (result != JVMTI_ERROR_NONE) {
  5589. + rollback();
  5590. + return result;
  5591. + }
  5592. +
  5593. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5594. +
  5595. +#ifdef ASSERT
  5596. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5597. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5598. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5599. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5600. + assert(new_version->new_version() == NULL, "Must be newest version");
  5601. +
  5602. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5603. + new_version()->print();
  5604. + new_version->super()->print();
  5605. + }
  5606. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5607. + }
  5608. +
  5609. + SystemDictionary::classes_do(check_class, THREAD);
  5610. +
  5611. +#endif
  5612. +
  5613. + RC_TRACE(0x00000001, ("Finished verification!"));
  5614. + return JVMTI_ERROR_NONE;
  5615. +}
  5616. +
  5617. +void VM_RedefineClasses::lock_threads() {
  5618. +
  5619. + RC_TIMER_START(_timer_wait_for_locks);
  5620. +
  5621. +
  5622. + JavaThread *javaThread = Threads::first();
  5623. + while (javaThread != NULL) {
  5624. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5625. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5626. + compilerThread->set_should_bailout(true);
  5627. + }
  5628. + javaThread = javaThread->next();
  5629. + }
  5630. +
  5631. + int cnt = 0;
  5632. + javaThread = Threads::first();
  5633. + while (javaThread != NULL) {
  5634. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5635. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5636. + compilerThread->compilation_mutex()->lock();
  5637. + cnt++;
  5638. + }
  5639. + javaThread = javaThread->next();
  5640. + }
  5641. +
  5642. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5643. +
  5644. + cnt = 0;
  5645. + javaThread = Threads::first();
  5646. + while (javaThread != NULL) {
  5647. + if (javaThread != Thread::current()) {
  5648. + javaThread->redefine_classes_mutex()->lock();
  5649. + }
  5650. + javaThread = javaThread->next();
  5651. + }
  5652. +
  5653. +
  5654. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5655. +
  5656. + RC_TIMER_STOP(_timer_wait_for_locks);
  5657. +}
  5658. +
  5659. +void VM_RedefineClasses::unlock_threads() {
  5660. +
  5661. + int cnt = 0;
  5662. + JavaThread *javaThread = Threads::first();
  5663. + Thread *thread = Thread::current();
  5664. + while (javaThread != NULL) {
  5665. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5666. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5667. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5668. + compilerThread->compilation_mutex()->unlock();
  5669. + cnt++;
  5670. + }
  5671. + }
  5672. + javaThread = javaThread->next();
  5673. + }
  5674. +
  5675. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5676. +
  5677. + cnt = 0;
  5678. + javaThread = Threads::first();
  5679. + while (javaThread != NULL) {
  5680. + if (javaThread != Thread::current()) {
  5681. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5682. + javaThread->redefine_classes_mutex()->unlock();
  5683. + }
  5684. + }
  5685. + javaThread = javaThread->next();
  5686. + }
  5687. +
  5688. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5689. +}
  5690. +
  5691. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5692. +
  5693. +
  5694. +
  5695. + // Compatibility mode => check for unsupported modification
  5696. +
  5697. +
  5698. + assert(scratch_class->old_version() != NULL, "must have old version");
  5699. + instanceKlassHandle the_class(scratch_class->old_version());
  5700. +
  5701. int i;
  5702. // Check superclasses, or rather their names, since superclasses themselves can be
  5703. // requested to replace.
  5704. // Check for NULL superclass first since this might be java.lang.Object
  5705. if (the_class->super() != scratch_class->super() &&
  5706. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5707. - Klass::cast(the_class->super())->name() !=
  5708. - Klass::cast(scratch_class->super())->name())) {
  5709. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5710. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5711. + Klass::cast(the_class->super())->name() !=
  5712. + Klass::cast(scratch_class->super())->name())) {
  5713. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5714. }
  5715. // Check if the number, names and order of directly implemented interfaces are the same.
  5716. @@ -622,8 +678,8 @@
  5717. }
  5718. for (i = 0; i < n_intfs; i++) {
  5719. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5720. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5721. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5722. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5723. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5724. }
  5725. }
  5726. @@ -772,12 +828,8 @@
  5727. idnum_owner->set_method_idnum(new_num);
  5728. }
  5729. k_new_method->set_method_idnum(old_num);
  5730. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5731. }
  5732. }
  5733. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5734. - k_new_method->name_and_sig_as_C_string(), ni,
  5735. - k_old_method->name_and_sig_as_C_string(), oi));
  5736. // advance to next pair of methods
  5737. ++oi;
  5738. ++ni;
  5739. @@ -786,11 +838,11 @@
  5740. // method added, see if it is OK
  5741. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5742. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5743. - // hack: private should be treated as final, but alas
  5744. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5745. - ) {
  5746. - // new methods must be private
  5747. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5748. + // hack: private should be treated as final, but alas
  5749. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5750. + ) {
  5751. + // new methods must be private
  5752. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5753. }
  5754. {
  5755. u2 num = the_class->next_method_idnum();
  5756. @@ -805,24 +857,19 @@
  5757. idnum_owner->set_method_idnum(new_num);
  5758. }
  5759. k_new_method->set_method_idnum(num);
  5760. - swap_all_method_annotations(new_num, num, scratch_class);
  5761. }
  5762. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5763. - k_new_method->name_and_sig_as_C_string(), ni));
  5764. ++ni; // advance to next new method
  5765. break;
  5766. case deleted:
  5767. // method deleted, see if it is OK
  5768. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5769. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5770. - // hack: private should be treated as final, but alas
  5771. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5772. - ) {
  5773. - // deleted methods must be private
  5774. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5775. + // hack: private should be treated as final, but alas
  5776. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5777. + ) {
  5778. + // deleted methods must be private
  5779. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5780. }
  5781. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5782. - k_old_method->name_and_sig_as_C_string(), oi));
  5783. ++oi; // advance to next old method
  5784. break;
  5785. default:
  5786. @@ -833,2120 +880,2265 @@
  5787. return JVMTI_ERROR_NONE;
  5788. }
  5789. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5790. -// Find new constant pool index value for old constant pool index value
  5791. -// by seaching the index map. Returns zero (0) if there is no mapped
  5792. -// value for the old constant pool index.
  5793. -int VM_RedefineClasses::find_new_index(int old_index) {
  5794. - if (_index_map_count == 0) {
  5795. - // map is empty so nothing can be found
  5796. - return 0;
  5797. + int result = Klass::NoRedefinition;
  5798. +
  5799. +
  5800. +
  5801. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5802. + new_class->name()->as_C_string()));
  5803. +
  5804. + assert(new_class->old_version() != NULL, "must have old version");
  5805. + instanceKlassHandle the_class(new_class->old_version());
  5806. +
  5807. + // Check whether class is in the error init state.
  5808. + if (the_class->is_in_error_state()) {
  5809. + // TBD #5057930: special error code is needed in 1.6
  5810. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5811. }
  5812. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5813. - // The old_index is out of range so it is not mapped. This should
  5814. - // not happen in regular constant pool merging use, but it can
  5815. - // happen if a corrupt annotation is processed.
  5816. - return 0;
  5817. - }
  5818. + int i;
  5819. - int value = _index_map_p->at(old_index);
  5820. - if (value == -1) {
  5821. - // the old_index is not mapped
  5822. - return 0;
  5823. - }
  5824. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5825. + // Check superclasses
  5826. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5827. + if (the_class->super() != new_class->super()) {
  5828. + // Super class changed
  5829. - return value;
  5830. -} // end find_new_index()
  5831. + klassOop cur_klass = the_class->super();
  5832. + while (cur_klass != NULL) {
  5833. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5834. + RC_TRACE(0x00000002, ("Removed super class %s",
  5835. + cur_klass->klass_part()->name()->as_C_string()));
  5836. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5837. -
  5838. -// Find new bootstrap specifier index value for old bootstrap specifier index
  5839. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  5840. -// value for the old bootstrap specifier index.
  5841. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  5842. - if (_operands_index_map_count == 0) {
  5843. - // map is empty so nothing can be found
  5844. - return -1;
  5845. - }
  5846. -
  5847. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  5848. - // The old_index is out of range so it is not mapped.
  5849. - // This should not happen in regular constant pool merging use.
  5850. - return -1;
  5851. - }
  5852. -
  5853. - int value = _operands_index_map_p->at(old_index);
  5854. -
  5855. - return value;
  5856. -} // end find_new_operand_index()
  5857. -
  5858. -
  5859. -// Returns true if the current mismatch is due to a resolved/unresolved
  5860. -// class pair. Otherwise, returns false.
  5861. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5862. - int index1, constantPoolHandle cp2, int index2) {
  5863. -
  5864. - jbyte t1 = cp1->tag_at(index1).value();
  5865. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5866. - return false; // wrong entry type; not our special case
  5867. - }
  5868. -
  5869. - jbyte t2 = cp2->tag_at(index2).value();
  5870. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5871. - return false; // wrong entry type; not our special case
  5872. - }
  5873. -
  5874. - if (t1 == t2) {
  5875. - return false; // not a mismatch; not our special case
  5876. - }
  5877. -
  5878. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5879. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5880. - if (strcmp(s1, s2) != 0) {
  5881. - return false; // strings don't match; not our special case
  5882. - }
  5883. -
  5884. - return true; // made it through the gauntlet; this is our special case
  5885. -} // end is_unresolved_class_mismatch()
  5886. -
  5887. -
  5888. -// Returns true if the current mismatch is due to a resolved/unresolved
  5889. -// string pair. Otherwise, returns false.
  5890. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5891. - int index1, constantPoolHandle cp2, int index2) {
  5892. -
  5893. - jbyte t1 = cp1->tag_at(index1).value();
  5894. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5895. - return false; // wrong entry type; not our special case
  5896. - }
  5897. -
  5898. - jbyte t2 = cp2->tag_at(index2).value();
  5899. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5900. - return false; // wrong entry type; not our special case
  5901. - }
  5902. -
  5903. - if (t1 == t2) {
  5904. - return false; // not a mismatch; not our special case
  5905. - }
  5906. -
  5907. - char *s1 = cp1->string_at_noresolve(index1);
  5908. - char *s2 = cp2->string_at_noresolve(index2);
  5909. - if (strcmp(s1, s2) != 0) {
  5910. - return false; // strings don't match; not our special case
  5911. - }
  5912. -
  5913. - return true; // made it through the gauntlet; this is our special case
  5914. -} // end is_unresolved_string_mismatch()
  5915. -
  5916. -
  5917. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5918. - // For consistency allocate memory using os::malloc wrapper.
  5919. - _scratch_classes = (instanceKlassHandle *)
  5920. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5921. - if (_scratch_classes == NULL) {
  5922. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5923. - }
  5924. -
  5925. - ResourceMark rm(THREAD);
  5926. -
  5927. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5928. - // state can only be NULL if the current thread is exiting which
  5929. - // should not happen since we're trying to do a RedefineClasses
  5930. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5931. - for (int i = 0; i < _class_count; i++) {
  5932. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5933. - // classes for primitives cannot be redefined
  5934. - if (!is_modifiable_class(mirror)) {
  5935. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5936. - }
  5937. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5938. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5939. - Symbol* the_class_sym = the_class->name();
  5940. -
  5941. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5942. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5943. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5944. - the_class->external_name(), _class_load_kind,
  5945. - os::available_memory() >> 10));
  5946. -
  5947. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5948. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5949. -
  5950. - // Parse the stream.
  5951. - Handle the_class_loader(THREAD, the_class->class_loader());
  5952. - Handle protection_domain(THREAD, the_class->protection_domain());
  5953. - // Set redefined class handle in JvmtiThreadState class.
  5954. - // This redefined class is sent to agent event handler for class file
  5955. - // load hook event.
  5956. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5957. -
  5958. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5959. - the_class_loader,
  5960. - protection_domain,
  5961. - &st,
  5962. - THREAD);
  5963. - // Clear class_being_redefined just to be sure.
  5964. - state->clear_class_being_redefined();
  5965. -
  5966. - // TODO: if this is retransform, and nothing changed we can skip it
  5967. -
  5968. - instanceKlassHandle scratch_class (THREAD, k);
  5969. -
  5970. - if (HAS_PENDING_EXCEPTION) {
  5971. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5972. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5973. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5974. - ex_name->as_C_string()));
  5975. - CLEAR_PENDING_EXCEPTION;
  5976. -
  5977. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5978. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5979. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5980. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5981. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5982. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5983. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5984. - // The message will be "XXX (wrong name: YYY)"
  5985. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5986. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5987. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5988. - } else { // Just in case more exceptions can be thrown..
  5989. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5990. - }
  5991. - }
  5992. -
  5993. - // Ensure class is linked before redefine
  5994. - if (!the_class->is_linked()) {
  5995. - the_class->link_class(THREAD);
  5996. - if (HAS_PENDING_EXCEPTION) {
  5997. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5998. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5999. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  6000. - ex_name->as_C_string()));
  6001. - CLEAR_PENDING_EXCEPTION;
  6002. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6003. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6004. - } else {
  6005. - return JVMTI_ERROR_INTERNAL;
  6006. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  6007. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  6008. + cur_klass->klass_part()->name()->as_C_string()));
  6009. + cur_klass->klass_part()->set_subtype_changed(true);
  6010. }
  6011. }
  6012. +
  6013. + cur_klass = cur_klass->klass_part()->super();
  6014. }
  6015. - // Do the validity checks in compare_and_normalize_class_versions()
  6016. - // before verifying the byte codes. By doing these checks first, we
  6017. - // limit the number of functions that require redirection from
  6018. - // the_class to scratch_class. In particular, we don't have to
  6019. - // modify JNI GetSuperclass() and thus won't change its performance.
  6020. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6021. - scratch_class);
  6022. - if (res != JVMTI_ERROR_NONE) {
  6023. - return res;
  6024. - }
  6025. -
  6026. - // verify what the caller passed us
  6027. - {
  6028. - // The bug 6214132 caused the verification to fail.
  6029. - // Information about the_class and scratch_class is temporarily
  6030. - // recorded into jvmtiThreadState. This data is used to redirect
  6031. - // the_class to scratch_class in the JVM_* functions called by the
  6032. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6033. - // description.
  6034. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6035. - Verifier::verify(
  6036. - scratch_class, Verifier::ThrowException, true, THREAD);
  6037. - }
  6038. -
  6039. - if (HAS_PENDING_EXCEPTION) {
  6040. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6041. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6042. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6043. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6044. - CLEAR_PENDING_EXCEPTION;
  6045. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6046. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6047. - } else {
  6048. - // tell the caller the bytecodes are bad
  6049. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6050. + cur_klass = new_class->super();
  6051. + while (cur_klass != NULL) {
  6052. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  6053. + RC_TRACE(0x00000002, ("Added super class %s",
  6054. + cur_klass->klass_part()->name()->as_C_string()));
  6055. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  6056. }
  6057. - }
  6058. -
  6059. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6060. - if (res != JVMTI_ERROR_NONE) {
  6061. - return res;
  6062. - }
  6063. -
  6064. - if (VerifyMergedCPBytecodes) {
  6065. - // verify what we have done during constant pool merging
  6066. - {
  6067. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6068. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6069. - }
  6070. -
  6071. - if (HAS_PENDING_EXCEPTION) {
  6072. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6073. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6074. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6075. - ("verify_byte_codes post merge-CP exception: '%s'",
  6076. - ex_name->as_C_string()));
  6077. - CLEAR_PENDING_EXCEPTION;
  6078. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6079. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6080. - } else {
  6081. - // tell the caller that constant pool merging screwed up
  6082. - return JVMTI_ERROR_INTERNAL;
  6083. - }
  6084. - }
  6085. - }
  6086. -
  6087. - Rewriter::rewrite(scratch_class, THREAD);
  6088. - if (!HAS_PENDING_EXCEPTION) {
  6089. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6090. - }
  6091. - if (HAS_PENDING_EXCEPTION) {
  6092. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6093. - CLEAR_PENDING_EXCEPTION;
  6094. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6095. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6096. - } else {
  6097. - return JVMTI_ERROR_INTERNAL;
  6098. - }
  6099. - }
  6100. -
  6101. - _scratch_classes[i] = scratch_class;
  6102. -
  6103. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6104. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6105. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6106. - the_class->external_name(), os::available_memory() >> 10));
  6107. - }
  6108. -
  6109. - return JVMTI_ERROR_NONE;
  6110. -}
  6111. -
  6112. -
  6113. -// Map old_index to new_index as needed. scratch_cp is only needed
  6114. -// for RC_TRACE() calls.
  6115. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6116. - int old_index, int new_index) {
  6117. - if (find_new_index(old_index) != 0) {
  6118. - // old_index is already mapped
  6119. - return;
  6120. - }
  6121. -
  6122. - if (old_index == new_index) {
  6123. - // no mapping is needed
  6124. - return;
  6125. - }
  6126. -
  6127. - _index_map_p->at_put(old_index, new_index);
  6128. - _index_map_count++;
  6129. -
  6130. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6131. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6132. -} // end map_index()
  6133. -
  6134. -
  6135. -// Map old_index to new_index as needed.
  6136. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  6137. - if (find_new_operand_index(old_index) != -1) {
  6138. - // old_index is already mapped
  6139. - return;
  6140. - }
  6141. -
  6142. - if (old_index == new_index) {
  6143. - // no mapping is needed
  6144. - return;
  6145. - }
  6146. -
  6147. - _operands_index_map_p->at_put(old_index, new_index);
  6148. - _operands_index_map_count++;
  6149. -
  6150. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  6151. -} // end map_index()
  6152. -
  6153. -
  6154. -// Merge old_cp and scratch_cp and return the results of the merge via
  6155. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6156. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6157. -// in *merge_cp_p. Also creates a map of indices from entries in
  6158. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6159. -// entries are only created for entries in scratch_cp that occupy a
  6160. -// different location in *merged_cp_p.
  6161. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6162. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6163. - int *merge_cp_length_p, TRAPS) {
  6164. -
  6165. - if (merge_cp_p == NULL) {
  6166. - assert(false, "caller must provide scatch constantPool");
  6167. - return false; // robustness
  6168. - }
  6169. - if (merge_cp_length_p == NULL) {
  6170. - assert(false, "caller must provide scatch CP length");
  6171. - return false; // robustness
  6172. - }
  6173. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6174. - // but the caller might be smart so make sure we have at least
  6175. - // the minimum.
  6176. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6177. - assert(false, "merge area too small");
  6178. - return false; // robustness
  6179. - }
  6180. -
  6181. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6182. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6183. - scratch_cp->length()));
  6184. -
  6185. - {
  6186. - // Pass 0:
  6187. - // The old_cp is copied to *merge_cp_p; this means that any code
  6188. - // using old_cp does not have to change. This work looks like a
  6189. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6190. - // handle one special case:
  6191. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6192. - // This will make verification happy.
  6193. -
  6194. - int old_i; // index into old_cp
  6195. -
  6196. - // index zero (0) is not used in constantPools
  6197. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6198. - // leave debugging crumb
  6199. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6200. - switch (old_tag) {
  6201. - case JVM_CONSTANT_Class:
  6202. - case JVM_CONSTANT_UnresolvedClass:
  6203. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6204. - // May be resolving while calling this so do the same for
  6205. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6206. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6207. - old_cp->klass_name_at(old_i));
  6208. - break;
  6209. -
  6210. - case JVM_CONSTANT_Double:
  6211. - case JVM_CONSTANT_Long:
  6212. - // just copy the entry to *merge_cp_p, but double and long take
  6213. - // two constant pool entries
  6214. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6215. - old_i++;
  6216. - break;
  6217. -
  6218. - default:
  6219. - // just copy the entry to *merge_cp_p
  6220. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6221. - break;
  6222. - }
  6223. - } // end for each old_cp entry
  6224. -
  6225. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  6226. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  6227. -
  6228. - // We don't need to sanity check that *merge_cp_length_p is within
  6229. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6230. - (*merge_cp_length_p) = old_i;
  6231. - }
  6232. -
  6233. - // merge_cp_len should be the same as old_cp->length() at this point
  6234. - // so this trace message is really a "warm-and-breathing" message.
  6235. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6236. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6237. -
  6238. - int scratch_i; // index into scratch_cp
  6239. - {
  6240. - // Pass 1a:
  6241. - // Compare scratch_cp entries to the old_cp entries that we have
  6242. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6243. - // exact duplicates (matching entry at same index) so we only
  6244. - // compare entries in the common indice range.
  6245. - int increment = 1;
  6246. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6247. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6248. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6249. - case JVM_CONSTANT_Double:
  6250. - case JVM_CONSTANT_Long:
  6251. - // double and long take two constant pool entries
  6252. - increment = 2;
  6253. - break;
  6254. -
  6255. - default:
  6256. - increment = 1;
  6257. - break;
  6258. - }
  6259. -
  6260. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6261. - scratch_i, CHECK_0);
  6262. - if (match) {
  6263. - // found a match at the same index so nothing more to do
  6264. - continue;
  6265. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6266. - *merge_cp_p, scratch_i)) {
  6267. - // The mismatch in compare_entry_to() above is because of a
  6268. - // resolved versus unresolved class entry at the same index
  6269. - // with the same string value. Since Pass 0 reverted any
  6270. - // class entries to unresolved class entries in *merge_cp_p,
  6271. - // we go with the unresolved class entry.
  6272. - continue;
  6273. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6274. - *merge_cp_p, scratch_i)) {
  6275. - // The mismatch in compare_entry_to() above is because of a
  6276. - // resolved versus unresolved string entry at the same index
  6277. - // with the same string value. We can live with whichever
  6278. - // happens to be at scratch_i in *merge_cp_p.
  6279. - continue;
  6280. - }
  6281. -
  6282. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6283. - CHECK_0);
  6284. - if (found_i != 0) {
  6285. - guarantee(found_i != scratch_i,
  6286. - "compare_entry_to() and find_matching_entry() do not agree");
  6287. -
  6288. - // Found a matching entry somewhere else in *merge_cp_p so
  6289. - // just need a mapping entry.
  6290. - map_index(scratch_cp, scratch_i, found_i);
  6291. - continue;
  6292. - }
  6293. -
  6294. - // The find_matching_entry() call above could fail to find a match
  6295. - // due to a resolved versus unresolved class or string entry situation
  6296. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6297. - // However, we would have to call is_unresolved_*_mismatch() over
  6298. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6299. - // worth the time.
  6300. -
  6301. - // No match found so we have to append this entry and any unique
  6302. - // referenced entries to *merge_cp_p.
  6303. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6304. - CHECK_0);
  6305. + cur_klass = cur_klass->klass_part()->super();
  6306. }
  6307. }
  6308. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6309. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6310. - *merge_cp_length_p, scratch_i, _index_map_count));
  6311. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  6312. + // Check interfaces
  6313. - if (scratch_i < scratch_cp->length()) {
  6314. - // Pass 1b:
  6315. - // old_cp is smaller than scratch_cp so there are entries in
  6316. - // scratch_cp that we have not yet processed. We take care of
  6317. - // those now.
  6318. - int increment = 1;
  6319. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6320. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6321. - case JVM_CONSTANT_Double:
  6322. - case JVM_CONSTANT_Long:
  6323. - // double and long take two constant pool entries
  6324. - increment = 2;
  6325. - break;
  6326. -
  6327. - default:
  6328. - increment = 1;
  6329. - break;
  6330. + // Interfaces removed?
  6331. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  6332. + for (i = 0; i<old_interfaces->length(); i++) {
  6333. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  6334. + if (!new_class->implements_interface_any_version(old_interface())) {
  6335. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  6336. + RC_TRACE(0x00000002, ("Removed interface %s",
  6337. + old_interface->name()->as_C_string()));
  6338. +
  6339. + if (!old_interface->has_subtype_changed()) {
  6340. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  6341. + old_interface->name()->as_C_string()));
  6342. + old_interface->set_subtype_changed(true);
  6343. }
  6344. -
  6345. - int found_i =
  6346. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6347. - if (found_i != 0) {
  6348. - // Found a matching entry somewhere else in *merge_cp_p so
  6349. - // just need a mapping entry.
  6350. - map_index(scratch_cp, scratch_i, found_i);
  6351. - continue;
  6352. - }
  6353. -
  6354. - // No match found so we have to append this entry and any unique
  6355. - // referenced entries to *merge_cp_p.
  6356. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6357. - CHECK_0);
  6358. }
  6359. -
  6360. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6361. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6362. - *merge_cp_length_p, scratch_i, _index_map_count));
  6363. - }
  6364. - finalize_operands_merge(*merge_cp_p, THREAD);
  6365. -
  6366. - return true;
  6367. -} // end merge_constant_pools()
  6368. -
  6369. -
  6370. -// Merge constant pools between the_class and scratch_class and
  6371. -// potentially rewrite bytecodes in scratch_class to use the merged
  6372. -// constant pool.
  6373. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6374. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6375. - TRAPS) {
  6376. - // worst case merged constant pool length is old and new combined
  6377. - int merge_cp_length = the_class->constants()->length()
  6378. - + scratch_class->constants()->length();
  6379. -
  6380. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6381. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6382. -
  6383. - // Constant pools are not easily reused so we allocate a new one
  6384. - // each time.
  6385. - // merge_cp is created unsafe for concurrent GC processing. It
  6386. - // should be marked safe before discarding it. Even though
  6387. - // garbage, if it crosses a card boundary, it may be scanned
  6388. - // in order to find the start of the first complete object on the card.
  6389. - constantPoolHandle merge_cp(THREAD,
  6390. - oopFactory::new_constantPool(merge_cp_length,
  6391. - oopDesc::IsUnsafeConc,
  6392. - THREAD));
  6393. - int orig_length = old_cp->orig_length();
  6394. - if (orig_length == 0) {
  6395. - // This old_cp is an actual original constant pool. We save
  6396. - // the original length in the merged constant pool so that
  6397. - // merge_constant_pools() can be more efficient. If a constant
  6398. - // pool has a non-zero orig_length() value, then that constant
  6399. - // pool was created by a merge operation in RedefineClasses.
  6400. - merge_cp->set_orig_length(old_cp->length());
  6401. - } else {
  6402. - // This old_cp is a merged constant pool from a previous
  6403. - // RedefineClasses() calls so just copy the orig_length()
  6404. - // value.
  6405. - merge_cp->set_orig_length(old_cp->orig_length());
  6406. }
  6407. - ResourceMark rm(THREAD);
  6408. - _index_map_count = 0;
  6409. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6410. -
  6411. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6412. - _operands_index_map_count = 0;
  6413. - _operands_index_map_p = new intArray(
  6414. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6415. -
  6416. - // reference to the cp holder is needed for copy_operands()
  6417. - merge_cp->set_pool_holder(scratch_class());
  6418. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6419. - &merge_cp_length, THREAD);
  6420. - merge_cp->set_pool_holder(NULL);
  6421. -
  6422. - if (!result) {
  6423. - // The merge can fail due to memory allocation failure or due
  6424. - // to robustness checks.
  6425. - return JVMTI_ERROR_INTERNAL;
  6426. + // Interfaces added?
  6427. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  6428. + for (i = 0; i<new_interfaces->length(); i++) {
  6429. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  6430. + result = result | Klass::ModifyClass;
  6431. + RC_TRACE(0x00000002, ("Added interface %s",
  6432. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  6433. + }
  6434. }
  6435. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6436. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6437. - if (_index_map_count == 0) {
  6438. - // there is nothing to map between the new and merged constant pools
  6439. + // Check whether class modifiers are the same.
  6440. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  6441. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  6442. + if (old_flags != new_flags) {
  6443. + // TODO (tw): Can this have any effects?
  6444. + }
  6445. - if (old_cp->length() == scratch_cp->length()) {
  6446. - // The old and new constant pools are the same length and the
  6447. - // index map is empty. This means that the three constant pools
  6448. - // are equivalent (but not the same). Unfortunately, the new
  6449. - // constant pool has not gone through link resolution nor have
  6450. - // the new class bytecodes gone through constant pool cache
  6451. - // rewriting so we can't use the old constant pool with the new
  6452. - // class.
  6453. + // Check if the number, names, types and order of fields declared in these classes
  6454. + // are the same.
  6455. + JavaFieldStream old_fs(the_class);
  6456. + JavaFieldStream new_fs(new_class);
  6457. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  6458. + // access
  6459. + old_flags = old_fs.access_flags().as_short();
  6460. + new_flags = new_fs.access_flags().as_short();
  6461. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  6462. + // (tw) Can this have any effects?
  6463. + }
  6464. + // offset
  6465. + if (old_fs.offset() != new_fs.offset()) {
  6466. + result = result | Klass::ModifyInstances;
  6467. + }
  6468. + // name and signature
  6469. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  6470. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  6471. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  6472. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  6473. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  6474. + result = result | Klass::ModifyInstances;
  6475. + }
  6476. + }
  6477. - merge_cp()->set_is_conc_safe(true);
  6478. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6479. - } else if (old_cp->length() < scratch_cp->length()) {
  6480. - // The old constant pool has fewer entries than the new constant
  6481. - // pool and the index map is empty. This means the new constant
  6482. - // pool is a superset of the old constant pool. However, the old
  6483. - // class bytecodes have already gone through constant pool cache
  6484. - // rewriting so we can't use the new constant pool with the old
  6485. - // class.
  6486. + if (!old_fs.done() || !new_fs.done()) {
  6487. + result = result | Klass::ModifyInstances;
  6488. + }
  6489. - merge_cp()->set_is_conc_safe(true);
  6490. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6491. + // Do a parallel walk through the old and new methods. Detect
  6492. + // cases where they match (exist in both), have been added in
  6493. + // the new methods, or have been deleted (exist only in the
  6494. + // old methods). The class file parser places methods in order
  6495. + // by method name, but does not order overloaded methods by
  6496. + // signature. In order to determine what fate befell the methods,
  6497. + // this code places the overloaded new methods that have matching
  6498. + // old methods in the same order as the old methods and places
  6499. + // new overloaded methods at the end of overloaded methods of
  6500. + // that name. The code for this order normalization is adapted
  6501. + // from the algorithm used in instanceKlass::find_method().
  6502. + // Since we are swapping out of order entries as we find them,
  6503. + // we only have to search forward through the overloaded methods.
  6504. + // Methods which are added and have the same name as an existing
  6505. + // method (but different signature) will be put at the end of
  6506. + // the methods with that name, and the name mismatch code will
  6507. + // handle them.
  6508. + objArrayHandle k_old_methods(the_class->methods());
  6509. + objArrayHandle k_new_methods(new_class->methods());
  6510. + int n_old_methods = k_old_methods->length();
  6511. + int n_new_methods = k_new_methods->length();
  6512. +
  6513. + int ni = 0;
  6514. + int oi = 0;
  6515. + while (true) {
  6516. + methodOop k_old_method;
  6517. + methodOop k_new_method;
  6518. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6519. +
  6520. + if (oi >= n_old_methods) {
  6521. + if (ni >= n_new_methods) {
  6522. + break; // we've looked at everything, done
  6523. + }
  6524. + // New method at the end
  6525. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6526. + method_was = added;
  6527. + } else if (ni >= n_new_methods) {
  6528. + // Old method, at the end, is deleted
  6529. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6530. + method_was = deleted;
  6531. } else {
  6532. - // The old constant pool has more entries than the new constant
  6533. - // pool and the index map is empty. This means that both the old
  6534. - // and merged constant pools are supersets of the new constant
  6535. - // pool.
  6536. + // There are more methods in both the old and new lists
  6537. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6538. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6539. + if (k_old_method->name() != k_new_method->name()) {
  6540. + // Methods are sorted by method name, so a mismatch means added
  6541. + // or deleted
  6542. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6543. + method_was = added;
  6544. + } else {
  6545. + method_was = deleted;
  6546. + }
  6547. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6548. + // Both the name and signature match
  6549. + method_was = matched;
  6550. + } else {
  6551. + // The name matches, but the signature doesn't, which means we have to
  6552. + // search forward through the new overloaded methods.
  6553. + int nj; // outside the loop for post-loop check
  6554. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6555. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6556. + if (k_old_method->name() != m->name()) {
  6557. + // reached another method name so no more overloaded methods
  6558. + method_was = deleted;
  6559. + break;
  6560. + }
  6561. + if (k_old_method->signature() == m->signature()) {
  6562. + // found a match so swap the methods
  6563. + k_new_methods->obj_at_put(ni, m);
  6564. + k_new_methods->obj_at_put(nj, k_new_method);
  6565. + k_new_method = m;
  6566. + method_was = matched;
  6567. + break;
  6568. + }
  6569. + }
  6570. - // Replace the new constant pool with a shrunken copy of the
  6571. - // merged constant pool; the previous new constant pool will
  6572. - // get GCed.
  6573. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6574. - THREAD);
  6575. - // drop local ref to the merged constant pool
  6576. - merge_cp()->set_is_conc_safe(true);
  6577. - merge_cp = constantPoolHandle();
  6578. - }
  6579. - } else {
  6580. - if (RC_TRACE_ENABLED(0x00040000)) {
  6581. - // don't want to loop unless we are tracing
  6582. - int count = 0;
  6583. - for (int i = 1; i < _index_map_p->length(); i++) {
  6584. - int value = _index_map_p->at(i);
  6585. -
  6586. - if (value != -1) {
  6587. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6588. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6589. - count++;
  6590. + if (nj >= n_new_methods) {
  6591. + // reached the end without a match; so method was deleted
  6592. + method_was = deleted;
  6593. }
  6594. }
  6595. }
  6596. - // We have entries mapped between the new and merged constant pools
  6597. - // so we have to rewrite some constant pool references.
  6598. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6599. - return JVMTI_ERROR_INTERNAL;
  6600. + switch (method_was) {
  6601. + case matched:
  6602. + // methods match, be sure modifiers do too
  6603. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6604. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6605. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6606. + // (tw) Can this have any effects? Probably yes on vtables?
  6607. + result = result | Klass::ModifyClass;
  6608. }
  6609. -
  6610. - // Replace the new constant pool with a shrunken copy of the
  6611. - // merged constant pool so now the rewritten bytecodes have
  6612. - // valid references; the previous new constant pool will get
  6613. - // GCed.
  6614. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6615. - THREAD);
  6616. - merge_cp()->set_is_conc_safe(true);
  6617. - }
  6618. - assert(old_cp()->is_conc_safe(), "Just checking");
  6619. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6620. -
  6621. - return JVMTI_ERROR_NONE;
  6622. -} // end merge_cp_and_rewrite()
  6623. -
  6624. -
  6625. -// Rewrite constant pool references in klass scratch_class.
  6626. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6627. - TRAPS) {
  6628. -
  6629. - // rewrite constant pool references in the methods:
  6630. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6631. - // propagate failure back to caller
  6632. - return false;
  6633. - }
  6634. -
  6635. - // rewrite constant pool references in the class_annotations:
  6636. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6637. - // propagate failure back to caller
  6638. - return false;
  6639. - }
  6640. -
  6641. - // rewrite constant pool references in the fields_annotations:
  6642. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6643. - // propagate failure back to caller
  6644. - return false;
  6645. - }
  6646. -
  6647. - // rewrite constant pool references in the methods_annotations:
  6648. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6649. - // propagate failure back to caller
  6650. - return false;
  6651. - }
  6652. -
  6653. - // rewrite constant pool references in the methods_parameter_annotations:
  6654. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6655. - THREAD)) {
  6656. - // propagate failure back to caller
  6657. - return false;
  6658. - }
  6659. -
  6660. - // rewrite constant pool references in the methods_default_annotations:
  6661. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6662. - THREAD)) {
  6663. - // propagate failure back to caller
  6664. - return false;
  6665. - }
  6666. -
  6667. - return true;
  6668. -} // end rewrite_cp_refs()
  6669. -
  6670. -
  6671. -// Rewrite constant pool references in the methods.
  6672. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6673. - instanceKlassHandle scratch_class, TRAPS) {
  6674. -
  6675. - objArrayHandle methods(THREAD, scratch_class->methods());
  6676. -
  6677. - if (methods.is_null() || methods->length() == 0) {
  6678. - // no methods so nothing to do
  6679. - return true;
  6680. - }
  6681. -
  6682. - // rewrite constant pool references in the methods:
  6683. - for (int i = methods->length() - 1; i >= 0; i--) {
  6684. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  6685. - methodHandle new_method;
  6686. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  6687. - if (!new_method.is_null()) {
  6688. - // the method has been replaced so save the new method version
  6689. - methods->obj_at_put(i, new_method());
  6690. + {
  6691. + u2 new_num = k_new_method->method_idnum();
  6692. + u2 old_num = k_old_method->method_idnum();
  6693. + if (new_num != old_num) {
  6694. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6695. + if (idnum_owner != NULL) {
  6696. + // There is already a method assigned this idnum -- switch them
  6697. + idnum_owner->set_method_idnum(new_num);
  6698. + }
  6699. + k_new_method->set_method_idnum(old_num);
  6700. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6701. + new_num,
  6702. + old_num));
  6703. + // swap_all_method_annotations(old_num, new_num, new_class);
  6704. + }
  6705. + }
  6706. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6707. + k_new_method->name_and_sig_as_C_string(), ni,
  6708. + k_old_method->name_and_sig_as_C_string(), oi));
  6709. + // advance to next pair of methods
  6710. + ++oi;
  6711. + ++ni;
  6712. + break;
  6713. + case added:
  6714. + // method added, see if it is OK
  6715. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6716. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6717. + // hack: private should be treated as final, but alas
  6718. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6719. + ) {
  6720. + // new methods must be private
  6721. + result = result | Klass::ModifyClass;
  6722. + }
  6723. + {
  6724. + u2 num = the_class->next_method_idnum();
  6725. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6726. + // cannot add any more methods
  6727. + result = result | Klass::ModifyClass;
  6728. + }
  6729. + u2 new_num = k_new_method->method_idnum();
  6730. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6731. + if (idnum_owner != NULL) {
  6732. + // There is already a method assigned this idnum -- switch them
  6733. + idnum_owner->set_method_idnum(new_num);
  6734. + }
  6735. + k_new_method->set_method_idnum(num);
  6736. + //swap_all_method_annotations(new_num, num, new_class);
  6737. + }
  6738. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6739. + k_new_method->name_and_sig_as_C_string(), ni));
  6740. + ++ni; // advance to next new method
  6741. + break;
  6742. + case deleted:
  6743. + // method deleted, see if it is OK
  6744. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6745. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6746. + // hack: private should be treated as final, but alas
  6747. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6748. + ) {
  6749. + // deleted methods must be private
  6750. + result = result | Klass::ModifyClass;
  6751. + }
  6752. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6753. + k_old_method->name_and_sig_as_C_string(), oi));
  6754. + ++oi; // advance to next old method
  6755. + break;
  6756. + default:
  6757. + ShouldNotReachHere();
  6758. }
  6759. }
  6760. - return true;
  6761. + if (new_class()->size() != new_class->old_version()->size()) {
  6762. + result |= Klass::ModifyClassSize;
  6763. + }
  6764. +
  6765. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6766. + result |= Klass::ModifyInstanceSize;
  6767. + }
  6768. +
  6769. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6770. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6771. + result |= Klass::HasInstanceTransformer;
  6772. + }
  6773. +
  6774. + // (tw) Check method bodies to be able to return NoChange?
  6775. + return result;
  6776. }
  6777. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6778. -// Rewrite constant pool references in the specific method. This code
  6779. -// was adapted from Rewriter::rewrite_method().
  6780. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  6781. - methodHandle *new_method_p, TRAPS) {
  6782. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6783. - *new_method_p = methodHandle(); // default is no new method
  6784. + private:
  6785. - // We cache a pointer to the bytecodes here in code_base. If GC
  6786. - // moves the methodOop, then the bytecodes will also move which
  6787. - // will likely cause a crash. We create a No_Safepoint_Verifier
  6788. - // object to detect whether we pass a possible safepoint in this
  6789. - // code block.
  6790. - No_Safepoint_Verifier nsv;
  6791. + GrowableArray<int> info;
  6792. + int curPosition;
  6793. + bool copy_backwards;
  6794. - // Bytecodes and their length
  6795. - address code_base = method->code_base();
  6796. - int code_length = method->code_size();
  6797. + public:
  6798. - int bc_length;
  6799. - for (int bci = 0; bci < code_length; bci += bc_length) {
  6800. - address bcp = code_base + bci;
  6801. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  6802. -
  6803. - bc_length = Bytecodes::length_for(c);
  6804. - if (bc_length == 0) {
  6805. - // More complicated bytecodes report a length of zero so
  6806. - // we have to try again a slightly different way.
  6807. - bc_length = Bytecodes::length_at(method(), bcp);
  6808. + bool does_copy_backwards() {
  6809. + return copy_backwards;
  6810. }
  6811. - assert(bc_length != 0, "impossible bytecode length");
  6812. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6813. - switch (c) {
  6814. - case Bytecodes::_ldc:
  6815. - {
  6816. - int cp_index = *(bcp + 1);
  6817. - int new_index = find_new_index(cp_index);
  6818. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6819. - if (StressLdcRewrite && new_index == 0) {
  6820. - // If we are stressing ldc -> ldc_w rewriting, then we
  6821. - // always need a new_index value.
  6822. - new_index = cp_index;
  6823. - }
  6824. - if (new_index != 0) {
  6825. - // the original index is mapped so we have more work to do
  6826. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  6827. - // The new value can still use ldc instead of ldc_w
  6828. - // unless we are trying to stress ldc -> ldc_w rewriting
  6829. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6830. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6831. - bcp, cp_index, new_index));
  6832. - *(bcp + 1) = new_index;
  6833. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6834. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6835. + }
  6836. +
  6837. + info.append(base_offset);
  6838. + info.append(0);
  6839. + curPosition = base_offset;
  6840. + copy_backwards = false;
  6841. + }
  6842. +
  6843. + GrowableArray<int> &finish() {
  6844. + info.append(0);
  6845. + return info;
  6846. + }
  6847. +
  6848. + virtual void do_new_field(fieldDescriptor* fd){
  6849. + int alignment = fd->offset() - curPosition;
  6850. + if (alignment > 0) {
  6851. + // This field was aligned, so we need to make sure that we fill the gap
  6852. + fill(alignment);
  6853. + }
  6854. +
  6855. + int size = size_of_type(fd->field_type());
  6856. + fill(size);
  6857. + }
  6858. +
  6859. + private:
  6860. +
  6861. + void fill(int size) {
  6862. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6863. + (*info.adr_at(info.length() - 1)) -= size;
  6864. + } else {
  6865. + info.append(-size);
  6866. + }
  6867. +
  6868. + curPosition += size;
  6869. + }
  6870. +
  6871. + int size_of_type(BasicType type) {
  6872. + int size = 0;
  6873. + switch(type) {
  6874. + case T_BOOLEAN:
  6875. + size = sizeof(jboolean);
  6876. + break;
  6877. +
  6878. + case T_CHAR:
  6879. + size = (sizeof(jchar));
  6880. + break;
  6881. +
  6882. + case T_FLOAT:
  6883. + size = (sizeof(jfloat));
  6884. + break;
  6885. +
  6886. + case T_DOUBLE:
  6887. + size = (sizeof(jdouble));
  6888. + break;
  6889. +
  6890. + case T_BYTE:
  6891. + size = (sizeof(jbyte));
  6892. + break;
  6893. +
  6894. + case T_SHORT:
  6895. + size = (sizeof(jshort));
  6896. + break;
  6897. +
  6898. + case T_INT:
  6899. + size = (sizeof(jint));
  6900. + break;
  6901. +
  6902. + case T_LONG:
  6903. + size = (sizeof(jlong));
  6904. + break;
  6905. +
  6906. + case T_OBJECT:
  6907. + case T_ARRAY:
  6908. + if (UseCompressedOops) {
  6909. + size = sizeof(narrowOop);
  6910. } else {
  6911. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6912. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  6913. - Bytecodes::name(c), bcp, cp_index, new_index));
  6914. - // the new value needs ldc_w instead of ldc
  6915. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  6916. - bcp = (address)inst_buffer;
  6917. - // construct new instruction sequence
  6918. - *bcp = Bytecodes::_ldc_w;
  6919. - bcp++;
  6920. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  6921. - // See comment below for difference between put_Java_u2()
  6922. - // and put_native_u2().
  6923. - Bytes::put_Java_u2(bcp, new_index);
  6924. + size = (sizeof(oop));
  6925. + }
  6926. + break;
  6927. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  6928. - methodHandle m;
  6929. - {
  6930. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  6931. + default:
  6932. + ShouldNotReachHere();
  6933. + }
  6934. - // ldc is 2 bytes and ldc_w is 3 bytes
  6935. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  6936. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  6937. - guarantee(false, "insert_space_at() failed");
  6938. + assert(size > 0, "");
  6939. + return size;
  6940. +
  6941. + }
  6942. +
  6943. + public:
  6944. +
  6945. + virtual void do_old_field(fieldDescriptor* fd){}
  6946. +
  6947. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6948. +
  6949. + int alignment = new_fd->offset() - curPosition;
  6950. + if (alignment > 0) {
  6951. + // This field was aligned, so we need to make sure that we fill the gap
  6952. + fill(alignment);
  6953. + }
  6954. +
  6955. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6956. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6957. +
  6958. + int offset = old_fd->offset();
  6959. + int size = size_of_type(old_fd->field_type());
  6960. +
  6961. + int prevEnd = -1;
  6962. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6963. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6964. + }
  6965. +
  6966. + if (prevEnd == offset) {
  6967. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6968. + } else {
  6969. + info.append(size);
  6970. + info.append(offset);
  6971. + }
  6972. +
  6973. + if (old_fd->offset() < new_fd->offset()) {
  6974. + copy_backwards = true;
  6975. + }
  6976. +
  6977. + transfer_special_access_flags(old_fd, new_fd);
  6978. +
  6979. + curPosition += size;
  6980. + }
  6981. + };
  6982. +
  6983. + UpdateFieldsEvolutionClosure cl(new_version);
  6984. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6985. +
  6986. + GrowableArray<int> result = cl.finish();
  6987. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6988. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6989. +
  6990. + if (RC_TRACE_ENABLED(0x00000002)) {
  6991. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6992. + new_version->klass_part()->name()->as_C_string()));
  6993. + if (cl.does_copy_backwards()) {
  6994. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6995. + }
  6996. + for (int i=0; i<result.length(); i++) {
  6997. + int curNum = result.at(i);
  6998. + if (curNum < 0) {
  6999. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  7000. + } else if (curNum > 0) {
  7001. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  7002. + i++;
  7003. + } else {
  7004. + RC_TRACE(0x00000002, ("\tEND"));
  7005. + }
  7006. + }
  7007. + }
  7008. +}
  7009. +
  7010. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  7011. + assert(FieldType::is_obj(signature), "");
  7012. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  7013. +}
  7014. +
  7015. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  7016. + if (klass->klass_part()->is_redefining()) {
  7017. + klass = klass->klass_part()->old_version();
  7018. + }
  7019. +
  7020. + // We found an instance klass!
  7021. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  7022. + GrowableArray< Pair<int, klassOop> > type_check_information;
  7023. +
  7024. + class MyFieldClosure : public FieldClosure {
  7025. +
  7026. + public:
  7027. +
  7028. + GrowableArray< Pair<int, klassOop> > *_arr;
  7029. +
  7030. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  7031. + _arr = arr;
  7032. + }
  7033. +
  7034. + virtual void do_field(fieldDescriptor* fd) {
  7035. + if (fd->field_type() == T_OBJECT) {
  7036. + Symbol* signature = fd->signature();
  7037. + if (FieldType::is_obj(signature)) {
  7038. + Symbol* name = signature_to_class_name(signature);
  7039. + klassOop field_klass;
  7040. + if (is_field_dangerous(name, fd, field_klass)) {
  7041. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  7042. + fd->name()->as_C_string(),
  7043. + fd->field_holder()->klass_part()->name()->as_C_string(),
  7044. + name->as_C_string()));
  7045. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  7046. + }
  7047. + }
  7048. +
  7049. + // Array fields can never be a problem!
  7050. + }
  7051. + }
  7052. +
  7053. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  7054. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  7055. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  7056. + if(field_klass != NULL) {
  7057. + if (field_klass->klass_part()->is_redefining()) {
  7058. + field_klass = field_klass->klass_part()->old_version();
  7059. + }
  7060. + if (field_klass->klass_part()->has_subtype_changed()) {
  7061. + return true;
  7062. + }
  7063. + }
  7064. + return false;
  7065. + }
  7066. + };
  7067. +
  7068. + MyFieldClosure fieldClosure(&type_check_information);
  7069. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  7070. +
  7071. + if (type_check_information.length() > 0) {
  7072. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  7073. + cur_instance_klass->store_type_check_information(type_check_information);
  7074. + }
  7075. +}
  7076. +
  7077. +bool VM_RedefineClasses::check_field_value_types() {
  7078. +
  7079. + Thread *THREAD = Thread::current();
  7080. + class CheckFieldTypesClosure : public ObjectClosure {
  7081. +
  7082. + private:
  7083. +
  7084. + bool _result;
  7085. +
  7086. + public:
  7087. +
  7088. + CheckFieldTypesClosure() {
  7089. + _result = true;
  7090. + }
  7091. +
  7092. + bool result() { return _result; }
  7093. +
  7094. + virtual void do_object(oop obj) {
  7095. +
  7096. + if (!_result) {
  7097. + return;
  7098. + }
  7099. +
  7100. + if (obj->is_objArray()) {
  7101. +
  7102. + objArrayOop array = objArrayOop(obj);
  7103. +
  7104. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  7105. +
  7106. + if (element_klass->klass_part()->has_subtype_changed()) {
  7107. + int length = array->length();
  7108. + for (int i=0; i<length; i++) {
  7109. + oop element = array->obj_at(i);
  7110. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  7111. + // Check subtype relationship to static type of array
  7112. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  7113. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  7114. + element_klass->klass_part()->name()->as_C_string(),
  7115. + i,
  7116. + element->blueprint()->name()->as_C_string()));
  7117. + _result = false;
  7118. + break;
  7119. }
  7120. }
  7121. -
  7122. - // return the new method so that the caller can update
  7123. - // the containing class
  7124. - *new_method_p = method = m;
  7125. - // switch our bytecode processing loop from the old method
  7126. - // to the new method
  7127. - code_base = method->code_base();
  7128. - code_length = method->code_size();
  7129. - bcp = code_base + bci;
  7130. - c = (Bytecodes::Code)(*bcp);
  7131. - bc_length = Bytecodes::length_for(c);
  7132. - assert(bc_length != 0, "sanity check");
  7133. - } // end we need ldc_w instead of ldc
  7134. - } // end if there is a mapped index
  7135. - } break;
  7136. -
  7137. - // these bytecodes have a two-byte constant pool index
  7138. - case Bytecodes::_anewarray : // fall through
  7139. - case Bytecodes::_checkcast : // fall through
  7140. - case Bytecodes::_getfield : // fall through
  7141. - case Bytecodes::_getstatic : // fall through
  7142. - case Bytecodes::_instanceof : // fall through
  7143. - case Bytecodes::_invokedynamic : // fall through
  7144. - case Bytecodes::_invokeinterface: // fall through
  7145. - case Bytecodes::_invokespecial : // fall through
  7146. - case Bytecodes::_invokestatic : // fall through
  7147. - case Bytecodes::_invokevirtual : // fall through
  7148. - case Bytecodes::_ldc_w : // fall through
  7149. - case Bytecodes::_ldc2_w : // fall through
  7150. - case Bytecodes::_multianewarray : // fall through
  7151. - case Bytecodes::_new : // fall through
  7152. - case Bytecodes::_putfield : // fall through
  7153. - case Bytecodes::_putstatic :
  7154. - {
  7155. - address p = bcp + 1;
  7156. - int cp_index = Bytes::get_Java_u2(p);
  7157. - int new_index = find_new_index(cp_index);
  7158. - if (new_index != 0) {
  7159. - // the original index is mapped so update w/ new value
  7160. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7161. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7162. - bcp, cp_index, new_index));
  7163. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7164. - // situation because it is reusing the constant pool index
  7165. - // location for a native index into the constantPoolCache.
  7166. - // Since we are updating the constant pool index prior to
  7167. - // verification and constantPoolCache initialization, we
  7168. - // need to keep the new index in Java byte order.
  7169. - Bytes::put_Java_u2(p, new_index);
  7170. + }
  7171. }
  7172. - } break;
  7173. +
  7174. + } else {
  7175. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  7176. + if (cur != NULL) {
  7177. + // Type check information exists for this oop
  7178. + while ((*cur).left() != -1) {
  7179. + check_field(obj, (*cur).left(), (*cur).right());
  7180. + cur++;
  7181. + }
  7182. + }
  7183. + }
  7184. }
  7185. - } // end for each bytecode
  7186. -} // end rewrite_cp_refs_in_method()
  7187. + void check_field(oop obj, int offset, klassOop static_type) {
  7188. + oop field_value = obj->obj_field(offset);
  7189. + if (field_value != NULL) {
  7190. + // Field is not null
  7191. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  7192. + // We are OK
  7193. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7194. + obj->klass()->klass_part()->name()->as_C_string(),
  7195. + static_type->klass_part()->name()->as_C_string(),
  7196. + offset,
  7197. + field_value->klass()->klass_part()->name()->as_C_string()));
  7198. + } else {
  7199. + // Failure!
  7200. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7201. + obj->klass()->klass_part()->name()->as_C_string(),
  7202. + static_type->klass_part()->name()->as_C_string(),
  7203. + offset,
  7204. + field_value->klass()->klass_part()->name()->as_C_string()));
  7205. + _result = false;
  7206. + }
  7207. + }
  7208. + }
  7209. + };
  7210. -// Rewrite constant pool references in the class_annotations field.
  7211. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7212. - instanceKlassHandle scratch_class, TRAPS) {
  7213. + CheckFieldTypesClosure myObjectClosure;
  7214. - typeArrayHandle class_annotations(THREAD,
  7215. - scratch_class->class_annotations());
  7216. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7217. - // no class_annotations so nothing to do
  7218. - return true;
  7219. + // make sure that heap is parsable (fills TLABs with filler objects)
  7220. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  7221. +
  7222. + // do the iteration
  7223. + // If this operation encounters a bad object when using CMS,
  7224. + // consider using safe_object_iterate() which avoids perm gen
  7225. + // objects that may contain bad references.
  7226. + Universe::heap()->object_iterate(&myObjectClosure);
  7227. +
  7228. + // when sharing is enabled we must iterate over the shared spaces
  7229. + if (UseSharedSpaces) {
  7230. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  7231. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  7232. + gen->ro_space()->object_iterate(&myObjectClosure);
  7233. + gen->rw_space()->object_iterate(&myObjectClosure);
  7234. }
  7235. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7236. - ("class_annotations length=%d", class_annotations->length()));
  7237. -
  7238. - int byte_i = 0; // byte index into class_annotations
  7239. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7240. - THREAD);
  7241. + return myObjectClosure.result();
  7242. }
  7243. -
  7244. -// Rewrite constant pool references in an annotations typeArray. This
  7245. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7246. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7247. -//
  7248. -// annotations_typeArray {
  7249. -// u2 num_annotations;
  7250. -// annotation annotations[num_annotations];
  7251. -// }
  7252. -//
  7253. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7254. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7255. -
  7256. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7257. - // not enough room for num_annotations field
  7258. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7259. - ("length() is too small for num_annotations field"));
  7260. - return false;
  7261. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  7262. + if (k->klass_part()->is_redefining()) {
  7263. + k = k->klass_part()->old_version();
  7264. }
  7265. - u2 num_annotations = Bytes::get_Java_u2((address)
  7266. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7267. - byte_i_ref += 2;
  7268. -
  7269. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7270. - ("num_annotations=%d", num_annotations));
  7271. -
  7272. - int calc_num_annotations = 0;
  7273. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7274. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7275. - byte_i_ref, THREAD)) {
  7276. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7277. - ("bad annotation_struct at %d", calc_num_annotations));
  7278. - // propagate failure back to caller
  7279. - return false;
  7280. - }
  7281. - }
  7282. - assert(num_annotations == calc_num_annotations, "sanity check");
  7283. -
  7284. - return true;
  7285. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7286. -
  7287. -
  7288. -// Rewrite constant pool references in the annotation struct portion of
  7289. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7290. -// the 2nd-edition of the VM spec:
  7291. -//
  7292. -// struct annotation {
  7293. -// u2 type_index;
  7294. -// u2 num_element_value_pairs;
  7295. -// {
  7296. -// u2 element_name_index;
  7297. -// element_value value;
  7298. -// } element_value_pairs[num_element_value_pairs];
  7299. -// }
  7300. -//
  7301. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7302. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7303. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7304. - // not enough room for smallest annotation_struct
  7305. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7306. - ("length() is too small for annotation_struct"));
  7307. - return false;
  7308. - }
  7309. -
  7310. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7311. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7312. -
  7313. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7314. - annotations_typeArray->byte_at_addr(
  7315. - byte_i_ref));
  7316. - byte_i_ref += 2;
  7317. -
  7318. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7319. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7320. - num_element_value_pairs));
  7321. -
  7322. - int calc_num_element_value_pairs = 0;
  7323. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7324. - calc_num_element_value_pairs++) {
  7325. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7326. - // not enough room for another element_name_index, let alone
  7327. - // the rest of another component
  7328. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7329. - ("length() is too small for element_name_index"));
  7330. - return false;
  7331. - }
  7332. -
  7333. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7334. - annotations_typeArray, byte_i_ref,
  7335. - "mapped old element_name_index=%d", THREAD);
  7336. -
  7337. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7338. - ("element_name_index=%d", element_name_index));
  7339. -
  7340. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7341. - byte_i_ref, THREAD)) {
  7342. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7343. - ("bad element_value at %d", calc_num_element_value_pairs));
  7344. - // propagate failure back to caller
  7345. - return false;
  7346. - }
  7347. - } // end for each component
  7348. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7349. - "sanity check");
  7350. -
  7351. - return true;
  7352. -} // end rewrite_cp_refs_in_annotation_struct()
  7353. -
  7354. -
  7355. -// Rewrite a constant pool reference at the current position in
  7356. -// annotations_typeArray if needed. Returns the original constant
  7357. -// pool reference if a rewrite was not needed or the new constant
  7358. -// pool reference if a rewrite was needed.
  7359. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7360. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7361. - const char * trace_mesg, TRAPS) {
  7362. -
  7363. - address cp_index_addr = (address)
  7364. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7365. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7366. - u2 new_cp_index = find_new_index(old_cp_index);
  7367. - if (new_cp_index != 0) {
  7368. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7369. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7370. - old_cp_index = new_cp_index;
  7371. - }
  7372. - byte_i_ref += 2;
  7373. - return old_cp_index;
  7374. + // We found an instance klass!
  7375. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  7376. + cur_instance_klass->clear_type_check_information();
  7377. }
  7378. +void VM_RedefineClasses::update_active_methods() {
  7379. -// Rewrite constant pool references in the element_value portion of an
  7380. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7381. -// the 2nd-edition of the VM spec:
  7382. -//
  7383. -// struct element_value {
  7384. -// u1 tag;
  7385. -// union {
  7386. -// u2 const_value_index;
  7387. -// {
  7388. -// u2 type_name_index;
  7389. -// u2 const_name_index;
  7390. -// } enum_const_value;
  7391. -// u2 class_info_index;
  7392. -// annotation annotation_value;
  7393. -// struct {
  7394. -// u2 num_values;
  7395. -// element_value values[num_values];
  7396. -// } array_value;
  7397. -// } value;
  7398. -// }
  7399. -//
  7400. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7401. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7402. + RC_TRACE(0x00000002, ("Updating active methods"));
  7403. + JavaThread *java_thread = Threads::first();
  7404. + while (java_thread != NULL) {
  7405. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7406. - // not enough room for a tag let alone the rest of an element_value
  7407. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7408. - ("length() is too small for a tag"));
  7409. + int stack_depth = 0;
  7410. + if (java_thread->has_last_Java_frame()) {
  7411. +
  7412. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  7413. +
  7414. + // vframes are resource allocated
  7415. + Thread* current_thread = Thread::current();
  7416. + ResourceMark rm(current_thread);
  7417. + HandleMark hm(current_thread);
  7418. +
  7419. + RegisterMap reg_map(java_thread);
  7420. + frame f = java_thread->last_frame();
  7421. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7422. + frame* last_entry_frame = NULL;
  7423. +
  7424. + while (vf != NULL) {
  7425. + if (vf->is_java_frame()) {
  7426. + // java frame (interpreted, compiled, ...)
  7427. + javaVFrame *jvf = javaVFrame::cast(vf);
  7428. +
  7429. + if (!(jvf->method()->is_native())) {
  7430. + int bci = jvf->bci();
  7431. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  7432. + ResourceMark rm(Thread::current());
  7433. + HandleMark hm;
  7434. + instanceKlassHandle klass(jvf->method()->method_holder());
  7435. +
  7436. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  7437. +
  7438. +
  7439. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  7440. + jvf->method()->name_and_sig_as_C_string()));
  7441. +
  7442. + if (RC_TRACE_ENABLED(0x01000000)) {
  7443. + int code_size = jvf->method()->code_size();
  7444. + char *code_base_old = (char*)jvf->method()->code_base();
  7445. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  7446. + for (int i=0; i<code_size; i++) {
  7447. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  7448. + }
  7449. + jvf->method()->print_codes_on(tty);
  7450. + jvf->method()->new_version()->print_codes_on(tty);
  7451. + }
  7452. +
  7453. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  7454. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  7455. +
  7456. +
  7457. + if (RC_TRACE_ENABLED(0x01000000)) {
  7458. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  7459. + tty->print_cr("old cp");
  7460. + for (int i=0; i<cp_old->length(); i++) {
  7461. + cp_old->entry_at(i)->print(tty, i);
  7462. + }
  7463. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  7464. + tty->print_cr("new cp");
  7465. + for (int i=0; i<cp_new->length(); i++) {
  7466. + cp_new->entry_at(i)->print(tty, i);
  7467. + }
  7468. + }
  7469. +
  7470. + iframe->set_method(jvf->method()->new_version(), bci);
  7471. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  7472. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  7473. +
  7474. + }
  7475. + }
  7476. + }
  7477. + vf = vf->sender();
  7478. + }
  7479. + }
  7480. +
  7481. + // Advance to next thread
  7482. + java_thread = java_thread->next();
  7483. + }
  7484. +}
  7485. +
  7486. +void VM_RedefineClasses::method_forwarding() {
  7487. +
  7488. + int forwarding_count = 0;
  7489. + JavaThread *java_thread = Threads::first();
  7490. + while (java_thread != NULL) {
  7491. +
  7492. + int stack_depth = 0;
  7493. + if (java_thread->has_last_Java_frame()) {
  7494. +
  7495. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7496. +
  7497. + // vframes are resource allocated
  7498. + Thread* current_thread = Thread::current();
  7499. + ResourceMark rm(current_thread);
  7500. + HandleMark hm(current_thread);
  7501. +
  7502. + RegisterMap reg_map(java_thread);
  7503. + frame f = java_thread->last_frame();
  7504. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7505. + frame* last_entry_frame = NULL;
  7506. +
  7507. + while (vf != NULL) {
  7508. + if (vf->is_java_frame()) {
  7509. + // java frame (interpreted, compiled, ...)
  7510. + javaVFrame *jvf = javaVFrame::cast(vf);
  7511. +
  7512. + if (!(jvf->method()->is_native())) {
  7513. + RC_TRACE(0x00008000, ("found method: %s",
  7514. + jvf->method()->name()->as_C_string()));
  7515. + ResourceMark rm(Thread::current());
  7516. + HandleMark hm;
  7517. + instanceKlassHandle klass(jvf->method()->method_holder());
  7518. + methodOop m = jvf->method();
  7519. + int bci = jvf->bci();
  7520. + RC_TRACE(0x00008000, ("klass redef %d",
  7521. + klass->is_redefining()));
  7522. +
  7523. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7524. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7525. + m->name()->as_C_string()));
  7526. +
  7527. + klassOop new_klass = klass->newest_version();
  7528. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7529. + RC_TRACE(0x00000002, ("%d %d",
  7530. + new_method,
  7531. + new_method->constMethod()->has_code_section_table()));
  7532. +
  7533. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7534. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7535. + new_method->name()->as_C_string()));
  7536. + m->set_forward_method(new_method);
  7537. + if (new_method->max_locals() != m->max_locals()) {
  7538. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7539. + }
  7540. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7541. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7542. + if (jvf->is_interpreted_frame()) {
  7543. + if (m->is_in_code_section(bci)) {
  7544. + // We must transfer now and cannot delay until next NOP.
  7545. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7546. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7547. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7548. + new_method->name()->as_C_string(),
  7549. + bci,
  7550. + new_bci));
  7551. + iframe->set_method(new_method, new_bci);
  7552. + } else {
  7553. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7554. + new_method->name()->as_C_string(),
  7555. + bci));
  7556. + }
  7557. + } else {
  7558. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7559. + new_method->name()->as_C_string()));
  7560. + }
  7561. + }
  7562. + }
  7563. + }
  7564. + }
  7565. + vf = vf->sender();
  7566. + }
  7567. + }
  7568. +
  7569. + // Advance to next thread
  7570. + java_thread = java_thread->next();
  7571. + }
  7572. +
  7573. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7574. + forwarding_count));
  7575. +}
  7576. +
  7577. +bool VM_RedefineClasses::check_method_stacks() {
  7578. +
  7579. + JavaThread *java_thread = Threads::first();
  7580. + while (java_thread != NULL) {
  7581. +
  7582. + int stack_depth = 0;
  7583. + if (java_thread->has_last_Java_frame()) {
  7584. +
  7585. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7586. +
  7587. + // vframes are resource allocated
  7588. + Thread* current_thread = Thread::current();
  7589. + ResourceMark rm(current_thread);
  7590. + HandleMark hm(current_thread);
  7591. +
  7592. + RegisterMap reg_map(java_thread);
  7593. + frame f = java_thread->last_frame();
  7594. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7595. + frame* last_entry_frame = NULL;
  7596. +
  7597. + while (vf != NULL) {
  7598. + if (vf->is_java_frame()) {
  7599. + // java frame (interpreted, compiled, ...)
  7600. + javaVFrame *jvf = javaVFrame::cast(vf);
  7601. +
  7602. + if (!(jvf->method()->is_native())) {
  7603. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7604. + ResourceMark rm(Thread::current());
  7605. + HandleMark hm;
  7606. + instanceKlassHandle klass(jvf->method()->method_holder());
  7607. +
  7608. + StackValueCollection *locals = jvf->locals();
  7609. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7610. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7611. +
  7612. + for (int i=0; i<locals->size(); i++) {
  7613. + StackValue *stack_value = locals->at(i);
  7614. + if (stack_value->type() == T_OBJECT) {
  7615. + Handle obj = stack_value->get_obj();
  7616. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7617. +
  7618. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7619. + bool result = false;
  7620. + methodOop method = jvf->method();
  7621. + if (method->has_localvariable_table()) {
  7622. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7623. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7624. +
  7625. + if (elem->slot == i) {
  7626. +
  7627. + // Matching index found
  7628. +
  7629. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7630. +
  7631. + // Also in range!!
  7632. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7633. + Symbol* klass_name = signature_to_class_name(signature);
  7634. +
  7635. + klassOop local_klass = SystemDictionary::find(klass_name, jvf->method()->method_holder()->klass_part()->class_loader(), jvf->method()->method_holder()->klass_part()->protection_domain(), Thread::current())->klass_part()->newest_version();
  7636. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7637. +
  7638. + // Field is not null
  7639. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7640. + // We are OK
  7641. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7642. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7643. + result = true;
  7644. + } else {
  7645. + // Failure!
  7646. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7647. + local_klass->klass_part()->name()->as_C_string(),
  7648. + cur->klass_part()->name()->as_C_string()));
  7649. + return false;
  7650. + }
  7651. + }
  7652. + }
  7653. +
  7654. + elem++;
  7655. + }
  7656. + } else {
  7657. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7658. + method->name_and_sig_as_C_string()));
  7659. + }
  7660. +
  7661. + if (!result) {
  7662. + return false;
  7663. + }
  7664. +
  7665. + RC_TRACE(0x00008000, ("Verifying class %s",
  7666. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7667. +
  7668. + Symbol* exception_name;
  7669. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7670. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7671. +
  7672. + Thread::current()->set_pretend_new_universe(true);
  7673. + ClassVerifier split_verifier(klass, Thread::current());
  7674. + split_verifier.verify_method(jvf->method(), Thread::current());
  7675. + exception_name = split_verifier.result();
  7676. + Thread::current()->set_pretend_new_universe(false);
  7677. +
  7678. + if (exception_name != NULL) {
  7679. +
  7680. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7681. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7682. + RC_TRACE(0x00000001, ("Exception: %s",
  7683. + exception_name->as_C_string()));
  7684. + RC_TRACE(0x00000001, ("Message: %s",
  7685. + message_buffer));
  7686. + Thread::current()->clear_pending_exception();
  7687. + return false;
  7688. + }
  7689. +
  7690. + }
  7691. + }
  7692. + }
  7693. + }
  7694. + }
  7695. + vf = vf->sender();
  7696. + }
  7697. + }
  7698. +
  7699. + // Advance to next thread
  7700. + java_thread = java_thread->next();
  7701. + }
  7702. +
  7703. + return true;
  7704. +}
  7705. +
  7706. +bool VM_RedefineClasses::check_method(methodOop method) {
  7707. +
  7708. +
  7709. + return true;
  7710. +}
  7711. +
  7712. +// Warning: destroys redefinition level values of klasses.
  7713. +bool VM_RedefineClasses::check_loaded_methods() {
  7714. +
  7715. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7716. +
  7717. + private:
  7718. +
  7719. + bool _result;
  7720. + GrowableArray<klassOop> *_dangerous_klasses;
  7721. +
  7722. + public:
  7723. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7724. + _result = true;
  7725. + _dangerous_klasses = dangerous_klasses;
  7726. + }
  7727. +
  7728. + bool result() {
  7729. + return _result;
  7730. + }
  7731. +
  7732. + bool is_class_dangerous(klassOop k) {
  7733. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7734. + }
  7735. +
  7736. + bool can_be_affected(instanceKlass *klass) {
  7737. +
  7738. + constantPoolOop cp = klass->constants();
  7739. +
  7740. + Thread *THREAD = Thread::current();
  7741. + klassOop k;
  7742. + Symbol* symbol;
  7743. +
  7744. + for (int i=1; i<cp->length(); i++) {
  7745. + jbyte tag = cp->tag_at(i).value();
  7746. + switch(tag) {
  7747. + case JVM_CONSTANT_Long:
  7748. + case JVM_CONSTANT_Double:
  7749. + i++;
  7750. + break;
  7751. +
  7752. + case JVM_CONSTANT_Utf8:
  7753. + case JVM_CONSTANT_Unicode:
  7754. + case JVM_CONSTANT_Integer:
  7755. + case JVM_CONSTANT_Float:
  7756. + case JVM_CONSTANT_String:
  7757. + case JVM_CONSTANT_Fieldref:
  7758. + case JVM_CONSTANT_Methodref:
  7759. + case JVM_CONSTANT_InterfaceMethodref:
  7760. + case JVM_CONSTANT_ClassIndex:
  7761. + case JVM_CONSTANT_UnresolvedString:
  7762. + case JVM_CONSTANT_StringIndex:
  7763. + case JVM_CONSTANT_UnresolvedClassInError:
  7764. + case JVM_CONSTANT_Object:
  7765. + // do nothing
  7766. + break;
  7767. +
  7768. + case JVM_CONSTANT_Class:
  7769. + k = cp->klass_at(i, CHECK_(true));
  7770. + if (is_class_dangerous(k)) {
  7771. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7772. + klass->name()->as_C_string(),
  7773. + i,
  7774. + k->klass_part()->name()->as_C_string()));
  7775. + return true;
  7776. + }
  7777. + break;
  7778. +
  7779. + case JVM_CONSTANT_NameAndType:
  7780. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7781. + if (symbol->byte_at(0) == '(') {
  7782. + // This must be a method
  7783. + SignatureStream signatureStream(symbol);
  7784. + while (true) {
  7785. +
  7786. + if (signatureStream.is_array()) {
  7787. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7788. + if (is_type_signature_dangerous(cur_signature)) {
  7789. + return true;
  7790. + }
  7791. + } else if (signatureStream.is_object()) {
  7792. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7793. + return true;
  7794. + }
  7795. + }
  7796. +
  7797. + if (signatureStream.at_return_type()) {
  7798. + break;
  7799. + }
  7800. +
  7801. + signatureStream.next();
  7802. + }
  7803. +
  7804. + } else if (is_type_signature_dangerous(symbol)) {
  7805. + return true;
  7806. + }
  7807. + break;
  7808. +
  7809. + case JVM_CONSTANT_UnresolvedClass:
  7810. + symbol = cp->unresolved_klass_at(i);
  7811. + if (is_symbol_dangerous(symbol)) {
  7812. + return true;
  7813. + }
  7814. + break;
  7815. +
  7816. + default:
  7817. + ShouldNotReachHere();
  7818. + }
  7819. + }
  7820. +
  7821. + return false;
  7822. + }
  7823. +
  7824. + bool is_type_signature_dangerous(Symbol* signature) {
  7825. + // This must be a field type
  7826. + if (FieldType::is_obj(signature)) {
  7827. + Symbol* name = signature_to_class_name(signature);
  7828. + if (is_symbol_dangerous(name)) {
  7829. + return true;
  7830. + }
  7831. + } else if (FieldType::is_array(signature)) {
  7832. + //jint dimension;
  7833. + //Symbol* object_key;
  7834. + FieldArrayInfo fd;
  7835. + FieldType::get_array_info(signature, fd, Thread::current());
  7836. + if (is_symbol_dangerous(fd.object_key())) {
  7837. + return true;
  7838. + }
  7839. + }
  7840. + return false;
  7841. + }
  7842. +
  7843. + bool is_symbol_dangerous(Symbol* symbol) {
  7844. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7845. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7846. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7847. + i,
  7848. + symbol->as_C_string()));
  7849. + return true;
  7850. + }
  7851. + }
  7852. + return false;
  7853. + }
  7854. +
  7855. + virtual void do_object(oop obj) {
  7856. +
  7857. + if (!_result) return;
  7858. +
  7859. + klassOop klassObj = (klassOop)obj;
  7860. + Thread *THREAD = Thread::current();
  7861. +
  7862. + // We found an instance klass!
  7863. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7864. + instanceKlassHandle handle(klassObj);
  7865. +
  7866. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7867. +
  7868. + if (!can_be_affected(klass)) {
  7869. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7870. + return;
  7871. + }
  7872. +
  7873. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7874. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7875. + _result = false;
  7876. + return;
  7877. + }
  7878. +
  7879. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7880. +
  7881. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7882. +
  7883. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7884. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7885. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7886. + //PENDING_EXCEPTION->print();
  7887. + CLEAR_PENDING_EXCEPTION;
  7888. + _result = false;
  7889. + }
  7890. +
  7891. + /*int method_count = klass->methods()->length();
  7892. + for (int i=0; i<method_count; i++) {
  7893. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7894. + if (!check_method(cur_method)) {
  7895. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7896. + }
  7897. + }*/
  7898. + }
  7899. + };
  7900. +
  7901. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7902. +
  7903. + GrowableArray<klassOop> dangerous_klasses;
  7904. + for (int i=0; i<_new_classes->length(); i++) {
  7905. + instanceKlassHandle handle = _new_classes->at(i);
  7906. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7907. + dangerous_klasses.append(handle());
  7908. + }
  7909. + }
  7910. +
  7911. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7912. + Thread::current()->set_pretend_new_universe(true);
  7913. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7914. + Thread::current()->set_pretend_new_universe(false);
  7915. +
  7916. +
  7917. + return checkLoadedMethodsClosure.result();
  7918. +}
  7919. +
  7920. +bool VM_RedefineClasses::check_type_consistency() {
  7921. +
  7922. + Universe::set_verify_in_progress(true);
  7923. +
  7924. + SystemDictionary::classes_do(calculate_type_check_information);
  7925. + bool result = check_field_value_types();
  7926. + SystemDictionary::classes_do(clear_type_check_information);
  7927. + if (!result) {
  7928. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7929. + Universe::set_verify_in_progress(false);
  7930. return false;
  7931. }
  7932. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7933. - byte_i_ref++;
  7934. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7935. + result = check_method_stacks();
  7936. + if (!result) {
  7937. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7938. + Universe::set_verify_in_progress(false);
  7939. + return false;
  7940. + }
  7941. - switch (tag) {
  7942. - // These BaseType tag values are from Table 4.2 in VM spec:
  7943. - case 'B': // byte
  7944. - case 'C': // char
  7945. - case 'D': // double
  7946. - case 'F': // float
  7947. - case 'I': // int
  7948. - case 'J': // long
  7949. - case 'S': // short
  7950. - case 'Z': // boolean
  7951. + result = check_loaded_methods();
  7952. + if (!result) {
  7953. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7954. + Universe::set_verify_in_progress(false);
  7955. + return false;
  7956. + }
  7957. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7958. - // the VM spec:
  7959. - case 's':
  7960. - {
  7961. - // For the above tag values (including the BaseType values),
  7962. - // value.const_value_index is right union field.
  7963. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7964. + Universe::set_verify_in_progress(false);
  7965. + return true;
  7966. +}
  7967. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7968. - // not enough room for a const_value_index
  7969. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7970. - ("length() is too small for a const_value_index"));
  7971. - return false;
  7972. +void VM_RedefineClasses::rollback() {
  7973. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7974. + SystemDictionary::rollback_redefinition();
  7975. +
  7976. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7977. + for (int i=0; i<_new_classes->length(); i++) {
  7978. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7979. + }
  7980. +
  7981. + for (int i=0; i<_new_classes->length(); i++) {
  7982. + instanceKlassHandle new_class = _new_classes->at(i);
  7983. + new_class->set_redefining(false);
  7984. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7985. + new_class->set_old_version(NULL);
  7986. + }
  7987. +
  7988. +}
  7989. +
  7990. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7991. + T heap_oop = oopDesc::load_heap_oop(p);
  7992. + if (!oopDesc::is_null(heap_oop)) {
  7993. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7994. + if (obj->is_instanceKlass()) {
  7995. + klassOop klass = (klassOop)obj;
  7996. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7997. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7998. + obj = klass->klass_part()->new_version();
  7999. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  8000. }
  8001. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  8002. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  8003. + // java.lang.Class instances.
  8004. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  8005. + if (klass_oop != NULL) {
  8006. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  8007. + obj = klass_oop->new_version()->java_mirror();
  8008. + } else if (klass_oop->klass_part()->is_redefining()) {
  8009. + obj = klass_oop->java_mirror();
  8010. + }
  8011. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  8012. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8013. - annotations_typeArray, byte_i_ref,
  8014. - "mapped old const_value_index=%d", THREAD);
  8015. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8016. - ("const_value_index=%d", const_value_index));
  8017. - } break;
  8018. -
  8019. - case 'e':
  8020. - {
  8021. - // for the above tag value, value.enum_const_value is right union field
  8022. -
  8023. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8024. - // not enough room for a enum_const_value
  8025. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8026. - ("length() is too small for a enum_const_value"));
  8027. - return false;
  8028. - }
  8029. -
  8030. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8031. - annotations_typeArray, byte_i_ref,
  8032. - "mapped old type_name_index=%d", THREAD);
  8033. -
  8034. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8035. - annotations_typeArray, byte_i_ref,
  8036. - "mapped old const_name_index=%d", THREAD);
  8037. -
  8038. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8039. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8040. - const_name_index));
  8041. - } break;
  8042. -
  8043. - case 'c':
  8044. - {
  8045. - // for the above tag value, value.class_info_index is right union field
  8046. -
  8047. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8048. - // not enough room for a class_info_index
  8049. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8050. - ("length() is too small for a class_info_index"));
  8051. - return false;
  8052. - }
  8053. -
  8054. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8055. - annotations_typeArray, byte_i_ref,
  8056. - "mapped old class_info_index=%d", THREAD);
  8057. -
  8058. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8059. - ("class_info_index=%d", class_info_index));
  8060. - } break;
  8061. -
  8062. - case '@':
  8063. - // For the above tag value, value.attr_value is the right union
  8064. - // field. This is a nested annotation.
  8065. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8066. - byte_i_ref, THREAD)) {
  8067. - // propagate failure back to caller
  8068. - return false;
  8069. - }
  8070. - break;
  8071. -
  8072. - case '[':
  8073. - {
  8074. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8075. - // not enough room for a num_values field
  8076. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8077. - ("length() is too small for a num_values field"));
  8078. - return false;
  8079. - }
  8080. -
  8081. - // For the above tag value, value.array_value is the right union
  8082. - // field. This is an array of nested element_value.
  8083. - u2 num_values = Bytes::get_Java_u2((address)
  8084. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8085. - byte_i_ref += 2;
  8086. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8087. -
  8088. - int calc_num_values = 0;
  8089. - for (; calc_num_values < num_values; calc_num_values++) {
  8090. - if (!rewrite_cp_refs_in_element_value(
  8091. - annotations_typeArray, byte_i_ref, THREAD)) {
  8092. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8093. - ("bad nested element_value at %d", calc_num_values));
  8094. - // propagate failure back to caller
  8095. - return false;
  8096. + // FIXME: DCEVM: better implementation?
  8097. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  8098. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  8099. + // case we need to run write barrier to make sure card table is properly updated. This will
  8100. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  8101. + if (Universe::heap()->is_in_reserved(p)) {
  8102. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  8103. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  8104. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  8105. + CardTableRS* _rs = (CardTableRS*)rs;
  8106. + _rs->inline_write_ref_field_gc(p, obj);
  8107. + }
  8108. }
  8109. }
  8110. - assert(num_values == calc_num_values, "sanity check");
  8111. - } break;
  8112. -
  8113. - default:
  8114. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8115. - return false;
  8116. - } // end decode tag field
  8117. -
  8118. - return true;
  8119. -} // end rewrite_cp_refs_in_element_value()
  8120. -
  8121. -
  8122. -// Rewrite constant pool references in a fields_annotations field.
  8123. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8124. - instanceKlassHandle scratch_class, TRAPS) {
  8125. -
  8126. - objArrayHandle fields_annotations(THREAD,
  8127. - scratch_class->fields_annotations());
  8128. -
  8129. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8130. - // no fields_annotations so nothing to do
  8131. - return true;
  8132. - }
  8133. -
  8134. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8135. - ("fields_annotations length=%d", fields_annotations->length()));
  8136. -
  8137. - for (int i = 0; i < fields_annotations->length(); i++) {
  8138. - typeArrayHandle field_annotations(THREAD,
  8139. - (typeArrayOop)fields_annotations->obj_at(i));
  8140. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8141. - // this field does not have any annotations so skip it
  8142. - continue;
  8143. - }
  8144. -
  8145. - int byte_i = 0; // byte index into field_annotations
  8146. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8147. - THREAD)) {
  8148. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8149. - ("bad field_annotations at %d", i));
  8150. - // propagate failure back to caller
  8151. - return false;
  8152. }
  8153. }
  8154. +}
  8155. - return true;
  8156. -} // end rewrite_cp_refs_in_fields_annotations()
  8157. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  8158. + markOop first_mark = first->mark();
  8159. + markOop second_mark = second->mark();
  8160. + first->set_mark(second_mark);
  8161. + second->set_mark(first_mark);
  8162. +}
  8163. +void VM_RedefineClasses::doit() {
  8164. + Thread *thread = Thread::current();
  8165. -// Rewrite constant pool references in a methods_annotations field.
  8166. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8167. - instanceKlassHandle scratch_class, TRAPS) {
  8168. + RC_TRACE(0x00000001, ("Entering doit!"));
  8169. - objArrayHandle methods_annotations(THREAD,
  8170. - scratch_class->methods_annotations());
  8171. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8172. - // no methods_annotations so nothing to do
  8173. - return true;
  8174. - }
  8175. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  8176. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8177. - ("methods_annotations length=%d", methods_annotations->length()));
  8178. + RC_TIMER_START(_timer_check_type);
  8179. - for (int i = 0; i < methods_annotations->length(); i++) {
  8180. - typeArrayHandle method_annotations(THREAD,
  8181. - (typeArrayOop)methods_annotations->obj_at(i));
  8182. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8183. - // this method does not have any annotations so skip it
  8184. - continue;
  8185. - }
  8186. -
  8187. - int byte_i = 0; // byte index into method_annotations
  8188. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8189. - THREAD)) {
  8190. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8191. - ("bad method_annotations at %d", i));
  8192. - // propagate failure back to caller
  8193. - return false;
  8194. - }
  8195. - }
  8196. -
  8197. - return true;
  8198. -} // end rewrite_cp_refs_in_methods_annotations()
  8199. -
  8200. -
  8201. -// Rewrite constant pool references in a methods_parameter_annotations
  8202. -// field. This "structure" is adapted from the
  8203. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8204. -// 4.8.17 of the 2nd-edition of the VM spec:
  8205. -//
  8206. -// methods_parameter_annotations_typeArray {
  8207. -// u1 num_parameters;
  8208. -// {
  8209. -// u2 num_annotations;
  8210. -// annotation annotations[num_annotations];
  8211. -// } parameter_annotations[num_parameters];
  8212. -// }
  8213. -//
  8214. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8215. - instanceKlassHandle scratch_class, TRAPS) {
  8216. -
  8217. - objArrayHandle methods_parameter_annotations(THREAD,
  8218. - scratch_class->methods_parameter_annotations());
  8219. -
  8220. - if (methods_parameter_annotations.is_null()
  8221. - || methods_parameter_annotations->length() == 0) {
  8222. - // no methods_parameter_annotations so nothing to do
  8223. - return true;
  8224. - }
  8225. -
  8226. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8227. - ("methods_parameter_annotations length=%d",
  8228. - methods_parameter_annotations->length()));
  8229. -
  8230. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8231. - typeArrayHandle method_parameter_annotations(THREAD,
  8232. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8233. - if (method_parameter_annotations.is_null()
  8234. - || method_parameter_annotations->length() == 0) {
  8235. - // this method does not have any parameter annotations so skip it
  8236. - continue;
  8237. - }
  8238. -
  8239. - if (method_parameter_annotations->length() < 1) {
  8240. - // not enough room for a num_parameters field
  8241. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8242. - ("length() is too small for a num_parameters field at %d", i));
  8243. - return false;
  8244. - }
  8245. -
  8246. - int byte_i = 0; // byte index into method_parameter_annotations
  8247. -
  8248. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8249. - byte_i++;
  8250. -
  8251. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8252. - ("num_parameters=%d", num_parameters));
  8253. -
  8254. - int calc_num_parameters = 0;
  8255. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8256. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8257. - method_parameter_annotations, byte_i, THREAD)) {
  8258. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8259. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8260. - // propagate failure back to caller
  8261. - return false;
  8262. - }
  8263. - }
  8264. - assert(num_parameters == calc_num_parameters, "sanity check");
  8265. - }
  8266. -
  8267. - return true;
  8268. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8269. -
  8270. -
  8271. -// Rewrite constant pool references in a methods_default_annotations
  8272. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8273. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8274. -//
  8275. -// methods_default_annotations_typeArray {
  8276. -// element_value default_value;
  8277. -// }
  8278. -//
  8279. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8280. - instanceKlassHandle scratch_class, TRAPS) {
  8281. -
  8282. - objArrayHandle methods_default_annotations(THREAD,
  8283. - scratch_class->methods_default_annotations());
  8284. -
  8285. - if (methods_default_annotations.is_null()
  8286. - || methods_default_annotations->length() == 0) {
  8287. - // no methods_default_annotations so nothing to do
  8288. - return true;
  8289. - }
  8290. -
  8291. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8292. - ("methods_default_annotations length=%d",
  8293. - methods_default_annotations->length()));
  8294. -
  8295. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8296. - typeArrayHandle method_default_annotations(THREAD,
  8297. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8298. - if (method_default_annotations.is_null()
  8299. - || method_default_annotations->length() == 0) {
  8300. - // this method does not have any default annotations so skip it
  8301. - continue;
  8302. - }
  8303. -
  8304. - int byte_i = 0; // byte index into method_default_annotations
  8305. -
  8306. - if (!rewrite_cp_refs_in_element_value(
  8307. - method_default_annotations, byte_i, THREAD)) {
  8308. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8309. - ("bad default element_value at %d", i));
  8310. - // propagate failure back to caller
  8311. - return false;
  8312. - }
  8313. - }
  8314. -
  8315. - return true;
  8316. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8317. -
  8318. -
  8319. -// Rewrite constant pool references in the method's stackmap table.
  8320. -// These "structures" are adapted from the StackMapTable_attribute that
  8321. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8322. -// (dated 2005.10.26):
  8323. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8324. -//
  8325. -// stack_map {
  8326. -// u2 number_of_entries;
  8327. -// stack_map_frame entries[number_of_entries];
  8328. -// }
  8329. -//
  8330. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8331. - methodHandle method, TRAPS) {
  8332. -
  8333. - if (!method->has_stackmap_table()) {
  8334. - return;
  8335. - }
  8336. -
  8337. - typeArrayOop stackmap_data = method->stackmap_data();
  8338. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8339. - address stackmap_end = stackmap_p + stackmap_data->length();
  8340. -
  8341. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8342. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8343. - stackmap_p += 2;
  8344. -
  8345. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8346. - ("number_of_entries=%u", number_of_entries));
  8347. -
  8348. - // walk through each stack_map_frame
  8349. - u2 calc_number_of_entries = 0;
  8350. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8351. - // The stack_map_frame structure is a u1 frame_type followed by
  8352. - // 0 or more bytes of data:
  8353. - //
  8354. - // union stack_map_frame {
  8355. - // same_frame;
  8356. - // same_locals_1_stack_item_frame;
  8357. - // same_locals_1_stack_item_frame_extended;
  8358. - // chop_frame;
  8359. - // same_frame_extended;
  8360. - // append_frame;
  8361. - // full_frame;
  8362. - // }
  8363. -
  8364. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8365. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8366. - // issues the following warning for the first if-statement below:
  8367. - //
  8368. - // "warning: comparison is always true due to limited range of data type"
  8369. - //
  8370. - u4 frame_type = *stackmap_p;
  8371. - stackmap_p++;
  8372. -
  8373. - // same_frame {
  8374. - // u1 frame_type = SAME; /* 0-63 */
  8375. - // }
  8376. - if (frame_type >= 0 && frame_type <= 63) {
  8377. - // nothing more to do for same_frame
  8378. - }
  8379. -
  8380. - // same_locals_1_stack_item_frame {
  8381. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8382. - // verification_type_info stack[1];
  8383. - // }
  8384. - else if (frame_type >= 64 && frame_type <= 127) {
  8385. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8386. - calc_number_of_entries, frame_type, THREAD);
  8387. - }
  8388. -
  8389. - // reserved for future use
  8390. - else if (frame_type >= 128 && frame_type <= 246) {
  8391. - // nothing more to do for reserved frame_types
  8392. - }
  8393. -
  8394. - // same_locals_1_stack_item_frame_extended {
  8395. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8396. - // u2 offset_delta;
  8397. - // verification_type_info stack[1];
  8398. - // }
  8399. - else if (frame_type == 247) {
  8400. - stackmap_p += 2;
  8401. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8402. - calc_number_of_entries, frame_type, THREAD);
  8403. - }
  8404. -
  8405. - // chop_frame {
  8406. - // u1 frame_type = CHOP; /* 248-250 */
  8407. - // u2 offset_delta;
  8408. - // }
  8409. - else if (frame_type >= 248 && frame_type <= 250) {
  8410. - stackmap_p += 2;
  8411. - }
  8412. -
  8413. - // same_frame_extended {
  8414. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8415. - // u2 offset_delta;
  8416. - // }
  8417. - else if (frame_type == 251) {
  8418. - stackmap_p += 2;
  8419. - }
  8420. -
  8421. - // append_frame {
  8422. - // u1 frame_type = APPEND; /* 252-254 */
  8423. - // u2 offset_delta;
  8424. - // verification_type_info locals[frame_type - 251];
  8425. - // }
  8426. - else if (frame_type >= 252 && frame_type <= 254) {
  8427. - assert(stackmap_p + 2 <= stackmap_end,
  8428. - "no room for offset_delta");
  8429. - stackmap_p += 2;
  8430. - u1 len = frame_type - 251;
  8431. - for (u1 i = 0; i < len; i++) {
  8432. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8433. - calc_number_of_entries, frame_type, THREAD);
  8434. - }
  8435. - }
  8436. -
  8437. - // full_frame {
  8438. - // u1 frame_type = FULL_FRAME; /* 255 */
  8439. - // u2 offset_delta;
  8440. - // u2 number_of_locals;
  8441. - // verification_type_info locals[number_of_locals];
  8442. - // u2 number_of_stack_items;
  8443. - // verification_type_info stack[number_of_stack_items];
  8444. - // }
  8445. - else if (frame_type == 255) {
  8446. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8447. - "no room for smallest full_frame");
  8448. - stackmap_p += 2;
  8449. -
  8450. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8451. - stackmap_p += 2;
  8452. -
  8453. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8454. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8455. - calc_number_of_entries, frame_type, THREAD);
  8456. - }
  8457. -
  8458. - // Use the largest size for the number_of_stack_items, but only get
  8459. - // the right number of bytes.
  8460. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8461. - stackmap_p += 2;
  8462. -
  8463. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8464. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8465. - calc_number_of_entries, frame_type, THREAD);
  8466. - }
  8467. - }
  8468. - } // end while there is a stack_map_frame
  8469. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8470. -} // end rewrite_cp_refs_in_stack_map_table()
  8471. -
  8472. -
  8473. -// Rewrite constant pool references in the verification type info
  8474. -// portion of the method's stackmap table. These "structures" are
  8475. -// adapted from the StackMapTable_attribute that is described in
  8476. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8477. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8478. -//
  8479. -// The verification_type_info structure is a u1 tag followed by 0 or
  8480. -// more bytes of data:
  8481. -//
  8482. -// union verification_type_info {
  8483. -// Top_variable_info;
  8484. -// Integer_variable_info;
  8485. -// Float_variable_info;
  8486. -// Long_variable_info;
  8487. -// Double_variable_info;
  8488. -// Null_variable_info;
  8489. -// UninitializedThis_variable_info;
  8490. -// Object_variable_info;
  8491. -// Uninitialized_variable_info;
  8492. -// }
  8493. -//
  8494. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8495. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8496. - u1 frame_type, TRAPS) {
  8497. -
  8498. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8499. - u1 tag = *stackmap_p_ref;
  8500. - stackmap_p_ref++;
  8501. -
  8502. - switch (tag) {
  8503. - // Top_variable_info {
  8504. - // u1 tag = ITEM_Top; /* 0 */
  8505. - // }
  8506. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8507. - case 0: // fall through
  8508. -
  8509. - // Integer_variable_info {
  8510. - // u1 tag = ITEM_Integer; /* 1 */
  8511. - // }
  8512. - case ITEM_Integer: // fall through
  8513. -
  8514. - // Float_variable_info {
  8515. - // u1 tag = ITEM_Float; /* 2 */
  8516. - // }
  8517. - case ITEM_Float: // fall through
  8518. -
  8519. - // Double_variable_info {
  8520. - // u1 tag = ITEM_Double; /* 3 */
  8521. - // }
  8522. - case ITEM_Double: // fall through
  8523. -
  8524. - // Long_variable_info {
  8525. - // u1 tag = ITEM_Long; /* 4 */
  8526. - // }
  8527. - case ITEM_Long: // fall through
  8528. -
  8529. - // Null_variable_info {
  8530. - // u1 tag = ITEM_Null; /* 5 */
  8531. - // }
  8532. - case ITEM_Null: // fall through
  8533. -
  8534. - // UninitializedThis_variable_info {
  8535. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8536. - // }
  8537. - case ITEM_UninitializedThis:
  8538. - // nothing more to do for the above tag types
  8539. - break;
  8540. -
  8541. - // Object_variable_info {
  8542. - // u1 tag = ITEM_Object; /* 7 */
  8543. - // u2 cpool_index;
  8544. - // }
  8545. - case ITEM_Object:
  8546. - {
  8547. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8548. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8549. - u2 new_cp_index = find_new_index(cpool_index);
  8550. - if (new_cp_index != 0) {
  8551. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8552. - ("mapped old cpool_index=%d", cpool_index));
  8553. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8554. - cpool_index = new_cp_index;
  8555. - }
  8556. - stackmap_p_ref += 2;
  8557. -
  8558. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8559. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8560. - frame_type, cpool_index));
  8561. - } break;
  8562. -
  8563. - // Uninitialized_variable_info {
  8564. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8565. - // u2 offset;
  8566. - // }
  8567. - case ITEM_Uninitialized:
  8568. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8569. - stackmap_p_ref += 2;
  8570. - break;
  8571. -
  8572. - default:
  8573. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8574. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8575. - ShouldNotReachHere();
  8576. - break;
  8577. - } // end switch (tag)
  8578. -} // end rewrite_cp_refs_in_verification_type_info()
  8579. -
  8580. -
  8581. -// Change the constant pool associated with klass scratch_class to
  8582. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8583. -// are copied from scratch_cp to a smaller constant pool and the
  8584. -// smaller constant pool is associated with scratch_class.
  8585. -void VM_RedefineClasses::set_new_constant_pool(
  8586. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8587. - int scratch_cp_length, TRAPS) {
  8588. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  8589. -
  8590. - // scratch_cp is a merged constant pool and has enough space for a
  8591. - // worst case merge situation. We want to associate the minimum
  8592. - // sized constant pool with the klass to save space.
  8593. - constantPoolHandle smaller_cp(THREAD,
  8594. - oopFactory::new_constantPool(scratch_cp_length,
  8595. - oopDesc::IsUnsafeConc,
  8596. - THREAD));
  8597. - // preserve orig_length() value in the smaller copy
  8598. - int orig_length = scratch_cp->orig_length();
  8599. - assert(orig_length != 0, "sanity check");
  8600. - smaller_cp->set_orig_length(orig_length);
  8601. -
  8602. - // attach klass to new constant pool
  8603. - // reference to the cp holder is needed for copy_operands()
  8604. - smaller_cp->set_pool_holder(scratch_class());
  8605. -
  8606. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8607. - scratch_cp = smaller_cp;
  8608. - smaller_cp()->set_is_conc_safe(true);
  8609. -
  8610. - // attach new constant pool to klass
  8611. - scratch_class->set_constants(scratch_cp());
  8612. -
  8613. - int i; // for portability
  8614. -
  8615. - // update each field in klass to use new constant pool indices as needed
  8616. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8617. - jshort cur_index = fs.name_index();
  8618. - jshort new_index = find_new_index(cur_index);
  8619. - if (new_index != 0) {
  8620. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8621. - ("field-name_index change: %d to %d", cur_index, new_index));
  8622. - fs.set_name_index(new_index);
  8623. - }
  8624. - cur_index = fs.signature_index();
  8625. - new_index = find_new_index(cur_index);
  8626. - if (new_index != 0) {
  8627. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8628. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8629. - fs.set_signature_index(new_index);
  8630. - }
  8631. - cur_index = fs.initval_index();
  8632. - new_index = find_new_index(cur_index);
  8633. - if (new_index != 0) {
  8634. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8635. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8636. - fs.set_initval_index(new_index);
  8637. - }
  8638. - cur_index = fs.generic_signature_index();
  8639. - new_index = find_new_index(cur_index);
  8640. - if (new_index != 0) {
  8641. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8642. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8643. - fs.set_generic_signature_index(new_index);
  8644. - }
  8645. - } // end for each field
  8646. -
  8647. - // Update constant pool indices in the inner classes info to use
  8648. - // new constant indices as needed. The inner classes info is a
  8649. - // quadruple:
  8650. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8651. - InnerClassesIterator iter(scratch_class);
  8652. - for (; !iter.done(); iter.next()) {
  8653. - int cur_index = iter.inner_class_info_index();
  8654. - if (cur_index == 0) {
  8655. - continue; // JVM spec. allows null inner class refs so skip it
  8656. - }
  8657. - int new_index = find_new_index(cur_index);
  8658. - if (new_index != 0) {
  8659. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8660. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8661. - iter.set_inner_class_info_index(new_index);
  8662. - }
  8663. - cur_index = iter.outer_class_info_index();
  8664. - new_index = find_new_index(cur_index);
  8665. - if (new_index != 0) {
  8666. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8667. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8668. - iter.set_outer_class_info_index(new_index);
  8669. - }
  8670. - cur_index = iter.inner_name_index();
  8671. - new_index = find_new_index(cur_index);
  8672. - if (new_index != 0) {
  8673. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8674. - ("inner_name change: %d to %d", cur_index, new_index));
  8675. - iter.set_inner_name_index(new_index);
  8676. - }
  8677. - } // end for each inner class
  8678. -
  8679. - // Attach each method in klass to the new constant pool and update
  8680. - // to use new constant pool indices as needed:
  8681. - objArrayHandle methods(THREAD, scratch_class->methods());
  8682. - for (i = methods->length() - 1; i >= 0; i--) {
  8683. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8684. - method->set_constants(scratch_cp());
  8685. -
  8686. - int new_index = find_new_index(method->name_index());
  8687. - if (new_index != 0) {
  8688. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8689. - ("method-name_index change: %d to %d", method->name_index(),
  8690. - new_index));
  8691. - method->set_name_index(new_index);
  8692. - }
  8693. - new_index = find_new_index(method->signature_index());
  8694. - if (new_index != 0) {
  8695. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8696. - ("method-signature_index change: %d to %d",
  8697. - method->signature_index(), new_index));
  8698. - method->set_signature_index(new_index);
  8699. - }
  8700. - new_index = find_new_index(method->generic_signature_index());
  8701. - if (new_index != 0) {
  8702. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8703. - ("method-generic_signature_index change: %d to %d",
  8704. - method->generic_signature_index(), new_index));
  8705. - method->set_generic_signature_index(new_index);
  8706. - }
  8707. -
  8708. - // Update constant pool indices in the method's checked exception
  8709. - // table to use new constant indices as needed.
  8710. - int cext_length = method->checked_exceptions_length();
  8711. - if (cext_length > 0) {
  8712. - CheckedExceptionElement * cext_table =
  8713. - method->checked_exceptions_start();
  8714. - for (int j = 0; j < cext_length; j++) {
  8715. - int cur_index = cext_table[j].class_cp_index;
  8716. - int new_index = find_new_index(cur_index);
  8717. - if (new_index != 0) {
  8718. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8719. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8720. - cext_table[j].class_cp_index = (u2)new_index;
  8721. - }
  8722. - } // end for each checked exception table entry
  8723. - } // end if there are checked exception table entries
  8724. -
  8725. - // Update each catch type index in the method's exception table
  8726. - // to use new constant pool indices as needed. The exception table
  8727. - // holds quadruple entries of the form:
  8728. - // (beg_bci, end_bci, handler_bci, klass_index)
  8729. -
  8730. - ExceptionTable ex_table(method());
  8731. - int ext_length = ex_table.length();
  8732. -
  8733. - for (int j = 0; j < ext_length; j ++) {
  8734. - int cur_index = ex_table.catch_type_index(j);
  8735. - int new_index = find_new_index(cur_index);
  8736. - if (new_index != 0) {
  8737. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8738. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8739. - ex_table.set_catch_type_index(j, new_index);
  8740. - }
  8741. - } // end for each exception table entry
  8742. -
  8743. - // Update constant pool indices in the method's local variable
  8744. - // table to use new constant indices as needed. The local variable
  8745. - // table hold sextuple entries of the form:
  8746. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8747. - int lvt_length = method->localvariable_table_length();
  8748. - if (lvt_length > 0) {
  8749. - LocalVariableTableElement * lv_table =
  8750. - method->localvariable_table_start();
  8751. - for (int j = 0; j < lvt_length; j++) {
  8752. - int cur_index = lv_table[j].name_cp_index;
  8753. - int new_index = find_new_index(cur_index);
  8754. - if (new_index != 0) {
  8755. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8756. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8757. - lv_table[j].name_cp_index = (u2)new_index;
  8758. - }
  8759. - cur_index = lv_table[j].descriptor_cp_index;
  8760. - new_index = find_new_index(cur_index);
  8761. - if (new_index != 0) {
  8762. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8763. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8764. - new_index));
  8765. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8766. - }
  8767. - cur_index = lv_table[j].signature_cp_index;
  8768. - new_index = find_new_index(cur_index);
  8769. - if (new_index != 0) {
  8770. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8771. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8772. - lv_table[j].signature_cp_index = (u2)new_index;
  8773. - }
  8774. - } // end for each local variable table entry
  8775. - } // end if there are local variable table entries
  8776. -
  8777. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8778. - } // end for each method
  8779. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8780. -} // end set_new_constant_pool()
  8781. -
  8782. -
  8783. -// Unevolving classes may point to methods of the_class directly
  8784. -// from their constant pool caches, itables, and/or vtables. We
  8785. -// use the SystemDictionary::classes_do() facility and this helper
  8786. -// to fix up these pointers.
  8787. -//
  8788. -// Note: We currently don't support updating the vtable in
  8789. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8790. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8791. - oop initiating_loader, TRAPS) {
  8792. - Klass *k = k_oop->klass_part();
  8793. - if (k->oop_is_instance()) {
  8794. - HandleMark hm(THREAD);
  8795. - instanceKlass *ik = (instanceKlass *) k;
  8796. -
  8797. - // HotSpot specific optimization! HotSpot does not currently
  8798. - // support delegation from the bootstrap class loader to a
  8799. - // user-defined class loader. This means that if the bootstrap
  8800. - // class loader is the initiating class loader, then it will also
  8801. - // be the defining class loader. This also means that classes
  8802. - // loaded by the bootstrap class loader cannot refer to classes
  8803. - // loaded by a user-defined class loader. Note: a user-defined
  8804. - // class loader can delegate to the bootstrap class loader.
  8805. - //
  8806. - // If the current class being redefined has a user-defined class
  8807. - // loader as its defining class loader, then we can skip all
  8808. - // classes loaded by the bootstrap class loader.
  8809. - bool is_user_defined =
  8810. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8811. - if (is_user_defined && ik->class_loader() == NULL) {
  8812. + if (!check_type_consistency()) {
  8813. + // (tw) TODO: Rollback the class redefinition
  8814. + rollback();
  8815. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  8816. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  8817. + RC_TIMER_STOP(_timer_check_type);
  8818. return;
  8819. }
  8820. - // This is a very busy routine. We don't want too much tracing
  8821. - // printed out.
  8822. - bool trace_name_printed = false;
  8823. + RC_TIMER_STOP(_timer_check_type);
  8824. - // Very noisy: only enable this call if you are trying to determine
  8825. - // that a specific class gets found by this routine.
  8826. - // RC_TRACE macro has an embedded ResourceMark
  8827. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8828. - // ("adjust check: name=%s", ik->external_name()));
  8829. - // trace_name_printed = true;
  8830. + } else {
  8831. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  8832. + }
  8833. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8834. - // if one exists. We discard scratch_class and we don't keep an
  8835. - // instanceKlass around to hold obsolete methods so we don't have
  8836. - // any other instanceKlass embedded vtables to update. The vtable
  8837. - // holds the methodOops for virtual (but not final) methods.
  8838. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8839. - // ik->vtable() creates a wrapper object; rm cleans it up
  8840. - ResourceMark rm(THREAD);
  8841. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8842. - _matching_new_methods,
  8843. - _matching_methods_length,
  8844. - &trace_name_printed);
  8845. + if (UseMethodForwardPoints) {
  8846. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  8847. + method_forwarding();
  8848. + }
  8849. +
  8850. + if (UseSharedSpaces) {
  8851. + // Sharing is enabled so we remap the shared readonly space to
  8852. + // shared readwrite, private just in case we need to redefine
  8853. + // a shared class. We do the remap during the doit() phase of
  8854. + // the safepoint to be safer.
  8855. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  8856. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  8857. + _result = JVMTI_ERROR_INTERNAL;
  8858. + return;
  8859. + }
  8860. + }
  8861. +
  8862. + RC_TIMER_START(_timer_prepare_redefinition);
  8863. + for (int i = 0; i < _new_classes->length(); i++) {
  8864. + redefine_single_class(_new_classes->at(i), thread);
  8865. + }
  8866. +
  8867. + // Deoptimize all compiled code that depends on this class
  8868. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  8869. +
  8870. + // Adjust constantpool caches and vtables for all classes
  8871. + // that reference methods of the evolved class.
  8872. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  8873. +
  8874. + RC_TIMER_STOP(_timer_prepare_redefinition);
  8875. + RC_TIMER_START(_timer_redefinition);
  8876. +
  8877. + class ChangePointersOopClosure : public OopClosure {
  8878. + virtual void do_oop(oop* o) {
  8879. + do_oop_work(o);
  8880. + }
  8881. +
  8882. + virtual void do_oop(narrowOop* o) {
  8883. + do_oop_work(o);
  8884. + }
  8885. + };
  8886. +
  8887. + class ChangePointersObjectClosure : public ObjectClosure {
  8888. +
  8889. + private:
  8890. +
  8891. + OopClosure *_closure;
  8892. + bool _needs_instance_update;
  8893. + GrowableArray<oop> *_updated_oops;
  8894. +
  8895. + public:
  8896. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  8897. +
  8898. + bool needs_instance_update() {
  8899. + return _needs_instance_update;
  8900. + }
  8901. +
  8902. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  8903. +
  8904. + virtual void do_object(oop obj) {
  8905. + if (!obj->is_instanceKlass()) {
  8906. + obj->oop_iterate(_closure);
  8907. +
  8908. + if (obj->blueprint()->is_redefining()) {
  8909. +
  8910. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8911. + if (_updated_oops == NULL) {
  8912. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  8913. + }
  8914. + _updated_oops->append(obj);
  8915. + }
  8916. +
  8917. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  8918. +
  8919. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  8920. + obj->set_klass_no_check(obj->blueprint()->old_version());
  8921. +
  8922. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  8923. + // We need an instance update => set back to old klass
  8924. + _needs_instance_update = true;
  8925. +
  8926. + } else {
  8927. + MarkSweep::update_fields(obj, obj);
  8928. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  8929. + }
  8930. + }
  8931. + }
  8932. +
  8933. + } else {
  8934. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  8935. + if (klass->is_redefining()) {
  8936. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  8937. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  8938. + old_klass->constants()->set_pool_holder(klass->old_version());
  8939. +
  8940. + // Initialize the new class! Special static initialization that does not execute the
  8941. + // static constructor but copies static field values from the old class if name
  8942. + // and signature of a static field match.
  8943. + klass->initialize_redefined_class();
  8944. + }
  8945. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  8946. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  8947. + // idubrov: will get new version of that class
  8948. + //klass->iterate_static_fields(_closure);
  8949. + }
  8950. + }
  8951. + };
  8952. +
  8953. + ChangePointersOopClosure oopClosure;
  8954. + ChangePointersObjectClosure objectClosure(&oopClosure);
  8955. +
  8956. + {
  8957. + SharedHeap::heap()->gc_prologue(true);
  8958. + Universe::root_oops_do(&oopClosure);
  8959. + Universe::heap()->object_iterate(&objectClosure);
  8960. + SharedHeap::heap()->gc_epilogue(false);
  8961. }
  8962. - // If the current class has an itable and we are either redefining an
  8963. - // interface or if the current class is a subclass of the_class, then
  8964. - // we potentially have to fix the itable. If we are redefining an
  8965. - // interface, then we have to call adjust_method_entries() for
  8966. - // every instanceKlass that has an itable since there isn't a
  8967. - // subclass relationship between an interface and an instanceKlass.
  8968. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8969. - || ik->is_subclass_of(_the_class_oop))) {
  8970. - // ik->itable() creates a wrapper object; rm cleans it up
  8971. - ResourceMark rm(THREAD);
  8972. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8973. - _matching_new_methods,
  8974. - _matching_methods_length,
  8975. - &trace_name_printed);
  8976. + // Swap marks to have same hashcodes
  8977. + for (int i=0; i<_new_classes->length(); i++) {
  8978. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  8979. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  8980. }
  8981. - // The constant pools in other classes (other_cp) can refer to
  8982. - // methods in the_class. We have to update method information in
  8983. - // other_cp's cache. If other_cp has a previous version, then we
  8984. - // have to repeat the process for each previous version. The
  8985. - // constant pool cache holds the methodOops for non-virtual
  8986. - // methods and for virtual, final methods.
  8987. - //
  8988. - // Special case: if the current class is the_class, then new_cp
  8989. - // has already been attached to the_class and old_cp has already
  8990. - // been added as a previous version. The new_cp doesn't have any
  8991. - // cached references to old methods so it doesn't need to be
  8992. - // updated. We can simply start with the previous version(s) in
  8993. - // that case.
  8994. - constantPoolHandle other_cp;
  8995. - constantPoolCacheOop cp_cache;
  8996. + _updated_oops = objectClosure.updated_oops();
  8997. - if (k_oop != _the_class_oop) {
  8998. - // this klass' constant pool cache may need adjustment
  8999. - other_cp = constantPoolHandle(ik->constants());
  9000. - cp_cache = other_cp->cache();
  9001. - if (cp_cache != NULL) {
  9002. - cp_cache->adjust_method_entries(_matching_old_methods,
  9003. - _matching_new_methods,
  9004. - _matching_methods_length,
  9005. - &trace_name_printed);
  9006. + if (objectClosure.needs_instance_update()){
  9007. +
  9008. + // Do a full garbage collection to update the instance sizes accordingly
  9009. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  9010. + Universe::set_redefining_gc_run(true);
  9011. + JvmtiGCMarker jgcm;
  9012. + notify_gc_begin(true);
  9013. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  9014. + notify_gc_end();
  9015. + Universe::set_redefining_gc_run(false);
  9016. + RC_TRACE(0x00000001, ("GC done!"));
  9017. + }
  9018. +
  9019. +
  9020. + if (RC_TRACE_ENABLED(0x00000001)) {
  9021. + if (_updated_oops != NULL) {
  9022. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  9023. + } else {
  9024. + RC_TRACE(0x00000001, ("No objects updated!"));
  9025. + }
  9026. + }
  9027. +
  9028. + // Unmark klassOops as "redefining"
  9029. + for (int i=0; i<_new_classes->length(); i++) {
  9030. + klassOop cur = _new_classes->at(i)();
  9031. + _new_classes->at(i)->set_redefining(false);
  9032. + _new_classes->at(i)->clear_update_information();
  9033. + _new_classes->at(i)->update_supers_to_newest_version();
  9034. +
  9035. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  9036. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9037. +
  9038. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  9039. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9040. +
  9041. + oop new_mirror = _new_classes->at(i)->java_mirror();
  9042. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  9043. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  9044. + }
  9045. + }
  9046. +
  9047. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  9048. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  9049. + }
  9050. +
  9051. + // Disable any dependent concurrent compilations
  9052. + SystemDictionary::notice_modification();
  9053. +
  9054. + // Set flag indicating that some invariants are no longer true.
  9055. + // See jvmtiExport.hpp for detailed explanation.
  9056. + JvmtiExport::set_has_redefined_a_class();
  9057. +
  9058. + // Clean up caches in the compiler interface and compiler threads
  9059. + CompileBroker::cleanup_after_redefinition();
  9060. +
  9061. +#ifdef ASSERT
  9062. +
  9063. + // Universe::verify();
  9064. + // JNIHandles::verify();
  9065. +
  9066. + SystemDictionary::classes_do(check_class, thread);
  9067. +#endif
  9068. +
  9069. + update_active_methods();
  9070. + RC_TIMER_STOP(_timer_redefinition);
  9071. +
  9072. +}
  9073. +
  9074. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  9075. +
  9076. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  9077. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  9078. +
  9079. +
  9080. + while (curArrayKlass != NULL) {
  9081. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  9082. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  9083. + curArrayKlass->update_supers_to_newest_version();
  9084. +
  9085. + curArrayKlass = NULL;
  9086. + if (higher_dimension != NULL) {
  9087. + curArrayKlass = arrayKlass::cast(higher_dimension);
  9088. + }
  9089. + }
  9090. +
  9091. +}
  9092. +
  9093. +void VM_RedefineClasses::doit_epilogue() {
  9094. +
  9095. + RC_TIMER_START(_timer_vm_op_epilogue);
  9096. +
  9097. + unlock_threads();
  9098. +
  9099. + ResourceMark mark;
  9100. +
  9101. + VM_GC_Operation::doit_epilogue();
  9102. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  9103. +
  9104. + GrowableArray<methodHandle> instanceTransformerMethods;
  9105. +
  9106. + // Call static transformers
  9107. + for (int i=0; i<_new_classes->length(); i++) {
  9108. +
  9109. + instanceKlassHandle klass = _new_classes->at(i);
  9110. +
  9111. + // Transfer init state
  9112. + if (klass->old_version() != NULL) {
  9113. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  9114. + if (state > instanceKlass::linked) {
  9115. + klass->initialize(Thread::current());
  9116. }
  9117. }
  9118. - {
  9119. - ResourceMark rm(THREAD);
  9120. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9121. - // contain a GrowableArray of handles. We have to clean up the
  9122. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9123. - // has destroyed the handles.
  9124. - {
  9125. - // the previous versions' constant pool caches may need adjustment
  9126. - PreviousVersionWalker pvw(ik);
  9127. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9128. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9129. - other_cp = pv_info->prev_constant_pool_handle();
  9130. - cp_cache = other_cp->cache();
  9131. - if (cp_cache != NULL) {
  9132. - cp_cache->adjust_method_entries(_matching_old_methods,
  9133. - _matching_new_methods,
  9134. - _matching_methods_length,
  9135. - &trace_name_printed);
  9136. - }
  9137. +
  9138. + // Find instance transformer method
  9139. +
  9140. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9141. +
  9142. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  9143. + klassOop cur_klass = klass();
  9144. + while (cur_klass != NULL) {
  9145. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  9146. + if (method != NULL) {
  9147. + methodHandle instanceTransformerMethod(method);
  9148. + instanceTransformerMethods.append(instanceTransformerMethod);
  9149. + break;
  9150. + } else {
  9151. + cur_klass = cur_klass->klass_part()->super();
  9152. }
  9153. - } // pvw is cleaned up
  9154. - } // rm is cleaned up
  9155. + }
  9156. + assert(cur_klass != NULL, "must have instance transformer method");
  9157. + } else {
  9158. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  9159. + }
  9160. + }
  9161. +
  9162. +
  9163. + // Call instance transformers
  9164. + if (_updated_oops != NULL) {
  9165. +
  9166. + for (int i=0; i<_updated_oops->length(); i++) {
  9167. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  9168. + Handle cur(_updated_oops->at(i));
  9169. + instanceKlassHandle klass(cur->klass());
  9170. +
  9171. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9172. +
  9173. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  9174. +
  9175. + RC_TRACE(0x00008000, ("executing transformer method"));
  9176. +
  9177. + Thread *__the_thread__ = Thread::current();
  9178. + JavaValue result(T_VOID);
  9179. + JavaCallArguments args(cur);
  9180. + JavaCalls::call(&result,
  9181. + method,
  9182. + &args,
  9183. + THREAD);
  9184. +
  9185. + // TODO: What to do with an exception here?
  9186. + if (HAS_PENDING_EXCEPTION) {
  9187. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  9188. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  9189. + ex_name->as_C_string()));
  9190. + CLEAR_PENDING_EXCEPTION;
  9191. + }
  9192. + }
  9193. + }
  9194. +
  9195. + delete _updated_oops;
  9196. + _updated_oops = NULL;
  9197. + }
  9198. +
  9199. + // Free the array of scratch classes
  9200. + delete _new_classes;
  9201. + _new_classes = NULL;
  9202. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  9203. +
  9204. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  9205. +}
  9206. +
  9207. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  9208. + // classes for primitives cannot be redefined
  9209. + if (java_lang_Class::is_primitive(klass_mirror)) {
  9210. + return false;
  9211. + }
  9212. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  9213. + // classes for arrays cannot be redefined
  9214. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  9215. + return false;
  9216. + }
  9217. + return true;
  9218. +}
  9219. +
  9220. +#ifdef ASSERT
  9221. +
  9222. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9223. + klassOop k_oop = k_oop_latest;
  9224. + while (k_oop != NULL) {
  9225. +
  9226. + instanceKlassHandle k_handle(THREAD, k_oop);
  9227. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  9228. + k_oop = k_oop->klass_part()->old_version();
  9229. + }
  9230. +}
  9231. +
  9232. +#endif
  9233. +
  9234. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  9235. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  9236. +// do that, they assume that cache entry is resolved already.
  9237. +static void unpatch_bytecode(methodOop method) {
  9238. + RawBytecodeStream bcs(method);
  9239. + Bytecodes::Code code;
  9240. + Bytecodes::Code java_code;
  9241. + while (!bcs.is_last_bytecode()) {
  9242. + code = bcs.raw_next();
  9243. + address bcp = bcs.bcp();
  9244. +
  9245. + if (code == Bytecodes::_breakpoint) {
  9246. + int bci = method->bci_from(bcp);
  9247. + code = method->orig_bytecode_at(bci);
  9248. + java_code = Bytecodes::java_code(code);
  9249. + if (code != java_code &&
  9250. + (java_code == Bytecodes::_getfield ||
  9251. + java_code == Bytecodes::_putfield ||
  9252. + java_code == Bytecodes::_aload_0)) {
  9253. + // Let breakpoint table handling unpatch bytecode
  9254. + method->set_orig_bytecode_at(bci, java_code);
  9255. + }
  9256. + } else {
  9257. + java_code = Bytecodes::java_code(code);
  9258. + if (code != java_code &&
  9259. + (java_code == Bytecodes::_getfield ||
  9260. + java_code == Bytecodes::_putfield ||
  9261. + java_code == Bytecodes::_aload_0)) {
  9262. + *bcp = java_code;
  9263. + }
  9264. + }
  9265. +
  9266. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  9267. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  9268. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  9269. + assert(code2 == Bytecodes::_fast_igetfield ||
  9270. + code2 == Bytecodes::_fast_agetfield ||
  9271. + code2 == Bytecodes::_fast_fgetfield, "");
  9272. + *(bcp + 1) = Bytecodes::java_code(code2);
  9273. + }
  9274. + }
  9275. +}
  9276. +
  9277. +// Unevolving classes may point to old methods directly
  9278. +// from their constant pool caches, itables, and/or vtables. We
  9279. +// use the SystemDictionary::classes_do() facility and this helper
  9280. +// to fix up these pointers. Additional field offsets and vtable indices
  9281. +// in the constant pool cache entries are fixed.
  9282. +//
  9283. +// Note: We currently don't support updating the vtable in
  9284. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9285. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9286. + klassOop k_oop = k_oop_latest;
  9287. + while (k_oop != NULL) {
  9288. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9289. +/*
  9290. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9291. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9292. +
  9293. + for (int i=0; i<_matching_methods_length; i++) {
  9294. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9295. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9296. + }*/
  9297. +
  9298. + Klass *k = k_oop->klass_part();
  9299. + if (k->oop_is_instance()) {
  9300. + HandleMark hm(THREAD);
  9301. + instanceKlass *ik = (instanceKlass *) k;
  9302. +
  9303. + constantPoolHandle other_cp;
  9304. + constantPoolCacheOop cp_cache;
  9305. +
  9306. + other_cp = constantPoolHandle(ik->constants());
  9307. +
  9308. + for (int i=0; i<other_cp->length(); i++) {
  9309. + if (other_cp->tag_at(i).is_klass()) {
  9310. + klassOop klass = other_cp->klass_at(i, THREAD);
  9311. + if (klass->klass_part()->new_version() != NULL) {
  9312. +
  9313. + // (tw) TODO: check why/if this is necessary
  9314. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9315. + }
  9316. + klass = other_cp->klass_at(i, THREAD);
  9317. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9318. + }
  9319. + }
  9320. +
  9321. + cp_cache = other_cp->cache();
  9322. +
  9323. + if (cp_cache != NULL) {
  9324. + cp_cache->adjust_entries(NULL,
  9325. + NULL,
  9326. + 0);
  9327. + }
  9328. +
  9329. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9330. + if (RewriteBytecodes) {
  9331. + ik->methods_do(unpatch_bytecode);
  9332. + }
  9333. + }
  9334. + k_oop = k_oop->klass_part()->old_version();
  9335. }
  9336. }
  9337. void VM_RedefineClasses::update_jmethod_ids() {
  9338. for (int j = 0; j < _matching_methods_length; ++j) {
  9339. - methodOop old_method = _matching_old_methods[j];
  9340. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9341. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9342. +
  9343. jmethodID jmid = old_method->find_jmethod_id_or_null();
  9344. + if (old_method->new_version() != NULL && jmid == NULL) {
  9345. + // (tw) Have to create jmethodID in this case
  9346. + jmid = old_method->jmethod_id();
  9347. + }
  9348. +
  9349. if (jmid != NULL) {
  9350. // There is a jmethodID, change it to point to the new method
  9351. - methodHandle new_method_h(_matching_new_methods[j]);
  9352. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9353. + if (old_method->new_version() == NULL) {
  9354. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9355. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9356. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9357. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9358. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9359. + } else {
  9360. + jmethodID mid = new_method_h->jmethod_id();
  9361. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9362. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9363. +
  9364. + }
  9365. JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9366. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9367. - "should be replaced");
  9368. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9369. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9370. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9371. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9372. +
  9373. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9374. }
  9375. }
  9376. }
  9377. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9378. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9379. - *emcp_method_count_p = 0;
  9380. - int obsolete_count = 0;
  9381. - int old_index = 0;
  9382. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9383. - methodOop old_method = _matching_old_methods[j];
  9384. - methodOop new_method = _matching_new_methods[j];
  9385. - methodOop old_array_method;
  9386. - // Maintain an old_index into the _old_methods array by skipping
  9387. - // deleted methods
  9388. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9389. - != old_method) {
  9390. - ++old_index;
  9391. - }
  9392. +// Deoptimize all compiled code that depends on this class.
  9393. +//
  9394. +// If the can_redefine_classes capability is obtained in the onload
  9395. +// phase then the compiler has recorded all dependencies from startup.
  9396. +// In that case we need only deoptimize and throw away all compiled code
  9397. +// that depends on the class.
  9398. +//
  9399. +// If can_redefine_classes is obtained sometime after the onload
  9400. +// phase then the dependency information may be incomplete. In that case
  9401. +// the first call to RedefineClasses causes all compiled code to be
  9402. +// thrown away. As can_redefine_classes has been obtained then
  9403. +// all future compilations will record dependencies so second and
  9404. +// subsequent calls to RedefineClasses need only throw away code
  9405. +// that depends on the class.
  9406. +//
  9407. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9408. + assert_locked_or_safepoint(Compile_lock);
  9409. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9410. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9411. - // the same with the exception of constant pool indices which may
  9412. - // differ. However, the constants referred to by those indices
  9413. - // must be the same.
  9414. - //
  9415. - // We use methods_EMCP() for comparison since constant pool
  9416. - // merging can remove duplicate constant pool entries that were
  9417. - // present in the old method and removed from the rewritten new
  9418. - // method. A faster binary comparison function would consider the
  9419. - // old and new methods to be different when they are actually
  9420. - // EMCP.
  9421. - //
  9422. - // The old and new methods are EMCP and you would think that we
  9423. - // could get rid of one of them here and now and save some space.
  9424. - // However, the concept of EMCP only considers the bytecodes and
  9425. - // the constant pool entries in the comparison. Other things,
  9426. - // e.g., the line number table (LNT) or the local variable table
  9427. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9428. - // method can have a new LNT that we need so we can't just
  9429. - // overwrite the new method with the old method.
  9430. - //
  9431. - // When this routine is called, we have already attached the new
  9432. - // methods to the_class so the old methods are effectively
  9433. - // overwritten. However, if an old method is still executing,
  9434. - // then the old method cannot be collected until sometime after
  9435. - // the old method call has returned. So the overwriting of old
  9436. - // methods by new methods will save us space except for those
  9437. - // (hopefully few) old methods that are still executing.
  9438. - //
  9439. - // A method refers to a constMethodOop and this presents another
  9440. - // possible avenue to space savings. The constMethodOop in the
  9441. - // new method contains possibly new attributes (LNT, LVT, etc).
  9442. - // At first glance, it seems possible to save space by replacing
  9443. - // the constMethodOop in the old method with the constMethodOop
  9444. - // from the new method. The old and new methods would share the
  9445. - // same constMethodOop and we would save the space occupied by
  9446. - // the old constMethodOop. However, the constMethodOop contains
  9447. - // a back reference to the containing method. Sharing the
  9448. - // constMethodOop between two methods could lead to confusion in
  9449. - // the code that uses the back reference. This would lead to
  9450. - // brittle code that could be broken in non-obvious ways now or
  9451. - // in the future.
  9452. - //
  9453. - // Another possibility is to copy the constMethodOop from the new
  9454. - // method to the old method and then overwrite the new method with
  9455. - // the old method. Since the constMethodOop contains the bytecodes
  9456. - // for the method embedded in the oop, this option would change
  9457. - // the bytecodes out from under any threads executing the old
  9458. - // method and make the thread's bcp invalid. Since EMCP requires
  9459. - // that the bytecodes be the same modulo constant pool indices, it
  9460. - // is straight forward to compute the correct new bcp in the new
  9461. - // constMethodOop from the old bcp in the old constMethodOop. The
  9462. - // time consuming part would be searching all the frames in all
  9463. - // of the threads to find all of the calls to the old method.
  9464. - //
  9465. - // It looks like we will have to live with the limited savings
  9466. - // that we get from effectively overwriting the old methods
  9467. - // when the new methods are attached to the_class.
  9468. + // All dependencies have been recorded from startup or this is a second or
  9469. + // subsequent use of RedefineClasses
  9470. - // track which methods are EMCP for add_previous_version() call
  9471. - emcp_methods->set_bit(old_index);
  9472. - (*emcp_method_count_p)++;
  9473. + // For now deopt all
  9474. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9475. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9476. + Universe::flush_evol_dependents_on(k_h);
  9477. + } else {
  9478. + CodeCache::mark_all_nmethods_for_deoptimization();
  9479. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9480. - // different jmethodID than the current method. An EMCP method
  9481. - // has the same jmethodID as the current method. Having the
  9482. - // same jmethodID for all EMCP versions of a method allows for
  9483. - // a consistent view of the EMCP methods regardless of which
  9484. - // EMCP method you happen to have in hand. For example, a
  9485. - // breakpoint set in one EMCP method will work for all EMCP
  9486. - // versions of the method including the current one.
  9487. - } else {
  9488. - // mark obsolete methods as such
  9489. - old_method->set_is_obsolete();
  9490. - obsolete_count++;
  9491. + ResourceMark rm(THREAD);
  9492. + DeoptimizationMarker dm;
  9493. - // obsolete methods need a unique idnum
  9494. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9495. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9496. -// u2 old_num = old_method->method_idnum();
  9497. - old_method->set_method_idnum(num);
  9498. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9499. + // Deoptimize all activations depending on marked nmethods
  9500. + Deoptimization::deoptimize_dependents();
  9501. +
  9502. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9503. + CodeCache::make_marked_nmethods_not_entrant();
  9504. +
  9505. + // From now on we know that the dependency information is complete
  9506. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9507. + }
  9508. +}
  9509. +
  9510. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9511. + methodOop old_method;
  9512. + methodOop new_method;
  9513. +
  9514. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9515. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9516. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9517. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9518. +
  9519. + _matching_methods_length = 0;
  9520. + _deleted_methods_length = 0;
  9521. + _added_methods_length = 0;
  9522. +
  9523. + int nj = 0;
  9524. + int oj = 0;
  9525. + while (true) {
  9526. + if (oj >= _old_methods->length()) {
  9527. + if (nj >= _new_methods->length()) {
  9528. + break; // we've looked at everything, done
  9529. }
  9530. + // New method at the end
  9531. + new_method = (methodOop) _new_methods->obj_at(nj);
  9532. + _added_methods[_added_methods_length++] = nj;
  9533. + ++nj;
  9534. + } else if (nj >= _new_methods->length()) {
  9535. + // Old method, at the end, is deleted
  9536. + old_method = (methodOop) _old_methods->obj_at(oj);
  9537. + _deleted_methods[_deleted_methods_length++] = oj;
  9538. + ++oj;
  9539. + } else {
  9540. + old_method = (methodOop) _old_methods->obj_at(oj);
  9541. + new_method = (methodOop) _new_methods->obj_at(nj);
  9542. + if (old_method->name() == new_method->name()) {
  9543. + if (old_method->signature() == new_method->signature()) {
  9544. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9545. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9546. + ++nj;
  9547. + ++oj;
  9548. + } else {
  9549. + // added overloaded have already been moved to the end,
  9550. + // so this is a deleted overloaded method
  9551. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9552. + ++oj;
  9553. + }
  9554. + } else { // names don't match
  9555. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9556. + // new method
  9557. + _added_methods[_added_methods_length++] = nj;//new_method;
  9558. + ++nj;
  9559. + } else {
  9560. + // deleted method
  9561. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9562. + ++oj;
  9563. + }
  9564. + }
  9565. + }
  9566. + }
  9567. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9568. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9569. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9570. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9571. +}
  9572. +
  9573. +
  9574. +
  9575. +// Install the redefinition of a class:
  9576. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9577. +// dependent compiled code)
  9578. +// - adjusting constant pool caches and vtables in other classes
  9579. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9580. +
  9581. + ResourceMark rm(THREAD);
  9582. +
  9583. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9584. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9585. +
  9586. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9587. +
  9588. +#ifndef JVMTI_KERNEL
  9589. + // Remove all breakpoints in methods of this class
  9590. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9591. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9592. +#endif // !JVMTI_KERNEL
  9593. +
  9594. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9595. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9596. + // cached and users of the cache care about each active version of
  9597. + // the method so we have to track this previous version.
  9598. + // Do this before methods get switched
  9599. + Universe::reflect_invoke_cache()->add_previous_version(
  9600. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9601. + }
  9602. +
  9603. + _old_methods = the_old_class->methods();
  9604. + _new_methods = the_new_class->methods();
  9605. + _the_class_oop = the_old_class();
  9606. + compute_added_deleted_matching_methods();
  9607. +
  9608. + // track which methods are EMCP for add_previous_version() call below
  9609. +
  9610. + // (tw) TODO: Check if we need the concept of EMCP?
  9611. + BitMap emcp_methods(_old_methods->length());
  9612. + int emcp_method_count = 0;
  9613. + emcp_methods.clear(); // clears 0..(length() - 1)
  9614. +
  9615. + // We need to mark methods as old!!
  9616. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9617. + update_jmethod_ids();
  9618. +
  9619. + // keep track of previous versions of this class
  9620. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9621. + emcp_method_count);
  9622. +
  9623. + // TODO:
  9624. + transfer_old_native_function_registrations(the_old_class);
  9625. +
  9626. +
  9627. +#ifdef ASSERT
  9628. +
  9629. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9630. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9631. +
  9632. + //JNIHandles::verify();
  9633. +
  9634. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9635. +
  9636. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9637. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9638. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9639. +
  9640. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9641. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9642. + }
  9643. +
  9644. + _old_methods->verify();
  9645. + _new_methods->verify();
  9646. +
  9647. + the_new_class->vtable()->verify(tty);
  9648. + the_old_class->vtable()->verify(tty);
  9649. +
  9650. +#endif
  9651. +
  9652. + // increment the classRedefinedCount field in the_class and in any
  9653. + // direct and indirect subclasses of the_class
  9654. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9655. +
  9656. +}
  9657. +
  9658. +
  9659. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9660. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9661. + *emcp_method_count_p = 0;
  9662. + int obsolete_count = 0;
  9663. + int old_index = 0;
  9664. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9665. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9666. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9667. + methodOop old_array_method;
  9668. +
  9669. + // Maintain an old_index into the _old_methods array by skipping
  9670. + // deleted methods
  9671. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9672. + != old_method) {
  9673. + ++old_index;
  9674. + }
  9675. +
  9676. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9677. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9678. + // the same with the exception of constant pool indices which may
  9679. + // differ. However, the constants referred to by those indices
  9680. + // must be the same.
  9681. + //
  9682. + // We use methods_EMCP() for comparison since constant pool
  9683. + // merging can remove duplicate constant pool entries that were
  9684. + // present in the old method and removed from the rewritten new
  9685. + // method. A faster binary comparison function would consider the
  9686. + // old and new methods to be different when they are actually
  9687. + // EMCP.
  9688. +
  9689. + // track which methods are EMCP for add_previous_version() call
  9690. + emcp_methods->set_bit(old_index);
  9691. + (*emcp_method_count_p)++;
  9692. +
  9693. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9694. + // different jmethodID than the current method. An EMCP method
  9695. + // has the same jmethodID as the current method. Having the
  9696. + // same jmethodID for all EMCP versions of a method allows for
  9697. + // a consistent view of the EMCP methods regardless of which
  9698. + // EMCP method you happen to have in hand. For example, a
  9699. + // breakpoint set in one EMCP method will work for all EMCP
  9700. + // versions of the method including the current one.
  9701. +
  9702. + old_method->set_new_version(new_method);
  9703. + new_method->set_old_version(old_method);
  9704. +
  9705. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9706. +
  9707. + // Transfer breakpoints
  9708. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9709. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9710. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9711. + RC_TRACE(0x00000002, ("%d / %d",
  9712. + bp->match(old_method), bp->match(new_method)));
  9713. + if (bp->match(old_method)) {
  9714. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9715. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9716. + new_method->set_breakpoint(bp->bci());
  9717. + }
  9718. + }
  9719. +
  9720. +
  9721. +
  9722. + } else {
  9723. + // mark obsolete methods as such
  9724. + old_method->set_is_obsolete();
  9725. + obsolete_count++;
  9726. +
  9727. + // With tracing we try not to "yack" too much. The position of
  9728. + // this trace assumes there are fewer obsolete methods than
  9729. + // EMCP methods.
  9730. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9731. + old_method->name()->as_C_string(),
  9732. + old_method->signature()->as_C_string()));
  9733. + }
  9734. + old_method->set_is_old();
  9735. + }
  9736. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9737. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9738. +
  9739. + //assert(old_method->vtable_index() < 0,
  9740. + // "cannot delete methods with vtable entries");;
  9741. +
  9742. + // Mark all deleted methods as old and obsolete
  9743. + old_method->set_is_old();
  9744. + old_method->set_is_obsolete();
  9745. + ++obsolete_count;
  9746. // With tracing we try not to "yack" too much. The position of
  9747. // this trace assumes there are fewer obsolete methods than
  9748. // EMCP methods.
  9749. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9750. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9751. old_method->name()->as_C_string(),
  9752. old_method->signature()->as_C_string()));
  9753. }
  9754. - old_method->set_is_old();
  9755. - }
  9756. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9757. - methodOop old_method = _deleted_methods[i];
  9758. -
  9759. - assert(old_method->vtable_index() < 0,
  9760. - "cannot delete methods with vtable entries");;
  9761. -
  9762. - // Mark all deleted methods as old and obsolete
  9763. - old_method->set_is_old();
  9764. - old_method->set_is_obsolete();
  9765. - ++obsolete_count;
  9766. - // With tracing we try not to "yack" too much. The position of
  9767. - // this trace assumes there are fewer obsolete methods than
  9768. - // EMCP methods.
  9769. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9770. - old_method->name()->as_C_string(),
  9771. - old_method->signature()->as_C_string()));
  9772. - }
  9773. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9774. - "sanity check");
  9775. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9776. - obsolete_count));
  9777. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9778. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9779. }
  9780. +
  9781. +// Increment the classRedefinedCount field in the specific instanceKlass
  9782. +// and in all direct and indirect subclasses.
  9783. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9784. + oop class_mirror = ik->java_mirror();
  9785. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9786. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9787. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9788. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9789. +}
  9790. +
  9791. +#ifndef PRODUCT
  9792. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9793. + Klass *k = k_oop->klass_part();
  9794. + if (k->oop_is_instance()) {
  9795. + HandleMark hm(THREAD);
  9796. + instanceKlass *ik = (instanceKlass *) k;
  9797. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9798. +
  9799. + if (ik->vtable_length() > 0) {
  9800. + ResourceMark rm(THREAD);
  9801. + if (!ik->vtable()->check_no_old_entries()) {
  9802. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9803. + k_oop->size()));
  9804. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9805. + ik->signature_name()));
  9806. + assert(false, "OLD method found");
  9807. + }
  9808. +
  9809. + ik->vtable()->verify(tty, true);
  9810. + }
  9811. + }
  9812. +}
  9813. +
  9814. +#endif
  9815. +
  9816. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9817. +{
  9818. + assert(original_klasses != NULL && result != NULL, "");
  9819. + this->_original_klasses = original_klasses;
  9820. + this->_result = result;
  9821. + SystemDictionary::classes_do(this);
  9822. +}
  9823. +
  9824. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9825. +{
  9826. + klassOop klass = (klassOop)obj;
  9827. + assert(!_result->contains(klass), "must not occur more than once!");
  9828. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9829. +
  9830. + for(int i=0; i<_original_klasses->length(); i++) {
  9831. + instanceKlassHandle cur = _original_klasses->at(i);
  9832. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9833. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9834. + _result->append(klass);
  9835. + break;
  9836. + }
  9837. + }
  9838. +}
  9839. +
  9840. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9841. +{
  9842. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9843. +
  9844. + for (int i=0; i<class_count; i++) {
  9845. +
  9846. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9847. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9848. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9849. + Handle the_class_loader(THREAD, the_class->class_loader());
  9850. + Handle protection_domain(THREAD, the_class->protection_domain());
  9851. +
  9852. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9853. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9854. + ClassFileParser cfp(&st);
  9855. +
  9856. + GrowableArray<Symbol*> symbolArr;
  9857. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9858. + the_class->name()->as_C_string()));
  9859. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9860. +
  9861. + for (int j=0; j<symbolArr.length(); j++) {
  9862. + Symbol* sym = symbolArr.at(j);
  9863. +
  9864. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9865. +
  9866. + for (int k=0; k<arr->length(); k++) {
  9867. + klassOop curOop = arr->at(k)();
  9868. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9869. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9870. + RC_TRACE(0x00000002, ("Found class to link"));
  9871. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9872. + break;
  9873. + }
  9874. + }
  9875. + }
  9876. + }
  9877. +
  9878. +
  9879. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9880. +
  9881. + for (int i=0; i<affected->length(); i++) {
  9882. +
  9883. + instanceKlassHandle klass = affected->at(i);
  9884. +
  9885. + klassOop superKlass = klass->super();
  9886. + if (affected->contains(superKlass)) {
  9887. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9888. + }
  9889. +
  9890. + objArrayOop superInterfaces = klass->local_interfaces();
  9891. + for (int j=0; j<superInterfaces->length(); j++) {
  9892. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9893. + if (arr->contains(interfaceKlass)) {
  9894. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9895. + }
  9896. + }
  9897. + }
  9898. +
  9899. + if (RC_TRACE_ENABLED(0x00000002)) {
  9900. + RC_TRACE(0x00000002, ("Identified links: "));
  9901. + for (int i=0; i<links->length(); i++) {
  9902. + RC_TRACE(0x00000002, ("%s to %s",
  9903. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9904. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9905. + }
  9906. + }
  9907. +
  9908. + for (int i=0; i<arr->length(); i++) {
  9909. +
  9910. + int j;
  9911. + for (j=i; j<arr->length(); j++) {
  9912. +
  9913. + int k;
  9914. + for (k=0; k<links->length(); k++) {
  9915. +
  9916. + klassOop k1 = links->adr_at(k)->right();
  9917. + klassOop k2 = arr->at(j)();
  9918. + if (k1 == k2) {
  9919. + break;
  9920. + }
  9921. + }
  9922. +
  9923. + if (k == links->length()) {
  9924. + break;
  9925. + }
  9926. + }
  9927. +
  9928. + if (j == arr->length()) {
  9929. + // circle detected
  9930. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9931. + }
  9932. +
  9933. + for (int k=0; k<links->length(); k++) {
  9934. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9935. + links->at_put(k, links->at(links->length() - 1));
  9936. + links->remove_at(links->length() - 1);
  9937. + k--;
  9938. + }
  9939. + }
  9940. +
  9941. + instanceKlassHandle tmp = arr->at(j);
  9942. + arr->at_put(j, arr->at(i));
  9943. + arr->at_put(i, tmp);
  9944. + }
  9945. +
  9946. + return JVMTI_ERROR_NONE;
  9947. +}
  9948. +
  9949. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9950. +
  9951. + if (_updated_oops != NULL) {
  9952. + for (int i=0; i<_updated_oops->length(); i++) {
  9953. + closure->do_oop(_updated_oops->adr_at(i));
  9954. + }
  9955. + }
  9956. +}
  9957. +
  9958. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9959. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9960. + to->set_is_field_access_watched(from->is_field_access_watched());
  9961. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9962. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  9963. + from->name()->as_C_string()));
  9964. + }
  9965. + update_klass_field_access_flag(to);
  9966. +}
  9967. +
  9968. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9969. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9970. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9971. + fi->set_access_flags(fd->access_flags().as_short());
  9972. +}
  9973. +
  9974. // This internal class transfers the native function registration from old methods
  9975. // to new methods. It is designed to handle both the simple case of unchanged
  9976. @@ -2969,7 +3161,7 @@
  9977. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9978. //
  9979. class TransferNativeFunctionRegistration {
  9980. - private:
  9981. +private:
  9982. instanceKlassHandle the_class;
  9983. int prefix_count;
  9984. char** prefixes;
  9985. @@ -2982,42 +3174,42 @@
  9986. // (2) with the prefix.
  9987. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9988. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9989. - Symbol* signature) {
  9990. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9991. - if (name_symbol != NULL) {
  9992. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9993. - if (method != NULL) {
  9994. - // Even if prefixed, intermediate methods must exist.
  9995. - if (method->is_native()) {
  9996. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9997. - return method;
  9998. - }
  9999. - if (depth < prefix_count) {
  10000. - // Try applying further prefixes (other than this one).
  10001. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10002. - if (method != NULL) {
  10003. - return method; // found
  10004. + Symbol* signature) {
  10005. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10006. + if (name_symbol != NULL) {
  10007. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10008. + if (method != NULL) {
  10009. + // Even if prefixed, intermediate methods must exist.
  10010. + if (method->is_native()) {
  10011. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10012. + return method;
  10013. }
  10014. + if (depth < prefix_count) {
  10015. + // Try applying further prefixes (other than this one).
  10016. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10017. + if (method != NULL) {
  10018. + return method; // found
  10019. + }
  10020. - // Try adding this prefix to the method name and see if it matches
  10021. - // another method name.
  10022. - char* prefix = prefixes[depth];
  10023. - size_t prefix_len = strlen(prefix);
  10024. - size_t trial_len = name_len + prefix_len;
  10025. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10026. - strcpy(trial_name_str, prefix);
  10027. - strcat(trial_name_str, name_str);
  10028. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10029. - signature);
  10030. - if (method != NULL) {
  10031. - // If found along this branch, it was prefixed, mark as such
  10032. - method->set_is_prefixed_native();
  10033. - return method; // found
  10034. + // Try adding this prefix to the method name and see if it matches
  10035. + // another method name.
  10036. + char* prefix = prefixes[depth];
  10037. + size_t prefix_len = strlen(prefix);
  10038. + size_t trial_len = name_len + prefix_len;
  10039. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10040. + strcpy(trial_name_str, prefix);
  10041. + strcat(trial_name_str, name_str);
  10042. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10043. + signature);
  10044. + if (method != NULL) {
  10045. + // If found along this branch, it was prefixed, mark as such
  10046. + method->set_is_prefixed_native();
  10047. + return method; // found
  10048. + }
  10049. }
  10050. }
  10051. }
  10052. - }
  10053. - return NULL; // This whole branch bore nothing
  10054. + return NULL; // This whole branch bore nothing
  10055. }
  10056. // Return the method name with old prefixes stripped away.
  10057. @@ -3042,10 +3234,10 @@
  10058. ResourceMark rm;
  10059. char* name_str = method_name_without_prefixes(method);
  10060. return search_prefix_name_space(0, name_str, strlen(name_str),
  10061. - method->signature());
  10062. + method->signature());
  10063. }
  10064. - public:
  10065. +public:
  10066. // Construct a native method transfer processor for this class.
  10067. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10068. @@ -3056,9 +3248,9 @@
  10069. }
  10070. // Attempt to transfer any of the old or deleted methods that are native
  10071. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  10072. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10073. for (int j = 0; j < methods_length; j++) {
  10074. - methodOop old_method = old_methods[j];
  10075. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10076. if (old_method->is_native() && old_method->has_native_function()) {
  10077. methodOop new_method = strip_and_search_for_new_native(old_method);
  10078. @@ -3067,7 +3259,9 @@
  10079. // Redefine does not send events (except CFLH), certainly not this
  10080. // behind the scenes re-registration.
  10081. new_method->set_native_function(old_method->native_function(),
  10082. - !methodOopDesc::native_bind_event_is_interesting);
  10083. + !methodOopDesc::native_bind_event_is_interesting);
  10084. +
  10085. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10086. }
  10087. }
  10088. }
  10089. @@ -3075,544 +3269,8 @@
  10090. };
  10091. // Don't lose the association between a native method and its JNI function.
  10092. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  10093. - TransferNativeFunctionRegistration transfer(the_class);
  10094. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  10095. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  10096. -}
  10097. -
  10098. -// Deoptimize all compiled code that depends on this class.
  10099. -//
  10100. -// If the can_redefine_classes capability is obtained in the onload
  10101. -// phase then the compiler has recorded all dependencies from startup.
  10102. -// In that case we need only deoptimize and throw away all compiled code
  10103. -// that depends on the class.
  10104. -//
  10105. -// If can_redefine_classes is obtained sometime after the onload
  10106. -// phase then the dependency information may be incomplete. In that case
  10107. -// the first call to RedefineClasses causes all compiled code to be
  10108. -// thrown away. As can_redefine_classes has been obtained then
  10109. -// all future compilations will record dependencies so second and
  10110. -// subsequent calls to RedefineClasses need only throw away code
  10111. -// that depends on the class.
  10112. -//
  10113. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  10114. - assert_locked_or_safepoint(Compile_lock);
  10115. -
  10116. - // All dependencies have been recorded from startup or this is a second or
  10117. - // subsequent use of RedefineClasses
  10118. - if (JvmtiExport::all_dependencies_are_recorded()) {
  10119. - Universe::flush_evol_dependents_on(k_h);
  10120. - } else {
  10121. - CodeCache::mark_all_nmethods_for_deoptimization();
  10122. -
  10123. - ResourceMark rm(THREAD);
  10124. - DeoptimizationMarker dm;
  10125. -
  10126. - // Deoptimize all activations depending on marked nmethods
  10127. - Deoptimization::deoptimize_dependents();
  10128. -
  10129. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  10130. - CodeCache::make_marked_nmethods_not_entrant();
  10131. -
  10132. - // From now on we know that the dependency information is complete
  10133. - JvmtiExport::set_all_dependencies_are_recorded(true);
  10134. - }
  10135. -}
  10136. -
  10137. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  10138. - methodOop old_method;
  10139. - methodOop new_method;
  10140. -
  10141. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10142. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10143. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  10144. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10145. -
  10146. - _matching_methods_length = 0;
  10147. - _deleted_methods_length = 0;
  10148. - _added_methods_length = 0;
  10149. -
  10150. - int nj = 0;
  10151. - int oj = 0;
  10152. - while (true) {
  10153. - if (oj >= _old_methods->length()) {
  10154. - if (nj >= _new_methods->length()) {
  10155. - break; // we've looked at everything, done
  10156. - }
  10157. - // New method at the end
  10158. - new_method = (methodOop) _new_methods->obj_at(nj);
  10159. - _added_methods[_added_methods_length++] = new_method;
  10160. - ++nj;
  10161. - } else if (nj >= _new_methods->length()) {
  10162. - // Old method, at the end, is deleted
  10163. - old_method = (methodOop) _old_methods->obj_at(oj);
  10164. - _deleted_methods[_deleted_methods_length++] = old_method;
  10165. - ++oj;
  10166. - } else {
  10167. - old_method = (methodOop) _old_methods->obj_at(oj);
  10168. - new_method = (methodOop) _new_methods->obj_at(nj);
  10169. - if (old_method->name() == new_method->name()) {
  10170. - if (old_method->signature() == new_method->signature()) {
  10171. - _matching_old_methods[_matching_methods_length ] = old_method;
  10172. - _matching_new_methods[_matching_methods_length++] = new_method;
  10173. - ++nj;
  10174. - ++oj;
  10175. - } else {
  10176. - // added overloaded have already been moved to the end,
  10177. - // so this is a deleted overloaded method
  10178. - _deleted_methods[_deleted_methods_length++] = old_method;
  10179. - ++oj;
  10180. - }
  10181. - } else { // names don't match
  10182. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10183. - // new method
  10184. - _added_methods[_added_methods_length++] = new_method;
  10185. - ++nj;
  10186. - } else {
  10187. - // deleted method
  10188. - _deleted_methods[_deleted_methods_length++] = old_method;
  10189. - ++oj;
  10190. - }
  10191. - }
  10192. - }
  10193. - }
  10194. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10195. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10196. -}
  10197. -
  10198. -
  10199. -
  10200. -// Install the redefinition of a class:
  10201. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10202. -// dependent compiled code)
  10203. -// - replacing parts in the_class with parts from scratch_class
  10204. -// - adding a weak reference to track the obsolete but interesting
  10205. -// parts of the_class
  10206. -// - adjusting constant pool caches and vtables in other classes
  10207. -// that refer to methods in the_class. These adjustments use the
  10208. -// SystemDictionary::classes_do() facility which only allows
  10209. -// a helper method to be specified. The interesting parameters
  10210. -// that we would like to pass to the helper method are saved in
  10211. -// static global fields in the VM operation.
  10212. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10213. - instanceKlassHandle scratch_class, TRAPS) {
  10214. -
  10215. - RC_TIMER_START(_timer_rsc_phase1);
  10216. -
  10217. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10218. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10219. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10220. -
  10221. - // Remove all breakpoints in methods of this class
  10222. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10223. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10224. -
  10225. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10226. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10227. - // cached and users of the cache care about each active version of
  10228. - // the method so we have to track this previous version.
  10229. - // Do this before methods get switched
  10230. - Universe::reflect_invoke_cache()->add_previous_version(
  10231. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10232. - }
  10233. -
  10234. - // Deoptimize all compiled code that depends on this class
  10235. - flush_dependent_code(the_class, THREAD);
  10236. -
  10237. - _old_methods = the_class->methods();
  10238. - _new_methods = scratch_class->methods();
  10239. - _the_class_oop = the_class_oop;
  10240. - compute_added_deleted_matching_methods();
  10241. - update_jmethod_ids();
  10242. -
  10243. - // Attach new constant pool to the original klass. The original
  10244. - // klass still refers to the old constant pool (for now).
  10245. - scratch_class->constants()->set_pool_holder(the_class());
  10246. -
  10247. -#if 0
  10248. - // In theory, with constant pool merging in place we should be able
  10249. - // to save space by using the new, merged constant pool in place of
  10250. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10251. - // the klass version we are replacing now and any constant pool(s) in
  10252. - // previous versions of klass. Nice theory, doesn't work in practice.
  10253. - // When this code is enabled, even simple programs throw NullPointer
  10254. - // exceptions. I'm guessing that this is caused by some constant pool
  10255. - // cache difference between the new, merged constant pool and the
  10256. - // constant pool that was just being used by the klass. I'm keeping
  10257. - // this code around to archive the idea, but the code has to remain
  10258. - // disabled for now.
  10259. -
  10260. - // Attach each old method to the new constant pool. This can be
  10261. - // done here since we are past the bytecode verification and
  10262. - // constant pool optimization phases.
  10263. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10264. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10265. - method->set_constants(scratch_class->constants());
  10266. - }
  10267. -
  10268. - {
  10269. - // walk all previous versions of the klass
  10270. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10271. - PreviousVersionWalker pvw(ik);
  10272. - instanceKlassHandle ikh;
  10273. - do {
  10274. - ikh = pvw.next_previous_version();
  10275. - if (!ikh.is_null()) {
  10276. - ik = ikh();
  10277. -
  10278. - // attach previous version of klass to the new constant pool
  10279. - ik->set_constants(scratch_class->constants());
  10280. -
  10281. - // Attach each method in the previous version of klass to the
  10282. - // new constant pool
  10283. - objArrayOop prev_methods = ik->methods();
  10284. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10285. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10286. - method->set_constants(scratch_class->constants());
  10287. - }
  10288. - }
  10289. - } while (!ikh.is_null());
  10290. - }
  10291. -#endif
  10292. -
  10293. - // Replace methods and constantpool
  10294. - the_class->set_methods(_new_methods);
  10295. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10296. - // and to be able to undo operation easily.
  10297. -
  10298. - constantPoolOop old_constants = the_class->constants();
  10299. - the_class->set_constants(scratch_class->constants());
  10300. - scratch_class->set_constants(old_constants); // See the previous comment.
  10301. -#if 0
  10302. - // We are swapping the guts of "the new class" with the guts of "the
  10303. - // class". Since the old constant pool has just been attached to "the
  10304. - // new class", it seems logical to set the pool holder in the old
  10305. - // constant pool also. However, doing this will change the observable
  10306. - // class hierarchy for any old methods that are still executing. A
  10307. - // method can query the identity of its "holder" and this query uses
  10308. - // the method's constant pool link to find the holder. The change in
  10309. - // holding class from "the class" to "the new class" can confuse
  10310. - // things.
  10311. - //
  10312. - // Setting the old constant pool's holder will also cause
  10313. - // verification done during vtable initialization below to fail.
  10314. - // During vtable initialization, the vtable's class is verified to be
  10315. - // a subtype of the method's holder. The vtable's class is "the
  10316. - // class" and the method's holder is gotten from the constant pool
  10317. - // link in the method itself. For "the class"'s directly implemented
  10318. - // methods, the method holder is "the class" itself (as gotten from
  10319. - // the new constant pool). The check works fine in this case. The
  10320. - // check also works fine for methods inherited from super classes.
  10321. - //
  10322. - // Miranda methods are a little more complicated. A miranda method is
  10323. - // provided by an interface when the class implementing the interface
  10324. - // does not provide its own method. These interfaces are implemented
  10325. - // internally as an instanceKlass. These special instanceKlasses
  10326. - // share the constant pool of the class that "implements" the
  10327. - // interface. By sharing the constant pool, the method holder of a
  10328. - // miranda method is the class that "implements" the interface. In a
  10329. - // non-redefine situation, the subtype check works fine. However, if
  10330. - // the old constant pool's pool holder is modified, then the check
  10331. - // fails because there is no class hierarchy relationship between the
  10332. - // vtable's class and "the new class".
  10333. -
  10334. - old_constants->set_pool_holder(scratch_class());
  10335. -#endif
  10336. -
  10337. - // track which methods are EMCP for add_previous_version() call below
  10338. - BitMap emcp_methods(_old_methods->length());
  10339. - int emcp_method_count = 0;
  10340. - emcp_methods.clear(); // clears 0..(length() - 1)
  10341. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10342. - transfer_old_native_function_registrations(the_class);
  10343. -
  10344. - // The class file bytes from before any retransformable agents mucked
  10345. - // with them was cached on the scratch class, move to the_class.
  10346. - // Note: we still want to do this if nothing needed caching since it
  10347. - // should get cleared in the_class too.
  10348. - if (the_class->get_cached_class_file_bytes() == 0) {
  10349. - // the_class doesn't have a cache yet so copy it
  10350. - the_class->set_cached_class_file(
  10351. - scratch_class->get_cached_class_file_bytes(),
  10352. - scratch_class->get_cached_class_file_len());
  10353. - }
  10354. -#ifndef PRODUCT
  10355. - else {
  10356. - assert(the_class->get_cached_class_file_bytes() ==
  10357. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10358. - assert(the_class->get_cached_class_file_len() ==
  10359. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10360. - }
  10361. -#endif
  10362. -
  10363. - // Replace inner_classes
  10364. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10365. - the_class->set_inner_classes(scratch_class->inner_classes());
  10366. - scratch_class->set_inner_classes(old_inner_classes);
  10367. -
  10368. - // Initialize the vtable and interface table after
  10369. - // methods have been rewritten
  10370. - {
  10371. - ResourceMark rm(THREAD);
  10372. - // no exception should happen here since we explicitly
  10373. - // do not check loader constraints.
  10374. - // compare_and_normalize_class_versions has already checked:
  10375. - // - classloaders unchanged, signatures unchanged
  10376. - // - all instanceKlasses for redefined classes reused & contents updated
  10377. - the_class->vtable()->initialize_vtable(false, THREAD);
  10378. - the_class->itable()->initialize_itable(false, THREAD);
  10379. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10380. - }
  10381. -
  10382. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10383. -
  10384. - // Copy the "source file name" attribute from new class version
  10385. - the_class->set_source_file_name(scratch_class->source_file_name());
  10386. -
  10387. - // Copy the "source debug extension" attribute from new class version
  10388. - the_class->set_source_debug_extension(
  10389. - scratch_class->source_debug_extension(),
  10390. - scratch_class->source_debug_extension() == NULL ? 0 :
  10391. - (int)strlen(scratch_class->source_debug_extension()));
  10392. -
  10393. - // Use of javac -g could be different in the old and the new
  10394. - if (scratch_class->access_flags().has_localvariable_table() !=
  10395. - the_class->access_flags().has_localvariable_table()) {
  10396. -
  10397. - AccessFlags flags = the_class->access_flags();
  10398. - if (scratch_class->access_flags().has_localvariable_table()) {
  10399. - flags.set_has_localvariable_table();
  10400. - } else {
  10401. - flags.clear_has_localvariable_table();
  10402. - }
  10403. - the_class->set_access_flags(flags);
  10404. - }
  10405. -
  10406. - // Replace class annotation fields values
  10407. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10408. - the_class->set_class_annotations(scratch_class->class_annotations());
  10409. - scratch_class->set_class_annotations(old_class_annotations);
  10410. -
  10411. - // Replace fields annotation fields values
  10412. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10413. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10414. - scratch_class->set_fields_annotations(old_fields_annotations);
  10415. -
  10416. - // Replace methods annotation fields values
  10417. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10418. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10419. - scratch_class->set_methods_annotations(old_methods_annotations);
  10420. -
  10421. - // Replace methods parameter annotation fields values
  10422. - objArrayOop old_methods_parameter_annotations =
  10423. - the_class->methods_parameter_annotations();
  10424. - the_class->set_methods_parameter_annotations(
  10425. - scratch_class->methods_parameter_annotations());
  10426. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10427. -
  10428. - // Replace methods default annotation fields values
  10429. - objArrayOop old_methods_default_annotations =
  10430. - the_class->methods_default_annotations();
  10431. - the_class->set_methods_default_annotations(
  10432. - scratch_class->methods_default_annotations());
  10433. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10434. -
  10435. - // Replace minor version number of class file
  10436. - u2 old_minor_version = the_class->minor_version();
  10437. - the_class->set_minor_version(scratch_class->minor_version());
  10438. - scratch_class->set_minor_version(old_minor_version);
  10439. -
  10440. - // Replace major version number of class file
  10441. - u2 old_major_version = the_class->major_version();
  10442. - the_class->set_major_version(scratch_class->major_version());
  10443. - scratch_class->set_major_version(old_major_version);
  10444. -
  10445. - // Replace CP indexes for class and name+type of enclosing method
  10446. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10447. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10448. - the_class->set_enclosing_method_indices(
  10449. - scratch_class->enclosing_method_class_index(),
  10450. - scratch_class->enclosing_method_method_index());
  10451. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10452. -
  10453. - // keep track of previous versions of this class
  10454. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10455. - emcp_method_count);
  10456. -
  10457. - RC_TIMER_STOP(_timer_rsc_phase1);
  10458. - RC_TIMER_START(_timer_rsc_phase2);
  10459. -
  10460. - // Adjust constantpool caches and vtables for all classes
  10461. - // that reference methods of the evolved class.
  10462. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10463. -
  10464. - // JSR-292 support
  10465. - MemberNameTable* mnt = the_class->member_names();
  10466. - if (mnt != NULL) {
  10467. - bool trace_name_printed = false;
  10468. - mnt->adjust_method_entries(_matching_old_methods,
  10469. - _matching_new_methods,
  10470. - _matching_methods_length,
  10471. - &trace_name_printed);
  10472. - }
  10473. -
  10474. - if (the_class->oop_map_cache() != NULL) {
  10475. - // Flush references to any obsolete methods from the oop map cache
  10476. - // so that obsolete methods are not pinned.
  10477. - the_class->oop_map_cache()->flush_obsolete_entries();
  10478. - }
  10479. -
  10480. - // increment the classRedefinedCount field in the_class and in any
  10481. - // direct and indirect subclasses of the_class
  10482. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10483. -
  10484. - // RC_TRACE macro has an embedded ResourceMark
  10485. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10486. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10487. - the_class->external_name(),
  10488. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10489. - os::available_memory() >> 10));
  10490. -
  10491. - RC_TIMER_STOP(_timer_rsc_phase2);
  10492. -} // end redefine_single_class()
  10493. -
  10494. -
  10495. -// Increment the classRedefinedCount field in the specific instanceKlass
  10496. -// and in all direct and indirect subclasses.
  10497. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10498. - oop class_mirror = ik->java_mirror();
  10499. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10500. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10501. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10502. -
  10503. - if (class_oop != _the_class_oop) {
  10504. - // _the_class_oop count is printed at end of redefine_single_class()
  10505. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10506. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10507. - }
  10508. -
  10509. - for (Klass *subk = ik->subklass(); subk != NULL;
  10510. - subk = subk->next_sibling()) {
  10511. - if (subk->oop_is_instance()) {
  10512. - // Only update instanceKlasses
  10513. - instanceKlass *subik = (instanceKlass*)subk;
  10514. - // recursively do subclasses of the current subclass
  10515. - increment_class_counter(subik, THREAD);
  10516. - }
  10517. - }
  10518. -}
  10519. -
  10520. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10521. - oop initiating_loader, TRAPS) {
  10522. - Klass *k = k_oop->klass_part();
  10523. - if (k->oop_is_instance()) {
  10524. - HandleMark hm(THREAD);
  10525. - instanceKlass *ik = (instanceKlass *) k;
  10526. - bool no_old_methods = true; // be optimistic
  10527. - ResourceMark rm(THREAD);
  10528. -
  10529. - // a vtable should never contain old or obsolete methods
  10530. - if (ik->vtable_length() > 0 &&
  10531. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  10532. - if (RC_TRACE_ENABLED(0x00004000)) {
  10533. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10534. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  10535. - " -- OLD or OBSOLETE method found -- class: %s",
  10536. - ik->signature_name()));
  10537. - ik->vtable()->dump_vtable();
  10538. - }
  10539. - no_old_methods = false;
  10540. - }
  10541. -
  10542. - // an itable should never contain old or obsolete methods
  10543. - if (ik->itable_length() > 0 &&
  10544. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  10545. - if (RC_TRACE_ENABLED(0x00004000)) {
  10546. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10547. - ("klassItable::check_no_old_or_obsolete_entries failure"
  10548. - " -- OLD or OBSOLETE method found -- class: %s",
  10549. - ik->signature_name()));
  10550. - ik->itable()->dump_itable();
  10551. - }
  10552. - no_old_methods = false;
  10553. - }
  10554. -
  10555. - // the constant pool cache should never contain old or obsolete methods
  10556. - if (ik->constants() != NULL &&
  10557. - ik->constants()->cache() != NULL &&
  10558. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  10559. - if (RC_TRACE_ENABLED(0x00004000)) {
  10560. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10561. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  10562. - " -- OLD or OBSOLETE method found -- class: %s",
  10563. - ik->signature_name()));
  10564. - ik->constants()->cache()->dump_cache();
  10565. - }
  10566. - no_old_methods = false;
  10567. - }
  10568. -
  10569. - if (!no_old_methods) {
  10570. - if (RC_TRACE_ENABLED(0x00004000)) {
  10571. - dump_methods();
  10572. - } else {
  10573. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  10574. - "to see more info about the following guarantee() failure.");
  10575. - }
  10576. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10577. - }
  10578. - }
  10579. -}
  10580. -
  10581. -void VM_RedefineClasses::dump_methods() {
  10582. - int j;
  10583. - RC_TRACE(0x00004000, ("_old_methods --"));
  10584. - for (j = 0; j < _old_methods->length(); ++j) {
  10585. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10586. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10587. - m->access_flags().print_on(tty);
  10588. - tty->print(" -- ");
  10589. - m->print_name(tty);
  10590. - tty->cr();
  10591. - }
  10592. - RC_TRACE(0x00004000, ("_new_methods --"));
  10593. - for (j = 0; j < _new_methods->length(); ++j) {
  10594. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10595. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10596. - m->access_flags().print_on(tty);
  10597. - tty->print(" -- ");
  10598. - m->print_name(tty);
  10599. - tty->cr();
  10600. - }
  10601. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10602. - for (j = 0; j < _matching_methods_length; ++j) {
  10603. - methodOop m = _matching_old_methods[j];
  10604. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10605. - m->access_flags().print_on(tty);
  10606. - tty->print(" -- ");
  10607. - m->print_name(tty);
  10608. - tty->cr();
  10609. - m = _matching_new_methods[j];
  10610. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10611. - m->access_flags().print_on(tty);
  10612. - tty->cr();
  10613. - }
  10614. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10615. - for (j = 0; j < _deleted_methods_length; ++j) {
  10616. - methodOop m = _deleted_methods[j];
  10617. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10618. - m->access_flags().print_on(tty);
  10619. - tty->print(" -- ");
  10620. - m->print_name(tty);
  10621. - tty->cr();
  10622. - }
  10623. - RC_TRACE(0x00004000, ("_added_methods --"));
  10624. - for (j = 0; j < _added_methods_length; ++j) {
  10625. - methodOop m = _added_methods[j];
  10626. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10627. - m->access_flags().print_on(tty);
  10628. - tty->print(" -- ");
  10629. - m->print_name(tty);
  10630. - tty->cr();
  10631. - }
  10632. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10633. + TransferNativeFunctionRegistration transfer(old_klass);
  10634. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10635. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10636. }
  10637. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10638. index bfac62c..d7ba79f 100644
  10639. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10640. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10641. @@ -1,26 +1,29 @@
  10642. /*
  10643. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10644. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10645. - *
  10646. - * This code is free software; you can redistribute it and/or modify it
  10647. - * under the terms of the GNU General Public License version 2 only, as
  10648. - * published by the Free Software Foundation.
  10649. - *
  10650. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10651. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10652. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10653. - * version 2 for more details (a copy is included in the LICENSE file that
  10654. - * accompanied this code).
  10655. - *
  10656. - * You should have received a copy of the GNU General Public License version
  10657. - * 2 along with this work; if not, write to the Free Software Foundation,
  10658. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10659. - *
  10660. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10661. - * or visit www.oracle.com if you need additional information or have any
  10662. - * questions.
  10663. - *
  10664. - */
  10665. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10666. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10667. +*
  10668. +* This code is free software; you can redistribute it and/or modify it
  10669. +* under the terms of the GNU General Public License version 2 only, as
  10670. +* published by the Free Software Foundation.
  10671. +*
  10672. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10673. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10674. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10675. +* version 2 for more details (a copy is included in the LICENSE file that
  10676. +* accompanied this code).
  10677. +*
  10678. +* You should have received a copy of the GNU General Public License version
  10679. +* 2 along with this work; if not, write to the Free Software Foundation,
  10680. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10681. +*
  10682. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10683. +* or visit www.oracle.com if you need additional information or have any
  10684. +* questions.
  10685. +*
  10686. +*/
  10687. +
  10688. +// New version that allows arbitrary changes to already loaded classes.
  10689. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10690. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10691. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10692. @@ -32,330 +35,27 @@
  10693. #include "oops/objArrayOop.hpp"
  10694. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10695. #include "runtime/vm_operations.hpp"
  10696. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10697. -// Introduction:
  10698. -//
  10699. -// The RedefineClasses() API is used to change the definition of one or
  10700. -// more classes. While the API supports redefining more than one class
  10701. -// in a single call, in general, the API is discussed in the context of
  10702. -// changing the definition of a single current class to a single new
  10703. -// class. For clarity, the current class is will always be called
  10704. -// "the_class" and the new class will always be called "scratch_class".
  10705. -//
  10706. -// The name "the_class" is used because there is only one structure
  10707. -// that represents a specific class; redefinition does not replace the
  10708. -// structure, but instead replaces parts of the structure. The name
  10709. -// "scratch_class" is used because the structure that represents the
  10710. -// new definition of a specific class is simply used to carry around
  10711. -// the parts of the new definition until they are used to replace the
  10712. -// appropriate parts in the_class. Once redefinition of a class is
  10713. -// complete, scratch_class is thrown away.
  10714. -//
  10715. -//
  10716. -// Implementation Overview:
  10717. -//
  10718. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10719. -// does the real work. The work is split in varying degrees between
  10720. -// doit_prologue(), doit() and doit_epilogue().
  10721. -//
  10722. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10723. -// safepoint. It does parameter verification and loads scratch_class
  10724. -// which involves:
  10725. -// - parsing the incoming class definition using the_class' class
  10726. -// loader and security context
  10727. -// - linking scratch_class
  10728. -// - merging constant pools and rewriting bytecodes as needed
  10729. -// for the merged constant pool
  10730. -// - verifying the bytecodes in scratch_class
  10731. -// - setting up the constant pool cache and rewriting bytecodes
  10732. -// as needed to use the cache
  10733. -// - finally, scratch_class is compared to the_class to verify
  10734. -// that it is a valid replacement class
  10735. -// - if everything is good, then scratch_class is saved in an
  10736. -// instance field in the VM operation for the doit() call
  10737. -//
  10738. -// Note: A JavaThread must do the above work.
  10739. -//
  10740. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10741. -// the new class definition(s) which involves:
  10742. -// - retrieving the scratch_class from the instance field in the
  10743. -// VM operation
  10744. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10745. -// dependent compiled code)
  10746. -// - replacing parts in the_class with parts from scratch_class
  10747. -// - adding weak reference(s) to track the obsolete but interesting
  10748. -// parts of the_class
  10749. -// - adjusting constant pool caches and vtables in other classes
  10750. -// that refer to methods in the_class. These adjustments use the
  10751. -// SystemDictionary::classes_do() facility which only allows
  10752. -// a helper method to be specified. The interesting parameters
  10753. -// that we would like to pass to the helper method are saved in
  10754. -// static global fields in the VM operation.
  10755. -// - telling the SystemDictionary to notice our changes
  10756. -//
  10757. -// Note: the above work must be done by the VMThread to be safe.
  10758. -//
  10759. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10760. -// is finished and the safepoint is done. It simply cleans up
  10761. -// memory allocated in doit_prologue() and used in doit().
  10762. -//
  10763. -//
  10764. -// Constant Pool Details:
  10765. -//
  10766. -// When the_class is redefined, we cannot just replace the constant
  10767. -// pool in the_class with the constant pool from scratch_class because
  10768. -// that could confuse obsolete methods that may still be running.
  10769. -// Instead, the constant pool from the_class, old_cp, is merged with
  10770. -// the constant pool from scratch_class, scratch_cp. The resulting
  10771. -// constant pool, merge_cp, replaces old_cp in the_class.
  10772. -//
  10773. -// The key part of any merging algorithm is the entry comparison
  10774. -// function so we have to know the types of entries in a constant pool
  10775. -// in order to merge two of them together. Constant pools can contain
  10776. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10777. -// is not presently used so we only have to worry about the other 11
  10778. -// entry types. For the purposes of constant pool merging, it is
  10779. -// helpful to know that the 11 entry types fall into 3 different
  10780. -// subtypes: "direct", "indirect" and "double-indirect".
  10781. -//
  10782. -// Direct CP entries contain data and do not contain references to
  10783. -// other CP entries. The following are direct CP entries:
  10784. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10785. -//
  10786. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10787. -// and no other data. The following are indirect CP entries:
  10788. -// JVM_CONSTANT_{Class,NameAndType,String}
  10789. -//
  10790. -// Double-indirect CP entries contain two references to indirect CP
  10791. -// entries and no other data. The following are double-indirect CP
  10792. -// entries:
  10793. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10794. -//
  10795. -// When comparing entries between two constant pools, the entry types
  10796. -// are compared first and if they match, then further comparisons are
  10797. -// made depending on the entry subtype. Comparing direct CP entries is
  10798. -// simply a matter of comparing the data associated with each entry.
  10799. -// Comparing both indirect and double-indirect CP entries requires
  10800. -// recursion.
  10801. -//
  10802. -// Fortunately, the recursive combinations are limited because indirect
  10803. -// CP entries can only refer to direct CP entries and double-indirect
  10804. -// CP entries can only refer to indirect CP entries. The following is
  10805. -// an example illustration of the deepest set of indirections needed to
  10806. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10807. -//
  10808. -// JVM_CONSTANT_Fieldref {
  10809. -// class_index => JVM_CONSTANT_Class {
  10810. -// name_index => JVM_CONSTANT_Utf8 {
  10811. -// <data-1>
  10812. -// }
  10813. -// }
  10814. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10815. -// name_index => JVM_CONSTANT_Utf8 {
  10816. -// <data-2>
  10817. -// }
  10818. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10819. -// <data-3>
  10820. -// }
  10821. -// }
  10822. -// }
  10823. -//
  10824. -// The above illustration is not a data structure definition for any
  10825. -// computer language. The curly braces ('{' and '}') are meant to
  10826. -// delimit the context of the "fields" in the CP entry types shown.
  10827. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10828. -// "=>", e.g., the class_index is used to indirectly reference a
  10829. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10830. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10831. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10832. -// have to do a total of 5 indirections just to get to the CP entries
  10833. -// that contain the interesting pieces of data and then we have to
  10834. -// fetch the three pieces of data. This means we have to do a total of
  10835. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10836. -// entries.
  10837. -//
  10838. -// Here is the indirection, data and dereference count for each entry
  10839. -// type:
  10840. -//
  10841. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10842. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10843. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10844. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10845. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10846. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10847. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10848. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10849. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10850. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10851. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10852. -//
  10853. -// So different subtypes of CP entries require different amounts of
  10854. -// work for a proper comparison.
  10855. -//
  10856. -// Now that we've talked about the different entry types and how to
  10857. -// compare them we need to get back to merging. This is not a merge in
  10858. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10859. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10860. -// preserving entry order. Next we append all the unique entries from
  10861. -// scratch_cp to merge_cp and we track the index changes from the
  10862. -// location in scratch_cp to the possibly new location in merge_cp.
  10863. -// When we are done, any obsolete code that is still running that
  10864. -// uses old_cp should not be able to observe any difference if it
  10865. -// were to use merge_cp. As for the new code in scratch_class, it is
  10866. -// modified to use the appropriate index values in merge_cp before it
  10867. -// is used to replace the code in the_class.
  10868. -//
  10869. -// There is one small complication in copying the entries from old_cp
  10870. -// to merge_cp. Two of the CP entry types are special in that they are
  10871. -// lazily resolved. Before explaining the copying complication, we need
  10872. -// to digress into CP entry resolution.
  10873. -//
  10874. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10875. -// the class file, but are not stored in memory as such until they are
  10876. -// resolved. The entries are not resolved unless they are used because
  10877. -// resolution is expensive. During class file parsing the entries are
  10878. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10879. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10880. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10881. -// have been parsed, but the index values in the entries have not been
  10882. -// validated. After the entire constant pool has been parsed, the index
  10883. -// values can be validated and then the entries are converted into
  10884. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10885. -// entries. During this conversion process, the UTF8 values that are
  10886. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10887. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10888. -// entries are modified to refer to the Symbol*s. This optimization
  10889. -// eliminates one level of indirection for those two CP entry types and
  10890. -// gets the entries ready for verification. During class file parsing
  10891. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10892. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10893. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10894. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10895. -// entries.
  10896. -//
  10897. -// Now we can get back to the copying complication. When we copy
  10898. -// entries from old_cp to merge_cp, we have to revert any
  10899. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10900. -// or verification will fail.
  10901. -//
  10902. -// It is important to explicitly state that the merging algorithm
  10903. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10904. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10905. -// entries in the merge_cp. This is done both to make verification
  10906. -// happy and to avoid adding more brittleness between RedefineClasses
  10907. -// and the constant pool cache. By allowing the constant pool cache
  10908. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10909. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10910. -// about those algorithms in RedefineClasses.
  10911. -//
  10912. -// Appending unique entries from scratch_cp to merge_cp is straight
  10913. -// forward for direct CP entries and most indirect CP entries. For the
  10914. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10915. -// indirect CP entry types, the presence of more than one piece of
  10916. -// interesting data makes appending the entries more complicated.
  10917. -//
  10918. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10919. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10920. -// If the index in scratch_cp is different than the destination index
  10921. -// in merge_cp, then the change in index value is tracked.
  10922. -//
  10923. -// Note: the above discussion for the direct CP entries also applies
  10924. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10925. -//
  10926. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10927. -// one data element at the end of the recursion, we know that we have
  10928. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10929. -// unique then it is appended to merge_cp before the current entry.
  10930. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10931. -// is updated to refer to the duplicate entry in merge_cp before it is
  10932. -// appended to merge_cp. Again, any changes in index values are tracked
  10933. -// as needed.
  10934. -//
  10935. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10936. -// types is theoretical. Since those entry types have already been
  10937. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10938. -// they are handled as direct CP entries.
  10939. -//
  10940. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10941. -// data elements at the end of the recursions, we know that we have
  10942. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10943. -// entries are appended to merge_cp before the current entry. For any
  10944. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10945. -// updated to refer to the duplicate entry in merge_cp before it is
  10946. -// appended to merge_cp. Again, any changes in index values are tracked
  10947. -// as needed.
  10948. -//
  10949. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10950. -// types, since there are two indirect CP entries and three data
  10951. -// elements at the end of the recursions, we know that we have between
  10952. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10953. -// above for an example of all six entries. The uniqueness algorithm
  10954. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10955. -// covered above. Any unique entries are appended to merge_cp before
  10956. -// the current entry. For any entries that are not unique, the current
  10957. -// entry is updated to refer to the duplicate entry in merge_cp before
  10958. -// it is appended to merge_cp. Again, any changes in index values are
  10959. -// tracked as needed.
  10960. -//
  10961. -//
  10962. -// Other Details:
  10963. -//
  10964. -// Details for other parts of RedefineClasses need to be written.
  10965. -// This is a placeholder section.
  10966. -//
  10967. -//
  10968. -// Open Issues (in no particular order):
  10969. -//
  10970. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10971. -//
  10972. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10973. -// domain since the initial version. This has been changed to pass
  10974. -// the_class->protection_domain(). This change has been tested with
  10975. -// all NSK tests and nothing broke, but what will adding it now break
  10976. -// in ways that we don't test?
  10977. -//
  10978. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10979. -// (indirect) use of the Relocator class that the max instruction
  10980. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10981. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10982. -// what it does to the bytecodes. More investigation is needed.
  10983. -//
  10984. -// - java.lang.Object methods can be called on arrays. This is
  10985. -// implemented via the arrayKlassOop vtable which we don't
  10986. -// update. For example, if we redefine java.lang.Object.toString(),
  10987. -// then the new version of the method will not be called for array
  10988. -// objects.
  10989. -//
  10990. -// - How do we know if redefine_single_class() and the guts of
  10991. -// instanceKlass are out of sync? I don't think this can be
  10992. -// automated, but we should probably order the work in
  10993. -// redefine_single_class() to match the order of field
  10994. -// definitions in instanceKlass. We also need to add some
  10995. -// comments about keeping things in sync.
  10996. -//
  10997. -// - set_new_constant_pool() is huge and we should consider refactoring
  10998. -// it into smaller chunks of work.
  10999. -//
  11000. -// - The exception table update code in set_new_constant_pool() defines
  11001. -// const values that are also defined in a local context elsewhere.
  11002. -// The same literal values are also used in elsewhere. We need to
  11003. -// coordinate a cleanup of these constants with Runtime.
  11004. -//
  11005. +#define RC_ABORT(error) { _result = error; return false; }
  11006. -class VM_RedefineClasses: public VM_Operation {
  11007. +class VM_RedefineClasses: public VM_GC_Operation {
  11008. private:
  11009. +
  11010. // These static fields are needed by SystemDictionary::classes_do()
  11011. // facility and the adjust_cpool_cache_and_vtable() helper:
  11012. static objArrayOop _old_methods;
  11013. static objArrayOop _new_methods;
  11014. - static methodOop* _matching_old_methods;
  11015. - static methodOop* _matching_new_methods;
  11016. - static methodOop* _deleted_methods;
  11017. - static methodOop* _added_methods;
  11018. + static int* _matching_old_methods;
  11019. + static int* _matching_new_methods;
  11020. + static int* _deleted_methods;
  11021. + static int* _added_methods;
  11022. static int _matching_methods_length;
  11023. static int _deleted_methods_length;
  11024. static int _added_methods_length;
  11025. static klassOop _the_class_oop;
  11026. +
  11027. + static int _revision_number;
  11028. // The instance fields are used to pass information from
  11029. // doit_prologue() to doit() and doit_epilogue().
  11030. @@ -370,42 +70,28 @@
  11031. // _index_map_p contains any entries.
  11032. int _index_map_count;
  11033. intArray * _index_map_p;
  11034. -
  11035. - // _operands_index_map_count is just an optimization for knowing if
  11036. - // _operands_index_map_p contains any entries.
  11037. - int _operands_cur_length;
  11038. - int _operands_index_map_count;
  11039. - intArray * _operands_index_map_p;
  11040. -
  11041. - // ptr to _class_count scratch_classes
  11042. - instanceKlassHandle * _scratch_classes;
  11043. - jvmtiError _res;
  11044. + GrowableArray<instanceKlassHandle>* _new_classes;
  11045. + GrowableArray<oop>* _updated_oops;
  11046. + jvmtiError _result;
  11047. + int _max_redefinition_flags;
  11048. // Performance measurement support. These timers do not cover all
  11049. // the work done for JVM/TI RedefineClasses() but they do cover
  11050. // the heavy lifting.
  11051. - elapsedTimer _timer_rsc_phase1;
  11052. - elapsedTimer _timer_rsc_phase2;
  11053. - elapsedTimer _timer_vm_op_prologue;
  11054. + elapsedTimer _timer_total;
  11055. + elapsedTimer _timer_prologue;
  11056. + elapsedTimer _timer_class_linking;
  11057. + elapsedTimer _timer_class_loading;
  11058. + elapsedTimer _timer_check_type;
  11059. + elapsedTimer _timer_prepare_redefinition;
  11060. + elapsedTimer _timer_wait_for_locks;
  11061. + elapsedTimer _timer_redefinition;
  11062. + elapsedTimer _timer_vm_op_epilogue;
  11063. - // These routines are roughly in call order unless otherwise noted.
  11064. -
  11065. - // Load the caller's new class definition(s) into _scratch_classes.
  11066. - // Constant pool merging work is done here as needed. Also calls
  11067. - // compare_and_normalize_class_versions() to verify the class
  11068. - // definition(s).
  11069. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  11070. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  11071. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  11072. jvmtiError load_new_class_versions(TRAPS);
  11073. -
  11074. - // Verify that the caller provided class definition(s) that meet
  11075. - // the restrictions of RedefineClasses. Normalize the order of
  11076. - // overloaded methods as needed.
  11077. - jvmtiError compare_and_normalize_class_versions(
  11078. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  11079. -
  11080. - // Swap annotations[i] with annotations[j]
  11081. - // Used by compare_and_normalize_class_versions() when normalizing
  11082. - // overloaded methods or changing idnum as when adding or deleting methods.
  11083. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  11084. // Figure out which new methods match old methods in name and signature,
  11085. // which methods have been added, and which are no longer present
  11086. @@ -414,103 +100,99 @@
  11087. // Change jmethodIDs to point to the new methods
  11088. void update_jmethod_ids();
  11089. - // In addition to marking methods as obsolete, this routine
  11090. - // records which methods are EMCP (Equivalent Module Constant
  11091. - // Pool) in the emcp_methods BitMap and returns the number of
  11092. - // EMCP methods via emcp_method_count_p. This information is
  11093. - // used when information about the previous version of the_class
  11094. - // is squirreled away.
  11095. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  11096. - int * emcp_method_count_p);
  11097. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11098. + class FindAffectedKlassesClosure : public ObjectClosure {
  11099. - // Unevolving classes may point to methods of the_class directly
  11100. - // from their constant pool caches, itables, and/or vtables. We
  11101. - // use the SystemDictionary::classes_do() facility and this helper
  11102. - // to fix up these pointers.
  11103. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  11104. + private:
  11105. + GrowableArray<instanceKlassHandle> *_original_klasses;
  11106. + GrowableArray<instanceKlassHandle> *_result;
  11107. +
  11108. + public:
  11109. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  11110. +
  11111. + virtual void do_object(oop obj);
  11112. + };
  11113. +
  11114. +
  11115. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  11116. // Install the redefinition of a class
  11117. - void redefine_single_class(jclass the_jclass,
  11118. - instanceKlassHandle scratch_class, TRAPS);
  11119. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  11120. // Increment the classRedefinedCount field in the specific instanceKlass
  11121. // and in all direct and indirect subclasses.
  11122. void increment_class_counter(instanceKlass *ik, TRAPS);
  11123. - // Support for constant pool merging (these routines are in alpha order):
  11124. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  11125. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11126. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11127. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11128. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  11129. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  11130. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11131. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11132. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11133. - int find_new_index(int old_index);
  11134. - int find_new_operand_index(int old_bootstrap_spec_index);
  11135. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  11136. - constantPoolHandle cp2, int index2);
  11137. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  11138. - constantPoolHandle cp2, int index2);
  11139. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  11140. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  11141. - bool merge_constant_pools(constantPoolHandle old_cp,
  11142. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  11143. - int *merge_cp_length_p, TRAPS);
  11144. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  11145. - instanceKlassHandle scratch_class, TRAPS);
  11146. - u2 rewrite_cp_ref_in_annotation_data(
  11147. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  11148. - const char * trace_mesg, TRAPS);
  11149. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  11150. - bool rewrite_cp_refs_in_annotation_struct(
  11151. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11152. - bool rewrite_cp_refs_in_annotations_typeArray(
  11153. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  11154. - bool rewrite_cp_refs_in_class_annotations(
  11155. - instanceKlassHandle scratch_class, TRAPS);
  11156. - bool rewrite_cp_refs_in_element_value(
  11157. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11158. - bool rewrite_cp_refs_in_fields_annotations(
  11159. - instanceKlassHandle scratch_class, TRAPS);
  11160. - void rewrite_cp_refs_in_method(methodHandle method,
  11161. - methodHandle * new_method_p, TRAPS);
  11162. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  11163. - bool rewrite_cp_refs_in_methods_annotations(
  11164. - instanceKlassHandle scratch_class, TRAPS);
  11165. - bool rewrite_cp_refs_in_methods_default_annotations(
  11166. - instanceKlassHandle scratch_class, TRAPS);
  11167. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  11168. - instanceKlassHandle scratch_class, TRAPS);
  11169. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  11170. - void rewrite_cp_refs_in_verification_type_info(
  11171. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  11172. - u1 frame_size, TRAPS);
  11173. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  11174. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  11175. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  11176. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  11177. - static void dump_methods();
  11178. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  11179. +
  11180. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  11181. +
  11182. +#ifdef ASSERT
  11183. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  11184. +#endif
  11185. +
  11186. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  11187. + void calculate_instance_update_information(klassOop new_version);
  11188. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  11189. +
  11190. + static void calculate_type_check_information(klassOop k);
  11191. + static void clear_type_check_information(klassOop k);
  11192. public:
  11193. - VM_RedefineClasses(jint class_count,
  11194. - const jvmtiClassDefinition *class_defs,
  11195. - JvmtiClassLoadKind class_load_kind);
  11196. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  11197. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  11198. + virtual ~VM_RedefineClasses();
  11199. +
  11200. + bool check_arguments();
  11201. bool doit_prologue();
  11202. void doit();
  11203. void doit_epilogue();
  11204. + void rollback();
  11205. - bool allow_nested_vm_operations() const { return true; }
  11206. - jvmtiError check_error() { return _res; }
  11207. + jvmtiError check_exception() const;
  11208. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  11209. + bool skip_operation() const { return false; }
  11210. + bool allow_nested_vm_operations() const { return true; }
  11211. + jvmtiError check_error() { return _result; }
  11212. +
  11213. + void update_active_methods();
  11214. +
  11215. + // Checks for type consistency after hierarchy change
  11216. + bool check_type_consistency();
  11217. + void calculate_type_check_information();
  11218. + bool check_field_value_types();
  11219. + void clear_type_check_information();
  11220. + bool check_method_stacks();
  11221. + bool check_loaded_methods();
  11222. + bool check_method(methodOop method);
  11223. + static Symbol* signature_to_class_name(Symbol* signature);
  11224. +
  11225. + void method_forwarding();
  11226. +
  11227. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11228. // Modifiable test must be shared between IsModifiableClass query
  11229. // and redefine implementation
  11230. static bool is_modifiable_class(oop klass_mirror);
  11231. +
  11232. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11233. + void oops_do(OopClosure* f);
  11234. +
  11235. + // Utility methods for transferring field access flags
  11236. +
  11237. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11238. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11239. +
  11240. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11241. +
  11242. + void lock_threads();
  11243. + void unlock_threads();
  11244. +
  11245. + template <class T> static void do_oop_work(T* p);
  11246. +
  11247. + static void swap_marks(oop first, oop second);
  11248. +
  11249. };
  11250. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11251. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  11252. index 60eaf97..07bb6e3 100644
  11253. --- a/src/share/vm/prims/methodComparator.cpp
  11254. +++ b/src/share/vm/prims/methodComparator.cpp
  11255. @@ -65,6 +65,7 @@
  11256. if (! args_same(c_old, c_new))
  11257. return false;
  11258. }
  11259. +
  11260. return true;
  11261. }
  11262. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  11263. index 41fc42d..53b3e0c 100644
  11264. --- a/src/share/vm/prims/nativeLookup.cpp
  11265. +++ b/src/share/vm/prims/nativeLookup.cpp
  11266. @@ -35,6 +35,7 @@
  11267. #include "oops/symbol.hpp"
  11268. #include "prims/jvm_misc.hpp"
  11269. #include "prims/nativeLookup.hpp"
  11270. +#include "prims/jvmtiRedefineClasses.hpp"
  11271. #include "runtime/arguments.hpp"
  11272. #include "runtime/handles.inline.hpp"
  11273. #include "runtime/javaCalls.hpp"
  11274. @@ -52,7 +53,6 @@
  11275. #ifdef TARGET_OS_FAMILY_bsd
  11276. # include "os_bsd.inline.hpp"
  11277. #endif
  11278. -
  11279. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11280. char* bytes = (char*)name->bytes() + begin;
  11281. @@ -138,6 +138,40 @@
  11282. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  11283. };
  11284. +// Helper function to call redefineClasses from Java Code
  11285. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11286. + ResourceMark rm(THREAD);
  11287. +
  11288. + JavaThread* current_thread = JavaThread::current();
  11289. + jbyte* bytecodes = NULL;
  11290. + const int class_count = 1;
  11291. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11292. +
  11293. + {
  11294. + ThreadToNativeFromVM ttnfv(thread);
  11295. + jboolean is_copy = JNI_FALSE;
  11296. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11297. + class_definitions[0].klass = target;
  11298. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11299. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11300. + }
  11301. +
  11302. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11303. + VMThread::execute(&op);
  11304. + int result = op.check_error();
  11305. +
  11306. + {
  11307. + ThreadToNativeFromVM ttnfv(thread);
  11308. + if (env->ExceptionOccurred()) {
  11309. + return -1;
  11310. + }
  11311. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11312. + }
  11313. +
  11314. + return result;
  11315. +JVM_END
  11316. +
  11317. +
  11318. static address lookup_special_native(char* jni_name) {
  11319. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11320. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11321. @@ -177,6 +211,9 @@
  11322. return entry;
  11323. }
  11324. }
  11325. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11326. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11327. + }
  11328. // Otherwise call static method findNative in ClassLoader
  11329. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11330. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  11331. index 36aebb4..153be8f 100644
  11332. --- a/src/share/vm/runtime/arguments.cpp
  11333. +++ b/src/share/vm/runtime/arguments.cpp
  11334. @@ -1875,6 +1875,15 @@
  11335. status = false;
  11336. }
  11337. + // (tw) Must use serial GC
  11338. + if (!UseSerialGC && i >= 1) {
  11339. + jio_fprintf(defaultStream::error_stream(),
  11340. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11341. + status = false;
  11342. + } else {
  11343. + UseSerialGC = true;
  11344. + }
  11345. +
  11346. return status;
  11347. }
  11348. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  11349. index 6e812ee..098f459 100644
  11350. --- a/src/share/vm/runtime/deoptimization.cpp
  11351. +++ b/src/share/vm/runtime/deoptimization.cpp
  11352. @@ -599,6 +599,38 @@
  11353. // Cleanup thread deopt data
  11354. cleanup_deopt_info(thread, array);
  11355. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11356. + {
  11357. + ResourceMark res_mark;
  11358. +
  11359. + // Verify that the just-unpacked frames match the interpreter's
  11360. + // notions of expression stack and locals
  11361. + vframeArray* cur_array = thread->vframe_array_last();
  11362. + RegisterMap rm(thread, false);
  11363. + rm.set_include_argument_oops(false);
  11364. + for (int i = 0; i < cur_array->frames(); i++) {
  11365. + vframeArrayElement* el = cur_array->element(i);
  11366. + frame* frame = el->iframe();
  11367. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11368. + RegisterMap reg_map(thread);
  11369. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11370. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11371. + methodOop method = iframe->method();
  11372. + int bci = iframe->bci();
  11373. + method = method->newest_version();
  11374. + iframe->set_method(method, bci);
  11375. +
  11376. + methodOop forward_method = method->forward_method();
  11377. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11378. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11379. + if (TraceRedefineClasses >= 2) {
  11380. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  11381. + }
  11382. + iframe->set_method(forward_method, new_bci);
  11383. + }
  11384. + }
  11385. + }
  11386. +
  11387. #ifndef PRODUCT
  11388. if (VerifyStack) {
  11389. ResourceMark res_mark;
  11390. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  11391. index aacd835..3772b3f 100644
  11392. --- a/src/share/vm/runtime/frame.cpp
  11393. +++ b/src/share/vm/runtime/frame.cpp
  11394. @@ -408,6 +408,12 @@
  11395. *interpreter_frame_method_addr() = method;
  11396. }
  11397. +// (tw) Sets constant pool cache oop
  11398. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11399. + assert(is_interpreted_frame(), "interpreted frame expected");
  11400. + *interpreter_frame_cache_addr() = cp;
  11401. +}
  11402. +
  11403. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11404. assert(is_interpreted_frame(), "Not an interpreted frame");
  11405. if (ProfileInterpreter) {
  11406. @@ -423,19 +429,27 @@
  11407. // The bcx was just converted from bci to bcp.
  11408. // Convert the mdx in parallel.
  11409. methodDataOop mdo = interpreter_frame_method()->method_data();
  11410. - assert(mdo != NULL, "");
  11411. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11412. - address mdp = mdo->di_to_dp(mdi);
  11413. - interpreter_frame_set_mdx((intptr_t)mdp);
  11414. + if (mdo == NULL) {
  11415. + interpreter_frame_set_mdx(0);
  11416. + } else {
  11417. + assert(mdo != NULL, "");
  11418. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11419. + address mdp = mdo->di_to_dp(mdi);
  11420. + interpreter_frame_set_mdx((intptr_t)mdp);
  11421. + }
  11422. }
  11423. } else {
  11424. if (is_now_bci) {
  11425. // The bcx was just converted from bcp to bci.
  11426. // Convert the mdx in parallel.
  11427. methodDataOop mdo = interpreter_frame_method()->method_data();
  11428. - assert(mdo != NULL, "");
  11429. - int mdi = mdo->dp_to_di((address)mdx);
  11430. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11431. + if (mdo == NULL) {
  11432. + interpreter_frame_set_mdx(0);
  11433. + } else {
  11434. + assert(mdo != NULL, "");
  11435. + int mdi = mdo->dp_to_di((address)mdx);
  11436. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11437. + }
  11438. }
  11439. }
  11440. }
  11441. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  11442. index 9c7bb72..04a6595 100644
  11443. --- a/src/share/vm/runtime/frame.hpp
  11444. +++ b/src/share/vm/runtime/frame.hpp
  11445. @@ -346,6 +346,7 @@
  11446. // Method & constant pool cache
  11447. methodOop interpreter_frame_method() const;
  11448. void interpreter_frame_set_method(methodOop method);
  11449. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11450. methodOop* interpreter_frame_method_addr() const;
  11451. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11452. #ifdef PPC
  11453. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  11454. index 7ec105c..32b60b8 100644
  11455. --- a/src/share/vm/runtime/globals.hpp
  11456. +++ b/src/share/vm/runtime/globals.hpp
  11457. @@ -1232,9 +1232,23 @@
  11458. product(bool, StressLdcRewrite, false, \
  11459. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11460. \
  11461. + product(bool, UseMethodForwardPoints, false, \
  11462. + "Use method forward points") \
  11463. + \
  11464. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11465. + "Maximum number of locals in forwarding method") \
  11466. + \
  11467. + product(intx, MethodForwardPointsMaxStack, 300, \
  11468. + "Maximum number of stack slots in forwarding method") \
  11469. + \
  11470. product(intx, TraceRedefineClasses, 0, \
  11471. "Trace level for JVMTI RedefineClasses") \
  11472. \
  11473. + product(bool, TimeRedefineClasses, false, \
  11474. + "Measure timing for JVMTI RedefineClasses") \
  11475. + \
  11476. + product(bool, AllowAdvancedClassRedefinition, true, \
  11477. + "Allow advanced class redefinition beyond swapping method bodies")\
  11478. develop(bool, StressMethodComparator, false, \
  11479. "run the MethodComparator on all loaded methods") \
  11480. \
  11481. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  11482. index 2875ee0..61fd8fe 100644
  11483. --- a/src/share/vm/runtime/interfaceSupport.hpp
  11484. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  11485. @@ -296,7 +296,7 @@
  11486. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11487. // We are leaving the VM at this point and going directly to native code.
  11488. // Block, if we are in the middle of a safepoint synchronization.
  11489. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11490. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11491. thread->frame_anchor()->make_walkable(thread);
  11492. trans_and_fence(_thread_in_vm, _thread_in_native);
  11493. // Check for pending. async. exceptions or suspends.
  11494. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11495. index edbba98..4a27925 100644
  11496. --- a/src/share/vm/runtime/javaCalls.cpp
  11497. +++ b/src/share/vm/runtime/javaCalls.cpp
  11498. @@ -60,7 +60,7 @@
  11499. bool clear_pending_exception = true;
  11500. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11501. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11502. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11503. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11504. _result = result;
  11505. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11506. index 3cbcaca..30839d7 100644
  11507. --- a/src/share/vm/runtime/jniHandles.cpp
  11508. +++ b/src/share/vm/runtime/jniHandles.cpp
  11509. @@ -112,6 +112,10 @@
  11510. }
  11511. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11512. + if (mh->newest_version() != mh()) {
  11513. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11514. + return (jmethodID) make_weak_global(mh_new);
  11515. + }
  11516. return (jmethodID) make_weak_global(mh);
  11517. }
  11518. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11519. index 2095237..c541434 100644
  11520. --- a/src/share/vm/runtime/mutex.cpp
  11521. +++ b/src/share/vm/runtime/mutex.cpp
  11522. @@ -1227,7 +1227,7 @@
  11523. // in increasing rank order (modulo any native ranks)
  11524. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11525. if (tmp->next() != NULL) {
  11526. - assert(tmp->rank() == Mutex::native ||
  11527. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11528. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11529. }
  11530. }
  11531. @@ -1247,7 +1247,7 @@
  11532. // in increasing rank order (modulo any native ranks)
  11533. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11534. if (tmp->next() != NULL) {
  11535. - assert(tmp->rank() == Mutex::native ||
  11536. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11537. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11538. }
  11539. }
  11540. @@ -1310,6 +1310,7 @@
  11541. // already hold Terminator_lock - may happen because of periodic safepoints
  11542. if (this->rank() != Mutex::native &&
  11543. this->rank() != Mutex::suspend_resume &&
  11544. + this->rank() != Mutex::redefine_classes &&
  11545. locks != NULL && locks->rank() <= this->rank() &&
  11546. !SafepointSynchronize::is_at_safepoint() &&
  11547. this != Interrupt_lock &&
  11548. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11549. index 7d2cd82..11eb32e 100644
  11550. --- a/src/share/vm/runtime/mutex.hpp
  11551. +++ b/src/share/vm/runtime/mutex.hpp
  11552. @@ -109,7 +109,8 @@
  11553. barrier = safepoint + 1,
  11554. nonleaf = barrier + 1,
  11555. max_nonleaf = nonleaf + 900,
  11556. - native = max_nonleaf + 1
  11557. + native = max_nonleaf + 1,
  11558. + redefine_classes = native + 1
  11559. };
  11560. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11561. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11562. index 77fddef..9d453d4 100644
  11563. --- a/src/share/vm/runtime/mutexLocker.cpp
  11564. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11565. @@ -49,6 +49,7 @@
  11566. // Consider using GCC's __read_mostly.
  11567. Mutex* Patching_lock = NULL;
  11568. +Mutex* RedefineClasses_lock = NULL;
  11569. Monitor* SystemDictionary_lock = NULL;
  11570. Mutex* PackageTable_lock = NULL;
  11571. Mutex* CompiledIC_lock = NULL;
  11572. @@ -91,6 +92,7 @@
  11573. Mutex* DirtyCardQ_FL_lock = NULL;
  11574. Monitor* DirtyCardQ_CBL_mon = NULL;
  11575. Mutex* Shared_DirtyCardQ_lock = NULL;
  11576. +Monitor* RedefinitionSync_lock = NULL;
  11577. Mutex* ParGCRareEvent_lock = NULL;
  11578. Mutex* EvacFailureStack_lock = NULL;
  11579. Mutex* DerivedPointerTableGC_lock = NULL;
  11580. @@ -208,6 +210,7 @@
  11581. def(HotCardCache_lock , Mutex , special , true );
  11582. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11583. }
  11584. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11585. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11586. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11587. def(CodeCache_lock , Mutex , special, true );
  11588. @@ -283,6 +286,7 @@
  11589. def(Debug3_lock , Mutex , nonleaf+4, true );
  11590. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11591. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11592. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11593. #ifdef INCLUDE_TRACE
  11594. def(JfrMsg_lock , Monitor, leaf, true);
  11595. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11596. index a6549b1..089ed11 100644
  11597. --- a/src/share/vm/runtime/mutexLocker.hpp
  11598. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11599. @@ -43,6 +43,8 @@
  11600. // Mutexes used in the VM.
  11601. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11602. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11603. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11604. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11605. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11606. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11607. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11608. index 1665d93..6baabba 100644
  11609. --- a/src/share/vm/runtime/reflection.cpp
  11610. +++ b/src/share/vm/runtime/reflection.cpp
  11611. @@ -468,7 +468,8 @@
  11612. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11613. if ( JDK_Version::is_gte_jdk14x_version()
  11614. && UseNewReflection
  11615. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11616. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11617. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11618. return true;
  11619. }
  11620. @@ -519,6 +520,12 @@
  11621. AccessFlags access,
  11622. bool classloader_only,
  11623. bool protected_restriction) {
  11624. +
  11625. + // (tw) Decide accessibility based on active version
  11626. + if (current_class != NULL) {
  11627. + current_class = current_class->klass_part()->active_version();
  11628. + }
  11629. +
  11630. // Verify that current_class can access a field of field_class, where that
  11631. // field's access bits are "access". We assume that we've already verified
  11632. // that current_class can access field_class.
  11633. @@ -560,7 +567,8 @@
  11634. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11635. if ( JDK_Version::is_gte_jdk14x_version()
  11636. && UseNewReflection
  11637. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11638. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11639. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11640. return true;
  11641. }
  11642. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11643. index 709d783..e0e19b1 100644
  11644. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11645. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11646. @@ -1137,7 +1137,20 @@
  11647. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11648. int retry_count = 0;
  11649. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11650. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11651. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11652. +
  11653. + // DCEVM: If we are executing an old method, this is OK!
  11654. + {
  11655. + ResourceMark rm(thread);
  11656. + RegisterMap cbl_map(thread, false);
  11657. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11658. +
  11659. + CodeBlob* caller_cb = caller_frame.cb();
  11660. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11661. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11662. + if (caller_nm->method()->is_old()) break;
  11663. + }
  11664. +
  11665. // If has a pending exception then there is no need to re-try to
  11666. // resolve this method.
  11667. // If the method has been redefined, we need to try again.
  11668. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11669. index c8644d0..2c54303 100644
  11670. --- a/src/share/vm/runtime/thread.cpp
  11671. +++ b/src/share/vm/runtime/thread.cpp
  11672. @@ -216,6 +216,8 @@
  11673. set_self_raw_id(0);
  11674. set_lgrp_id(-1);
  11675. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11676. +
  11677. // allocated data structures
  11678. set_osthread(NULL);
  11679. set_resource_area(new (mtThread)ResourceArea());
  11680. @@ -249,6 +251,7 @@
  11681. omFreeProvision = 32 ;
  11682. omInUseList = NULL ;
  11683. omInUseCount = 0 ;
  11684. + _pretend_new_universe = false;
  11685. #ifdef ASSERT
  11686. _visited_for_critical_count = false;
  11687. @@ -880,6 +883,15 @@
  11688. bool Thread::owns_locks_but_compiled_lock() const {
  11689. for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11690. if (cur != Compile_lock) return true;
  11691. + }
  11692. + return false;
  11693. +}
  11694. +
  11695. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11696. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11697. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11698. + return true;
  11699. + }
  11700. }
  11701. return false;
  11702. }
  11703. @@ -1637,7 +1649,7 @@
  11704. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11705. assert(JavaThread::current() == this, "sanity check");
  11706. - assert(!Thread::current()->owns_locks(), "sanity check");
  11707. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11708. DTRACE_THREAD_PROBE(start, this);
  11709. @@ -3193,7 +3205,7 @@
  11710. // Create a CompilerThread
  11711. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11712. -: JavaThread(&compiler_thread_entry) {
  11713. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11714. _env = NULL;
  11715. _log = NULL;
  11716. _task = NULL;
  11717. @@ -3201,6 +3213,7 @@
  11718. _counters = counters;
  11719. _buffer_blob = NULL;
  11720. _scanned_nmethod = NULL;
  11721. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11722. #ifndef PRODUCT
  11723. _ideal_graph_printer = NULL;
  11724. @@ -3230,6 +3243,7 @@
  11725. int Threads::_number_of_non_daemon_threads = 0;
  11726. int Threads::_return_code = 0;
  11727. size_t JavaThread::_stack_size_at_create = 0;
  11728. +bool Threads::_wait_at_instrumentation_entry = false;
  11729. // All JavaThreads
  11730. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11731. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11732. index 774bd27..4ca4502 100644
  11733. --- a/src/share/vm/runtime/thread.hpp
  11734. +++ b/src/share/vm/runtime/thread.hpp
  11735. @@ -203,10 +203,13 @@
  11736. void enter_signal_handler() { _num_nested_signal++; }
  11737. void leave_signal_handler() { _num_nested_signal--; }
  11738. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11739. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11740. private:
  11741. // Debug tracing
  11742. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11743. +
  11744. + Mutex* _redefine_classes_mutex;
  11745. // Active_handles points to a block of handles
  11746. JNIHandleBlock* _active_handles;
  11747. @@ -530,10 +533,15 @@
  11748. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11749. int _lgrp_id;
  11750. +
  11751. + bool _pretend_new_universe;
  11752. +
  11753. public:
  11754. // Stack overflow support
  11755. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11756. + 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; } }
  11757. + bool pretend_new_universe() { return _pretend_new_universe; }
  11758. void set_stack_base(address base) { _stack_base = base; }
  11759. size_t stack_size() const { return _stack_size; }
  11760. void set_stack_size(size_t size) { _stack_size = size; }
  11761. @@ -570,6 +578,7 @@
  11762. void print_owned_locks() const { print_owned_locks_on(tty); }
  11763. Monitor* owned_locks() const { return _owned_locks; }
  11764. bool owns_locks() const { return owned_locks() != NULL; }
  11765. + bool owns_locks_but_redefine_classes_lock() const;
  11766. bool owns_locks_but_compiled_lock() const;
  11767. // Deadlock detection
  11768. @@ -1793,6 +1802,8 @@
  11769. CompileTask* _task;
  11770. CompileQueue* _queue;
  11771. BufferBlob* _buffer_blob;
  11772. + bool _should_bailout;
  11773. + Mutex* _compilation_mutex;
  11774. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11775. @@ -1802,12 +1813,16 @@
  11776. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11777. + bool should_bailout() const { return _should_bailout; }
  11778. + void set_should_bailout(bool b) { _should_bailout = false; }
  11779. +
  11780. bool is_Compiler_thread() const { return true; }
  11781. // Hide this compiler thread from external view.
  11782. bool is_hidden_from_external_view() const { return true; }
  11783. CompileQueue* queue() { return _queue; }
  11784. CompilerCounters* counters() { return _counters; }
  11785. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11786. // Get/set the thread's compilation environment.
  11787. ciEnv* env() { return _env; }
  11788. @@ -1862,6 +1877,7 @@
  11789. static int _number_of_threads;
  11790. static int _number_of_non_daemon_threads;
  11791. static int _return_code;
  11792. + static bool _wait_at_instrumentation_entry;
  11793. public:
  11794. // Thread management
  11795. @@ -1873,6 +1889,9 @@
  11796. static JavaThread* first() { return _thread_list; }
  11797. static void threads_do(ThreadClosure* tc);
  11798. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11799. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11800. +
  11801. // Initializes the vm and creates the vm thread
  11802. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11803. static void convert_vm_init_libraries_to_agents();
  11804. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11805. index a8c66f1..b50e33e 100644
  11806. --- a/src/share/vm/runtime/vframe.cpp
  11807. +++ b/src/share/vm/runtime/vframe.cpp
  11808. @@ -258,6 +258,46 @@
  11809. return fr().interpreter_frame_method();
  11810. }
  11811. +// (tw) Sets interpreter frame method.
  11812. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11813. + methodOop old_method = fr().interpreter_frame_method();
  11814. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11815. + if (old_method == new_method) return;
  11816. + u_char *old_bcp = bcp();
  11817. + int old_bci = bci();
  11818. + fr().interpreter_frame_set_method(new_method);
  11819. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11820. + u_char *new_bcp = new_method->code_base() + new_bci;
  11821. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11822. +
  11823. + set_bcp(new_bcp);
  11824. +
  11825. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11826. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11827. +
  11828. + switch (code) {
  11829. + case Bytecodes::_invokevirtual :
  11830. + case Bytecodes::_invokespecial :
  11831. + case Bytecodes::_invokestatic :
  11832. + case Bytecodes::_invokeinterface: {
  11833. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11834. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11835. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11836. + break;
  11837. + }
  11838. +
  11839. + case Bytecodes::_invokedynamic: {
  11840. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11841. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11842. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11843. + break;
  11844. + }
  11845. + }
  11846. +
  11847. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11848. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11849. +}
  11850. +
  11851. StackValueCollection* interpretedVFrame::locals() const {
  11852. int length = method()->max_locals();
  11853. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11854. index badfea5..edbc5c7 100644
  11855. --- a/src/share/vm/runtime/vframe.hpp
  11856. +++ b/src/share/vm/runtime/vframe.hpp
  11857. @@ -163,6 +163,7 @@
  11858. StackValueCollection* locals() const;
  11859. StackValueCollection* expressions() const;
  11860. GrowableArray<MonitorInfo*>* monitors() const;
  11861. + void set_method(methodOop method, int new_bci);
  11862. void set_locals(StackValueCollection* values) const;
  11863. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11864. index 0a3e0da..3d294e1 100644
  11865. --- a/src/share/vm/runtime/vmThread.cpp
  11866. +++ b/src/share/vm/runtime/vmThread.cpp
  11867. @@ -694,6 +694,10 @@
  11868. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11869. Thread::oops_do(f, cf);
  11870. _vm_queue->oops_do(f);
  11871. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11872. + if (_cur_vm_operation != NULL) {
  11873. + _cur_vm_operation->oops_do(f);
  11874. + }
  11875. }
  11876. //------------------------------------------------------------------------------------------------------------------
  11877. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11878. index 03f254d..c9e0efc 100644
  11879. --- a/src/share/vm/utilities/exceptions.cpp
  11880. +++ b/src/share/vm/utilities/exceptions.cpp
  11881. @@ -254,6 +254,8 @@
  11882. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11883. assert(!thread->has_pending_exception(), "already has exception");
  11884. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11885. + Thread::current()->set_pretend_new_universe(false);
  11886. Handle h_exception;
  11887. // Resolve exception klass
  11888. @@ -285,6 +287,7 @@
  11889. h_exception = Handle(thread, thread->pending_exception());
  11890. thread->clear_pending_exception();
  11891. }
  11892. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11893. return h_exception;
  11894. }
  11895. @@ -295,6 +298,8 @@
  11896. Symbol* signature, JavaCallArguments *args,
  11897. Handle h_cause,
  11898. Handle h_loader, Handle h_protection_domain) {
  11899. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11900. + Thread::current()->set_pretend_new_universe(false);
  11901. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11902. // Future: object initializer should take a cause argument
  11903. @@ -317,6 +322,8 @@
  11904. h_exception = Handle(thread, thread->pending_exception());
  11905. thread->clear_pending_exception();
  11906. }
  11907. +
  11908. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11909. return h_exception;
  11910. }
  11911. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11912. index ea92a80..05e940e 100644
  11913. --- a/src/share/vm/utilities/growableArray.hpp
  11914. +++ b/src/share/vm/utilities/growableArray.hpp
  11915. @@ -145,6 +145,33 @@
  11916. assert(on_stack(), "fast ResourceObj path only");
  11917. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11918. }
  11919. +
  11920. +};
  11921. +
  11922. +template<class E, class F> class Pair : public StackObj
  11923. +{
  11924. +private:
  11925. + E _left;
  11926. + F _right;
  11927. +
  11928. +public:
  11929. +
  11930. + Pair() {
  11931. +
  11932. + }
  11933. +
  11934. + Pair(E left, F right) {
  11935. + this->_left = left;
  11936. + this->_right = right;
  11937. + }
  11938. +
  11939. + E left() {
  11940. + return _left;
  11941. + }
  11942. +
  11943. + F right() {
  11944. + return _right;
  11945. + }
  11946. };
  11947. template<class E> class GrowableArray : public GenericGrowableArray {