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-jdk7u45-b08.patch 512KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034
  1. diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make
  2. index 2310141..8ddb2ab 100644
  3. --- a/make/bsd/makefiles/gcc.make
  4. +++ b/make/bsd/makefiles/gcc.make
  5. @@ -116,7 +116,10 @@ CFLAGS += $(VM_PICFLAG)
  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 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  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 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  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 @@ void TemplateTable::jvmti_post_field_access(Register cache,
  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 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  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 @@ void TemplateTable::getstatic(int byte_no) {
  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 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  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 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  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 @@ void TemplateTable::fast_accessfield(TosState state) {
  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 @@ void TemplateTable::invokevirtual_helper(Register index,
  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 @@ void TemplateTable::invokeinterface(int byte_no) {
  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 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  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 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  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 @@ void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  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 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  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 @@ void TemplateTable::getstatic(int byte_no) {
  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 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  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 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  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 @@ void TemplateTable::fast_accessfield(TosState state) {
  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 @@ void TemplateTable::invokevirtual_helper(Register index,
  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 @@ void TemplateTable::invokeinterface(int byte_no) {
  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/os/bsd/vm/attachListener_bsd.cpp b/src/os/bsd/vm/attachListener_bsd.cpp
  320. index dac5195..e939dcd 100644
  321. --- a/src/os/bsd/vm/attachListener_bsd.cpp
  322. +++ b/src/os/bsd/vm/attachListener_bsd.cpp
  323. @@ -460,14 +460,14 @@ AttachOperation* AttachListener::dequeue() {
  324. void AttachListener::vm_start() {
  325. char fn[UNIX_PATH_MAX];
  326. - struct stat64 st;
  327. + struct stat st;
  328. int ret;
  329. int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
  330. os::get_temp_directory(), os::current_process_id());
  331. assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
  332. - RESTARTABLE(::stat64(fn, &st), ret);
  333. + RESTARTABLE(::stat(fn, &st), ret);
  334. if (ret == 0) {
  335. ret = ::unlink(fn);
  336. if (ret == -1) {
  337. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  338. index 9a8ca61..196ab25 100644
  339. --- a/src/share/vm/c1/c1_Compilation.hpp
  340. +++ b/src/share/vm/c1/c1_Compilation.hpp
  341. @@ -242,8 +242,8 @@ class Compilation: public StackObj {
  342. #define BAILOUT(msg) { bailout(msg); return; }
  343. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  344. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  345. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  346. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  347. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  348. class InstructionMark: public StackObj {
  349. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  350. index e20db5d..57f37db 100644
  351. --- a/src/share/vm/ci/ciEnv.cpp
  352. +++ b/src/share/vm/ci/ciEnv.cpp
  353. @@ -1172,3 +1172,11 @@ void ciEnv::record_out_of_memory_failure() {
  354. // If memory is low, we stop compiling methods.
  355. record_method_not_compilable("out of memory");
  356. }
  357. +
  358. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  359. +void ciEnv::cleanup_after_redefinition() {
  360. +
  361. + if (_factory != NULL) {
  362. + _factory->cleanup_after_redefinition();
  363. + }
  364. +}
  365. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  366. index 103e532..abe2e37 100644
  367. --- a/src/share/vm/ci/ciEnv.hpp
  368. +++ b/src/share/vm/ci/ciEnv.hpp
  369. @@ -417,6 +417,8 @@ public:
  370. void record_failure(const char* reason);
  371. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  372. void record_out_of_memory_failure();
  373. +
  374. + void cleanup_after_redefinition();
  375. };
  376. #endif // SHARE_VM_CI_CIENV_HPP
  377. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  378. index e0ab96b..36efef4 100644
  379. --- a/src/share/vm/ci/ciObjectFactory.cpp
  380. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  381. @@ -296,6 +296,11 @@ ciObject* ciObjectFactory::get(oop key) {
  382. // into the table. We need to recompute our index.
  383. index = find(keyHandle(), _ci_objects);
  384. }
  385. +
  386. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  387. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  388. + return _ci_objects->at(index);
  389. + }
  390. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  391. insert(index, new_object, _ci_objects);
  392. return new_object;
  393. @@ -764,3 +769,50 @@ void ciObjectFactory::print() {
  394. _unloaded_instances->length(),
  395. _unloaded_klasses->length());
  396. }
  397. +
  398. +// DCEVM: Resoring the ciObject arrays after class redefinition
  399. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  400. +
  401. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  402. + oop last = NULL;
  403. + for (int j = 0; j< objects->length(); j++) {
  404. + oop o = objects->at(j)->get_oop();
  405. + if (last >= o) {
  406. + int cur_last_index = j - 1;
  407. + oop cur_last = last;
  408. + while (cur_last >= o) {
  409. +
  410. + // Swap the two objects to guarantee ordering
  411. + ciObject *tmp = objects->at(cur_last_index);
  412. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  413. + objects->at_put(cur_last_index + 1, tmp);
  414. +
  415. + // Decrement index to move one step to the left
  416. + cur_last_index--;
  417. + if (cur_last_index < 0) {
  418. + break;
  419. + }
  420. + cur_last = objects->at(cur_last_index)->get_oop();
  421. + }
  422. + } else {
  423. + assert(last < o, "out of order");
  424. + last = o;
  425. + }
  426. + }
  427. +
  428. +#ifdef ASSERT
  429. + if (CIObjectFactoryVerify) {
  430. + oop last = NULL;
  431. + for (int j = 0; j< objects->length(); j++) {
  432. + oop o = objects->at(j)->get_oop();
  433. + assert(last < o, "out of order");
  434. + last = o;
  435. + }
  436. + }
  437. +#endif // ASSERT
  438. +}
  439. +
  440. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  441. +void ciObjectFactory::cleanup_after_redefinition() {
  442. + sort_ci_objects(_ci_objects);
  443. +}
  444. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  445. index 26cc2c3..855a4ac 100644
  446. --- a/src/share/vm/ci/ciObjectFactory.hpp
  447. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  448. @@ -38,6 +38,7 @@
  449. class ciObjectFactory : public ResourceObj {
  450. friend class VMStructs;
  451. friend class ciEnv;
  452. + friend class CompileBroker;
  453. private:
  454. static volatile bool _initialized;
  455. @@ -137,6 +138,11 @@ public:
  456. void print_contents();
  457. void print();
  458. +
  459. +private:
  460. +
  461. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  462. + void cleanup_after_redefinition();
  463. };
  464. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  465. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  466. index 6ffa4bf..4ea4e2b 100644
  467. --- a/src/share/vm/classfile/classFileParser.cpp
  468. +++ b/src/share/vm/classfile/classFileParser.cpp
  469. @@ -795,6 +795,7 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  470. Handle class_loader,
  471. Handle protection_domain,
  472. Symbol* class_name,
  473. + KlassHandle old_klass,
  474. TRAPS) {
  475. ClassFileStream* cfs = stream();
  476. assert(length > 0, "only called for length>0");
  477. @@ -813,6 +814,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  478. interface_index, CHECK_(nullHandle));
  479. if (cp->tag_at(interface_index).is_klass()) {
  480. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  481. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  482. + interf = KlassHandle(THREAD, interf->newest_version());
  483. + }
  484. } else {
  485. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  486. @@ -825,6 +829,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  487. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  488. unresolved_klass, class_loader, protection_domain,
  489. false, CHECK_(nullHandle));
  490. + if (!old_klass.is_null()) {
  491. + k = k->klass_part()->newest_version();
  492. + }
  493. interf = KlassHandle(THREAD, k);
  494. }
  495. @@ -1912,6 +1919,8 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  496. int runtime_invisible_parameter_annotations_length = 0;
  497. u1* annotation_default = NULL;
  498. int annotation_default_length = 0;
  499. + u2 code_section_table_length;
  500. + typeArrayHandle code_section_table;
  501. // Parse code and exceptions attribute
  502. u2 method_attributes_count = cfs->get_u2_fast();
  503. @@ -2081,6 +2090,24 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  504. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  505. stackmap_data = typeArrayHandle(THREAD, sm);
  506. parsed_stackmap_attribute = true;
  507. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  508. + int length = code_attribute_length;
  509. + int value_count = length / sizeof(u2);
  510. + int line_count = length / 3;
  511. + if (TraceRedefineClasses >= 3) {
  512. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  513. + }
  514. + code_section_table_length = value_count;
  515. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  516. + code_section_table->set_length(value_count);
  517. +
  518. + for (int i = 0; i < value_count; ++i) {
  519. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  520. + code_section_table->short_at_put(i, value);
  521. + if (TraceRedefineClasses >= 4) {
  522. + tty->print_cr("Code section table at %d: %d", i, value);
  523. + }
  524. + }
  525. } else {
  526. // Skip unknown attributes
  527. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  528. @@ -2206,6 +2233,18 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  529. }
  530. #endif
  531. + // DCEVM: TODO: Get a different solution for the problem of method forward
  532. + // points and variable sized interpreter frames.
  533. + if (UseMethodForwardPoints) {
  534. + if (max_stack > MethodForwardPointsMaxStack) {
  535. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  536. + }
  537. + if (max_locals > MethodForwardPointsMaxLocals) {
  538. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  539. + }
  540. + max_stack = MethodForwardPointsMaxStack;
  541. + max_locals = MethodForwardPointsMaxLocals;
  542. + }
  543. // Fill in code attribute information
  544. m->set_max_stack(max_stack);
  545. m->set_max_locals(max_locals);
  546. @@ -2219,6 +2258,8 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  547. */
  548. m->constMethod()->set_stackmap_data(stackmap_data());
  549. + m->constMethod()->set_code_section_table(code_section_table());
  550. +
  551. // Copy byte codes
  552. m->set_code(code_start);
  553. @@ -2792,6 +2833,15 @@ void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp,
  554. "Invalid Deprecated classfile attribute length %u in class file %s",
  555. attribute_length, CHECK);
  556. }
  557. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  558. + // DCEVM: Check for deleted field attribute
  559. + _field_redefinition_policy = cfs->get_u1_fast();
  560. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  561. + // DCEVM: Check for deleted static field attribute
  562. + _static_field_redefinition_policy = cfs->get_u1_fast();
  563. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  564. + // DCEVM: Check for deleted method attribute
  565. + _method_redefinition_policy = cfs->get_u1_fast();
  566. } else if (_major_version >= JAVA_1_5_VERSION) {
  567. if (tag == vmSymbols::tag_signature()) {
  568. if (attribute_length != 2) {
  569. @@ -2895,6 +2945,17 @@ void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) {
  570. }
  571. k->set_inner_classes(_inner_classes());
  572. k->set_class_annotations(_annotations());
  573. +
  574. +
  575. + if (_field_redefinition_policy != 0xff) {
  576. + k->set_field_redefinition_policy(_field_redefinition_policy);
  577. + }
  578. + if (_static_field_redefinition_policy != 0xff) {
  579. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  580. + }
  581. + if (_method_redefinition_policy != 0xff) {
  582. + k->set_method_redefinition_policy(_method_redefinition_policy);
  583. + }
  584. }
  585. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  586. @@ -2918,9 +2979,126 @@ typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annota
  587. }
  588. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  589. +// them in a growable array.
  590. +void ClassFileParser::findSuperSymbols(Symbol* name,
  591. + Handle class_loader,
  592. + Handle protection_domain,
  593. + KlassHandle old_klass,
  594. + GrowableArray<Symbol*> &handles,
  595. + TRAPS) {
  596. +
  597. + _cp_patches = NULL;
  598. + // So that JVMTI can cache class file in the state before retransformable agents
  599. + // have modified it
  600. + unsigned char *cached_class_file_bytes = NULL;
  601. +
  602. + ClassFileStream* cfs = stream();
  603. +
  604. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  605. +
  606. + instanceKlassHandle nullHandle;
  607. +
  608. + // Save the class file name for easier error message printing.
  609. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  610. +
  611. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  612. + // Magic value
  613. + u4 magic = cfs->get_u4_fast();
  614. + if (magic != JAVA_CLASSFILE_MAGIC) {
  615. + // Invalid class file!
  616. + return;
  617. + }
  618. +
  619. + // Version numbers
  620. + u2 minor_version = cfs->get_u2_fast();
  621. + u2 major_version = cfs->get_u2_fast();
  622. +
  623. + // Check version numbers - we check this even with verifier off
  624. + if (!is_supported_version(major_version, minor_version)) {
  625. +
  626. + // Unsupported version!
  627. + return;
  628. + }
  629. +
  630. + _major_version = major_version;
  631. + _minor_version = minor_version;
  632. +
  633. +
  634. + // Check if verification needs to be relaxed for this class file
  635. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  636. + _relax_verify = Verifier::relax_verify_for(class_loader());
  637. + _need_verify = false;
  638. +
  639. + // Constant pool
  640. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  641. + int cp_size = cp->length();
  642. +
  643. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  644. +
  645. + // Access flags
  646. + AccessFlags access_flags;
  647. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  648. +
  649. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  650. + // Set abstract bit for old class files for backward compatibility
  651. + flags |= JVM_ACC_ABSTRACT;
  652. + }
  653. + access_flags.set_flags(flags);
  654. +
  655. + // This class and superclass
  656. + instanceKlassHandle super_klass;
  657. + u2 this_class_index = cfs->get_u2_fast();
  658. + check_property(
  659. + valid_cp_range(this_class_index, cp_size) &&
  660. + cp->tag_at(this_class_index).is_unresolved_klass(),
  661. + "Invalid this class index %u in constant pool in class file %s",
  662. + this_class_index, CHECK);
  663. +
  664. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  665. + assert(class_name != NULL, "class_name can't be null");
  666. +
  667. + // Update _class_name which could be null previously to be class_name
  668. + _class_name = class_name;
  669. +
  670. + // DCEVM: DO NOT release all handles when parsing is done
  671. + {// HandleMark hm(THREAD);
  672. +
  673. + // Checks if name in class file matches requested name
  674. + if (name != NULL && class_name != name) {
  675. + return;
  676. + }
  677. +
  678. + u2 super_class_index = cfs->get_u2_fast();
  679. +
  680. + if (super_class_index != 0) {
  681. + Symbol* super_class = cp->klass_name_at(super_class_index);
  682. + handles.append(super_class);
  683. + } else {
  684. + // DCEVM: This redefinition must be for the Object class.
  685. + }
  686. +
  687. + // Interfaces
  688. + u2 itfs_len = cfs->get_u2_fast();
  689. + objArrayHandle local_interfaces;
  690. + if (itfs_len == 0) {
  691. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  692. + } else {
  693. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  694. + }
  695. +
  696. + for (int i=0; i<local_interfaces->length(); i++) {
  697. + oop o = local_interfaces->obj_at(i);
  698. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  699. + handles.append(interface_handle);
  700. + }
  701. + }
  702. +}
  703. +
  704. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  705. Handle class_loader,
  706. Handle protection_domain,
  707. + KlassHandle old_klass,
  708. KlassHandle host_klass,
  709. GrowableArray<Handle>* cp_patches,
  710. TempNewSymbol& parsed_name,
  711. @@ -2971,10 +3149,13 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  712. unsigned char* ptr = cfs->buffer();
  713. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  714. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  715. + Thread::current()->set_pretend_new_universe(false);
  716. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  717. &ptr, &end_ptr,
  718. &cached_class_file_bytes,
  719. &cached_class_file_length);
  720. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  721. if (ptr != cfs->buffer()) {
  722. // JVMTI agent has modified class file data.
  723. @@ -3130,7 +3311,11 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  724. // However, make sure it is not an array type.
  725. bool is_array = false;
  726. if (cp->tag_at(super_class_index).is_klass()) {
  727. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  728. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  729. + if (!old_klass.is_null()) {
  730. + resolved_klass = resolved_klass->klass_part()->newest_version();
  731. + }
  732. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  733. if (_need_verify)
  734. is_array = super_klass->oop_is_array();
  735. } else if (_need_verify) {
  736. @@ -3148,7 +3333,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  737. if (itfs_len == 0) {
  738. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  739. } else {
  740. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  741. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  742. }
  743. u2 java_fields_count = 0;
  744. @@ -3202,7 +3387,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  745. protection_domain,
  746. true,
  747. CHECK_(nullHandle));
  748. -
  749. + if (!old_klass.is_null()) {
  750. + k = k->klass_part()->newest_version();
  751. + }
  752. KlassHandle kh (THREAD, k);
  753. super_klass = instanceKlassHandle(THREAD, kh());
  754. }
  755. @@ -3591,6 +3778,19 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  756. rt = REF_NONE;
  757. } else {
  758. rt = super_klass->reference_type();
  759. +
  760. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  761. + if (name == vmSymbols::java_lang_ref_Reference()) {
  762. + rt = REF_OTHER;
  763. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  764. + rt = REF_SOFT;
  765. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  766. + rt = REF_WEAK;
  767. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  768. + rt = REF_FINAL;
  769. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  770. + rt = REF_PHANTOM;
  771. + }
  772. }
  773. // We can now create the basic klassOop for this klass
  774. @@ -3691,7 +3891,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  775. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  776. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  777. - set_precomputed_flags(this_klass);
  778. + set_precomputed_flags(this_klass, old_klass);
  779. // reinitialize modifiers, using the InnerClasses attribute
  780. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  781. @@ -3714,6 +3914,10 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  782. // Allocate mirror and initialize static fields
  783. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  784. + if (rt == REF_OTHER) {
  785. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  786. + }
  787. +
  788. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  789. false /* not shared class */);
  790. @@ -3856,7 +4060,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  791. }
  792. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  793. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  794. klassOop super = k->super();
  795. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  796. @@ -3864,7 +4068,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  797. if (!_has_empty_finalizer) {
  798. if (_has_finalizer ||
  799. (super != NULL && super->klass_part()->has_finalizer())) {
  800. - k->set_has_finalizer();
  801. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  802. + k->set_has_finalizer();
  803. + }
  804. }
  805. }
  806. @@ -3880,7 +4086,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  807. // Check if this klass supports the java.lang.Cloneable interface
  808. if (SystemDictionary::Cloneable_klass_loaded()) {
  809. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  810. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  811. k->set_is_cloneable();
  812. }
  813. }
  814. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  815. index 314ec5e..a35bf67 100644
  816. --- a/src/share/vm/classfile/classFileParser.hpp
  817. +++ b/src/share/vm/classfile/classFileParser.hpp
  818. @@ -64,6 +64,9 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  819. int _sde_length;
  820. typeArrayHandle _inner_classes;
  821. typeArrayHandle _annotations;
  822. + u1 _field_redefinition_policy;
  823. + u1 _static_field_redefinition_policy;
  824. + u1 _method_redefinition_policy;
  825. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  826. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  827. @@ -151,6 +154,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  828. Handle class_loader,
  829. Handle protection_domain,
  830. Symbol* class_name,
  831. + KlassHandle old_klass,
  832. TRAPS);
  833. // Field parsing
  834. @@ -237,7 +241,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  835. unsigned int nonstatic_oop_map_count,
  836. int* nonstatic_oop_offsets,
  837. unsigned int* nonstatic_oop_counts);
  838. - void set_precomputed_flags(instanceKlassHandle k);
  839. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  840. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  841. objArrayHandle local_ifs, TRAPS);
  842. @@ -337,7 +341,12 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  843. public:
  844. // Constructor
  845. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  846. + ClassFileParser(ClassFileStream* st) {
  847. + set_stream(st);
  848. + _field_redefinition_policy = 0xff;
  849. + _static_field_redefinition_policy = 0xff;
  850. + _method_redefinition_policy = 0xff;
  851. + }
  852. // Parse .class file and return new klassOop. The klassOop is not hooked up
  853. // to the system dictionary or any other structures, so a .class file can
  854. @@ -349,21 +358,33 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  855. instanceKlassHandle parseClassFile(Symbol* name,
  856. Handle class_loader,
  857. Handle protection_domain,
  858. + KlassHandle old_klass,
  859. TempNewSymbol& parsed_name,
  860. bool verify,
  861. TRAPS) {
  862. KlassHandle no_host_klass;
  863. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  864. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  865. }
  866. instanceKlassHandle parseClassFile(Symbol* name,
  867. Handle class_loader,
  868. Handle protection_domain,
  869. + KlassHandle old_klass,
  870. KlassHandle host_klass,
  871. GrowableArray<Handle>* cp_patches,
  872. TempNewSymbol& parsed_name,
  873. bool verify,
  874. TRAPS);
  875. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  876. +
  877. + // DCEVM: Creates symbol handles for the super class and the interfaces
  878. + void findSuperSymbols(Symbol* name,
  879. + Handle class_loader,
  880. + Handle protection_domain,
  881. + KlassHandle old_klass,
  882. + GrowableArray<Symbol*> &handles,
  883. + TRAPS);
  884. +
  885. // Verifier checks
  886. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  887. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  888. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  889. index a2e61a4..450e19f 100644
  890. --- a/src/share/vm/classfile/classLoader.cpp
  891. +++ b/src/share/vm/classfile/classLoader.cpp
  892. @@ -915,6 +915,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
  893. instanceKlassHandle result = parser.parseClassFile(h_name,
  894. class_loader,
  895. protection_domain,
  896. + KlassHandle(),
  897. parsed_name,
  898. false,
  899. CHECK_(h));
  900. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  901. index 78e76cc..ee21f3a 100644
  902. --- a/src/share/vm/classfile/dictionary.cpp
  903. +++ b/src/share/vm/classfile/dictionary.cpp
  904. @@ -326,6 +326,21 @@ void Dictionary::classes_do(void f(klassOop)) {
  905. }
  906. }
  907. +
  908. +// DCEVM: Just the classes from defining class loaders
  909. +void Dictionary::classes_do(ObjectClosure *closure) {
  910. + for (int index = 0; index < table_size(); index++) {
  911. + for (DictionaryEntry* probe = bucket(index);
  912. + probe != NULL;
  913. + probe = probe->next()) {
  914. + klassOop k = probe->klass();
  915. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  916. + closure->do_object(k);
  917. + }
  918. + }
  919. + }
  920. +}
  921. +
  922. // Added for initialize_itable_for_klass to handle exceptions
  923. // Just the classes from defining class loaders
  924. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  925. @@ -433,6 +448,33 @@ void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
  926. add_entry(index, entry);
  927. }
  928. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  929. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  930. +
  931. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  932. + bool found = false;
  933. + for (int index = 0; index < table_size(); index++) {
  934. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  935. + if (entry->klass() == old_class()) {
  936. + entry->set_literal(k());
  937. + found = true;
  938. + }
  939. + }
  940. + }
  941. +
  942. + return found;
  943. +}
  944. +
  945. +// DCEVM: Undo previous updates to the system dictionary
  946. +void Dictionary::rollback_redefinition() {
  947. + for (int index = 0; index < table_size(); index++) {
  948. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  949. + if (entry->klass()->klass_part()->is_redefining()) {
  950. + entry->set_literal(entry->klass()->klass_part()->old_version());
  951. + }
  952. + }
  953. + }
  954. +}
  955. // This routine does not lock the system dictionary.
  956. //
  957. @@ -459,12 +501,22 @@ DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
  958. return NULL;
  959. }
  960. +// DCEVM: return old version if we are not in the new universe?
  961. +klassOop Dictionary::intercept_for_version(klassOop k) {
  962. + if (k == NULL) return k;
  963. +
  964. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  965. + return k->klass_part()->old_version();
  966. + }
  967. +
  968. + return k;
  969. +}
  970. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  971. Handle loader, Handle protection_domain, TRAPS) {
  972. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  973. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  974. - return entry->klass();
  975. + return intercept_for_version(entry->klass());
  976. } else {
  977. return NULL;
  978. }
  979. @@ -477,7 +529,7 @@ klassOop Dictionary::find_class(int index, unsigned int hash,
  980. assert (index == index_for(name, loader), "incorrect index?");
  981. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  982. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  983. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  984. }
  985. @@ -489,7 +541,7 @@ klassOop Dictionary::find_shared_class(int index, unsigned int hash,
  986. assert (index == index_for(name, Handle()), "incorrect index?");
  987. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  988. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  989. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  990. }
  991. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  992. index bd33760..186d0eb 100644
  993. --- a/src/share/vm/classfile/dictionary.hpp
  994. +++ b/src/share/vm/classfile/dictionary.hpp
  995. @@ -73,6 +73,10 @@ public:
  996. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  997. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  998. +
  999. + void rollback_redefinition();
  1000. +
  1001. klassOop find_class(int index, unsigned int hash,
  1002. Symbol* name, Handle loader);
  1003. @@ -89,6 +93,7 @@ public:
  1004. void classes_do(void f(klassOop, TRAPS), TRAPS);
  1005. void classes_do(void f(klassOop, oop));
  1006. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  1007. + void classes_do(ObjectClosure *closure);
  1008. void methods_do(void f(methodOop));
  1009. @@ -105,6 +110,7 @@ public:
  1010. bool do_unloading(BoolObjectClosure* is_alive);
  1011. // Protection domains
  1012. + static klassOop intercept_for_version(klassOop k);
  1013. klassOop find(int index, unsigned int hash, Symbol* name,
  1014. Handle loader, Handle protection_domain, TRAPS);
  1015. bool is_valid_protection_domain(int index, unsigned int hash,
  1016. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  1017. index f8b10b3..cb68d82 100644
  1018. --- a/src/share/vm/classfile/javaClasses.cpp
  1019. +++ b/src/share/vm/classfile/javaClasses.cpp
  1020. @@ -1798,7 +1798,7 @@ Handle java_lang_reflect_Method::create(TRAPS) {
  1021. klassOop klass = SystemDictionary::reflect_Method_klass();
  1022. // This class is eagerly initialized during VM initialization, since we keep a refence
  1023. // to one of the methods
  1024. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1025. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1026. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1027. }
  1028. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1029. index b741cfa..8ce5287 100644
  1030. --- a/src/share/vm/classfile/javaClasses.hpp
  1031. +++ b/src/share/vm/classfile/javaClasses.hpp
  1032. @@ -213,7 +213,6 @@ class java_lang_String : AllStatic {
  1033. class java_lang_Class : AllStatic {
  1034. friend class VMStructs;
  1035. -
  1036. private:
  1037. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1038. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1039. index 8650cd9..965cce2 100644
  1040. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1041. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1042. @@ -449,7 +449,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
  1043. if (k != NULL) {
  1044. // We found the class in the system dictionary, so we should
  1045. // make sure that the klassOop matches what we already have.
  1046. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1047. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1048. } else {
  1049. // If we don't find the class in the system dictionary, it
  1050. // has to be in the placeholders table.
  1051. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1052. index d01b2c4..1ad80f7 100644
  1053. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1054. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1055. @@ -106,7 +106,7 @@ public:
  1056. klassOop klass() { return literal(); }
  1057. klassOop* klass_addr() { return literal_addr(); }
  1058. - void set_klass(klassOop k) { set_literal(k); }
  1059. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1060. LoaderConstraintEntry* next() {
  1061. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1062. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1063. index 899153a..fa45c6d 100644
  1064. --- a/src/share/vm/classfile/systemDictionary.cpp
  1065. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1066. @@ -157,6 +157,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_load
  1067. // can return a null klass
  1068. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1069. }
  1070. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1071. return klass;
  1072. }
  1073. @@ -199,7 +200,8 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
  1074. // Forwards to resolve_instance_class_or_null
  1075. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1076. - assert(!THREAD->is_Compiler_thread(),
  1077. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1078. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1079. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1080. class_name->as_C_string(),
  1081. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1082. @@ -961,6 +963,7 @@ klassOop SystemDictionary::parse_stream(Symbol* class_name,
  1083. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1084. class_loader,
  1085. protection_domain,
  1086. + KlassHandle(),
  1087. host_klass,
  1088. cp_patches,
  1089. parsed_name,
  1090. @@ -1022,7 +1025,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1091. Handle protection_domain,
  1092. ClassFileStream* st,
  1093. bool verify,
  1094. + KlassHandle old_class,
  1095. TRAPS) {
  1096. + bool redefine_classes_locked = false;
  1097. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1098. + Thread::current()->redefine_classes_mutex()->lock();
  1099. + redefine_classes_locked = true;
  1100. + }
  1101. +
  1102. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1103. // or all classloaders with UnsyncloadClass do not acquire lock here
  1104. bool DoObjectLock = true;
  1105. @@ -1050,9 +1060,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1106. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1107. class_loader,
  1108. protection_domain,
  1109. + old_class,
  1110. parsed_name,
  1111. verify,
  1112. THREAD);
  1113. + if (!old_class.is_null() && !k.is_null()) {
  1114. + k->set_redefining(true);
  1115. + k->set_old_version(old_class());
  1116. + }
  1117. const char* pkg = "java/";
  1118. if (!HAS_PENDING_EXCEPTION &&
  1119. @@ -1087,13 +1102,18 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1120. // Add class just loaded
  1121. // If a class loader supports parallel classloading handle parallel define requests
  1122. // find_or_define_instance_class may return a different instanceKlass
  1123. - if (is_parallelCapable(class_loader)) {
  1124. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1125. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1126. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1127. } else {
  1128. - define_instance_class(k, THREAD);
  1129. + define_instance_class(k, old_class, THREAD);
  1130. }
  1131. }
  1132. + if (redefine_classes_locked) {
  1133. + Thread::current()->redefine_classes_mutex()->unlock();
  1134. + }
  1135. +
  1136. // If parsing the class file or define_instance_class failed, we
  1137. // need to remove the placeholder added on our behalf. But we
  1138. // must make sure parsed_name is valid first (it won't be if we had
  1139. @@ -1122,7 +1142,7 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1140. MutexLocker mu(SystemDictionary_lock, THREAD);
  1141. klassOop check = find_class(parsed_name, class_loader);
  1142. - assert(check == k(), "should be present in the dictionary");
  1143. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1144. klassOop check2 = find_class(h_name, h_loader);
  1145. assert(check == check2, "name inconsistancy in SystemDictionary");
  1146. @@ -1349,7 +1369,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
  1147. }
  1148. }
  1149. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1150. +void SystemDictionary::rollback_redefinition() {
  1151. + dictionary()->rollback_redefinition();
  1152. +}
  1153. +
  1154. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1155. Handle class_loader_h(THREAD, k->class_loader());
  1156. @@ -1376,13 +1400,23 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1157. Symbol* name_h = k->name();
  1158. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1159. int d_index = dictionary()->hash_to_index(d_hash);
  1160. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1161. +
  1162. + // DCEVM: Update version of the klassOop in the system dictionary
  1163. + // TODO: Check for thread safety!
  1164. + if (!old_class.is_null()) {
  1165. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1166. + assert (ok, "must have found old class and updated!");
  1167. + }
  1168. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1169. +
  1170. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1171. // Register class just loaded with class loader (placed in Vector)
  1172. // Note we do this before updating the dictionary, as this can
  1173. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1174. // class in the dictionary and will not update the class hierarchy).
  1175. - if (k->class_loader() != NULL) {
  1176. + // (tw) Only register if not redefining a class.
  1177. + if (k->class_loader() != NULL && old_class.is_null()) {
  1178. methodHandle m(THREAD, Universe::loader_addClass_method());
  1179. JavaValue result(T_VOID);
  1180. JavaCallArguments args(class_loader_h);
  1181. @@ -1408,8 +1442,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1182. }
  1183. k->eager_initialize(THREAD);
  1184. + // (tw) Only notify jvmti if not redefining a class.
  1185. // notify jvmti
  1186. - if (JvmtiExport::should_post_class_load()) {
  1187. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1188. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1189. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1190. @@ -1482,7 +1517,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
  1191. }
  1192. }
  1193. - define_instance_class(k, THREAD);
  1194. + define_instance_class(k, KlassHandle(), THREAD);
  1195. Handle linkage_exception = Handle(); // null handle
  1196. @@ -1612,6 +1647,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
  1197. Universe::flush_dependents_on(k);
  1198. }
  1199. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1200. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1201. + assert(k.not_null(), "just checking");
  1202. +
  1203. + k->remove_from_sibling_list();
  1204. +
  1205. + // TODO: Remove from interfaces.
  1206. +}
  1207. // ----------------------------------------------------------------------------
  1208. // GC support
  1209. @@ -1701,6 +1744,24 @@ void SystemDictionary::oops_do(OopClosure* f) {
  1210. }
  1211. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1212. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1213. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1214. + f->do_oop((oop*) &_well_known_klasses[k]);
  1215. + }
  1216. +
  1217. + {
  1218. + for (int i = 0; i < T_VOID+1; i++) {
  1219. + if (_box_klasses[i] != NULL) {
  1220. + assert(i >= T_BOOLEAN, "checking");
  1221. + f->do_oop((oop*) &_box_klasses[i]);
  1222. + }
  1223. + }
  1224. + }
  1225. +
  1226. + // TODO: Check if we need to call FilterFieldsMap
  1227. +}
  1228. +
  1229. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1230. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1231. f->do_oop((oop*) &_well_known_klasses[k]);
  1232. @@ -1733,6 +1794,11 @@ void SystemDictionary::classes_do(void f(klassOop)) {
  1233. dictionary()->classes_do(f);
  1234. }
  1235. +// (tw) Iterate over all classes in the dictionary.
  1236. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1237. + dictionary()->classes_do(closure);
  1238. +}
  1239. +
  1240. // Added for initialize_itable_for_klass
  1241. // Just the classes from defining class loaders
  1242. // Don't iterate over placeholders
  1243. @@ -1869,7 +1935,9 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) {
  1244. // Preload ref klasses and set reference types
  1245. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1246. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1247. +
  1248. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1249. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1250. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1251. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1252. @@ -1955,7 +2023,11 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
  1253. // also holds array classes
  1254. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1255. - if ((defining == true) || (k() != check)) {
  1256. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1257. + ResourceMark rm(Thread::current());
  1258. + 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());
  1259. + k()->print();
  1260. + check->print();
  1261. linkage_error = "loader (instance of %s): attempted duplicate class "
  1262. "definition for name: \"%s\"";
  1263. } else {
  1264. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1265. index adf82e5..e316f8e 100644
  1266. --- a/src/share/vm/classfile/systemDictionary.hpp
  1267. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1268. @@ -268,7 +268,7 @@ public:
  1269. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1270. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1271. Handle protection_domain,
  1272. - ClassFileStream* st, bool verify, TRAPS);
  1273. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1274. // Lookup an already loaded class. If not found NULL is returned.
  1275. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1276. @@ -309,6 +309,8 @@ public:
  1277. // Iterate over all klasses in dictionary
  1278. // Just the classes from defining class loaders
  1279. static void classes_do(void f(klassOop));
  1280. + static void classes_do(ObjectClosure *closure);
  1281. + static void preloaded_classes_do(OopClosure *closure);
  1282. // Added for initialize_itable_for_klass to handle exceptions
  1283. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1284. // All classes, and their class loaders
  1285. @@ -415,6 +417,8 @@ public:
  1286. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1287. }
  1288. + static void rollback_redefinition();
  1289. +
  1290. public:
  1291. #define WK_KLASS_DECLARE(name, symbol, option) \
  1292. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1293. @@ -596,7 +600,7 @@ private:
  1294. // after waiting, but before reentering SystemDictionary_lock
  1295. // to preserve lock order semantics.
  1296. static void double_lock_wait(Handle lockObject, TRAPS);
  1297. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1298. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1299. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1300. Handle class_loader,
  1301. instanceKlassHandle k, TRAPS);
  1302. @@ -615,12 +619,17 @@ private:
  1303. // Setup link to hierarchy
  1304. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1305. +public:
  1306. +
  1307. + // Remove link to hierarchy
  1308. + static void remove_from_hierarchy(instanceKlassHandle k);
  1309. +
  1310. +private:
  1311. // event based tracing
  1312. static void post_class_load_event(TracingTime start_time, instanceKlassHandle k,
  1313. Handle initiating_loader);
  1314. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1315. -private:
  1316. // We pass in the hashtable index so we can calculate it outside of
  1317. // the SystemDictionary_lock.
  1318. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1319. index da188bb..53455df 100644
  1320. --- a/src/share/vm/classfile/verifier.cpp
  1321. +++ b/src/share/vm/classfile/verifier.cpp
  1322. @@ -106,7 +106,7 @@ bool Verifier::relax_verify_for(oop loader) {
  1323. return !need_verify;
  1324. }
  1325. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1326. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1327. HandleMark hm;
  1328. ResourceMark rm(THREAD);
  1329. @@ -117,7 +117,8 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1330. const char* klassName = klass->external_name();
  1331. bool can_failover = FailOverToOldVerifier &&
  1332. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1333. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1334. + may_use_old_verifier;
  1335. // If the class should be verified, first see if we can use the split
  1336. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1337. @@ -138,6 +139,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1338. tty->print_cr(
  1339. "Fail over class verification to old verifier for: %s", klassName);
  1340. }
  1341. + assert(may_use_old_verifier, "");
  1342. exception_name = inference_verify(
  1343. klass, message_buffer, message_buffer_len, THREAD);
  1344. }
  1345. @@ -145,6 +147,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1346. exception_message = split_verifier.exception_message();
  1347. }
  1348. } else {
  1349. + assert(may_use_old_verifier, "");
  1350. exception_name = inference_verify(
  1351. klass, message_buffer, message_buffer_len, THREAD);
  1352. }
  1353. @@ -159,6 +162,9 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1354. }
  1355. tty->print_cr("End class verification for: %s", klassName);
  1356. }
  1357. + } else if (TraceClassInitialization) {
  1358. + // (tw) Output not verified classes
  1359. + tty->print_cr("Class %s was not verified", klassName);
  1360. }
  1361. if (HAS_PENDING_EXCEPTION) {
  1362. @@ -210,7 +216,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
  1363. // NOTE: this is called too early in the bootstrapping process to be
  1364. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1365. (refl_magic_klass == NULL ||
  1366. - !klass->is_subtype_of(refl_magic_klass) ||
  1367. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1368. VerifyReflectionBytecodes)
  1369. );
  1370. }
  1371. @@ -517,7 +523,7 @@ void ErrorContext::stackmap_details(outputStream* ss, methodOop method) const {
  1372. ClassVerifier::ClassVerifier(
  1373. instanceKlassHandle klass, TRAPS)
  1374. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1375. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1376. _this_type = VerificationType::reference_type(klass->name());
  1377. // Create list to hold symbols in reference area.
  1378. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1379. @@ -547,7 +553,7 @@ void ClassVerifier::verify_class(TRAPS) {
  1380. _klass->external_name());
  1381. }
  1382. - objArrayHandle methods(THREAD, _klass->methods());
  1383. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1384. int num_methods = methods->length();
  1385. for (int index = 0; index < num_methods; index++) {
  1386. @@ -2444,7 +2450,10 @@ void ClassVerifier::verify_invoke_instructions(
  1387. VerificationType stack_object_type =
  1388. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1389. if (current_type() != stack_object_type) {
  1390. - assert(cp->cache() == NULL, "not rewritten yet");
  1391. +
  1392. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1393. + //assert(cp->cache() == NULL, "not rewritten yet");
  1394. +
  1395. Symbol* ref_class_name =
  1396. cp->klass_name_at(cp->klass_ref_index_at(index));
  1397. // See the comments in verify_field_instructions() for
  1398. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1399. index 4457f4a..b1b96f2 100644
  1400. --- a/src/share/vm/classfile/verifier.hpp
  1401. +++ b/src/share/vm/classfile/verifier.hpp
  1402. @@ -47,7 +47,7 @@ class Verifier : AllStatic {
  1403. * Otherwise, no exception is thrown and the return indicates the
  1404. * error.
  1405. */
  1406. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1407. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1408. // Return false if the class is loaded by the bootstrap loader,
  1409. // or if defineClass was called requesting skipping verification
  1410. @@ -256,7 +256,10 @@ class ClassVerifier : public StackObj {
  1411. ErrorContext _error_context; // contains information about an error
  1412. +public:
  1413. void verify_method(methodHandle method, TRAPS);
  1414. +
  1415. +private:
  1416. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1417. void verify_exception_handler_table(u4 code_length, char* code_data,
  1418. int& min, int& max, TRAPS);
  1419. @@ -329,6 +332,7 @@ class ClassVerifier : public StackObj {
  1420. VerificationType object_type() const;
  1421. + instanceKlassHandle _klass_to_verify;
  1422. instanceKlassHandle _klass; // the class being verified
  1423. methodHandle _method; // current method being verified
  1424. VerificationType _this_type; // the verification type of the current class
  1425. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1426. index b4595c6..341de7a 100644
  1427. --- a/src/share/vm/classfile/vmSymbols.hpp
  1428. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1429. @@ -138,6 +138,10 @@
  1430. template(tag_annotation_default, "AnnotationDefault") \
  1431. template(tag_enclosing_method, "EnclosingMethod") \
  1432. template(tag_bootstrap_methods, "BootstrapMethods") \
  1433. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1434. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1435. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1436. + template(tag_code_sections, "CodeSections") \
  1437. \
  1438. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1439. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1440. @@ -377,6 +381,10 @@
  1441. template(oop_size_name, "oop_size") \
  1442. template(static_oop_field_count_name, "static_oop_field_count") \
  1443. \
  1444. + /* mutator in case of class redefinition */ \
  1445. + template(static_transformer_name, "$staticTransformer") \
  1446. + template(transformer_name, "$transformer") \
  1447. + \
  1448. /* non-intrinsic name/signature pairs: */ \
  1449. template(register_method_name, "register") \
  1450. do_alias(register_method_signature, object_void_signature) \
  1451. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1452. index 0feca89..cfa1958 100644
  1453. --- a/src/share/vm/compiler/compileBroker.cpp
  1454. +++ b/src/share/vm/compiler/compileBroker.cpp
  1455. @@ -1181,6 +1181,14 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1456. int comp_level,
  1457. methodHandle hot_method, int hot_count,
  1458. const char* comment, Thread* THREAD) {
  1459. + JavaThread* thread = JavaThread::current();
  1460. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1461. + return NULL; // FIXME: DCEVM: should we do something else?
  1462. + }
  1463. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1464. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1465. + }
  1466. +
  1467. // make sure arguments make sense
  1468. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1469. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1470. @@ -1260,6 +1268,7 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1471. }
  1472. // RedefineClasses() has replaced this method; just return
  1473. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1474. if (method->is_old()) {
  1475. return NULL;
  1476. }
  1477. @@ -1592,6 +1601,8 @@ void CompileBroker::compiler_thread_loop() {
  1478. // Never compile a method if breakpoints are present in it
  1479. if (method()->number_of_breakpoints() == 0) {
  1480. + thread->compilation_mutex()->lock();
  1481. + thread->set_should_bailout(false);
  1482. // Compile the method.
  1483. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1484. #ifdef COMPILER1
  1485. @@ -1615,6 +1626,7 @@ void CompileBroker::compiler_thread_loop() {
  1486. // After compilation is disabled, remove remaining methods from queue
  1487. method->clear_queued_for_compilation();
  1488. }
  1489. + thread->compilation_mutex()->unlock();
  1490. }
  1491. }
  1492. }
  1493. @@ -2164,3 +2176,15 @@ void CompileBroker::print_compiler_threads_on(outputStream* st) {
  1494. st->cr();
  1495. #endif
  1496. }
  1497. +
  1498. +// (tw) Clean up compiler interface after a class redefinition step
  1499. +void CompileBroker::cleanup_after_redefinition() {
  1500. + int num_threads = _method_threads->length();
  1501. +
  1502. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1503. + for (int i=0; i<num_threads; i++) {
  1504. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1505. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1506. + }
  1507. + }
  1508. +}
  1509. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1510. index 29f2b22..37989d1 100644
  1511. --- a/src/share/vm/compiler/compileBroker.hpp
  1512. +++ b/src/share/vm/compiler/compileBroker.hpp
  1513. @@ -408,6 +408,7 @@ class CompileBroker: AllStatic {
  1514. static void print_compiler_threads_on(outputStream* st);
  1515. + static void cleanup_after_redefinition();
  1516. static int get_total_compile_count() { return _total_compile_count; }
  1517. static int get_total_bailout_count() { return _total_bailout_count; }
  1518. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1519. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1520. index b0c9ec8..b3298e0 100644
  1521. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1522. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1523. @@ -162,6 +162,13 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
  1524. }
  1525. }
  1526. +
  1527. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1528. + CompactPoint* cp, HeapWord* compact_top) {
  1529. + ShouldNotReachHere();
  1530. + return NULL;
  1531. +}
  1532. +
  1533. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1534. // update the block offset table. Removed initialize_threshold call because
  1535. // CFLS does not use a block offset array for contiguous spaces.
  1536. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1537. index 3b7bb9a..de7e54b 100644
  1538. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1539. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1540. @@ -149,6 +149,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
  1541. // Support for compacting cms
  1542. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1543. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1544. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1545. // Initialization helpers.
  1546. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1547. index 29841d8..a13a35d 100644
  1548. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1549. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1550. @@ -32,6 +32,8 @@
  1551. #include "oops/objArrayKlass.inline.hpp"
  1552. #include "oops/oop.inline.hpp"
  1553. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1554. +
  1555. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1556. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1557. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1558. @@ -357,3 +359,86 @@ void MarkSweep::trace(const char* msg) {
  1559. }
  1560. #endif
  1561. +
  1562. +// (tw) Copy the rescued objects to their destination address after compaction.
  1563. +void MarkSweep::copy_rescued_objects_back() {
  1564. +
  1565. + if (_rescued_oops != NULL) {
  1566. +
  1567. + for (int i=0; i<_rescued_oops->length(); i++) {
  1568. + oop rescued_obj = _rescued_oops->at(i);
  1569. +
  1570. + int size = rescued_obj->size();
  1571. + oop new_obj = rescued_obj->forwardee();
  1572. +
  1573. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1574. + MarkSweep::update_fields(rescued_obj, new_obj);
  1575. + } else {
  1576. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1577. + }
  1578. +
  1579. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1580. +
  1581. + new_obj->init_mark();
  1582. + assert(new_obj->is_oop(), "must be a valid oop");
  1583. + }
  1584. + _rescued_oops->clear();
  1585. + _rescued_oops = NULL;
  1586. + }
  1587. +}
  1588. +
  1589. +// (tw) Update instances of a class whose fields changed.
  1590. +void MarkSweep::update_fields(oop q, oop new_location) {
  1591. +
  1592. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1593. +
  1594. + klassOop old_klass_oop = q->klass();
  1595. + klassOop new_klass_oop = q->blueprint()->new_version();
  1596. +
  1597. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1598. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1599. +
  1600. + int size = q->size_given_klass(old_klass);
  1601. + int new_size = q->size_given_klass(new_klass);
  1602. +
  1603. + oop tmp_obj = q;
  1604. +
  1605. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1606. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1607. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1608. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1609. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1610. + }
  1611. + }
  1612. +
  1613. + int *cur = new_klass_oop->klass_part()->update_information();
  1614. +
  1615. + tmp_obj->set_klass_no_check(new_klass_oop);
  1616. +
  1617. + if (cur == NULL) {
  1618. + assert(size == new_size, "just checking");
  1619. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1620. + } else {
  1621. + int destOffset = 0;
  1622. + while (*cur != 0) {
  1623. + if (*cur > 0) {
  1624. + int size = *cur;
  1625. + cur++;
  1626. + int offset = *cur;
  1627. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1628. + destOffset += size;
  1629. + cur++;
  1630. + } else {
  1631. + assert(*cur < 0, "");
  1632. + int skip = -*cur;
  1633. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1634. + destOffset += skip;
  1635. + cur++;
  1636. + }
  1637. + }
  1638. + }
  1639. +
  1640. + if (tmp_obj != q) {
  1641. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1642. + }
  1643. +}
  1644. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1645. index eb8252c..b96a677 100644
  1646. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1647. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1648. @@ -117,8 +117,12 @@ class MarkSweep : AllStatic {
  1649. friend class AdjustPointerClosure;
  1650. friend class KeepAliveClosure;
  1651. friend class VM_MarkSweep;
  1652. + friend class GenMarkSweep;
  1653. friend void marksweep_init();
  1654. +public:
  1655. + static GrowableArray<oop>* _rescued_oops;
  1656. +
  1657. //
  1658. // Vars
  1659. //
  1660. @@ -208,6 +212,8 @@ class MarkSweep : AllStatic {
  1661. template <class T> static inline void mark_and_push(T* p);
  1662. static inline void push_objarray(oop obj, size_t index);
  1663. + static void copy_rescued_objects_back();
  1664. + static void update_fields(oop q, oop new_location);
  1665. static void follow_stack(); // Empty marking stack.
  1666. static void preserve_mark(oop p, markOop mark);
  1667. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1668. index 32c0bdb..7e30e78 100644
  1669. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1670. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1671. @@ -402,7 +402,7 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
  1672. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1673. assert(h_exception->is_oop(), "just checking");
  1674. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1675. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1676. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1677. if (ExitVMOnVerifyError) vm_exit(-1);
  1678. ShouldNotReachHere();
  1679. }
  1680. @@ -656,6 +656,82 @@ IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDes
  1681. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1682. IRT_END
  1683. +// (tw) Correctly resolve method when running old code.
  1684. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1685. + {
  1686. + MonitorLockerEx ml(RedefinitionSync_lock);
  1687. + while (Threads::wait_at_instrumentation_entry()) {
  1688. + ml.wait();
  1689. + }
  1690. + }
  1691. + frame f = last_frame(thread);
  1692. + methodOop m = f.interpreter_frame_method();
  1693. + methodOop forward_method = m->forward_method();
  1694. + if (forward_method != NULL) {
  1695. + int bci = f.interpreter_frame_bci();
  1696. +
  1697. + if (TraceRedefineClasses >= 3) {
  1698. + 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));
  1699. + }
  1700. +
  1701. + int next_bci = bci - 1;
  1702. + // First try bci before NOP.
  1703. + if (!m->is_in_code_section(next_bci)) {
  1704. + // Try bci after NOP.
  1705. + next_bci = bci + 1;
  1706. + if (!m->is_in_code_section(next_bci)) return;
  1707. + }
  1708. +
  1709. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1710. + if (TraceRedefineClasses >= 2) {
  1711. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1712. + }
  1713. + RegisterMap reg_map(thread);
  1714. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1715. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1716. + iframe->set_method(forward_method, new_bci - 1);
  1717. + }
  1718. +IRT_END
  1719. +
  1720. +// (tw) Correctly resolve method when running old code.
  1721. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1722. + // extract receiver from the outgoing argument list if necessary
  1723. + Handle receiver(thread, receiverOop);
  1724. +
  1725. + // TODO: Check for invokeinterface!
  1726. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1727. +
  1728. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1729. + klassOop klass = receiverOop->klass();
  1730. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1731. + klass = klass->klass_part()->old_version();
  1732. + }
  1733. +
  1734. + // TODO: Check for correctness if different vtable indices in different versions?
  1735. +
  1736. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1737. + thread->set_vm_result(method);
  1738. +IRT_END
  1739. +
  1740. +// Correctly resolve interface method when running old code.
  1741. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1742. +
  1743. + // extract receiver from the outgoing argument list if necessary
  1744. + Handle receiver(thread, receiverOop);
  1745. +
  1746. + // TODO: Check for invokeinterface!
  1747. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1748. +
  1749. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1750. + klassOop klass = receiverOop->klass();
  1751. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1752. + klass = klass->klass_part()->old_version();
  1753. + }
  1754. +
  1755. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1756. + thread->set_vm_result(method);
  1757. +IRT_END
  1758. +
  1759. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1760. // extract receiver from the outgoing argument list if necessary
  1761. Handle receiver(thread, NULL);
  1762. @@ -684,6 +760,10 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes
  1763. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1764. int retry_count = 0;
  1765. while (info.resolved_method()->is_old()) {
  1766. + // (tw) If we are executing an old method, this is OK!
  1767. + if (method(thread)->is_old()) {
  1768. + break;
  1769. + }
  1770. // It is very unlikely that method is redefined more than 100 times
  1771. // in the middle of resolve. If it is looping here more than 100 times
  1772. // means then there could be a bug here.
  1773. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1774. index 7ec8e49..b60f062 100644
  1775. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1776. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1777. @@ -140,6 +140,9 @@ class InterpreterRuntime: AllStatic {
  1778. static void post_method_entry(JavaThread *thread);
  1779. static void post_method_exit (JavaThread *thread);
  1780. static int interpreter_contains(address pc);
  1781. + static void forward_method(JavaThread *thread);
  1782. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1783. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1784. // Native signature handlers
  1785. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1786. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1787. index b17f405..6acf287 100644
  1788. --- a/src/share/vm/interpreter/linkResolver.cpp
  1789. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1790. @@ -153,8 +153,8 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass
  1791. // Klass resolution
  1792. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1793. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1794. - sel_klass->as_klassOop(),
  1795. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1796. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1797. true)) {
  1798. ResourceMark rm(THREAD);
  1799. Exceptions::fthrow(
  1800. @@ -338,7 +338,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
  1801. // We'll check for the method name first, as that's most likely
  1802. // to be false (so we'll short-circuit out of these tests).
  1803. if (sel_method->name() == vmSymbols::clone_name() &&
  1804. - sel_klass() == SystemDictionary::Object_klass() &&
  1805. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1806. resolved_klass->oop_is_array()) {
  1807. // We need to change "protected" to "public".
  1808. assert(flags.is_protected(), "clone not protected?");
  1809. @@ -404,6 +404,156 @@ void LinkResolver::resolve_method_statically(methodHandle& resolved_method, Klas
  1810. }
  1811. }
  1812. +
  1813. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1814. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1815. +
  1816. + // Interface method lookup?
  1817. + if (is_interface) {
  1818. +
  1819. + // lookup method in this interface or its super, java.lang.Object
  1820. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1821. +
  1822. + if (resolved_method.is_null()) {
  1823. + // lookup method in all the super-interfaces
  1824. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1825. + }
  1826. +
  1827. + // Other methods
  1828. + } else {
  1829. + Handle nested_exception;
  1830. +
  1831. + // 2. lookup method in resolved klass and its super klasses
  1832. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1833. +
  1834. + if (resolved_method.is_null()) { // not found in the class hierarchy
  1835. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1836. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1837. +
  1838. + if (resolved_method.is_null()) {
  1839. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1840. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1841. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1842. + if (HAS_PENDING_EXCEPTION) {
  1843. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1844. + CLEAR_PENDING_EXCEPTION;
  1845. + }
  1846. + }
  1847. + }
  1848. + }
  1849. +}
  1850. +
  1851. +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) {
  1852. +
  1853. + // First attempt unversioned
  1854. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1855. +
  1856. +
  1857. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1858. +
  1859. + // 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).
  1860. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1861. + if (is_static) {
  1862. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1863. + }
  1864. +
  1865. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1866. +
  1867. + if (redefinition_policy != Klass::DynamicCheck) {
  1868. +
  1869. + if (redefinition_policy == Klass::AccessOldMembers) {
  1870. + // Forget looked up fields
  1871. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1872. + }
  1873. +
  1874. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1875. +
  1876. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1877. +
  1878. + // Select correct version for resolved klass.
  1879. + find_correct_resolved_klass(resolved_klass, current_klass);
  1880. +
  1881. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1882. +
  1883. + // FIXME: idubrov
  1884. + //if (sel_klass.is_null()) {
  1885. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1886. + //} else {
  1887. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1888. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1889. + //}
  1890. + }
  1891. + }
  1892. + }
  1893. +}
  1894. +
  1895. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1896. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1897. +
  1898. + // First attempt unversioned
  1899. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1900. +
  1901. + // (tw) Are we in an old method that wants to see a different view on the world?
  1902. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1903. +
  1904. + // 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).
  1905. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1906. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1907. +
  1908. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1909. +
  1910. + // We do not throw the exception
  1911. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1912. + // Forget any new member lookup
  1913. + resolved_method = methodHandle(THREAD, NULL);
  1914. + }
  1915. +
  1916. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1917. +
  1918. + if (resolved_method.is_null()) {
  1919. +
  1920. + // Select correct version for resolved klass.
  1921. + find_correct_resolved_klass(resolved_klass, current_klass);
  1922. +
  1923. + // Now do the lookup in a second attempt with a different resolved klass.
  1924. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1925. +
  1926. + // FIXME: idubrov
  1927. + //IF_TRACE_RC2 {
  1928. + // ResourceMark rm(THREAD);
  1929. + // if (resolved_method.is_null()) {
  1930. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1931. + // } else {
  1932. + // assert(resolved_method->is_old(), "must be old method!");
  1933. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1934. + // }
  1935. + //}
  1936. + }
  1937. + }
  1938. + }
  1939. +
  1940. + if (resolved_method.is_null()) {
  1941. + // no method found
  1942. + ResourceMark rm(THREAD);
  1943. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1944. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1945. + method_name,
  1946. + method_signature));
  1947. + }
  1948. +}
  1949. +
  1950. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1951. + int current_klass_revision = current_klass->revision_number();
  1952. + int resolved_klass_revision = resolved_klass->revision_number();
  1953. + // FIXME: idubrov
  1954. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1955. +
  1956. + while (resolved_klass->revision_number() > current_klass_revision) {
  1957. + assert(resolved_klass->old_version(), "must have old version");
  1958. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1959. + }
  1960. +}
  1961. +
  1962. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1963. Symbol* method_name, Symbol* method_signature,
  1964. KlassHandle current_klass, bool check_access, TRAPS) {
  1965. @@ -416,35 +566,8 @@ void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle res
  1966. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1967. }
  1968. - Handle nested_exception;
  1969. -
  1970. - // 2. lookup method in resolved klass and its super klasses
  1971. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1972. -
  1973. - if (resolved_method.is_null()) { // not found in the class hierarchy
  1974. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1975. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1976. -
  1977. - if (resolved_method.is_null()) {
  1978. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1979. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1980. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1981. - if (HAS_PENDING_EXCEPTION) {
  1982. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1983. - CLEAR_PENDING_EXCEPTION;
  1984. - }
  1985. - }
  1986. -
  1987. - if (resolved_method.is_null()) {
  1988. - // 4. method lookup failed
  1989. - ResourceMark rm(THREAD);
  1990. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1991. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1992. - method_name,
  1993. - method_signature),
  1994. - nested_exception);
  1995. - }
  1996. - }
  1997. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1998. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1999. // 5. check if method is concrete
  2000. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  2001. @@ -512,20 +635,7 @@ void LinkResolver::resolve_interface_method(methodHandle& resolved_method,
  2002. }
  2003. // lookup method in this interface or its super, java.lang.Object
  2004. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  2005. -
  2006. - if (resolved_method.is_null()) {
  2007. - // lookup method in all the super-interfaces
  2008. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  2009. - if (resolved_method.is_null()) {
  2010. - // no method found
  2011. - ResourceMark rm(THREAD);
  2012. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  2013. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  2014. - method_name,
  2015. - method_signature));
  2016. - }
  2017. - }
  2018. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  2019. if (check_access) {
  2020. HandleMark hm(THREAD);
  2021. @@ -612,9 +722,14 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  2022. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  2023. }
  2024. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  2025. +
  2026. // Resolve instance field
  2027. fieldDescriptor fd; // find_field initializes fd if found
  2028. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  2029. +
  2030. + KlassHandle sel_klass;
  2031. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  2032. +
  2033. // check if field exists; i.e., if a klass containing the field def has been selected
  2034. if (sel_klass.is_null()){
  2035. ResourceMark rm(THREAD);
  2036. @@ -622,7 +737,6 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  2037. }
  2038. // check access
  2039. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  2040. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  2041. // check for errors
  2042. @@ -634,7 +748,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  2043. }
  2044. // Final fields can only be accessed from its own class.
  2045. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  2046. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2047. THROW(vmSymbols::java_lang_IllegalAccessError());
  2048. }
  2049. @@ -839,7 +953,7 @@ void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHand
  2050. bool check_access, bool check_null_and_abstract, TRAPS) {
  2051. methodHandle resolved_method;
  2052. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2053. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2054. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2055. }
  2056. // throws linktime exceptions
  2057. @@ -869,6 +983,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  2058. KlassHandle resolved_klass,
  2059. Handle recv,
  2060. KlassHandle recv_klass,
  2061. + KlassHandle current_klass,
  2062. bool check_null_and_abstract,
  2063. TRAPS) {
  2064. @@ -917,7 +1032,40 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  2065. // recv_klass might be an arrayKlassOop but all vtables start at
  2066. // the same place. The cast is to avoid virtual call and assertion.
  2067. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2068. +
  2069. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2070. + // have anything in common, as the receiver type could've been hotswapped.
  2071. + // Does not always work (method could be resolved with correct dynamic type and later
  2072. + // be called at the same place with a wrong dynamic type).
  2073. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2074. +
  2075. + // The vTable must be based on the view of the world of the resolved method
  2076. + klassOop method_holder = resolved_method->method_holder();
  2077. +
  2078. + if (method_holder->klass_part()->new_version() != NULL) {
  2079. + // We are executing in old code
  2080. + // FIXME: idubrov
  2081. + //TRACE_RC2("Calling a method in old code");
  2082. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2083. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2084. + }
  2085. + }
  2086. +
  2087. + if (inst->is_subtype_of(method_holder)) {
  2088. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2089. + } else {
  2090. +
  2091. + tty->print_cr("Failure:");
  2092. + inst->as_klassOop()->print();
  2093. + inst->super()->print();
  2094. + juint off = inst->super_check_offset();
  2095. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2096. + sup->print();
  2097. + method_holder->print();
  2098. +
  2099. + bool b = inst->is_subtype_of(method_holder);
  2100. + 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!");
  2101. + }
  2102. }
  2103. }
  2104. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2105. index dfd74f9..cf6e44a 100644
  2106. --- a/src/share/vm/interpreter/linkResolver.hpp
  2107. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2108. @@ -110,7 +110,11 @@ class CallInfo: public LinkInfo {
  2109. // It does all necessary link-time checks & throws exceptions if necessary.
  2110. class LinkResolver: AllStatic {
  2111. - private:
  2112. +private:
  2113. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2114. + 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);
  2115. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2116. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2117. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2118. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2119. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2120. @@ -133,7 +137,7 @@ class LinkResolver: AllStatic {
  2121. 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);
  2122. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2123. - 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);
  2124. + 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);
  2125. 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);
  2126. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2127. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2128. index 17e9f26..e77500f 100644
  2129. --- a/src/share/vm/interpreter/templateTable.hpp
  2130. +++ b/src/share/vm/interpreter/templateTable.hpp
  2131. @@ -329,8 +329,8 @@ class TemplateTable: AllStatic {
  2132. static void shouldnotreachhere();
  2133. // jvmti support
  2134. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2135. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2136. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2137. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2138. static void jvmti_post_fast_field_mod();
  2139. // debugging of TemplateGenerator
  2140. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2141. index 76e18d8..6af7c14 100644
  2142. --- a/src/share/vm/memory/genMarkSweep.cpp
  2143. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2144. @@ -421,6 +421,7 @@ void GenMarkSweep::mark_sweep_phase4() {
  2145. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2146. // here (perm_gen first rather than last), so we tell the validate code
  2147. // to use a higher index (saved from phase2) when verifying perm_gen.
  2148. + assert(_rescued_oops == NULL, "must be empty before processing");
  2149. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2150. Generation* pg = gch->perm_gen();
  2151. @@ -433,10 +434,14 @@ void GenMarkSweep::mark_sweep_phase4() {
  2152. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2153. + MarkSweep::copy_rescued_objects_back();
  2154. +
  2155. GenCompactClosure blk;
  2156. gch->generation_iterate(&blk, true);
  2157. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2158. + MarkSweep::copy_rescued_objects_back();
  2159. +
  2160. pg->post_compact(); // Shared spaces verification.
  2161. }
  2162. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2163. index 350f583..59faad1 100644
  2164. --- a/src/share/vm/memory/permGen.cpp
  2165. +++ b/src/share/vm/memory/permGen.cpp
  2166. @@ -57,7 +57,12 @@ HeapWord* PermGen::mem_allocate_in_gen(size_t size, Generation* gen) {
  2167. for (;;) {
  2168. {
  2169. - MutexLocker ml(Heap_lock);
  2170. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2171. + Monitor *lock = Heap_lock;
  2172. + if (SafepointSynchronize::is_at_safepoint()) {
  2173. + lock = NULL;
  2174. + }
  2175. + MutexLockerEx ml(lock);
  2176. if ((obj = gen->allocate(size, false)) != NULL) {
  2177. return obj;
  2178. }
  2179. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2180. index f97bc34..9b20d08 100644
  2181. --- a/src/share/vm/memory/space.cpp
  2182. +++ b/src/share/vm/memory/space.cpp
  2183. @@ -378,6 +378,31 @@ void CompactibleSpace::clear(bool mangle_space) {
  2184. _compaction_top = bottom();
  2185. }
  2186. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2187. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2188. +CompactPoint* cp, HeapWord* compact_top) {
  2189. + // First check if we should switch compaction space
  2190. + assert(this == cp->space, "'this' should be current compaction space.");
  2191. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2192. + while (size > compaction_max_size) {
  2193. + // switch to next compaction space
  2194. + cp->space->set_compaction_top(compact_top);
  2195. + cp->space = cp->space->next_compaction_space();
  2196. + if (cp->space == NULL) {
  2197. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2198. + assert(cp->gen != NULL, "compaction must succeed");
  2199. + cp->space = cp->gen->first_compaction_space();
  2200. + assert(cp->space != NULL, "generation must have a first compaction space");
  2201. + }
  2202. + compact_top = cp->space->bottom();
  2203. + cp->space->set_compaction_top(compact_top);
  2204. + cp->threshold = cp->space->initialize_threshold();
  2205. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2206. + }
  2207. +
  2208. + return compact_top;
  2209. +}
  2210. +
  2211. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2212. CompactPoint* cp, HeapWord* compact_top) {
  2213. // q is alive
  2214. @@ -401,7 +426,7 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2215. }
  2216. // store the forwarding pointer into the mark word
  2217. - if ((HeapWord*)q != compact_top) {
  2218. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2219. q->forward_to(oop(compact_top));
  2220. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2221. } else {
  2222. @@ -449,7 +474,208 @@ void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  2223. // Faster object search.
  2224. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2225. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2226. + if (!Universe::is_redefining_gc_run()) {
  2227. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2228. + return;
  2229. + }
  2230. +
  2231. + /* Compute the new addresses for the live objects and store it in the mark
  2232. + * Used by universe::mark_sweep_phase2()
  2233. + */
  2234. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2235. +
  2236. + /* We're sure to be here before any objects are compacted into this
  2237. + * space, so this is a good time to initialize this:
  2238. + */
  2239. + set_compaction_top(bottom());
  2240. +
  2241. + if (cp->space == NULL) {
  2242. + assert(cp->gen != NULL, "need a generation");
  2243. + assert(cp->threshold == NULL, "just checking");
  2244. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2245. + cp->space = cp->gen->first_compaction_space();
  2246. + compact_top = cp->space->bottom();
  2247. + cp->space->set_compaction_top(compact_top);
  2248. + cp->threshold = cp->space->initialize_threshold();
  2249. + } else {
  2250. + compact_top = cp->space->compaction_top();
  2251. + }
  2252. +
  2253. + /* We allow some amount of garbage towards the bottom of the space, so
  2254. + * we don't start compacting before there is a significant gain to be made.
  2255. + * Occasionally, we want to ensure a full compaction, which is determined
  2256. + * by the MarkSweepAlwaysCompactCount parameter.
  2257. + */
  2258. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2259. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2260. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2261. +
  2262. + size_t allowed_deadspace = 0;
  2263. + if (skip_dead) {
  2264. + int ratio = (int)allowed_dead_ratio();
  2265. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2266. + }
  2267. +
  2268. + HeapWord* q = bottom();
  2269. + HeapWord* t = end();
  2270. +
  2271. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2272. + live object. */
  2273. + HeapWord* first_dead = end();/* The first dead object. */
  2274. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2275. + first header of preceding free area. */
  2276. + _first_dead = first_dead;
  2277. +
  2278. + const intx interval = PrefetchScanIntervalInBytes;
  2279. +
  2280. + while (q < t) {
  2281. + assert(!block_is_obj(q) ||
  2282. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2283. + oop(q)->mark()->has_bias_pattern(),
  2284. + "these are the only valid states during a mark sweep");
  2285. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2286. + /* prefetch beyond q */
  2287. + Prefetch::write(q, interval);
  2288. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2289. + size_t size = block_size(q);
  2290. +
  2291. + // DCEVM: begin
  2292. + //////////////////////////////////////////////////////////////////////////
  2293. + size_t forward_size = size;
  2294. +
  2295. + // Compute the forward sizes and leave out objects whose position could
  2296. + // possibly overlap other objects.
  2297. +
  2298. + // DCEVM: There is a new version of the class of q => different size
  2299. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2300. +
  2301. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2302. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2303. + forward_size = new_size;
  2304. + }
  2305. +
  2306. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2307. +
  2308. + bool rescueing = false;
  2309. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2310. + if (MarkSweep::_rescued_oops == NULL) {
  2311. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2312. + }
  2313. + // FIXME: idubrov
  2314. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2315. + MarkSweep::_rescued_oops->append(oop(q));
  2316. + } else {
  2317. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2318. + }
  2319. +
  2320. + if ((size != forward_size || rescueing) && q < first_dead) {
  2321. + // (tw) This object moves => first_dead must be set to here!
  2322. + first_dead = q;
  2323. + }
  2324. + //////////////////////////////////////////////////////////////////////////
  2325. + q += size;
  2326. + end_of_live = q;
  2327. + } else {
  2328. + /* run over all the contiguous dead objects */
  2329. + HeapWord* end = q;
  2330. + do {
  2331. + /* prefetch beyond end */
  2332. + Prefetch::write(end, interval);
  2333. + end += block_size(end);
  2334. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2335. +
  2336. + /* see if we might want to pretend this object is alive so that
  2337. + * we don't have to compact quite as often.
  2338. + */
  2339. + if (allowed_deadspace > 0 && q == compact_top) {
  2340. + size_t sz = pointer_delta(end, q);
  2341. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2342. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2343. + q = end;
  2344. + end_of_live = end;
  2345. + continue;
  2346. + }
  2347. + }
  2348. +
  2349. + /* otherwise, it really is a free region. */
  2350. +
  2351. + /* for the previous LiveRange, record the end of the live objects. */
  2352. + if (liveRange) {
  2353. + liveRange->set_end(q);
  2354. + }
  2355. +
  2356. + /* record the current LiveRange object.
  2357. + * liveRange->start() is overlaid on the mark word.
  2358. + */
  2359. + liveRange = (LiveRange*)q;
  2360. + liveRange->set_start(end);
  2361. + liveRange->set_end(end);
  2362. +
  2363. + /* see if this is the first dead region. */
  2364. + if (q < first_dead) {
  2365. + first_dead = q;
  2366. + }
  2367. +
  2368. + /* move on to the next object */
  2369. + q = end;
  2370. + }
  2371. + }
  2372. +
  2373. + //////////////////////////////////////////////////////////////////////////
  2374. + // Compute the forwarding addresses for the objects that need to be
  2375. + // rescued.
  2376. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2377. + if (MarkSweep::_rescued_oops != NULL) {
  2378. + // FIXME: idubrov
  2379. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2380. +
  2381. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2382. + oop q = MarkSweep::_rescued_oops->at(i);
  2383. +
  2384. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2385. + size_t size = block_size((HeapWord*)q);
  2386. +
  2387. + size_t forward_size = size;
  2388. +
  2389. + // (tw) There is a new version of the class of q => different size
  2390. + if (oop(q)->blueprint()->new_version() != NULL) {
  2391. +
  2392. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2393. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2394. + forward_size = new_size;
  2395. + }
  2396. +
  2397. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2398. + assert(compact_top <= t, "must not write over end of space!");
  2399. + }
  2400. + MarkSweep::_rescued_oops->clear();
  2401. + MarkSweep::_rescued_oops = NULL;
  2402. + }
  2403. + //////////////////////////////////////////////////////////////////////////
  2404. +
  2405. + assert(q == t, "just checking");
  2406. + if (liveRange != NULL) {
  2407. + liveRange->set_end(q);
  2408. + }
  2409. + _end_of_live = end_of_live;
  2410. + if (end_of_live < first_dead) {
  2411. + first_dead = end_of_live;
  2412. + }
  2413. + _first_dead = first_dead;
  2414. +
  2415. +// FIXME: idubrov
  2416. +// if (_first_dead > top()) {
  2417. +// _first_dead = top();
  2418. +// }
  2419. +//
  2420. +// if (_end_of_live > top()) {
  2421. +// _end_of_live = top();
  2422. +// }
  2423. + assert(_first_dead <= top(), "Must be smaller equal");
  2424. + assert(_end_of_live <= top(), "Must be smaller equal");
  2425. +
  2426. + /* save the compaction_top of the compaction space. */
  2427. + cp->space->set_compaction_top(compact_top);
  2428. }
  2429. void Space::adjust_pointers() {
  2430. @@ -490,17 +716,313 @@ void Space::adjust_pointers() {
  2431. assert(q == t, "just checking");
  2432. }
  2433. +
  2434. +#ifdef ASSERT
  2435. +
  2436. +int CompactibleSpace::space_index(oop obj) {
  2437. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2438. +
  2439. + if (heap->is_in_permanent(obj)) {
  2440. + return -1;
  2441. + }
  2442. +
  2443. + int index = 0;
  2444. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2445. + Generation* gen = heap->get_gen(i);
  2446. + CompactibleSpace* space = gen->first_compaction_space();
  2447. + while (space != NULL) {
  2448. + if (space->is_in_reserved(obj)) {
  2449. + return index;
  2450. + }
  2451. + space = space->next_compaction_space();
  2452. + index++;
  2453. + }
  2454. + }
  2455. +
  2456. + tty->print_cr("could not compute space_index for %08xh", obj);
  2457. + index = 0;
  2458. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2459. + Generation* gen = heap->get_gen(i);
  2460. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2461. +
  2462. + CompactibleSpace* space = gen->first_compaction_space();
  2463. + while (space != NULL) {
  2464. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2465. + space = space->next_compaction_space();
  2466. + index++;
  2467. + }
  2468. + }
  2469. +
  2470. + ShouldNotReachHere();
  2471. + return 0;
  2472. +}
  2473. +#endif
  2474. +
  2475. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2476. +
  2477. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2478. +
  2479. + if (old_obj->is_perm()) {
  2480. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2481. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2482. + return true;
  2483. + }
  2484. + }
  2485. +
  2486. + int size = old_obj->size();
  2487. + int original_size = size;
  2488. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2489. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2490. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2491. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2492. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2493. + }
  2494. +
  2495. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2496. +
  2497. + if (is_in_reserved(new_obj)) {
  2498. + // Old and new address are in same space, so just compare the address.
  2499. + // Must rescue if object moves towards the top of the space.
  2500. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2501. + return normalComparison;
  2502. +
  2503. + } else {
  2504. +
  2505. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2506. +
  2507. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2508. + if (tenured_gen->is_in_reserved(new_obj)) {
  2509. + // Must never rescue when moving from the new into the old generation.
  2510. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2511. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2512. + return false;
  2513. +
  2514. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2515. + // Must always rescue when moving from the old into the new generation.
  2516. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2517. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2518. + return true;
  2519. +
  2520. + } else {
  2521. + // In the new generation, eden is located before the from space, so a
  2522. + // simple pointer comparison is sufficient.
  2523. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2524. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2525. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2526. + return normalComparison;
  2527. + }
  2528. + }
  2529. +}
  2530. +
  2531. +oop CompactibleSpace::rescue(oop old_obj) {
  2532. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2533. +
  2534. + int size = old_obj->size();
  2535. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2536. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2537. +
  2538. + if (MarkSweep::_rescued_oops == NULL) {
  2539. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2540. + }
  2541. +
  2542. + MarkSweep::_rescued_oops->append(rescued_obj);
  2543. + return rescued_obj;
  2544. +}
  2545. +
  2546. void CompactibleSpace::adjust_pointers() {
  2547. // Check first is there is any work to do.
  2548. if (used() == 0) {
  2549. return; // Nothing to do.
  2550. }
  2551. -
  2552. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2553. + /* adjust all the interior pointers to point at the new locations of objects
  2554. + * Used by MarkSweep::mark_sweep_phase3() */
  2555. +
  2556. + HeapWord* q = bottom();
  2557. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2558. +
  2559. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2560. +
  2561. + debug_only(HeapWord* prev_q = NULL);
  2562. + debug_only(HeapWord* prev_prev_q = NULL);
  2563. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2564. + if (q < t && _first_dead > q &&
  2565. + !oop(q)->is_gc_marked()) {
  2566. + /* we have a chunk of the space which hasn't moved and we've
  2567. + * reinitialized the mark word during the previous pass, so we can't
  2568. + * use is_gc_marked for the traversal. */
  2569. + HeapWord* end = _first_dead;
  2570. +
  2571. + while (q < end) {
  2572. + /* I originally tried to conjoin "block_start(q) == q" to the
  2573. + * assertion below, but that doesn't work, because you can't
  2574. + * accurately traverse previous objects to get to the current one
  2575. + * after their pointers (including pointers into permGen) have been
  2576. + * updated, until the actual compaction is done. dld, 4/00 */
  2577. + assert(block_is_obj(q),
  2578. + "should be at block boundaries, and should be looking at objs");
  2579. +
  2580. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2581. +
  2582. + /* point all the oops to the new location */
  2583. + size_t size = oop(q)->adjust_pointers();
  2584. + size = adjust_obj_size(size);
  2585. +
  2586. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2587. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2588. +
  2589. + debug_only(prev_prev_prev_q = prev_prev_q);
  2590. + debug_only(prev_prev_q = prev_q);
  2591. + debug_only(prev_q = q);
  2592. + q += size;
  2593. + }
  2594. +
  2595. + // (tw) first_dead can be live object!
  2596. + q = _first_dead;
  2597. +
  2598. +// if (_first_dead == t) {
  2599. +// q = t;
  2600. +// } else {
  2601. +// /* $$$ This is funky. Using this to read the previously written
  2602. +// * LiveRange. See also use below. */
  2603. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2604. +// }
  2605. + }
  2606. +
  2607. + const intx interval = PrefetchScanIntervalInBytes;
  2608. +
  2609. + debug_only(prev_q = NULL);
  2610. + debug_only(prev_prev_q = NULL);
  2611. + debug_only(prev_prev_prev_q = NULL);
  2612. + while (q < t) {
  2613. + /* prefetch beyond q */
  2614. + Prefetch::write(q, interval);
  2615. + if (oop(q)->is_gc_marked()) {
  2616. + /* q is alive */
  2617. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2618. + /* point all the oops to the new location */
  2619. + size_t size = oop(q)->adjust_pointers();
  2620. + size = adjust_obj_size(size);
  2621. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2622. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2623. + debug_only(prev_prev_prev_q = prev_prev_q);
  2624. + debug_only(prev_prev_q = prev_q);
  2625. + debug_only(prev_q = q);
  2626. + q += size;
  2627. + } else {
  2628. + /* q is not a live object, so its mark should point at the next
  2629. + * live object */
  2630. + debug_only(prev_prev_prev_q = prev_prev_q);
  2631. + debug_only(prev_prev_q = prev_q);
  2632. + debug_only(prev_q = q);
  2633. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2634. + assert(q > prev_q, "we should be moving forward through memory");
  2635. + }
  2636. + }
  2637. +
  2638. + assert(q == t, "just checking");
  2639. }
  2640. void CompactibleSpace::compact() {
  2641. - SCAN_AND_COMPACT(obj_size);
  2642. +
  2643. + if(!Universe::is_redefining_gc_run()) {
  2644. + SCAN_AND_COMPACT(obj_size);
  2645. + return;
  2646. + }
  2647. +
  2648. + /* Copy all live objects to their new location
  2649. + * Used by MarkSweep::mark_sweep_phase4() */
  2650. +
  2651. + HeapWord* q = bottom();
  2652. + HeapWord* const t = _end_of_live;
  2653. + debug_only(HeapWord* prev_q = NULL);
  2654. +
  2655. + if (q < t && _first_dead > q &&
  2656. + !oop(q)->is_gc_marked()) {
  2657. + debug_only(
  2658. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2659. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2660. + * the traversal. */
  2661. + HeapWord* const end = _first_dead;
  2662. +
  2663. + while (q < end) {
  2664. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2665. + assert(!oop(q)->is_gc_marked(),
  2666. + "should be unmarked (special dense prefix handling)");
  2667. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2668. + debug_only(prev_q = q);
  2669. + q += size;
  2670. + }
  2671. + ) /* debug_only */
  2672. + // (tw) first_dead can be live object!
  2673. + q = _first_dead;
  2674. +
  2675. + //if (_first_dead == t) {
  2676. + // q = t;
  2677. + //} else {
  2678. + ///* $$$ Funky */
  2679. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2680. + //}
  2681. + }
  2682. +
  2683. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2684. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2685. + while (q < t) {
  2686. + if (!oop(q)->is_gc_marked()) {
  2687. + /* mark is pointer to next marked oop */
  2688. + debug_only(prev_q = q);
  2689. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2690. + assert(q > prev_q, "we should be moving forward through memory");
  2691. + } else {
  2692. + /* prefetch beyond q */
  2693. + Prefetch::read(q, scan_interval);
  2694. +
  2695. + /* size and destination */
  2696. + size_t size = obj_size(q);
  2697. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2698. +
  2699. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2700. + oop dest_obj = rescue(oop(q));
  2701. + debug_only(Copy::fill_to_words(q, size, 0));
  2702. + } else {
  2703. +
  2704. + /* prefetch beyond compaction_top */
  2705. + Prefetch::write(compaction_top, copy_interval);
  2706. +
  2707. + /* copy object and reinit its mark */
  2708. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2709. + compaction_top));
  2710. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2711. +
  2712. + if (oop(q)->blueprint()->new_version() != NULL) {
  2713. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2714. + } else {
  2715. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2716. + }
  2717. + oop(compaction_top)->init_mark();
  2718. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2719. + }
  2720. +
  2721. + debug_only(prev_q = q);
  2722. + q += size;
  2723. + }
  2724. + }
  2725. +
  2726. + /* Let's remember if we were empty before we did the compaction. */
  2727. + bool was_empty = used_region().is_empty();
  2728. + /* Reset space after compaction is complete */
  2729. + reset_after_compaction();
  2730. + /* We do this clear, below, since it has overloaded meanings for some */
  2731. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2732. + /* compacted into will have had their offset table thresholds updated */
  2733. + /* continuously, but those that weren't need to have their thresholds */
  2734. + /* re-initialized. Also mangles unused area for debugging. */
  2735. + if (used_region().is_empty()) {
  2736. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2737. + } else {
  2738. + if (ZapUnusedHeapArea) mangle_unused_area();
  2739. + }
  2740. +
  2741. + //SCAN_AND_COMPACT(obj_size);
  2742. }
  2743. void Space::print_short() const { print_short_on(tty); }
  2744. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2745. index ef2f2c6..b54d470 100644
  2746. --- a/src/share/vm/memory/space.hpp
  2747. +++ b/src/share/vm/memory/space.hpp
  2748. @@ -445,6 +445,9 @@ public:
  2749. // indicates when the next such action should be taken.
  2750. virtual void prepare_for_compaction(CompactPoint* cp);
  2751. // MarkSweep support phase3
  2752. + DEBUG_ONLY(int space_index(oop obj));
  2753. + bool must_rescue(oop old_obj, oop new_obj);
  2754. + oop rescue(oop old_obj);
  2755. virtual void adjust_pointers();
  2756. // MarkSweep support phase4
  2757. virtual void compact();
  2758. @@ -475,6 +478,10 @@ public:
  2759. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2760. HeapWord* compact_top);
  2761. + // (tw)
  2762. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2763. + HeapWord* compact_top);
  2764. +
  2765. // Return a size with adjusments as required of the space.
  2766. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2767. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2768. index 8ce17d9..4c1ba52 100644
  2769. --- a/src/share/vm/memory/universe.cpp
  2770. +++ b/src/share/vm/memory/universe.cpp
  2771. @@ -100,6 +100,8 @@
  2772. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2773. #endif
  2774. +bool Universe::_is_redefining_gc_run = false;
  2775. +
  2776. // Known objects
  2777. klassOop Universe::_boolArrayKlassObj = NULL;
  2778. klassOop Universe::_byteArrayKlassObj = NULL;
  2779. @@ -204,6 +206,38 @@ void Universe::system_classes_do(void f(klassOop)) {
  2780. f(systemObjArrayKlassObj());
  2781. }
  2782. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2783. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2784. +
  2785. + class AlwaysTrueClosure: public BoolObjectClosure {
  2786. + public:
  2787. + void do_object(oop p) { ShouldNotReachHere(); }
  2788. + bool do_object_b(oop p) { return true; }
  2789. + };
  2790. + AlwaysTrueClosure always_true;
  2791. +
  2792. + // General strong roots
  2793. + Universe::oops_do(oopClosure);
  2794. + JNIHandles::oops_do(oopClosure);
  2795. + Threads::oops_do(oopClosure, NULL);
  2796. + ObjectSynchronizer::oops_do(oopClosure);
  2797. + FlatProfiler::oops_do(oopClosure);
  2798. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2799. + JvmtiExport::oops_do(oopClosure);
  2800. + // SO_AllClasses
  2801. + SystemDictionary::oops_do(oopClosure);
  2802. +
  2803. + // Now adjust pointers in remaining weak roots. (All of which should
  2804. + // have been cleared if they pointed to non-surviving objects.)
  2805. + // Global (weak) JNI handles
  2806. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2807. +
  2808. + CodeCache::oops_do(oopClosure);
  2809. + StringTable::oops_do(oopClosure);
  2810. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2811. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2812. +}
  2813. +
  2814. void Universe::oops_do(OopClosure* f, bool do_all) {
  2815. f->do_oop((oop*) &_int_mirror);
  2816. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2817. index da21a8b..676675e 100644
  2818. --- a/src/share/vm/memory/universe.hpp
  2819. +++ b/src/share/vm/memory/universe.hpp
  2820. @@ -127,6 +127,8 @@ class Universe: AllStatic {
  2821. friend class SystemDictionary;
  2822. friend class VMStructs;
  2823. friend class CompactingPermGenGen;
  2824. + friend class Space;
  2825. + friend class ContiguousSpace;
  2826. friend class VM_PopulateDumpSharedSpace;
  2827. friend jint universe_init();
  2828. @@ -258,7 +260,18 @@ class Universe: AllStatic {
  2829. static void compute_verify_oop_data();
  2830. + static bool _is_redefining_gc_run;
  2831. +
  2832. public:
  2833. +
  2834. + static bool is_redefining_gc_run() {
  2835. + return _is_redefining_gc_run;
  2836. + }
  2837. +
  2838. + static void set_redefining_gc_run(bool b) {
  2839. + _is_redefining_gc_run = b;
  2840. + }
  2841. +
  2842. // Known classes in the VM
  2843. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2844. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2845. @@ -403,6 +416,8 @@ class Universe: AllStatic {
  2846. // Iteration
  2847. + static void root_oops_do(OopClosure *f);
  2848. +
  2849. // Apply "f" to the addresses of all the direct heap pointers maintained
  2850. // as static fields of "Universe".
  2851. static void oops_do(OopClosure* f, bool do_all = false);
  2852. @@ -419,6 +434,7 @@ class Universe: AllStatic {
  2853. // Debugging
  2854. static bool verify_in_progress() { return _verify_in_progress; }
  2855. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2856. static void verify(bool silent, VerifyOption option);
  2857. static void verify(bool silent) {
  2858. verify(silent, VerifyOption_Default /* option */);
  2859. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2860. index 4aa1155..2738ea9 100644
  2861. --- a/src/share/vm/oops/arrayKlass.cpp
  2862. +++ b/src/share/vm/oops/arrayKlass.cpp
  2863. @@ -129,9 +129,9 @@ objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
  2864. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2865. // An array is a subtype of Serializable, Clonable, and Object
  2866. - return k == SystemDictionary::Object_klass()
  2867. - || k == SystemDictionary::Cloneable_klass()
  2868. - || k == SystemDictionary::Serializable_klass();
  2869. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2870. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2871. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2872. }
  2873. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2874. index e74811f..be3fe7d 100644
  2875. --- a/src/share/vm/oops/constMethodKlass.cpp
  2876. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2877. @@ -102,6 +102,7 @@ void constMethodKlass::oop_follow_contents(oop obj) {
  2878. constMethodOop cm = constMethodOop(obj);
  2879. MarkSweep::mark_and_push(cm->adr_constants());
  2880. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2881. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2882. // Performance tweak: We skip iterating over the klass pointer since we
  2883. // know that Universe::constMethodKlassObj never moves.
  2884. }
  2885. @@ -113,6 +114,7 @@ void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
  2886. constMethodOop cm_oop = constMethodOop(obj);
  2887. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2888. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2889. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2890. // Performance tweak: We skip iterating over the klass pointer since we
  2891. // know that Universe::constMethodKlassObj never moves.
  2892. }
  2893. @@ -123,6 +125,7 @@ int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  2894. constMethodOop cm = constMethodOop(obj);
  2895. blk->do_oop(cm->adr_constants());
  2896. blk->do_oop(cm->adr_stackmap_data());
  2897. + blk->do_oop(cm->adr_code_section_table());
  2898. // Get size before changing pointers.
  2899. // Don't call size() or oop_size() since that is a virtual call.
  2900. int size = cm->object_size();
  2901. @@ -138,6 +141,8 @@ int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr)
  2902. if (mr.contains(adr)) blk->do_oop(adr);
  2903. adr = cm->adr_stackmap_data();
  2904. if (mr.contains(adr)) blk->do_oop(adr);
  2905. + adr = cm->adr_code_section_table();
  2906. + if (mr.contains(adr)) blk->do_oop(adr);
  2907. // Get size before changing pointers.
  2908. // Don't call size() or oop_size() since that is a virtual call.
  2909. int size = cm->object_size();
  2910. @@ -152,6 +157,7 @@ int constMethodKlass::oop_adjust_pointers(oop obj) {
  2911. constMethodOop cm = constMethodOop(obj);
  2912. MarkSweep::adjust_pointer(cm->adr_constants());
  2913. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2914. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2915. // Get size before changing pointers.
  2916. // Don't call size() or oop_size() since that is a virtual call.
  2917. int size = cm->object_size();
  2918. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2919. index 549192b..5cea5c4 100644
  2920. --- a/src/share/vm/oops/constMethodOop.hpp
  2921. +++ b/src/share/vm/oops/constMethodOop.hpp
  2922. @@ -129,7 +129,7 @@ private:
  2923. public:
  2924. oop* oop_block_beg() const { return adr_constants(); }
  2925. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2926. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2927. private:
  2928. //
  2929. @@ -141,6 +141,9 @@ private:
  2930. // Raw stackmap data for the method
  2931. typeArrayOop _stackmap_data;
  2932. + // (tw) Table mapping code sections for method forward points.
  2933. + typeArrayOop _code_section_table;
  2934. +
  2935. //
  2936. // End of the oop block.
  2937. //
  2938. @@ -195,6 +198,28 @@ public:
  2939. }
  2940. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2941. + // code section table
  2942. + typeArrayOop code_section_table() const { return _code_section_table; }
  2943. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2944. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2945. + static const int ValuesPerCodeSectionEntry = 3;
  2946. + int code_section_entries() const {
  2947. + if (!has_code_section_table()) return 0;
  2948. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2949. + }
  2950. +
  2951. + int code_section_new_index_at(int index) const {
  2952. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2953. + }
  2954. +
  2955. + int code_section_original_index_at(int index) const {
  2956. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2957. + }
  2958. +
  2959. + int code_section_length_at(int index) const {
  2960. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2961. + }
  2962. +
  2963. void init_fingerprint() {
  2964. const uint64_t initval = CONST64(0x8000000000000000);
  2965. _fingerprint = initval;
  2966. @@ -301,6 +326,7 @@ public:
  2967. // Garbage collection support
  2968. oop* adr_constants() const { return (oop*)&_constants; }
  2969. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2970. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2971. bool is_conc_safe() { return _is_conc_safe; }
  2972. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2973. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2974. index ad62921..f39f202 100644
  2975. --- a/src/share/vm/oops/cpCacheOop.cpp
  2976. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2977. @@ -37,9 +37,15 @@
  2978. // Implememtation of ConstantPoolCacheEntry
  2979. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2980. + _flags = other->_flags; // flags
  2981. +}
  2982. +
  2983. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2984. assert(0 < index && index < 0x10000, "sanity check");
  2985. _indices = index;
  2986. + _f1 = NULL;
  2987. + _f2 = 0;
  2988. assert(constant_pool_index() == index, "");
  2989. }
  2990. @@ -162,7 +168,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2991. int vtable_index) {
  2992. assert(!is_secondary_entry(), "");
  2993. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2994. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2995. + // (tw) No longer valid assert
  2996. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2997. int byte_no = -1;
  2998. bool change_to_virtual = false;
  2999. @@ -183,6 +190,7 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  3000. set_method_flags(as_TosState(method->result_type()),
  3001. ( 1 << is_vfinal_shift) |
  3002. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3003. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  3004. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  3005. method()->size_of_parameters());
  3006. set_f2_as_vfinal_method(method());
  3007. @@ -190,9 +198,13 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  3008. assert(vtable_index >= 0, "valid index");
  3009. assert(!method->is_final_method(), "sanity");
  3010. set_method_flags(as_TosState(method->result_type()),
  3011. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  3012. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  3013. method()->size_of_parameters());
  3014. set_f2(vtable_index);
  3015. +
  3016. + // (tw) save method holder in f1 for virtual calls
  3017. + set_f1(method());
  3018. }
  3019. byte_no = 2;
  3020. break;
  3021. @@ -206,7 +218,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  3022. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  3023. set_method_flags(as_TosState(method->result_type()),
  3024. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  3025. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  3026. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3027. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3028. method()->size_of_parameters());
  3029. set_f1(method());
  3030. byte_no = 1;
  3031. @@ -259,7 +272,7 @@ void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index)
  3032. set_f1(interf);
  3033. set_f2(index);
  3034. set_method_flags(as_TosState(method->result_type()),
  3035. - 0, // no option bits
  3036. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3037. method()->size_of_parameters());
  3038. set_bytecode_1(Bytecodes::_invokeinterface);
  3039. }
  3040. @@ -520,27 +533,12 @@ void ConstantPoolCacheEntry::update_pointers() {
  3041. // If this constantPoolCacheEntry refers to old_method then update it
  3042. // to refer to new_method.
  3043. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3044. - methodOop new_method, bool * trace_name_printed) {
  3045. + methodOop new_method) {
  3046. if (is_vfinal()) {
  3047. - // virtual and final so _f2 contains method ptr instead of vtable index
  3048. - if (f2_as_vfinal_method() == old_method) {
  3049. - // match old_method so need an update
  3050. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3051. - _f2 = (intptr_t)new_method;
  3052. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3053. - if (!(*trace_name_printed)) {
  3054. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3055. - RC_TRACE_MESG(("adjust: name=%s",
  3056. - Klass::cast(old_method->method_holder())->external_name()));
  3057. - *trace_name_printed = true;
  3058. - }
  3059. - // RC_TRACE macro has an embedded ResourceMark
  3060. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3061. - new_method->name()->as_C_string(),
  3062. - new_method->signature()->as_C_string()));
  3063. - }
  3064. -
  3065. + // virtual and final so f2() contains method ptr instead of vtable index
  3066. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3067. + initialize_entry(constant_pool_index());
  3068. return true;
  3069. }
  3070. @@ -548,84 +546,27 @@ bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3071. return false;
  3072. }
  3073. - if ((oop)_f1 == NULL) {
  3074. - // NULL f1() means this is a virtual entry so bail out
  3075. - // We are assuming that the vtable index does not need change.
  3076. + // (tw) check how to update interface methods!
  3077. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3078. +
  3079. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3080. + initialize_entry(constant_pool_index());
  3081. + return true;
  3082. + }
  3083. +
  3084. return false;
  3085. }
  3086. if ((oop)_f1 == old_method) {
  3087. _f1 = new_method;
  3088. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3089. - if (!(*trace_name_printed)) {
  3090. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3091. - RC_TRACE_MESG(("adjust: name=%s",
  3092. - Klass::cast(old_method->method_holder())->external_name()));
  3093. - *trace_name_printed = true;
  3094. - }
  3095. - // RC_TRACE macro has an embedded ResourceMark
  3096. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3097. - new_method->name()->as_C_string(),
  3098. - new_method->signature()->as_C_string()));
  3099. - }
  3100. -
  3101. return true;
  3102. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3103. + initialize_entry(constant_pool_index());
  3104. }
  3105. return false;
  3106. }
  3107. -// a constant pool cache entry should never contain old or obsolete methods
  3108. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3109. - if (is_vfinal()) {
  3110. - // virtual and final so _f2 contains method ptr instead of vtable index
  3111. - methodOop m = (methodOop)_f2;
  3112. - // Return false if _f2 refers to an old or an obsolete method.
  3113. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3114. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3115. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3116. - // _f1 == NULL || !_f1->is_method() are OK here
  3117. - return true;
  3118. - }
  3119. -
  3120. - methodOop m = (methodOop)_f1;
  3121. - // return false if _f1 refers to an old or an obsolete method
  3122. - return (!m->is_old() && !m->is_obsolete());
  3123. -}
  3124. -
  3125. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3126. - if (!is_method_entry()) {
  3127. - // not a method entry so not interesting by default
  3128. - return false;
  3129. - }
  3130. -
  3131. - methodOop m = NULL;
  3132. - if (is_vfinal()) {
  3133. - // virtual and final so _f2 contains method ptr instead of vtable index
  3134. - m = f2_as_vfinal_method();
  3135. - } else if (is_f1_null()) {
  3136. - // NULL _f1 means this is a virtual entry so also not interesting
  3137. - return false;
  3138. - } else {
  3139. - oop f1 = _f1; // _f1 is volatile
  3140. - if (!f1->is_method()) {
  3141. - // _f1 can also contain a klassOop for an interface
  3142. - return false;
  3143. - }
  3144. - m = f1_as_method();
  3145. - }
  3146. -
  3147. - assert(m != NULL && m->is_method(), "sanity check");
  3148. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3149. - // robustness for above sanity checks or method is not in
  3150. - // the interesting class
  3151. - return false;
  3152. - }
  3153. -
  3154. - // the method is in the interesting class so the entry is interesting
  3155. - return true;
  3156. -}
  3157. -
  3158. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3159. // print separator
  3160. if (index == 0) st->print_cr(" -------------");
  3161. @@ -663,60 +604,18 @@ void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
  3162. }
  3163. }
  3164. -// RedefineClasses() API support:
  3165. -// If any entry of this constantPoolCache points to any of
  3166. -// old_methods, replace it with the corresponding new_method.
  3167. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3168. - int methods_length, bool * trace_name_printed) {
  3169. -
  3170. - if (methods_length == 0) {
  3171. - // nothing to do if there are no methods
  3172. - return;
  3173. - }
  3174. -
  3175. - // get shorthand for the interesting class
  3176. - klassOop old_holder = old_methods[0]->method_holder();
  3177. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3178. + int methods_length) {
  3179. for (int i = 0; i < length(); i++) {
  3180. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3181. - // skip uninteresting methods
  3182. - continue;
  3183. - }
  3184. -
  3185. - // The constantPoolCache contains entries for several different
  3186. - // things, but we only care about methods. In fact, we only care
  3187. - // about methods in the same class as the one that contains the
  3188. - // old_methods. At this point, we have an interesting entry.
  3189. -
  3190. - for (int j = 0; j < methods_length; j++) {
  3191. - methodOop old_method = old_methods[j];
  3192. - methodOop new_method = new_methods[j];
  3193. -
  3194. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3195. - trace_name_printed)) {
  3196. - // current old_method matched this entry and we updated it so
  3197. - // break out and get to the next interesting entry if there one
  3198. - break;
  3199. - }
  3200. + if (entry_at(i)->is_field_entry()) {
  3201. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3202. + // point to changed fields
  3203. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3204. + } else if(entry_at(i)->is_method_entry()) {
  3205. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3206. }
  3207. }
  3208. }
  3209. -// the constant pool cache should never contain old or obsolete methods
  3210. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3211. - for (int i = 1; i < length(); i++) {
  3212. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3213. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3214. - return false;
  3215. - }
  3216. - }
  3217. - return true;
  3218. -}
  3219. -void constantPoolCacheOopDesc::dump_cache() {
  3220. - for (int i = 1; i < length(); i++) {
  3221. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3222. - entry_at(i)->print(tty, i);
  3223. - }
  3224. - }
  3225. -}
  3226. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3227. index ef26775..6f37d81 100644
  3228. --- a/src/share/vm/oops/cpCacheOop.hpp
  3229. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3230. @@ -136,7 +136,8 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3231. void set_bytecode_2(Bytecodes::Code code);
  3232. void set_f1(oop f1) {
  3233. oop existing_f1 = _f1; // read once
  3234. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3235. + // (tw) need to relax assertion for redefinition
  3236. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3237. oop_store(&_f1, f1);
  3238. }
  3239. void release_set_f1(oop f1);
  3240. @@ -167,6 +168,7 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3241. tos_state_mask = right_n_bits(tos_state_bits),
  3242. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3243. // misc. option bits; can be any bit position in [16..27]
  3244. + is_old_method_shift = 19,
  3245. is_vfinal_shift = 20,
  3246. is_volatile_shift = 21,
  3247. is_final_shift = 22,
  3248. @@ -200,6 +202,8 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3249. void initialize_entry(int original_index); // initialize primary entry
  3250. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3251. + void copy_from(ConstantPoolCacheEntry *other);
  3252. +
  3253. void set_field( // sets entry to resolved field state
  3254. Bytecodes::Code get_code, // the bytecode used for reading the field
  3255. Bytecodes::Code put_code, // the bytecode used for writing the field
  3256. @@ -361,10 +365,7 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3257. // trace_name_printed is set to true if the current call has
  3258. // printed the klass name so that other routines in the adjust_*
  3259. // group don't print the klass name.
  3260. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3261. - bool * trace_name_printed);
  3262. - bool check_no_old_or_obsolete_entries();
  3263. - bool is_interesting_method_entry(klassOop k);
  3264. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3265. // Debugging & Printing
  3266. void print (outputStream* st, int index) const;
  3267. @@ -485,16 +486,9 @@ class constantPoolCacheOopDesc: public oopDesc {
  3268. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3269. }
  3270. - // RedefineClasses() API support:
  3271. - // If any entry of this constantPoolCache points to any of
  3272. - // old_methods, replace it with the corresponding new_method.
  3273. - // trace_name_printed is set to true if the current call has
  3274. - // printed the klass name so that other routines in the adjust_*
  3275. - // group don't print the klass name.
  3276. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3277. - int methods_length, bool * trace_name_printed);
  3278. - bool check_no_old_or_obsolete_entries();
  3279. - void dump_cache();
  3280. + // (tw) Update method and field references
  3281. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3282. + int methods_length);
  3283. };
  3284. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3285. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3286. index cd3dce0..2a0a2aa 100644
  3287. --- a/src/share/vm/oops/instanceKlass.cpp
  3288. +++ b/src/share/vm/oops/instanceKlass.cpp
  3289. @@ -250,12 +250,118 @@ void instanceKlass::initialize(TRAPS) {
  3290. }
  3291. +void instanceKlass::initialize_redefined_class() {
  3292. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3293. + name()->as_C_string()));
  3294. +
  3295. + assert(!is_initialized(), "");
  3296. + assert(this->old_version() != NULL, "");
  3297. + assert(is_linked(), "must be linked before");
  3298. +
  3299. +
  3300. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3301. + class UpdateStaticFieldClosure : public FieldClosure {
  3302. +
  3303. + private:
  3304. + instanceKlassHandle this_oop;
  3305. +
  3306. + public:
  3307. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3308. + this->this_oop = this_oop;
  3309. + }
  3310. +
  3311. + virtual void do_field(fieldDescriptor* fd) {
  3312. + fieldDescriptor result;
  3313. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3314. +
  3315. + if (found && result.is_static()) {
  3316. + int old_offset = result.offset();
  3317. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3318. +
  3319. + oop new_location = this_oop()->java_mirror();
  3320. + oop old_location = this_oop->old_version()->java_mirror();
  3321. + int offset = fd->offset();
  3322. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3323. + fd->name()->as_C_string(), old_offset, offset));
  3324. +
  3325. + oop cur_oop;
  3326. +
  3327. + switch(result.field_type()) {
  3328. +
  3329. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3330. +
  3331. + case T_BOOLEAN:
  3332. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3333. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3334. + break;
  3335. +
  3336. + case T_CHAR:
  3337. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3338. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3339. + break;
  3340. +
  3341. + case T_FLOAT:
  3342. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3343. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3344. + break;
  3345. +
  3346. + case T_DOUBLE:
  3347. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3348. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3349. + break;
  3350. +
  3351. + case T_BYTE:
  3352. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3353. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3354. + break;
  3355. +
  3356. + case T_SHORT:
  3357. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3358. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3359. + break;
  3360. +
  3361. + case T_INT:
  3362. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3363. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3364. + break;
  3365. +
  3366. + case T_LONG:
  3367. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3368. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3369. + break;
  3370. +
  3371. + case T_OBJECT:
  3372. + case T_ARRAY:
  3373. + cur_oop = old_location->obj_field(old_offset);
  3374. + new_location->obj_field_put_raw(offset, cur_oop);
  3375. + old_location->obj_field_put_raw(old_offset, NULL);
  3376. + break;
  3377. +
  3378. + default:
  3379. + ShouldNotReachHere();
  3380. + }
  3381. + } else {
  3382. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3383. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3384. + // field not found
  3385. + // (tw) TODO: Probably this call is not necessary here!
  3386. + // FIXME: idubrov
  3387. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3388. + }
  3389. + }
  3390. + };
  3391. +
  3392. + UpdateStaticFieldClosure cl(this_oop);
  3393. + this->do_local_static_fields(&cl);
  3394. +}
  3395. +
  3396. +
  3397. bool instanceKlass::verify_code(
  3398. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3399. // 1) Verify the bytecodes
  3400. Verifier::Mode mode =
  3401. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3402. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3403. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3404. }
  3405. @@ -362,7 +468,13 @@ bool instanceKlass::link_class_impl(
  3406. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3407. jt->get_thread_stat()->perf_timers_addr(),
  3408. PerfClassTraceTime::CLASS_VERIFY);
  3409. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3410. + if (this_oop->is_redefining()) {
  3411. + Thread::current()->set_pretend_new_universe(true);
  3412. + }
  3413. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3414. + if (this_oop->is_redefining()) {
  3415. + Thread::current()->set_pretend_new_universe(false);
  3416. + }
  3417. if (!verify_ok) {
  3418. return false;
  3419. }
  3420. @@ -400,7 +512,8 @@ bool instanceKlass::link_class_impl(
  3421. }
  3422. #endif
  3423. this_oop->set_init_state(linked);
  3424. - if (JvmtiExport::should_post_class_prepare()) {
  3425. + // (tw) Must check for old version in order to prevent infinite loops.
  3426. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3427. Thread *thread = THREAD;
  3428. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3429. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3430. @@ -673,6 +786,18 @@ bool instanceKlass::implements_interface(klassOop k) const {
  3431. return false;
  3432. }
  3433. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3434. + k = k->klass_part()->newest_version();
  3435. + if (this->newest_version() == k) return true;
  3436. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3437. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3438. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3439. + return true;
  3440. + }
  3441. + }
  3442. + return false;
  3443. +}
  3444. +
  3445. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3446. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3447. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3448. @@ -801,7 +926,25 @@ methodOop instanceKlass::class_initializer() {
  3449. }
  3450. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3451. +
  3452. + ResourceMark rm(THREAD);
  3453. methodHandle h_method(THREAD, this_oop->class_initializer());
  3454. +
  3455. + if (this_oop->revision_number() != -1){
  3456. + methodOop m = NULL;
  3457. + if (AllowAdvancedClassRedefinition) {
  3458. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3459. + }
  3460. + methodHandle method(m);
  3461. + if (method() != NULL && method()->is_static()) {
  3462. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3463. + h_method = method;
  3464. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3465. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3466. + return;
  3467. + }
  3468. + }
  3469. +
  3470. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3471. if (TraceClassInitialization) {
  3472. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3473. @@ -949,6 +1092,137 @@ void instanceKlass::methods_do(void f(methodOop method)) {
  3474. }
  3475. }
  3476. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3477. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3478. + for (int i=0; i<values.length(); i++) {
  3479. + arr[i] = values.at(i);
  3480. + }
  3481. + set_update_information(arr);
  3482. +}
  3483. +
  3484. +void instanceKlass::clear_update_information() {
  3485. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3486. + set_update_information(NULL);
  3487. +}
  3488. +
  3489. +typedef Pair<int, klassOop> typeInfoPair;
  3490. +
  3491. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3492. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3493. + for (int i=0; i<values.length(); i++) {
  3494. + arr[i] = values.at(i);
  3495. + }
  3496. + set_type_check_information(arr);
  3497. +}
  3498. +
  3499. +void instanceKlass::clear_type_check_information() {
  3500. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3501. + set_type_check_information(NULL);
  3502. +}
  3503. +
  3504. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3505. +
  3506. + assert (old_version() != NULL, "must have old version!");
  3507. +
  3508. + klassOop old_klass_oop = old_version();
  3509. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3510. + instanceKlass *new_klass = this;
  3511. +
  3512. + fieldDescriptor fd;
  3513. + fieldDescriptor old_fd;
  3514. +
  3515. + instanceKlass *cur_new_klass = new_klass;
  3516. + klassOop cur_new_klass_oop = this->as_klassOop();
  3517. +
  3518. + if (_fields_not_changed) {
  3519. +
  3520. + class MyFieldClosure : public FieldClosure {
  3521. +
  3522. + FieldEvolutionClosure *_cl;
  3523. + public:
  3524. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3525. + virtual void do_field(fieldDescriptor* fd) {
  3526. + _cl->do_changed_field(fd, fd);
  3527. + }
  3528. + };
  3529. +
  3530. + MyFieldClosure mfc(cl);
  3531. + do_nonstatic_fields(&mfc);
  3532. + } else {
  3533. +
  3534. + _fields_not_changed = true;
  3535. + GrowableArray<fieldDescriptor> fds;
  3536. + while (true) {
  3537. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3538. + fd.initialize(cur_new_klass_oop, fs.index());
  3539. + if (fd.is_static()) {
  3540. + continue;
  3541. + }
  3542. + fds.append(fd);
  3543. + }
  3544. +
  3545. + if (cur_new_klass->super() != NULL) {
  3546. + cur_new_klass_oop = cur_new_klass->super();
  3547. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3548. + } else {
  3549. + break;
  3550. + }
  3551. + }
  3552. +
  3553. + GrowableArray<fieldDescriptor> sortedFds;
  3554. + while (fds.length() > 0) {
  3555. + int minOffset = 0x7fffffff;
  3556. + int minIndex = -1;
  3557. + for (int i=0; i<fds.length(); i++) {
  3558. + int curOffset = fds.adr_at(i)->offset();
  3559. + if (curOffset < minOffset) {
  3560. + minOffset = curOffset;
  3561. + minIndex = i;
  3562. + }
  3563. + }
  3564. +
  3565. + sortedFds.append(fds.at(minIndex));
  3566. + fds.remove_at(minIndex);
  3567. + }
  3568. +
  3569. +
  3570. + for (int i=0; i<sortedFds.length(); i++) {
  3571. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3572. +
  3573. + char found = 0;
  3574. + instanceKlass *cur_old_klass = old_klass;
  3575. + klassOop cur_old_klass_oop = old_klass_oop;
  3576. + while (true) {
  3577. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3578. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3579. + if (old_fd.is_static()) {
  3580. + continue;
  3581. + }
  3582. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3583. + found = 1;
  3584. + break;
  3585. + }
  3586. + }
  3587. + if (!found && cur_old_klass->super()) {
  3588. + cur_old_klass_oop = cur_old_klass->super();
  3589. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3590. + } else {
  3591. + break;
  3592. + }
  3593. + }
  3594. +
  3595. + if (found) {
  3596. + if (old_fd.offset() != fd.offset()) {
  3597. + _fields_not_changed = false;
  3598. + }
  3599. + cl->do_changed_field(&old_fd, &fd);
  3600. + } else {
  3601. + _fields_not_changed = false;
  3602. + cl->do_new_field(&fd);
  3603. + }
  3604. + }
  3605. + }
  3606. +}
  3607. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3608. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3609. @@ -1368,6 +1642,20 @@ jmethodID instanceKlass::jmethod_id_or_null(methodOop method) {
  3610. return id;
  3611. }
  3612. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3613. + size_t idnum = (size_t)method->method_idnum();
  3614. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3615. + size_t length; // length assigned as debugging crumb
  3616. + jmethodID id = NULL;
  3617. + if (jmeths != NULL && // If there is a cache
  3618. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3619. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3620. + return true;
  3621. + }
  3622. +
  3623. + return false;
  3624. +}
  3625. +
  3626. // Cache an itable index
  3627. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3628. @@ -1527,6 +1815,13 @@ void instanceKlass::remove_dependent_nmethod(nmethod* nm) {
  3629. last = b;
  3630. b = b->next();
  3631. }
  3632. +
  3633. + // (tw) Hack as dependencies get wrong version of klassOop
  3634. + if(this->old_version() != NULL) {
  3635. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3636. + return;
  3637. + }
  3638. +
  3639. #ifdef ASSERT
  3640. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3641. nm->print();
  3642. @@ -2382,6 +2677,9 @@ void instanceKlass::oop_print_on(oop obj, outputStream* st) {
  3643. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3644. st->print(BULLET"fake entry for mirror: ");
  3645. mirrored_klass->print_value_on(st);
  3646. + if (mirrored_klass != NULL) {
  3647. + 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());
  3648. + }
  3649. st->cr();
  3650. st->print(BULLET"fake entry resolved_constructor: ");
  3651. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3652. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3653. index 8a849cb..f41f13c 100644
  3654. --- a/src/share/vm/oops/instanceKlass.hpp
  3655. +++ b/src/share/vm/oops/instanceKlass.hpp
  3656. @@ -101,6 +101,22 @@ public:
  3657. virtual void do_field(fieldDescriptor* fd) = 0;
  3658. };
  3659. +// (tw) Iterates over the fields of the old and new class
  3660. +class FieldEvolutionClosure : public StackObj {
  3661. +public:
  3662. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3663. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3664. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3665. +};
  3666. +
  3667. +// (tw) Iterates over the methods of the old and new class
  3668. +class MethodEvolutionClosure : public StackObj {
  3669. +public:
  3670. + virtual void do_new_method(methodOop oop) = 0;
  3671. + virtual void do_old_method(methodOop oop) = 0;
  3672. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3673. +};
  3674. +
  3675. #ifndef PRODUCT
  3676. // Print fields.
  3677. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3678. @@ -285,6 +301,11 @@ class instanceKlass: public Klass {
  3679. // _idnum_allocated_count.
  3680. u1 _init_state; // state of class
  3681. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3682. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3683. + // information is cached.
  3684. + bool _fields_not_changed;
  3685. +
  3686. u1 _reference_type; // reference type
  3687. // embedded Java vtable follows here
  3688. @@ -452,6 +473,7 @@ class instanceKlass: public Klass {
  3689. // initialization (virtuals from Klass)
  3690. bool should_be_initialized() const; // means that initialize should be called
  3691. void initialize(TRAPS);
  3692. + void initialize_redefined_class();
  3693. void link_class(TRAPS);
  3694. bool link_class_or_fail(TRAPS); // returns false on failure
  3695. void unlink_class();
  3696. @@ -629,6 +651,7 @@ class instanceKlass: public Klass {
  3697. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3698. size_t *length_p, jmethodID* id_p);
  3699. jmethodID jmethod_id_or_null(methodOop method);
  3700. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3701. // cached itable index support
  3702. void set_cached_itable_index(size_t idnum, int index);
  3703. @@ -711,6 +734,7 @@ class instanceKlass: public Klass {
  3704. // subclass/subinterface checks
  3705. bool implements_interface(klassOop k) const;
  3706. + bool implements_interface_any_version(klassOop k) const;
  3707. // Access to the implementor of an interface.
  3708. klassOop implementor() const
  3709. @@ -760,6 +784,12 @@ class instanceKlass: public Klass {
  3710. void do_local_static_fields(FieldClosure* cl);
  3711. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3712. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3713. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3714. + void store_update_information(GrowableArray<int> &values);
  3715. + void clear_update_information();
  3716. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3717. + void clear_type_check_information();
  3718. +
  3719. void methods_do(void f(methodOop method));
  3720. void array_klasses_do(void f(klassOop k));
  3721. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3722. index 8e7dc12..63d6dc4 100644
  3723. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3724. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3725. @@ -480,6 +480,28 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  3726. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3727. klassKlass::oop_print_on(obj, st);
  3728. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3729. +
  3730. + st->print(BULLET"revision: %d", ik->revision_number());
  3731. +
  3732. + if (ik->new_version() != NULL) {
  3733. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3734. + }
  3735. +
  3736. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3737. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3738. + }
  3739. +
  3740. + if (ik->old_version() != NULL) {
  3741. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3742. + }
  3743. +
  3744. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3745. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3746. + }
  3747. +
  3748. + st->cr();
  3749. +
  3750. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3751. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3752. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3753. @@ -663,7 +685,7 @@ void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
  3754. }
  3755. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3756. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3757. - guarantee(sib->super() == super, "siblings should have same superklass");
  3758. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3759. sib = sib->next_sibling();
  3760. }
  3761. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3762. index 7db4f03..1171487 100644
  3763. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3764. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3765. @@ -455,10 +455,13 @@ void instanceRefKlass::update_nonstatic_oop_maps(klassOop k) {
  3766. instanceKlass* ik = instanceKlass::cast(k);
  3767. // Check that we have the right class
  3768. - debug_only(static bool first_time = true);
  3769. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3770. - "Invalid update of maps");
  3771. - debug_only(first_time = false);
  3772. +
  3773. + // (tw) Asserts no longer valid for class redefinition
  3774. + // debug_only(static bool first_time = true);
  3775. +
  3776. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3777. + // "Invalid update of maps");
  3778. + //debug_only(first_time = false);
  3779. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3780. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3781. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3782. index 596d5ad..767588c 100644
  3783. --- a/src/share/vm/oops/klass.cpp
  3784. +++ b/src/share/vm/oops/klass.cpp
  3785. @@ -55,6 +55,26 @@ bool Klass::is_subclass_of(klassOop k) const {
  3786. return false;
  3787. }
  3788. +void Klass::update_supers_to_newest_version() {
  3789. +
  3790. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3791. +
  3792. + for (uint i=0; i<primary_super_limit(); i++) {
  3793. + klassOop cur = _primary_supers[i];
  3794. + if (cur != NULL) {
  3795. + _primary_supers[i] = cur->klass_part()->newest_version();
  3796. + }
  3797. + }
  3798. +
  3799. + // Scan the array-of-objects
  3800. + int cnt = secondary_supers()->length();
  3801. + for (int i = 0; i < cnt; i++) {
  3802. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3803. + if (cur != NULL) {
  3804. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3805. + }
  3806. + }
  3807. +}
  3808. bool Klass::search_secondary_supers(klassOop k) const {
  3809. // Put some extra logic here out-of-line, before the search proper.
  3810. // This cuts down the size of the inline method.
  3811. @@ -161,6 +181,16 @@ klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
  3812. kl->set_alloc_size(0);
  3813. TRACE_INIT_ID(kl);
  3814. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3815. + kl->set_redefining(false);
  3816. + kl->set_new_version(NULL);
  3817. + kl->set_old_version(NULL);
  3818. + kl->set_redefinition_index(-1);
  3819. + kl->set_revision_number(-1);
  3820. + kl->set_field_redefinition_policy(DynamicCheck);
  3821. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3822. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3823. +
  3824. kl->set_prototype_header(markOopDesc::prototype());
  3825. kl->set_biased_lock_revocation_count(0);
  3826. kl->set_last_biased_lock_bulk_revocation_time(0);
  3827. @@ -232,7 +262,7 @@ void Klass::initialize_supers(klassOop k, TRAPS) {
  3828. set_super(NULL);
  3829. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3830. assert(super_depth() == 0, "Object must already be initialized properly");
  3831. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3832. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3833. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3834. "initialize this only once to a non-trivial value");
  3835. set_super(k);
  3836. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3837. index bcbd4e7..d086b5d 100644
  3838. --- a/src/share/vm/oops/klass.hpp
  3839. +++ b/src/share/vm/oops/klass.hpp
  3840. @@ -170,6 +170,7 @@ class Klass_vtbl {
  3841. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3842. };
  3843. +template<class L, class R> class Pair;
  3844. class Klass : public Klass_vtbl {
  3845. friend class VMStructs;
  3846. @@ -222,6 +223,39 @@ class Klass : public Klass_vtbl {
  3847. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3848. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3849. + // (tw) Different class redefinition flags of code evolution.
  3850. + enum RedefinitionFlags {
  3851. +
  3852. + // This class is not redefined at all!
  3853. + NoRedefinition,
  3854. +
  3855. + // There are changes to the class meta data.
  3856. + ModifyClass = 1,
  3857. +
  3858. + // The size of the class meta data changes.
  3859. + ModifyClassSize = ModifyClass << 1,
  3860. +
  3861. + // There are change to the instance format.
  3862. + ModifyInstances = ModifyClassSize << 1,
  3863. +
  3864. + // The size of instances changes.
  3865. + ModifyInstanceSize = ModifyInstances << 1,
  3866. +
  3867. + // A super type of this class is removed.
  3868. + RemoveSuperType = ModifyInstanceSize << 1,
  3869. +
  3870. + // This class (or one of its super classes) has an instance transformer method.
  3871. + HasInstanceTransformer = RemoveSuperType << 1,
  3872. + };
  3873. +
  3874. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3875. + enum RedefinitionPolicy {
  3876. + StaticCheck,
  3877. + DynamicCheck,
  3878. + AccessDeletedMembers,
  3879. + AccessOldMembers
  3880. + };
  3881. +
  3882. protected:
  3883. //
  3884. // The oop block. All oop fields must be declared here and only oop fields
  3885. @@ -241,6 +275,10 @@ class Klass : public Klass_vtbl {
  3886. oop _java_mirror;
  3887. // Superclass
  3888. klassOop _super;
  3889. + // Old class
  3890. + klassOop _old_version;
  3891. + // New class
  3892. + klassOop _new_version;
  3893. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3894. klassOop _subklass;
  3895. // Sibling link (or NULL); links all subklasses of a klass
  3896. @@ -253,6 +291,19 @@ class Klass : public Klass_vtbl {
  3897. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3898. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3899. + // (tw) Non-oop fields for enhanced class redefinition
  3900. + jint _revision_number; // The revision number for redefined classes
  3901. + jint _redefinition_index; // Index of this class when performing the redefinition
  3902. + bool _subtype_changed;
  3903. + int _redefinition_flags; // Level of class redefinition
  3904. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3905. + int * _update_information; // Update information
  3906. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3907. + char _method_redefinition_policy;
  3908. + char _field_redefinition_policy;
  3909. + char _static_field_redefinition_policy;
  3910. + bool _is_redefining;
  3911. +
  3912. #ifndef PRODUCT
  3913. int _verify_count; // to avoid redundant verifies
  3914. #endif
  3915. @@ -301,6 +352,99 @@ class Klass : public Klass_vtbl {
  3916. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3917. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3918. + // BEGIN class redefinition utilities
  3919. +
  3920. + // double links between new and old version of a class
  3921. + klassOop old_version() const { return _old_version; }
  3922. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3923. + klassOop new_version() const { return _new_version; }
  3924. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3925. +
  3926. + // A subtype of this class is no longer a subtype
  3927. + bool has_subtype_changed() const { return _subtype_changed; }
  3928. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3929. + _subtype_changed = b; }
  3930. + // state of being redefined
  3931. + int redefinition_index() const { return _redefinition_index; }
  3932. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3933. + void set_redefining(bool b) { _is_redefining = b; }
  3934. + bool is_redefining() const { return _is_redefining; }
  3935. + int redefinition_flags() const { return _redefinition_flags; }
  3936. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3937. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3938. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3939. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3940. +
  3941. + // update information
  3942. + int *update_information() const { return _update_information; }
  3943. + void set_update_information(int *info) { _update_information = info; }
  3944. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3945. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3946. +
  3947. + bool is_same_or_older_version(klassOop klass) const {
  3948. + if (Klass::cast(klass) == this) { return true; }
  3949. + else if (_old_version == NULL) { return false; }
  3950. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3951. + }
  3952. +
  3953. + // Revision number for redefined classes, -1 for originally loaded classes
  3954. + jint revision_number() const {
  3955. + return _revision_number;
  3956. + }
  3957. +
  3958. + bool was_redefined() const {
  3959. + return _revision_number != -1;
  3960. + }
  3961. +
  3962. + void set_revision_number(jint number) {
  3963. + _revision_number = number;
  3964. + }
  3965. +
  3966. + char method_redefinition_policy() {
  3967. + return _method_redefinition_policy;
  3968. + }
  3969. +
  3970. + void set_method_redefinition_policy(char v) {
  3971. + _method_redefinition_policy = v;
  3972. + }
  3973. +
  3974. + char field_redefinition_policy() {
  3975. + return _field_redefinition_policy;
  3976. + }
  3977. +
  3978. + void set_field_redefinition_policy(char v) {
  3979. + _field_redefinition_policy = v;
  3980. + }
  3981. +
  3982. + char static_field_redefinition_policy() {
  3983. + return _static_field_redefinition_policy;
  3984. + }
  3985. +
  3986. + void set_static_field_redefinition_policy(char v) {
  3987. + _static_field_redefinition_policy = v;
  3988. + }
  3989. +
  3990. + klassOop oldest_version() const {
  3991. + if (_old_version == NULL) { return this->as_klassOop(); }
  3992. + else { return _old_version->klass_part()->oldest_version(); };
  3993. + }
  3994. +
  3995. + klassOop newest_version() const {
  3996. + if (_new_version == NULL) { return this->as_klassOop(); }
  3997. + else { return _new_version->klass_part()->newest_version(); };
  3998. + }
  3999. +
  4000. + klassOop active_version() const {
  4001. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  4002. + else { return _new_version->klass_part()->active_version(); };
  4003. + }
  4004. +
  4005. + bool is_newest_version() const {
  4006. + return _new_version == NULL;
  4007. + }
  4008. +
  4009. + // END class redefinition utilities
  4010. +
  4011. objArrayOop secondary_supers() const { return _secondary_supers; }
  4012. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  4013. @@ -361,6 +505,8 @@ class Klass : public Klass_vtbl {
  4014. void set_next_sibling(klassOop s);
  4015. oop* adr_super() const { return (oop*)&_super; }
  4016. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4017. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4018. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  4019. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  4020. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  4021. @@ -490,6 +636,7 @@ class Klass : public Klass_vtbl {
  4022. return search_secondary_supers(k);
  4023. }
  4024. }
  4025. + void update_supers_to_newest_version();
  4026. bool search_secondary_supers(klassOop k) const;
  4027. // Find LCA in class hierarchy
  4028. @@ -816,6 +963,8 @@ class Klass : public Klass_vtbl {
  4029. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  4030. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  4031. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  4032. #endif // SHARE_VM_OOPS_KLASS_HPP
  4033. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  4034. index 06809d5..9c08f32 100644
  4035. --- a/src/share/vm/oops/klassKlass.cpp
  4036. +++ b/src/share/vm/oops/klassKlass.cpp
  4037. @@ -68,6 +68,8 @@ void klassKlass::oop_follow_contents(oop obj) {
  4038. Klass* k = Klass::cast(klassOop(obj));
  4039. // If we are alive it is valid to keep our superclass and subtype caches alive
  4040. MarkSweep::mark_and_push(k->adr_super());
  4041. + MarkSweep::mark_and_push(k->adr_old_version());
  4042. + MarkSweep::mark_and_push(k->adr_new_version());
  4043. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4044. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  4045. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4046. @@ -87,6 +89,8 @@ void klassKlass::oop_follow_contents(ParCompactionManager* cm,
  4047. Klass* k = Klass::cast(klassOop(obj));
  4048. // If we are alive it is valid to keep our superclass and subtype caches alive
  4049. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4050. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4051. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4052. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4053. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4054. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4055. @@ -106,6 +110,8 @@ int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  4056. int size = oop_size(obj);
  4057. Klass* k = Klass::cast(klassOop(obj));
  4058. blk->do_oop(k->adr_super());
  4059. + blk->do_oop(k->adr_old_version());
  4060. + blk->do_oop(k->adr_new_version());
  4061. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4062. blk->do_oop(k->adr_primary_supers()+i);
  4063. blk->do_oop(k->adr_secondary_super_cache());
  4064. @@ -134,6 +140,10 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4065. oop* adr;
  4066. adr = k->adr_super();
  4067. if (mr.contains(adr)) blk->do_oop(adr);
  4068. + adr = k->adr_old_version();
  4069. + if (mr.contains(adr)) blk->do_oop(adr);
  4070. + adr = k->adr_new_version();
  4071. + if (mr.contains(adr)) blk->do_oop(adr);
  4072. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4073. adr = k->adr_primary_supers()+i;
  4074. if (mr.contains(adr)) blk->do_oop(adr);
  4075. @@ -147,6 +157,8 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4076. // The following are "weak links" in the perm gen and are
  4077. // treated specially in a later phase of a perm gen collection.
  4078. assert(oop(k)->is_perm(), "should be in perm");
  4079. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4080. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4081. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4082. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4083. if (blk->should_remember_klasses()
  4084. @@ -167,6 +179,8 @@ int klassKlass::oop_adjust_pointers(oop obj) {
  4085. Klass* k = Klass::cast(klassOop(obj));
  4086. MarkSweep::adjust_pointer(k->adr_super());
  4087. + MarkSweep::adjust_pointer(k->adr_new_version());
  4088. + MarkSweep::adjust_pointer(k->adr_old_version());
  4089. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4090. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4091. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4092. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4093. index f212fc5..9731a9c 100644
  4094. --- a/src/share/vm/oops/klassOop.hpp
  4095. +++ b/src/share/vm/oops/klassOop.hpp
  4096. @@ -41,8 +41,10 @@ class klassOopDesc : public oopDesc {
  4097. // returns the Klass part containing dispatching behavior
  4098. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4099. - // Convenience wrapper
  4100. + // Convenience wrappers
  4101. inline oop java_mirror() const;
  4102. + inline klassOop old_version() const;
  4103. + inline klassOop new_version() const;
  4104. private:
  4105. // These have no implementation since klassOop should never be accessed in this fashion
  4106. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4107. index 94e2e04..09d3088 100644
  4108. --- a/src/share/vm/oops/klassVtable.cpp
  4109. +++ b/src/share/vm/oops/klassVtable.cpp
  4110. @@ -97,7 +97,8 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4111. vtable_length = Universe::base_vtable_size();
  4112. }
  4113. - if (super == NULL && !Universe::is_bootstrapping() &&
  4114. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4115. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4116. vtable_length != Universe::base_vtable_size()) {
  4117. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4118. // only way this should happen is from
  4119. @@ -107,9 +108,9 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4120. vtable_length = Universe::base_vtable_size();
  4121. }
  4122. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4123. - "bad vtable size for class Object");
  4124. + "bad vtable size for class Object");*/
  4125. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4126. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4127. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4128. }
  4129. int klassVtable::index_of(methodOop m, int len) const {
  4130. @@ -657,20 +658,6 @@ bool klassVtable::check_no_old_or_obsolete_entries() {
  4131. return true;
  4132. }
  4133. -void klassVtable::dump_vtable() {
  4134. - tty->print_cr("vtable dump --");
  4135. - for (int i = 0; i < length(); i++) {
  4136. - methodOop m = unchecked_method_at(i);
  4137. - if (m != NULL) {
  4138. - tty->print(" (%5d) ", i);
  4139. - m->access_flags().print_on(tty);
  4140. - tty->print(" -- ");
  4141. - m->print_name(tty);
  4142. - tty->cr();
  4143. - }
  4144. - }
  4145. -}
  4146. -
  4147. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4148. void klassVtable::clear_vtable() {
  4149. for (int i = 0; i < _length; i++) table()[i].clear();
  4150. @@ -1241,6 +1228,7 @@ void klassVtable::verify(outputStream* st, bool forced) {
  4151. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4152. vtableEntry* vte = &vt->table()[index];
  4153. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4154. if (vte->method()->name() != table()[index].method()->name() ||
  4155. vte->method()->signature() != table()[index].method()->signature()) {
  4156. fatal("mismatched name/signature of vtable entries");
  4157. @@ -1260,6 +1248,8 @@ void klassVtable::print() {
  4158. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4159. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4160. + // (tw) TODO: Check: Does not hold?
  4161. + if (method() != NULL) {
  4162. assert(method() != NULL, "must have set method");
  4163. method()->verify();
  4164. // we sub_type, because it could be a miranda method
  4165. @@ -1267,7 +1257,13 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4166. #ifndef PRODUCT
  4167. print();
  4168. #endif
  4169. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4170. + klassOop first_klass = vt->klass()();
  4171. + klassOop second_klass = method()->method_holder();
  4172. + // (tw) the following fatal does not work for old versions of classes
  4173. + if (first_klass->klass_part()->is_newest_version()) {
  4174. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4175. + }
  4176. + }
  4177. }
  4178. }
  4179. @@ -1275,7 +1271,7 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4180. void vtableEntry::print() {
  4181. ResourceMark rm;
  4182. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4183. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4184. if (Verbose) {
  4185. tty->print("m %#lx ", (address)method());
  4186. }
  4187. @@ -1342,6 +1338,33 @@ void klassVtable::print_statistics() {
  4188. tty->print_cr("%6d bytes total", total);
  4189. }
  4190. +bool klassVtable::check_no_old_entries() {
  4191. + // Check that there really is no entry
  4192. + for (int i = 0; i < length(); i++) {
  4193. + methodOop m = unchecked_method_at(i);
  4194. + if (m != NULL) {
  4195. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4196. + return false;
  4197. + }
  4198. + }
  4199. + }
  4200. + return true;
  4201. +}
  4202. +
  4203. +void klassVtable::dump_vtable() {
  4204. + tty->print_cr("vtable dump --");
  4205. + for (int i = 0; i < length(); i++) {
  4206. + methodOop m = unchecked_method_at(i);
  4207. + if (m != NULL) {
  4208. + tty->print(" (%5d) ", i);
  4209. + m->access_flags().print_on(tty);
  4210. + tty->print(" -- ");
  4211. + m->print_name(tty);
  4212. + tty->cr();
  4213. + }
  4214. + }
  4215. +}
  4216. +
  4217. int klassItable::_total_classes; // Total no. of classes with itables
  4218. long klassItable::_total_size; // Total no. of bytes used for itables
  4219. diff --git a/src/share/vm/oops/klassVtable.hpp b/src/share/vm/oops/klassVtable.hpp
  4220. index 405b0c7..0c8d2f7 100644
  4221. --- a/src/share/vm/oops/klassVtable.hpp
  4222. +++ b/src/share/vm/oops/klassVtable.hpp
  4223. @@ -100,6 +100,7 @@ class klassVtable : public ResourceObj {
  4224. int methods_length, bool * trace_name_printed);
  4225. bool check_no_old_or_obsolete_entries();
  4226. void dump_vtable();
  4227. + bool check_no_old_entries();
  4228. // Garbage collection
  4229. void oop_follow_contents();
  4230. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4231. index 75d0b09..f1b7d2f 100644
  4232. --- a/src/share/vm/oops/methodKlass.cpp
  4233. +++ b/src/share/vm/oops/methodKlass.cpp
  4234. @@ -93,6 +93,10 @@ methodOop methodKlass::allocate(constMethodHandle xconst,
  4235. m->set_adapter_entry(NULL);
  4236. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4237. + m->set_forward_method(NULL);
  4238. + m->set_new_version(NULL);
  4239. + m->set_old_version(NULL);
  4240. +
  4241. if (access_flags.is_native()) {
  4242. m->clear_native_function();
  4243. m->set_signature_handler(NULL);
  4244. @@ -122,6 +126,9 @@ void methodKlass::oop_follow_contents(oop obj) {
  4245. // Performance tweak: We skip iterating over the klass pointer since we
  4246. // know that Universe::methodKlassObj never moves.
  4247. MarkSweep::mark_and_push(m->adr_constMethod());
  4248. + MarkSweep::mark_and_push(m->adr_forward_method());
  4249. + MarkSweep::mark_and_push(m->adr_new_version());
  4250. + MarkSweep::mark_and_push(m->adr_old_version());
  4251. if (m->method_data() != NULL) {
  4252. MarkSweep::mark_and_push(m->adr_method_data());
  4253. }
  4254. @@ -135,6 +142,9 @@ void methodKlass::oop_follow_contents(ParCompactionManager* cm,
  4255. // Performance tweak: We skip iterating over the klass pointer since we
  4256. // know that Universe::methodKlassObj never moves.
  4257. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4258. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4259. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4260. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4261. #ifdef COMPILER2
  4262. if (m->method_data() != NULL) {
  4263. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4264. @@ -152,6 +162,9 @@ int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  4265. // Performance tweak: We skip iterating over the klass pointer since we
  4266. // know that Universe::methodKlassObj never moves
  4267. blk->do_oop(m->adr_constMethod());
  4268. + blk->do_oop(m->adr_forward_method());
  4269. + blk->do_oop(m->adr_new_version());
  4270. + blk->do_oop(m->adr_old_version());
  4271. if (m->method_data() != NULL) {
  4272. blk->do_oop(m->adr_method_data());
  4273. }
  4274. @@ -170,6 +183,12 @@ int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4275. oop* adr;
  4276. adr = m->adr_constMethod();
  4277. if (mr.contains(adr)) blk->do_oop(adr);
  4278. + adr = m->adr_new_version();
  4279. + if (mr.contains(adr)) blk->do_oop(adr);
  4280. + adr = m->adr_forward_method();
  4281. + if (mr.contains(adr)) blk->do_oop(adr);
  4282. + adr = m->adr_old_version();
  4283. + if (mr.contains(adr)) blk->do_oop(adr);
  4284. if (m->method_data() != NULL) {
  4285. adr = m->adr_method_data();
  4286. if (mr.contains(adr)) blk->do_oop(adr);
  4287. @@ -187,6 +206,9 @@ int methodKlass::oop_adjust_pointers(oop obj) {
  4288. // Performance tweak: We skip iterating over the klass pointer since we
  4289. // know that Universe::methodKlassObj never moves.
  4290. MarkSweep::adjust_pointer(m->adr_constMethod());
  4291. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4292. + MarkSweep::adjust_pointer(m->adr_new_version());
  4293. + MarkSweep::adjust_pointer(m->adr_old_version());
  4294. if (m->method_data() != NULL) {
  4295. MarkSweep::adjust_pointer(m->adr_method_data());
  4296. }
  4297. @@ -202,6 +224,9 @@ int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
  4298. assert(obj->is_method(), "should be method");
  4299. methodOop m = methodOop(obj);
  4300. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4301. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4302. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4303. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4304. #ifdef COMPILER2
  4305. if (m->method_data() != NULL) {
  4306. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4307. @@ -222,7 +247,18 @@ void methodKlass::oop_print_on(oop obj, outputStream* st) {
  4308. methodOop m = methodOop(obj);
  4309. // get the effect of PrintOopAddress, always, for methods:
  4310. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4311. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4312. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4313. +
  4314. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4315. + st->print(" (old)");
  4316. + }
  4317. + st->cr();
  4318. +
  4319. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4320. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4321. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4322. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4323. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4324. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4325. m->constants()->print_value_on(st); st->cr();
  4326. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4327. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4328. index 4f59d3a..5cdf147 100644
  4329. --- a/src/share/vm/oops/methodOop.cpp
  4330. +++ b/src/share/vm/oops/methodOop.cpp
  4331. @@ -328,6 +328,70 @@ void methodOopDesc::cleanup_inline_caches() {
  4332. }
  4333. +bool methodOopDesc::is_in_code_section(int bci) {
  4334. + // There is no table => every bci is in the code section table.
  4335. + if (!constMethod()->has_code_section_table()) return true;
  4336. +
  4337. + constMethodOop m = constMethod();
  4338. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4339. + u2 new_index = m->code_section_new_index_at(i);
  4340. + u2 length = m->code_section_length_at(i);
  4341. + if (bci >= new_index && bci < new_index + length) {
  4342. + // We are in a specified code section.
  4343. + return true;
  4344. + }
  4345. + }
  4346. +
  4347. + return false;
  4348. +}
  4349. +
  4350. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4351. + int original_bci = -1;
  4352. + if (constMethod()->has_code_section_table()) {
  4353. + assert(is_in_code_section(bci), "can only forward in section");
  4354. + // First calculate back to original bci.
  4355. + constMethodOop m = constMethod();
  4356. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4357. + u2 new_index = m->code_section_new_index_at(i);
  4358. + u2 original_index = m->code_section_original_index_at(i);
  4359. + u2 length = m->code_section_length_at(i);
  4360. + if (bci >= new_index && bci < new_index + length) {
  4361. + // We are in a specified code section.
  4362. + original_bci = bci - new_index + original_index;
  4363. + break;
  4364. + }
  4365. + }
  4366. + assert (original_bci != -1, "must have been in code section");
  4367. + } else {
  4368. + // No code sections specified => we are in an original method.
  4369. + original_bci = bci;
  4370. + }
  4371. +
  4372. + // We know the original bci => match to new method.
  4373. + int new_bci = -1;
  4374. + if (new_method->constMethod()->has_code_section_table()) {
  4375. + // Map to new bci.
  4376. + constMethodOop m = new_method->constMethod();
  4377. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4378. + u2 new_index = m->code_section_new_index_at(i);
  4379. + u2 original_index = m->code_section_original_index_at(i);
  4380. + u2 length = m->code_section_length_at(i);
  4381. + if (original_bci >= original_index && original_bci < original_index + length) {
  4382. + new_bci = original_bci - original_index + new_index;
  4383. + break;
  4384. + }
  4385. + }
  4386. + assert (new_bci != -1, "must have found new code section");
  4387. +
  4388. + } else {
  4389. + // We are in an original method.
  4390. + new_bci = original_bci;
  4391. + }
  4392. +
  4393. + return new_bci;
  4394. +}
  4395. +
  4396. +
  4397. int methodOopDesc::extra_stack_words() {
  4398. // not an inline function, to avoid a header dependency on Interpreter
  4399. return extra_stack_entries() * Interpreter::stackElementSize;
  4400. @@ -1061,6 +1125,9 @@ methodHandle methodOopDesc::clone_with_new_data(methodHandle m, u_char* new_code
  4401. // Reset correct method/const method, method size, and parameter info
  4402. newm->set_constMethod(newcm);
  4403. + newm->set_forward_method(newm->forward_method());
  4404. + newm->set_new_version(newm->new_version());
  4405. + newm->set_old_version(newm->old_version());
  4406. newm->constMethod()->set_code_size(new_code_length);
  4407. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4408. newm->set_method_size(new_method_size);
  4409. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4410. index 486e106..11e52bb 100644
  4411. --- a/src/share/vm/oops/methodOop.hpp
  4412. +++ b/src/share/vm/oops/methodOop.hpp
  4413. @@ -114,6 +114,11 @@ class methodOopDesc : public oopDesc {
  4414. AccessFlags _access_flags; // Access flags
  4415. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4416. // note: can have vtables with >2**16 elements (because of inheritance)
  4417. + // (tw) Newer version of method available?
  4418. + methodOop _forward_method;
  4419. + methodOop _new_version;
  4420. + methodOop _old_version;
  4421. +
  4422. #ifdef CC_INTERP
  4423. int _result_index; // C++ interpreter needs for converting results to/from stack
  4424. #endif
  4425. @@ -175,6 +180,32 @@ class methodOopDesc : public oopDesc {
  4426. int name_index() const { return constMethod()->name_index(); }
  4427. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4428. + methodOop forward_method() const {return _forward_method; }
  4429. + void set_forward_method(methodOop m) { _forward_method = m; }
  4430. + bool has_forward_method() const { return forward_method() != NULL; }
  4431. + methodOop new_version() const {return _new_version; }
  4432. + void set_new_version(methodOop m) { _new_version = m; }
  4433. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4434. +
  4435. + methodOop old_version() const {return _old_version; };
  4436. + void set_old_version(methodOop m) {
  4437. + if (m == NULL) {
  4438. + _old_version = NULL;
  4439. + return;
  4440. + }
  4441. +
  4442. + assert(_old_version == NULL, "may only be set once");
  4443. + assert(this->code_size() == m->code_size(), "must have same code length");
  4444. + _old_version = m;
  4445. + }
  4446. +
  4447. + methodOop oldest_version() const {
  4448. + if(_old_version == NULL) return (methodOop)this;
  4449. + else {
  4450. + return old_version()->oldest_version();
  4451. + }
  4452. + }
  4453. +
  4454. // signature
  4455. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4456. int signature_index() const { return constMethod()->signature_index(); }
  4457. @@ -670,6 +701,10 @@ class methodOopDesc : public oopDesc {
  4458. // Inline cache support
  4459. void cleanup_inline_caches();
  4460. + // (tw) Method forwarding support.
  4461. + bool is_in_code_section(int bci);
  4462. + int calculate_forward_bci(int bci, methodOop new_method);
  4463. +
  4464. // Find if klass for method is loaded
  4465. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4466. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4467. @@ -734,6 +769,9 @@ class methodOopDesc : public oopDesc {
  4468. // Garbage collection support
  4469. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4470. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4471. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4472. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4473. oop* adr_method_data() const { return (oop*)&_method_data; }
  4474. };
  4475. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4476. index 5982c88..4873fca 100644
  4477. --- a/src/share/vm/oops/oop.hpp
  4478. +++ b/src/share/vm/oops/oop.hpp
  4479. @@ -95,6 +95,7 @@ class oopDesc {
  4480. narrowOop* compressed_klass_addr();
  4481. void set_klass(klassOop k);
  4482. + void set_klass_no_check(klassOop k);
  4483. // For klass field compression
  4484. int klass_gap() const;
  4485. @@ -135,6 +136,7 @@ class oopDesc {
  4486. bool is_array() const;
  4487. bool is_objArray() const;
  4488. bool is_klass() const;
  4489. + bool is_instanceKlass() const;
  4490. bool is_thread() const;
  4491. bool is_method() const;
  4492. bool is_constMethod() const;
  4493. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4494. index f4eb2f7..0acb346 100644
  4495. --- a/src/share/vm/oops/oop.inline.hpp
  4496. +++ b/src/share/vm/oops/oop.inline.hpp
  4497. @@ -123,6 +123,14 @@ inline void oopDesc::set_klass(klassOop k) {
  4498. }
  4499. }
  4500. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4501. + if (UseCompressedOops) {
  4502. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4503. + } else {
  4504. + oop_store_without_check(klass_addr(), (oop) k);
  4505. + }
  4506. +}
  4507. +
  4508. inline int oopDesc::klass_gap() const {
  4509. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4510. }
  4511. @@ -156,6 +164,7 @@ inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_
  4512. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4513. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4514. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4515. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4516. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4517. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4518. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4519. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4520. index 2123991..6cbd78c 100644
  4521. --- a/src/share/vm/prims/jni.cpp
  4522. +++ b/src/share/vm/prims/jni.cpp
  4523. @@ -406,7 +406,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
  4524. }
  4525. }
  4526. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4527. - Handle(), &st, true,
  4528. + Handle(), &st, true, KlassHandle(),
  4529. CHECK_NULL);
  4530. if (TraceClassResolution && k != NULL) {
  4531. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4532. index 7dcd968..d59052f 100644
  4533. --- a/src/share/vm/prims/jvm.cpp
  4534. +++ b/src/share/vm/prims/jvm.cpp
  4535. @@ -872,7 +872,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
  4536. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4537. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4538. protection_domain, &st,
  4539. - verify != 0,
  4540. + verify != 0, KlassHandle(),
  4541. CHECK_NULL);
  4542. if (TraceClassResolution && k != NULL) {
  4543. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4544. index 4ac6b82..30b8e84 100644
  4545. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4546. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4547. @@ -290,7 +290,10 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4548. class_definitions[index].klass = jcls;
  4549. }
  4550. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4551. - VMThread::execute(&op);
  4552. + {
  4553. + MutexLocker sd_mutex(RedefineClasses_lock);
  4554. + VMThread::execute(&op);
  4555. + }
  4556. return (op.check_error());
  4557. } /* end RetransformClasses */
  4558. @@ -299,9 +302,12 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4559. // class_definitions - pre-checked for NULL
  4560. jvmtiError
  4561. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4562. -//TODO: add locking
  4563. +
  4564. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4565. - VMThread::execute(&op);
  4566. + {
  4567. + MutexLocker sd_mutex(RedefineClasses_lock);
  4568. + VMThread::execute(&op);
  4569. + }
  4570. return (op.check_error());
  4571. } /* end RedefineClasses */
  4572. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4573. index ec8ede3..2bd5983 100644
  4574. --- a/src/share/vm/prims/jvmtiExport.cpp
  4575. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4576. @@ -2296,7 +2296,7 @@ JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(N
  4577. // iterate over any code blob descriptors collected and post a
  4578. // DYNAMIC_CODE_GENERATED event to the profiler.
  4579. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4580. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4581. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4582. // iterate over any code blob descriptors that we collected
  4583. if (_code_blobs != NULL) {
  4584. for (int i=0; i<_code_blobs->length(); i++) {
  4585. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4586. index d3fa140..f4f8b57 100644
  4587. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4588. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4589. @@ -286,6 +286,8 @@ address JvmtiBreakpoint::getBcp() {
  4590. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4591. ((methodOopDesc*)_method->*meth_act)(_bci);
  4592. + // DCEVM: TODO: Check how we can implement this differently here!
  4593. +
  4594. // add/remove breakpoint to/from versions of the method that
  4595. // are EMCP. Directly or transitively obsolete methods are
  4596. // not saved in the PreviousVersionInfo.
  4597. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4598. index eb52388..640e7da 100644
  4599. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4600. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4601. @@ -1,5 +1,5 @@
  4602. /*
  4603. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  4604. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4605. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4606. *
  4607. * This code is free software; you can redistribute it and/or modify it
  4608. @@ -30,498 +30,637 @@
  4609. #include "interpreter/rewriter.hpp"
  4610. #include "memory/gcLocker.hpp"
  4611. #include "memory/universe.inline.hpp"
  4612. -#include "oops/fieldStreams.hpp"
  4613. +#include "memory/cardTableRS.hpp"
  4614. #include "oops/klassVtable.hpp"
  4615. +#include "oops/fieldStreams.hpp"
  4616. #include "prims/jvmtiImpl.hpp"
  4617. #include "prims/jvmtiRedefineClasses.hpp"
  4618. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4619. #include "prims/methodComparator.hpp"
  4620. #include "runtime/deoptimization.hpp"
  4621. #include "runtime/relocator.hpp"
  4622. #include "utilities/bitMap.inline.hpp"
  4623. +#include "compiler/compileBroker.hpp"
  4624. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4625. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4626. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4627. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4628. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4629. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4630. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4631. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4632. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4633. +int* VM_RedefineClasses::_added_methods = NULL;
  4634. int VM_RedefineClasses::_matching_methods_length = 0;
  4635. int VM_RedefineClasses::_deleted_methods_length = 0;
  4636. int VM_RedefineClasses::_added_methods_length = 0;
  4637. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4638. +// Holds the revision number of the current class redefinition
  4639. +int VM_RedefineClasses::_revision_number = -1;
  4640. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4641. - const jvmtiClassDefinition *class_defs,
  4642. - JvmtiClassLoadKind class_load_kind) {
  4643. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4644. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4645. + RC_TIMER_START(_timer_total);
  4646. _class_count = class_count;
  4647. _class_defs = class_defs;
  4648. _class_load_kind = class_load_kind;
  4649. - _res = JVMTI_ERROR_NONE;
  4650. + _updated_oops = NULL;
  4651. + _result = JVMTI_ERROR_NONE;
  4652. }
  4653. -bool VM_RedefineClasses::doit_prologue() {
  4654. - if (_class_count == 0) {
  4655. - _res = JVMTI_ERROR_NONE;
  4656. - return false;
  4657. +VM_RedefineClasses::~VM_RedefineClasses() {
  4658. + {
  4659. + MonitorLockerEx ml(RedefinitionSync_lock);
  4660. + Threads::set_wait_at_instrumentation_entry(false);
  4661. + ml.notify_all();
  4662. + }
  4663. +
  4664. + unlock_threads();
  4665. + RC_TIMER_STOP(_timer_total);
  4666. +
  4667. + if (TimeRedefineClasses) {
  4668. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4669. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4670. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4671. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4672. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4673. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4674. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4675. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4676. + tty->print_cr("------------------------------------------------------------------");
  4677. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4678. }
  4679. - if (_class_defs == NULL) {
  4680. - _res = JVMTI_ERROR_NULL_POINTER;
  4681. - return false;
  4682. +}
  4683. +
  4684. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4685. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4686. +
  4687. + // Create array with all classes for which the redefine command was given
  4688. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4689. + for (int i=0; i<_class_count; i++) {
  4690. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4691. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4692. + klasses_to_redefine.append(klass_handle);
  4693. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4694. }
  4695. - for (int i = 0; i < _class_count; i++) {
  4696. - if (_class_defs[i].klass == NULL) {
  4697. - _res = JVMTI_ERROR_INVALID_CLASS;
  4698. - return false;
  4699. - }
  4700. - if (_class_defs[i].class_byte_count == 0) {
  4701. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4702. - return false;
  4703. - }
  4704. - if (_class_defs[i].class_bytes == NULL) {
  4705. - _res = JVMTI_ERROR_NULL_POINTER;
  4706. - return false;
  4707. +
  4708. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4709. + GrowableArray<instanceKlassHandle> affected_classes;
  4710. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4711. +
  4712. + // Trace affected classes
  4713. + if (RC_TRACE_ENABLED(0x00000001)) {
  4714. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4715. + affected_classes.length()));
  4716. + for (int i=0; i<affected_classes.length(); i++) {
  4717. + RC_TRACE(0x00000001, ("%s",
  4718. + affected_classes.at(i)->name()->as_C_string()));
  4719. }
  4720. }
  4721. - // Start timer after all the sanity checks; not quite accurate, but
  4722. - // better than adding a bunch of stop() calls.
  4723. - RC_TIMER_START(_timer_vm_op_prologue);
  4724. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4725. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4726. + all_affected_klasses->appendAll(&affected_classes);
  4727. - // We first load new class versions in the prologue, because somewhere down the
  4728. - // call chain it is required that the current thread is a Java thread.
  4729. - _res = load_new_class_versions(Thread::current());
  4730. - if (_res != JVMTI_ERROR_NONE) {
  4731. - // Free os::malloc allocated memory in load_new_class_version.
  4732. - os::free(_scratch_classes);
  4733. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4734. - return false;
  4735. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4736. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4737. + if (RC_TRACE_ENABLED(0x00000001)) {
  4738. + RC_TRACE(0x00000001, ("Redefine order: "));
  4739. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4740. + RC_TRACE(0x00000001, ("%s",
  4741. + all_affected_klasses->at(i)->name()->as_C_string()));
  4742. + }
  4743. }
  4744. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4745. - return true;
  4746. + return result;
  4747. }
  4748. -void VM_RedefineClasses::doit() {
  4749. - Thread *thread = Thread::current();
  4750. +// Searches for the class bytes of the given class and returns them as a byte array.
  4751. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4752. - if (UseSharedSpaces) {
  4753. - // Sharing is enabled so we remap the shared readonly space to
  4754. - // shared readwrite, private just in case we need to redefine
  4755. - // a shared class. We do the remap during the doit() phase of
  4756. - // the safepoint to be safer.
  4757. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4758. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4759. - ("failed to remap shared readonly space to readwrite, private"));
  4760. - _res = JVMTI_ERROR_INTERNAL;
  4761. - return;
  4762. + *not_changed = false;
  4763. +
  4764. + // Search for the index in the redefinition array that corresponds to the current class
  4765. + int j;
  4766. + for (j=0; j<_class_count; j++) {
  4767. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4768. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4769. + if (the_class_oop == the_class()) {
  4770. + break;
  4771. }
  4772. }
  4773. - for (int i = 0; i < _class_count; i++) {
  4774. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4775. - }
  4776. - // Disable any dependent concurrent compilations
  4777. - SystemDictionary::notice_modification();
  4778. + if (j == _class_count) {
  4779. - // Set flag indicating that some invariants are no longer true.
  4780. - // See jvmtiExport.hpp for detailed explanation.
  4781. - JvmtiExport::set_has_redefined_a_class();
  4782. + *not_changed = true;
  4783. -// check_class() is optionally called for product bits, but is
  4784. -// always called for non-product bits.
  4785. -#ifdef PRODUCT
  4786. - if (RC_TRACE_ENABLED(0x00004000)) {
  4787. -#endif
  4788. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4789. - SystemDictionary::classes_do(check_class, thread);
  4790. -#ifdef PRODUCT
  4791. - }
  4792. -#endif
  4793. -}
  4794. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4795. + // so the user did not specify a different bytecode for that class.
  4796. -void VM_RedefineClasses::doit_epilogue() {
  4797. - // Free os::malloc allocated memory.
  4798. - // The memory allocated in redefine will be free'ed in next VM operation.
  4799. - os::free(_scratch_classes);
  4800. -
  4801. - if (RC_TRACE_ENABLED(0x00000004)) {
  4802. - // Used to have separate timers for "doit" and "all", but the timer
  4803. - // overhead skewed the measurements.
  4804. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4805. - _timer_rsc_phase2.milliseconds();
  4806. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4807. -
  4808. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4809. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4810. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4811. - RC_TRACE(0x00000004,
  4812. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4813. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4814. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4815. + // not cached, we need to reconstitute the class file from VM representation
  4816. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4817. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4818. +
  4819. + JvmtiClassFileReconstituter reconstituter(the_class);
  4820. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4821. + return reconstituter.get_error();
  4822. + }
  4823. +
  4824. + *class_byte_count = (jint)reconstituter.class_file_size();
  4825. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4826. +
  4827. + } else {
  4828. +
  4829. + // it is cached, get it from the cache
  4830. + *class_byte_count = the_class->get_cached_class_file_len();
  4831. + *class_bytes = the_class->get_cached_class_file_bytes();
  4832. + }
  4833. +
  4834. + } else {
  4835. +
  4836. + // Redefine with bytecodes at index j
  4837. + *class_bytes = _class_defs[j].class_bytes;
  4838. + *class_byte_count = _class_defs[j].class_byte_count;
  4839. }
  4840. +
  4841. + return JVMTI_ERROR_NONE;
  4842. }
  4843. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4844. - // classes for primitives cannot be redefined
  4845. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4846. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4847. +bool VM_RedefineClasses::doit_prologue() {
  4848. +
  4849. + _revision_number++;
  4850. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4851. +
  4852. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4853. + RC_TIMER_START(_timer_prologue);
  4854. +
  4855. + if (!check_arguments()) {
  4856. + RC_TIMER_STOP(_timer_prologue);
  4857. return false;
  4858. }
  4859. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4860. - // classes for arrays cannot be redefined
  4861. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4862. +
  4863. + // We first load new class versions in the prologue, because somewhere down the
  4864. + // call chain it is required that the current thread is a Java thread.
  4865. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4866. + _result = load_new_class_versions(Thread::current());
  4867. +
  4868. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4869. + if (_result != JVMTI_ERROR_NONE) {
  4870. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4871. + delete _new_classes;
  4872. + _new_classes = NULL;
  4873. + RC_TIMER_STOP(_timer_prologue);
  4874. return false;
  4875. }
  4876. +
  4877. + RC_TRACE(0x00000001, ("nearly finished"));
  4878. + VM_GC_Operation::doit_prologue();
  4879. + RC_TIMER_STOP(_timer_prologue);
  4880. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4881. return true;
  4882. }
  4883. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4884. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4885. -// direct CP entries, there is just the current entry to append. For
  4886. -// indirect and double-indirect CP entries, there are zero or more
  4887. -// referenced CP entries along with the current entry to append.
  4888. -// Indirect and double-indirect CP entries are handled by recursive
  4889. -// calls to append_entry() as needed. The referenced CP entries are
  4890. -// always appended to *merge_cp_p before the referee CP entry. These
  4891. -// referenced CP entries may already exist in *merge_cp_p in which case
  4892. -// there is nothing extra to append and only the current entry is
  4893. -// appended.
  4894. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4895. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4896. - TRAPS) {
  4897. -
  4898. - // append is different depending on entry tag type
  4899. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4900. -
  4901. - // The old verifier is implemented outside the VM. It loads classes,
  4902. - // but does not resolve constant pool entries directly so we never
  4903. - // see Class entries here with the old verifier. Similarly the old
  4904. - // verifier does not like Class entries in the input constant pool.
  4905. - // The split-verifier is implemented in the VM so it can optionally
  4906. - // and directly resolve constant pool entries to load classes. The
  4907. - // split-verifier can accept either Class entries or UnresolvedClass
  4908. - // entries in the input constant pool. We revert the appended copy
  4909. - // back to UnresolvedClass so that either verifier will be happy
  4910. - // with the constant pool entry.
  4911. - case JVM_CONSTANT_Class:
  4912. - {
  4913. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4914. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4915. - scratch_cp->klass_name_at(scratch_i));
  4916. -
  4917. - if (scratch_i != *merge_cp_length_p) {
  4918. - // The new entry in *merge_cp_p is at a different index than
  4919. - // the new entry in scratch_cp so we need to map the index values.
  4920. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4921. - }
  4922. - (*merge_cp_length_p)++;
  4923. - } break;
  4924. -
  4925. - // these are direct CP entries so they can be directly appended,
  4926. - // but double and long take two constant pool entries
  4927. - case JVM_CONSTANT_Double: // fall through
  4928. - case JVM_CONSTANT_Long:
  4929. - {
  4930. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4931. - THREAD);
  4932. -
  4933. - if (scratch_i != *merge_cp_length_p) {
  4934. - // The new entry in *merge_cp_p is at a different index than
  4935. - // the new entry in scratch_cp so we need to map the index values.
  4936. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4937. - }
  4938. - (*merge_cp_length_p) += 2;
  4939. - } break;
  4940. -
  4941. - // these are direct CP entries so they can be directly appended
  4942. - case JVM_CONSTANT_Float: // fall through
  4943. - case JVM_CONSTANT_Integer: // fall through
  4944. - case JVM_CONSTANT_Utf8: // fall through
  4945. -
  4946. - // This was an indirect CP entry, but it has been changed into
  4947. - // an interned string so this entry can be directly appended.
  4948. - case JVM_CONSTANT_String: // fall through
  4949. -
  4950. - // These were indirect CP entries, but they have been changed into
  4951. - // Symbol*s so these entries can be directly appended.
  4952. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4953. - case JVM_CONSTANT_UnresolvedString:
  4954. - {
  4955. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4956. - THREAD);
  4957. +// Checks basic properties of the arguments of the redefinition command.
  4958. +bool VM_RedefineClasses::check_arguments() {
  4959. - if (scratch_i != *merge_cp_length_p) {
  4960. - // The new entry in *merge_cp_p is at a different index than
  4961. - // the new entry in scratch_cp so we need to map the index values.
  4962. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4963. - }
  4964. - (*merge_cp_length_p)++;
  4965. - } break;
  4966. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4967. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4968. + for (int i = 0; i < _class_count; i++) {
  4969. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4970. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4971. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4972. + }
  4973. - // this is an indirect CP entry so it needs special handling
  4974. - case JVM_CONSTANT_NameAndType:
  4975. - {
  4976. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4977. - int new_name_ref_i = 0;
  4978. - bool match = (name_ref_i < *merge_cp_length_p) &&
  4979. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  4980. - THREAD);
  4981. - if (!match) {
  4982. - // forward reference in *merge_cp_p or not a direct match
  4983. + return true;
  4984. +}
  4985. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  4986. - THREAD);
  4987. - if (found_i != 0) {
  4988. - guarantee(found_i != name_ref_i,
  4989. - "compare_entry_to() and find_matching_entry() do not agree");
  4990. -
  4991. - // Found a matching entry somewhere else in *merge_cp_p so
  4992. - // just need a mapping entry.
  4993. - new_name_ref_i = found_i;
  4994. - map_index(scratch_cp, name_ref_i, found_i);
  4995. - } else {
  4996. - // no match found so we have to append this entry to *merge_cp_p
  4997. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  4998. - THREAD);
  4999. - // The above call to append_entry() can only append one entry
  5000. - // so the post call query of *merge_cp_length_p is only for
  5001. - // the sake of consistency.
  5002. - new_name_ref_i = *merge_cp_length_p - 1;
  5003. +jvmtiError VM_RedefineClasses::check_exception() const {
  5004. + Thread* THREAD = Thread::current();
  5005. + if (HAS_PENDING_EXCEPTION) {
  5006. +
  5007. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5008. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  5009. + ex_name->as_C_string()));
  5010. + if (TraceRedefineClasses >= 1) {
  5011. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  5012. + tty->print_cr("");
  5013. + }
  5014. + CLEAR_PENDING_EXCEPTION;
  5015. +
  5016. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5017. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5018. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5019. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5020. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5021. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5022. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5023. + // The message will be "XXX (wrong name: YYY)"
  5024. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  5025. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5026. + return JVMTI_ERROR_OUT_OF_MEMORY;
  5027. + } else {
  5028. + // Just in case more exceptions can be thrown..
  5029. + return JVMTI_ERROR_FAILS_VERIFICATION;
  5030. + }
  5031. + }
  5032. +
  5033. + return JVMTI_ERROR_NONE;
  5034. +}
  5035. +
  5036. +// Loads all new class versions and stores the instanceKlass handles in an array.
  5037. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5038. +
  5039. + ResourceMark rm(THREAD);
  5040. +
  5041. + RC_TRACE(0x00000001, ("==================================================================="));
  5042. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  5043. + _class_count));
  5044. +
  5045. + // Retrieve an array of all classes that need to be redefined
  5046. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  5047. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  5048. + if (err != JVMTI_ERROR_NONE) {
  5049. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  5050. + (int)err));
  5051. + return err;
  5052. + }
  5053. +
  5054. +
  5055. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5056. +
  5057. + _max_redefinition_flags = Klass::NoRedefinition;
  5058. + jvmtiError result = JVMTI_ERROR_NONE;
  5059. +
  5060. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5061. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  5062. + i+1, all_affected_klasses.length()));
  5063. +
  5064. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5065. + RC_TRACE(0x00000002, ("name=%s",
  5066. + the_class->name()->as_C_string()));
  5067. +
  5068. + the_class->link_class(THREAD);
  5069. + result = check_exception();
  5070. + if (result != JVMTI_ERROR_NONE) break;
  5071. +
  5072. + // Find new class bytes
  5073. + const unsigned char* class_bytes;
  5074. + jint class_byte_count;
  5075. + jvmtiError error;
  5076. + jboolean not_changed;
  5077. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  5078. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  5079. + (int)error));
  5080. + result = error;
  5081. + break;
  5082. + }
  5083. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  5084. +
  5085. +
  5086. + // Set redefined class handle in JvmtiThreadState class.
  5087. + // This redefined class is sent to agent event handler for class file
  5088. + // load hook event.
  5089. + state->set_class_being_redefined(&the_class, _class_load_kind);
  5090. +
  5091. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  5092. +
  5093. + RC_TIMER_STOP(_timer_prologue);
  5094. + RC_TIMER_START(_timer_class_loading);
  5095. +
  5096. +
  5097. + // Parse the stream.
  5098. + Handle the_class_loader(THREAD, the_class->class_loader());
  5099. + Handle protection_domain(THREAD, the_class->protection_domain());
  5100. + Symbol* the_class_sym = the_class->name();
  5101. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  5102. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  5103. + the_class_loader,
  5104. + protection_domain,
  5105. + &st,
  5106. + true,
  5107. + the_class,
  5108. + THREAD));
  5109. +
  5110. + not_changed = false;
  5111. +
  5112. + RC_TIMER_STOP(_timer_class_loading);
  5113. + RC_TIMER_START(_timer_prologue);
  5114. +
  5115. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  5116. + // Clear class_being_redefined just to be sure.
  5117. + state->clear_class_being_redefined();
  5118. +
  5119. + result = check_exception();
  5120. + if (result != JVMTI_ERROR_NONE) break;
  5121. +
  5122. +#ifdef ASSERT
  5123. +
  5124. + assert(new_class() != NULL, "Class could not be loaded!");
  5125. + assert(new_class() != the_class(), "must be different");
  5126. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5127. +
  5128. +
  5129. + objArrayOop k_interfaces = new_class->local_interfaces();
  5130. + for (int j=0; j<k_interfaces->length(); j++) {
  5131. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5132. + }
  5133. +
  5134. + if (!THREAD->is_Compiler_thread()) {
  5135. +
  5136. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5137. + the_class->name()->as_C_string(),
  5138. + (address)(the_class->class_loader()),
  5139. + (address)(the_class->protection_domain())));
  5140. + // If we are on the compiler thread, we must not try to resolve a class.
  5141. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5142. +
  5143. + if (systemLookup != NULL) {
  5144. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5145. +
  5146. +
  5147. + Klass *subklass = new_class()->klass_part()->subklass();
  5148. + while (subklass != NULL) {
  5149. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5150. + subklass = subklass->next_sibling();
  5151. }
  5152. + } else {
  5153. + // This can happen for reflection generated classes.. ?
  5154. + CLEAR_PENDING_EXCEPTION;
  5155. }
  5156. + }
  5157. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5158. - int new_signature_ref_i = 0;
  5159. - match = (signature_ref_i < *merge_cp_length_p) &&
  5160. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  5161. - signature_ref_i, THREAD);
  5162. - if (!match) {
  5163. - // forward reference in *merge_cp_p or not a direct match
  5164. -
  5165. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  5166. - *merge_cp_p, THREAD);
  5167. - if (found_i != 0) {
  5168. - guarantee(found_i != signature_ref_i,
  5169. - "compare_entry_to() and find_matching_entry() do not agree");
  5170. -
  5171. - // Found a matching entry somewhere else in *merge_cp_p so
  5172. - // just need a mapping entry.
  5173. - new_signature_ref_i = found_i;
  5174. - map_index(scratch_cp, signature_ref_i, found_i);
  5175. - } else {
  5176. - // no match found so we have to append this entry to *merge_cp_p
  5177. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  5178. - merge_cp_length_p, THREAD);
  5179. - // The above call to append_entry() can only append one entry
  5180. - // so the post call query of *merge_cp_length_p is only for
  5181. - // the sake of consistency.
  5182. - new_signature_ref_i = *merge_cp_length_p - 1;
  5183. - }
  5184. +#endif
  5185. +
  5186. + if (RC_TRACE_ENABLED(0x00000001)) {
  5187. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5188. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5189. + new_class->name()->as_C_string(),
  5190. + new_class->layout_helper(),
  5191. + the_class->layout_helper()));
  5192. }
  5193. + }
  5194. - // If the referenced entries already exist in *merge_cp_p, then
  5195. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5196. - // In that case, all we are appending is the current entry.
  5197. - if (new_name_ref_i == 0) {
  5198. - new_name_ref_i = name_ref_i;
  5199. - } else {
  5200. - RC_TRACE(0x00080000,
  5201. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5202. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5203. + // Set the new version of the class
  5204. + new_class->set_revision_number(_revision_number);
  5205. + new_class->set_redefinition_index(i);
  5206. + the_class->set_new_version(new_class());
  5207. + _new_classes->append(new_class);
  5208. +
  5209. + assert(new_class->new_version() == NULL, "");
  5210. +
  5211. + int redefinition_flags = Klass::NoRedefinition;
  5212. +
  5213. + if (not_changed) {
  5214. + redefinition_flags = Klass::NoRedefinition;
  5215. + } else if (AllowAdvancedClassRedefinition) {
  5216. + redefinition_flags = calculate_redefinition_flags(new_class);
  5217. + } else {
  5218. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5219. + if (allowed != JVMTI_ERROR_NONE) {
  5220. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5221. + result = allowed;
  5222. + break;
  5223. }
  5224. - if (new_signature_ref_i == 0) {
  5225. - new_signature_ref_i = signature_ref_i;
  5226. - } else {
  5227. - RC_TRACE(0x00080000,
  5228. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5229. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5230. + redefinition_flags = Klass::ModifyClass;
  5231. + }
  5232. +
  5233. + if (new_class->super() != NULL) {
  5234. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5235. + }
  5236. +
  5237. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5238. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5239. + }
  5240. +
  5241. + new_class->set_redefinition_flags(redefinition_flags);
  5242. +
  5243. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5244. +
  5245. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5246. + // TODO: Check if watch access flags of static fields are updated correctly.
  5247. + calculate_instance_update_information(_new_classes->at(i)());
  5248. + } else {
  5249. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5250. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5251. +
  5252. + fieldDescriptor fd_new;
  5253. + fieldDescriptor fd_old;
  5254. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5255. + fd_new.initialize(new_class(), fs.index());
  5256. + fd_old.initialize(new_class->old_version(), fs.index());
  5257. + transfer_special_access_flags(&fd_old, &fd_new);
  5258. }
  5259. + }
  5260. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5261. - new_name_ref_i, new_signature_ref_i);
  5262. - if (scratch_i != *merge_cp_length_p) {
  5263. - // The new entry in *merge_cp_p is at a different index than
  5264. - // the new entry in scratch_cp so we need to map the index values.
  5265. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5266. + if (RC_TRACE_ENABLED(0x00000008)) {
  5267. + if (new_class->super() != NULL) {
  5268. + RC_TRACE(0x00000008, ("Super class is %s",
  5269. + new_class->super()->klass_part()->name()->as_C_string()));
  5270. }
  5271. - (*merge_cp_length_p)++;
  5272. - } break;
  5273. + }
  5274. - // this is a double-indirect CP entry so it needs special handling
  5275. - case JVM_CONSTANT_Fieldref: // fall through
  5276. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5277. - case JVM_CONSTANT_Methodref:
  5278. - {
  5279. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5280. - int new_klass_ref_i = 0;
  5281. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  5282. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  5283. - THREAD);
  5284. - if (!match) {
  5285. - // forward reference in *merge_cp_p or not a direct match
  5286. +#ifdef ASSERT
  5287. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5288. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  5289. - THREAD);
  5290. - if (found_i != 0) {
  5291. - guarantee(found_i != klass_ref_i,
  5292. - "compare_entry_to() and find_matching_entry() do not agree");
  5293. -
  5294. - // Found a matching entry somewhere else in *merge_cp_p so
  5295. - // just need a mapping entry.
  5296. - new_klass_ref_i = found_i;
  5297. - map_index(scratch_cp, klass_ref_i, found_i);
  5298. - } else {
  5299. - // no match found so we have to append this entry to *merge_cp_p
  5300. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  5301. - THREAD);
  5302. - // The above call to append_entry() can only append one entry
  5303. - // so the post call query of *merge_cp_length_p is only for
  5304. - // the sake of consistency. Without the optimization where we
  5305. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  5306. - // could be appended.
  5307. - new_klass_ref_i = *merge_cp_length_p - 1;
  5308. - }
  5309. - }
  5310. + the_class->vtable()->verify(tty);
  5311. + new_class->vtable()->verify(tty);
  5312. +#endif
  5313. - int name_and_type_ref_i =
  5314. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5315. - int new_name_and_type_ref_i = 0;
  5316. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  5317. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  5318. - name_and_type_ref_i, THREAD);
  5319. - if (!match) {
  5320. - // forward reference in *merge_cp_p or not a direct match
  5321. -
  5322. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  5323. - *merge_cp_p, THREAD);
  5324. - if (found_i != 0) {
  5325. - guarantee(found_i != name_and_type_ref_i,
  5326. - "compare_entry_to() and find_matching_entry() do not agree");
  5327. -
  5328. - // Found a matching entry somewhere else in *merge_cp_p so
  5329. - // just need a mapping entry.
  5330. - new_name_and_type_ref_i = found_i;
  5331. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  5332. - } else {
  5333. - // no match found so we have to append this entry to *merge_cp_p
  5334. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  5335. - merge_cp_length_p, THREAD);
  5336. - // The above call to append_entry() can append more than
  5337. - // one entry so the post call query of *merge_cp_length_p
  5338. - // is required in order to get the right index for the
  5339. - // JVM_CONSTANT_NameAndType entry.
  5340. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  5341. + RC_TRACE(0x00000002, ("Verification done!"));
  5342. +
  5343. + if (i == all_affected_klasses.length() - 1) {
  5344. +
  5345. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5346. +
  5347. + RC_TIMER_STOP(_timer_prologue);
  5348. + lock_threads();
  5349. + RC_TIMER_START(_timer_prologue);
  5350. +
  5351. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5352. +
  5353. + klassOop initial_klass = all_affected_klasses.at(j)();
  5354. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5355. + Klass *cur_klass = initial_subklass;
  5356. + while(cur_klass != NULL) {
  5357. +
  5358. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5359. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5360. + if (!all_affected_klasses.contains(handle)) {
  5361. +
  5362. + int k = i + 1;
  5363. + for (; k<all_affected_klasses.length(); k++) {
  5364. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5365. + break;
  5366. + }
  5367. + }
  5368. + all_affected_klasses.insert_before(k, handle);
  5369. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5370. + cur_klass->name()->as_C_string()));
  5371. + }
  5372. + }
  5373. +
  5374. + cur_klass = cur_klass->next_sibling();
  5375. }
  5376. }
  5377. - // If the referenced entries already exist in *merge_cp_p, then
  5378. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  5379. - // 0. In that case, all we are appending is the current entry.
  5380. - if (new_klass_ref_i == 0) {
  5381. - new_klass_ref_i = klass_ref_i;
  5382. - }
  5383. - if (new_name_and_type_ref_i == 0) {
  5384. - new_name_and_type_ref_i = name_and_type_ref_i;
  5385. - }
  5386. + int new_count = all_affected_klasses.length() - 1 - i;
  5387. + if (new_count != 0) {
  5388. - const char *entry_name;
  5389. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5390. - case JVM_CONSTANT_Fieldref:
  5391. - entry_name = "Fieldref";
  5392. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5393. - new_name_and_type_ref_i);
  5394. - break;
  5395. - case JVM_CONSTANT_InterfaceMethodref:
  5396. - entry_name = "IFMethodref";
  5397. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5398. - new_klass_ref_i, new_name_and_type_ref_i);
  5399. - break;
  5400. - case JVM_CONSTANT_Methodref:
  5401. - entry_name = "Methodref";
  5402. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5403. - new_name_and_type_ref_i);
  5404. - break;
  5405. - default:
  5406. - guarantee(false, "bad switch");
  5407. - break;
  5408. + unlock_threads();
  5409. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5410. + new_count));
  5411. }
  5412. + }
  5413. + }
  5414. - if (klass_ref_i != new_klass_ref_i) {
  5415. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5416. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5417. - }
  5418. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5419. - RC_TRACE(0x00080000,
  5420. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5421. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5422. - new_name_and_type_ref_i));
  5423. - }
  5424. + if (result != JVMTI_ERROR_NONE) {
  5425. + rollback();
  5426. + return result;
  5427. + }
  5428. - if (scratch_i != *merge_cp_length_p) {
  5429. - // The new entry in *merge_cp_p is at a different index than
  5430. - // the new entry in scratch_cp so we need to map the index values.
  5431. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5432. - }
  5433. - (*merge_cp_length_p)++;
  5434. - } break;
  5435. + RC_TIMER_STOP(_timer_prologue);
  5436. + RC_TIMER_START(_timer_class_linking);
  5437. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5438. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5439. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5440. + instanceKlassHandle new_class(the_class->new_version());
  5441. - // At this stage, Class or UnresolvedClass could be here, but not
  5442. - // ClassIndex
  5443. - case JVM_CONSTANT_ClassIndex: // fall through
  5444. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5445. + i,
  5446. + all_affected_klasses.length(),
  5447. + the_class->name()->as_C_string()));
  5448. + new_class->link_class(THREAD);
  5449. +
  5450. + result = check_exception();
  5451. + if (result != JVMTI_ERROR_NONE) break;
  5452. + }
  5453. + RC_TIMER_STOP(_timer_class_linking);
  5454. + RC_TIMER_START(_timer_prologue);
  5455. - // Invalid is used as the tag for the second constant pool entry
  5456. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5457. - // not be seen by itself.
  5458. - case JVM_CONSTANT_Invalid: // fall through
  5459. + if (result != JVMTI_ERROR_NONE) {
  5460. + rollback();
  5461. + return result;
  5462. + }
  5463. - // At this stage, String or UnresolvedString could be here, but not
  5464. - // StringIndex
  5465. - case JVM_CONSTANT_StringIndex: // fall through
  5466. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5467. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5468. - // here
  5469. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5470. +#ifdef ASSERT
  5471. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5472. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5473. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5474. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5475. + assert(new_version->new_version() == NULL, "Must be newest version");
  5476. - default:
  5477. - {
  5478. - // leave a breadcrumb
  5479. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5480. - ShouldNotReachHere();
  5481. - } break;
  5482. - } // end switch tag value
  5483. -} // end append_entry()
  5484. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5485. + new_version()->print();
  5486. + new_version->super()->print();
  5487. + }
  5488. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5489. + }
  5490. +
  5491. + SystemDictionary::classes_do(check_class, THREAD);
  5492. +
  5493. +#endif
  5494. +
  5495. + RC_TRACE(0x00000001, ("Finished verification!"));
  5496. + return JVMTI_ERROR_NONE;
  5497. +}
  5498. +
  5499. +void VM_RedefineClasses::lock_threads() {
  5500. +
  5501. + RC_TIMER_START(_timer_wait_for_locks);
  5502. +
  5503. +
  5504. + JavaThread *javaThread = Threads::first();
  5505. + while (javaThread != NULL) {
  5506. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5507. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5508. + compilerThread->set_should_bailout(true);
  5509. + }
  5510. + javaThread = javaThread->next();
  5511. + }
  5512. +
  5513. + int cnt = 0;
  5514. + javaThread = Threads::first();
  5515. + while (javaThread != NULL) {
  5516. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5517. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5518. + compilerThread->compilation_mutex()->lock();
  5519. + cnt++;
  5520. + }
  5521. + javaThread = javaThread->next();
  5522. + }
  5523. +
  5524. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5525. +
  5526. + cnt = 0;
  5527. + javaThread = Threads::first();
  5528. + while (javaThread != NULL) {
  5529. + if (javaThread != Thread::current()) {
  5530. + javaThread->redefine_classes_mutex()->lock();
  5531. + }
  5532. + javaThread = javaThread->next();
  5533. + }
  5534. +
  5535. +
  5536. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5537. +
  5538. + RC_TIMER_STOP(_timer_wait_for_locks);
  5539. +}
  5540. +void VM_RedefineClasses::unlock_threads() {
  5541. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5542. - typeArrayOop save;
  5543. + int cnt = 0;
  5544. + JavaThread *javaThread = Threads::first();
  5545. + Thread *thread = Thread::current();
  5546. + while (javaThread != NULL) {
  5547. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5548. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5549. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5550. + compilerThread->compilation_mutex()->unlock();
  5551. + cnt++;
  5552. + }
  5553. + }
  5554. + javaThread = javaThread->next();
  5555. + }
  5556. - save = scratch_class->get_method_annotations_of(i);
  5557. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5558. - scratch_class->set_method_annotations_of(j, save);
  5559. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5560. - save = scratch_class->get_method_parameter_annotations_of(i);
  5561. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5562. - scratch_class->set_method_parameter_annotations_of(j, save);
  5563. + cnt = 0;
  5564. + javaThread = Threads::first();
  5565. + while (javaThread != NULL) {
  5566. + if (javaThread != Thread::current()) {
  5567. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5568. + javaThread->redefine_classes_mutex()->unlock();
  5569. + }
  5570. + }
  5571. + javaThread = javaThread->next();
  5572. + }
  5573. - save = scratch_class->get_method_default_annotations_of(i);
  5574. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5575. - scratch_class->set_method_default_annotations_of(j, save);
  5576. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5577. }
  5578. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5579. +
  5580. +
  5581. +
  5582. + // Compatibility mode => check for unsupported modification
  5583. +
  5584. +
  5585. + assert(scratch_class->old_version() != NULL, "must have old version");
  5586. + instanceKlassHandle the_class(scratch_class->old_version());
  5587. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5588. - instanceKlassHandle the_class,
  5589. - instanceKlassHandle scratch_class) {
  5590. int i;
  5591. // Check superclasses, or rather their names, since superclasses themselves can be
  5592. // requested to replace.
  5593. // Check for NULL superclass first since this might be java.lang.Object
  5594. if (the_class->super() != scratch_class->super() &&
  5595. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5596. - Klass::cast(the_class->super())->name() !=
  5597. - Klass::cast(scratch_class->super())->name())) {
  5598. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5599. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5600. + Klass::cast(the_class->super())->name() !=
  5601. + Klass::cast(scratch_class->super())->name())) {
  5602. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5603. }
  5604. // Check if the number, names and order of directly implemented interfaces are the same.
  5605. @@ -539,8 +678,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5606. }
  5607. for (i = 0; i < n_intfs; i++) {
  5608. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5609. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5610. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5611. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5612. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5613. }
  5614. }
  5615. @@ -689,12 +828,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5616. idnum_owner->set_method_idnum(new_num);
  5617. }
  5618. k_new_method->set_method_idnum(old_num);
  5619. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5620. }
  5621. }
  5622. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5623. - k_new_method->name_and_sig_as_C_string(), ni,
  5624. - k_old_method->name_and_sig_as_C_string(), oi));
  5625. // advance to next pair of methods
  5626. ++oi;
  5627. ++ni;
  5628. @@ -703,11 +838,11 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5629. // method added, see if it is OK
  5630. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5631. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5632. - // hack: private should be treated as final, but alas
  5633. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5634. - ) {
  5635. - // new methods must be private
  5636. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5637. + // hack: private should be treated as final, but alas
  5638. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5639. + ) {
  5640. + // new methods must be private
  5641. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5642. }
  5643. {
  5644. u2 num = the_class->next_method_idnum();
  5645. @@ -722,24 +857,19 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5646. idnum_owner->set_method_idnum(new_num);
  5647. }
  5648. k_new_method->set_method_idnum(num);
  5649. - swap_all_method_annotations(new_num, num, scratch_class);
  5650. }
  5651. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5652. - k_new_method->name_and_sig_as_C_string(), ni));
  5653. ++ni; // advance to next new method
  5654. break;
  5655. case deleted:
  5656. // method deleted, see if it is OK
  5657. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5658. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5659. - // hack: private should be treated as final, but alas
  5660. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5661. - ) {
  5662. - // deleted methods must be private
  5663. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5664. + // hack: private should be treated as final, but alas
  5665. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5666. + ) {
  5667. + // deleted methods must be private
  5668. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5669. }
  5670. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5671. - k_old_method->name_and_sig_as_C_string(), oi));
  5672. ++oi; // advance to next old method
  5673. break;
  5674. default:
  5675. @@ -750,2200 +880,1783 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5676. return JVMTI_ERROR_NONE;
  5677. }
  5678. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5679. -// Find new constant pool index value for old constant pool index value
  5680. -// by seaching the index map. Returns zero (0) if there is no mapped
  5681. -// value for the old constant pool index.
  5682. -int VM_RedefineClasses::find_new_index(int old_index) {
  5683. - if (_index_map_count == 0) {
  5684. - // map is empty so nothing can be found
  5685. - return 0;
  5686. - }
  5687. -
  5688. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5689. - // The old_index is out of range so it is not mapped. This should
  5690. - // not happen in regular constant pool merging use, but it can
  5691. - // happen if a corrupt annotation is processed.
  5692. - return 0;
  5693. - }
  5694. -
  5695. - int value = _index_map_p->at(old_index);
  5696. - if (value == -1) {
  5697. - // the old_index is not mapped
  5698. - return 0;
  5699. - }
  5700. -
  5701. - return value;
  5702. -} // end find_new_index()
  5703. -
  5704. + int result = Klass::NoRedefinition;
  5705. -// Returns true if the current mismatch is due to a resolved/unresolved
  5706. -// class pair. Otherwise, returns false.
  5707. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5708. - int index1, constantPoolHandle cp2, int index2) {
  5709. - jbyte t1 = cp1->tag_at(index1).value();
  5710. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5711. - return false; // wrong entry type; not our special case
  5712. - }
  5713. - jbyte t2 = cp2->tag_at(index2).value();
  5714. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5715. - return false; // wrong entry type; not our special case
  5716. - }
  5717. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5718. + new_class->name()->as_C_string()));
  5719. - if (t1 == t2) {
  5720. - return false; // not a mismatch; not our special case
  5721. - }
  5722. + assert(new_class->old_version() != NULL, "must have old version");
  5723. + instanceKlassHandle the_class(new_class->old_version());
  5724. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5725. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5726. - if (strcmp(s1, s2) != 0) {
  5727. - return false; // strings don't match; not our special case
  5728. + // Check whether class is in the error init state.
  5729. + if (the_class->is_in_error_state()) {
  5730. + // TBD #5057930: special error code is needed in 1.6
  5731. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5732. }
  5733. - return true; // made it through the gauntlet; this is our special case
  5734. -} // end is_unresolved_class_mismatch()
  5735. + int i;
  5736. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5737. + // Check superclasses
  5738. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5739. + if (the_class->super() != new_class->super()) {
  5740. + // Super class changed
  5741. +
  5742. + klassOop cur_klass = the_class->super();
  5743. + while (cur_klass != NULL) {
  5744. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5745. + RC_TRACE(0x00000002, ("Removed super class %s",
  5746. + cur_klass->klass_part()->name()->as_C_string()));
  5747. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5748. +
  5749. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5750. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5751. + cur_klass->klass_part()->name()->as_C_string()));
  5752. + cur_klass->klass_part()->set_subtype_changed(true);
  5753. + }
  5754. + }
  5755. -// Returns true if the current mismatch is due to a resolved/unresolved
  5756. -// string pair. Otherwise, returns false.
  5757. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5758. - int index1, constantPoolHandle cp2, int index2) {
  5759. + cur_klass = cur_klass->klass_part()->super();
  5760. + }
  5761. - jbyte t1 = cp1->tag_at(index1).value();
  5762. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5763. - return false; // wrong entry type; not our special case
  5764. + cur_klass = new_class->super();
  5765. + while (cur_klass != NULL) {
  5766. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5767. + RC_TRACE(0x00000002, ("Added super class %s",
  5768. + cur_klass->klass_part()->name()->as_C_string()));
  5769. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5770. + }
  5771. + cur_klass = cur_klass->klass_part()->super();
  5772. + }
  5773. + }
  5774. +
  5775. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5776. + // Check interfaces
  5777. +
  5778. + // Interfaces removed?
  5779. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5780. + for (i = 0; i<old_interfaces->length(); i++) {
  5781. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5782. + if (!new_class->implements_interface_any_version(old_interface())) {
  5783. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5784. + RC_TRACE(0x00000002, ("Removed interface %s",
  5785. + old_interface->name()->as_C_string()));
  5786. +
  5787. + if (!old_interface->has_subtype_changed()) {
  5788. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5789. + old_interface->name()->as_C_string()));
  5790. + old_interface->set_subtype_changed(true);
  5791. + }
  5792. + }
  5793. }
  5794. - jbyte t2 = cp2->tag_at(index2).value();
  5795. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5796. - return false; // wrong entry type; not our special case
  5797. + // Interfaces added?
  5798. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5799. + for (i = 0; i<new_interfaces->length(); i++) {
  5800. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5801. + result = result | Klass::ModifyClass;
  5802. + RC_TRACE(0x00000002, ("Added interface %s",
  5803. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  5804. + }
  5805. }
  5806. - if (t1 == t2) {
  5807. - return false; // not a mismatch; not our special case
  5808. - }
  5809. - char *s1 = cp1->string_at_noresolve(index1);
  5810. - char *s2 = cp2->string_at_noresolve(index2);
  5811. - if (strcmp(s1, s2) != 0) {
  5812. - return false; // strings don't match; not our special case
  5813. - }
  5814. -
  5815. - return true; // made it through the gauntlet; this is our special case
  5816. -} // end is_unresolved_string_mismatch()
  5817. -
  5818. -
  5819. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5820. - // For consistency allocate memory using os::malloc wrapper.
  5821. - _scratch_classes = (instanceKlassHandle *)
  5822. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5823. - if (_scratch_classes == NULL) {
  5824. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5825. + // Check whether class modifiers are the same.
  5826. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5827. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5828. + if (old_flags != new_flags) {
  5829. + // TODO (tw): Can this have any effects?
  5830. }
  5831. - ResourceMark rm(THREAD);
  5832. -
  5833. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5834. - // state can only be NULL if the current thread is exiting which
  5835. - // should not happen since we're trying to do a RedefineClasses
  5836. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5837. - for (int i = 0; i < _class_count; i++) {
  5838. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5839. - // classes for primitives cannot be redefined
  5840. - if (!is_modifiable_class(mirror)) {
  5841. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5842. + // Check if the number, names, types and order of fields declared in these classes
  5843. + // are the same.
  5844. + JavaFieldStream old_fs(the_class);
  5845. + JavaFieldStream new_fs(new_class);
  5846. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5847. + // access
  5848. + old_flags = old_fs.access_flags().as_short();
  5849. + new_flags = new_fs.access_flags().as_short();
  5850. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5851. + // (tw) Can this have any effects?
  5852. }
  5853. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5854. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5855. - Symbol* the_class_sym = the_class->name();
  5856. -
  5857. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5858. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5859. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5860. - the_class->external_name(), _class_load_kind,
  5861. - os::available_memory() >> 10));
  5862. + // offset
  5863. + if (old_fs.offset() != new_fs.offset()) {
  5864. + result = result | Klass::ModifyInstances;
  5865. + }
  5866. + // name and signature
  5867. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5868. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5869. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5870. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5871. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5872. + result = result | Klass::ModifyInstances;
  5873. + }
  5874. + }
  5875. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5876. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5877. + if (!old_fs.done() || !new_fs.done()) {
  5878. + result = result | Klass::ModifyInstances;
  5879. + }
  5880. - // Parse the stream.
  5881. - Handle the_class_loader(THREAD, the_class->class_loader());
  5882. - Handle protection_domain(THREAD, the_class->protection_domain());
  5883. - // Set redefined class handle in JvmtiThreadState class.
  5884. - // This redefined class is sent to agent event handler for class file
  5885. - // load hook event.
  5886. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5887. + // Do a parallel walk through the old and new methods. Detect
  5888. + // cases where they match (exist in both), have been added in
  5889. + // the new methods, or have been deleted (exist only in the
  5890. + // old methods). The class file parser places methods in order
  5891. + // by method name, but does not order overloaded methods by
  5892. + // signature. In order to determine what fate befell the methods,
  5893. + // this code places the overloaded new methods that have matching
  5894. + // old methods in the same order as the old methods and places
  5895. + // new overloaded methods at the end of overloaded methods of
  5896. + // that name. The code for this order normalization is adapted
  5897. + // from the algorithm used in instanceKlass::find_method().
  5898. + // Since we are swapping out of order entries as we find them,
  5899. + // we only have to search forward through the overloaded methods.
  5900. + // Methods which are added and have the same name as an existing
  5901. + // method (but different signature) will be put at the end of
  5902. + // the methods with that name, and the name mismatch code will
  5903. + // handle them.
  5904. + objArrayHandle k_old_methods(the_class->methods());
  5905. + objArrayHandle k_new_methods(new_class->methods());
  5906. + int n_old_methods = k_old_methods->length();
  5907. + int n_new_methods = k_new_methods->length();
  5908. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5909. - the_class_loader,
  5910. - protection_domain,
  5911. - &st,
  5912. - THREAD);
  5913. - // Clear class_being_redefined just to be sure.
  5914. - state->clear_class_being_redefined();
  5915. + int ni = 0;
  5916. + int oi = 0;
  5917. + while (true) {
  5918. + methodOop k_old_method;
  5919. + methodOop k_new_method;
  5920. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  5921. - // TODO: if this is retransform, and nothing changed we can skip it
  5922. -
  5923. - instanceKlassHandle scratch_class (THREAD, k);
  5924. -
  5925. - if (HAS_PENDING_EXCEPTION) {
  5926. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5927. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5928. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5929. - ex_name->as_C_string()));
  5930. - CLEAR_PENDING_EXCEPTION;
  5931. -
  5932. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5933. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5934. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5935. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5936. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5937. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5938. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5939. - // The message will be "XXX (wrong name: YYY)"
  5940. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5941. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5942. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5943. - } else { // Just in case more exceptions can be thrown..
  5944. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5945. - }
  5946. - }
  5947. -
  5948. - // Ensure class is linked before redefine
  5949. - if (!the_class->is_linked()) {
  5950. - the_class->link_class(THREAD);
  5951. - if (HAS_PENDING_EXCEPTION) {
  5952. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5953. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5954. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5955. - ex_name->as_C_string()));
  5956. - CLEAR_PENDING_EXCEPTION;
  5957. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5958. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5959. + if (oi >= n_old_methods) {
  5960. + if (ni >= n_new_methods) {
  5961. + break; // we've looked at everything, done
  5962. + }
  5963. + // New method at the end
  5964. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5965. + method_was = added;
  5966. + } else if (ni >= n_new_methods) {
  5967. + // Old method, at the end, is deleted
  5968. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5969. + method_was = deleted;
  5970. + } else {
  5971. + // There are more methods in both the old and new lists
  5972. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5973. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5974. + if (k_old_method->name() != k_new_method->name()) {
  5975. + // Methods are sorted by method name, so a mismatch means added
  5976. + // or deleted
  5977. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  5978. + method_was = added;
  5979. } else {
  5980. - return JVMTI_ERROR_INTERNAL;
  5981. + method_was = deleted;
  5982. + }
  5983. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5984. + // Both the name and signature match
  5985. + method_was = matched;
  5986. + } else {
  5987. + // The name matches, but the signature doesn't, which means we have to
  5988. + // search forward through the new overloaded methods.
  5989. + int nj; // outside the loop for post-loop check
  5990. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5991. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5992. + if (k_old_method->name() != m->name()) {
  5993. + // reached another method name so no more overloaded methods
  5994. + method_was = deleted;
  5995. + break;
  5996. + }
  5997. + if (k_old_method->signature() == m->signature()) {
  5998. + // found a match so swap the methods
  5999. + k_new_methods->obj_at_put(ni, m);
  6000. + k_new_methods->obj_at_put(nj, k_new_method);
  6001. + k_new_method = m;
  6002. + method_was = matched;
  6003. + break;
  6004. + }
  6005. + }
  6006. +
  6007. + if (nj >= n_new_methods) {
  6008. + // reached the end without a match; so method was deleted
  6009. + method_was = deleted;
  6010. }
  6011. }
  6012. }
  6013. - // Do the validity checks in compare_and_normalize_class_versions()
  6014. - // before verifying the byte codes. By doing these checks first, we
  6015. - // limit the number of functions that require redirection from
  6016. - // the_class to scratch_class. In particular, we don't have to
  6017. - // modify JNI GetSuperclass() and thus won't change its performance.
  6018. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6019. - scratch_class);
  6020. - if (res != JVMTI_ERROR_NONE) {
  6021. - return res;
  6022. + switch (method_was) {
  6023. + case matched:
  6024. + // methods match, be sure modifiers do too
  6025. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6026. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6027. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6028. + // (tw) Can this have any effects? Probably yes on vtables?
  6029. + result = result | Klass::ModifyClass;
  6030. }
  6031. -
  6032. - // verify what the caller passed us
  6033. {
  6034. - // The bug 6214132 caused the verification to fail.
  6035. - // Information about the_class and scratch_class is temporarily
  6036. - // recorded into jvmtiThreadState. This data is used to redirect
  6037. - // the_class to scratch_class in the JVM_* functions called by the
  6038. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6039. - // description.
  6040. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6041. - Verifier::verify(
  6042. - scratch_class, Verifier::ThrowException, true, THREAD);
  6043. - }
  6044. -
  6045. - if (HAS_PENDING_EXCEPTION) {
  6046. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6047. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6048. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6049. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6050. - CLEAR_PENDING_EXCEPTION;
  6051. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6052. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6053. - } else {
  6054. - // tell the caller the bytecodes are bad
  6055. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6056. + u2 new_num = k_new_method->method_idnum();
  6057. + u2 old_num = k_old_method->method_idnum();
  6058. + if (new_num != old_num) {
  6059. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6060. + if (idnum_owner != NULL) {
  6061. + // There is already a method assigned this idnum -- switch them
  6062. + idnum_owner->set_method_idnum(new_num);
  6063. + }
  6064. + k_new_method->set_method_idnum(old_num);
  6065. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6066. + new_num,
  6067. + old_num));
  6068. + // swap_all_method_annotations(old_num, new_num, new_class);
  6069. }
  6070. }
  6071. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6072. + k_new_method->name_and_sig_as_C_string(), ni,
  6073. + k_old_method->name_and_sig_as_C_string(), oi));
  6074. + // advance to next pair of methods
  6075. + ++oi;
  6076. + ++ni;
  6077. + break;
  6078. + case added:
  6079. + // method added, see if it is OK
  6080. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6081. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6082. + // hack: private should be treated as final, but alas
  6083. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6084. + ) {
  6085. + // new methods must be private
  6086. + result = result | Klass::ModifyClass;
  6087. + }
  6088. + {
  6089. + u2 num = the_class->next_method_idnum();
  6090. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6091. + // cannot add any more methods
  6092. + result = result | Klass::ModifyClass;
  6093. + }
  6094. + u2 new_num = k_new_method->method_idnum();
  6095. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6096. + if (idnum_owner != NULL) {
  6097. + // There is already a method assigned this idnum -- switch them
  6098. + idnum_owner->set_method_idnum(new_num);
  6099. + }
  6100. + k_new_method->set_method_idnum(num);
  6101. + //swap_all_method_annotations(new_num, num, new_class);
  6102. + }
  6103. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6104. + k_new_method->name_and_sig_as_C_string(), ni));
  6105. + ++ni; // advance to next new method
  6106. + break;
  6107. + case deleted:
  6108. + // method deleted, see if it is OK
  6109. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6110. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6111. + // hack: private should be treated as final, but alas
  6112. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6113. + ) {
  6114. + // deleted methods must be private
  6115. + result = result | Klass::ModifyClass;
  6116. + }
  6117. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6118. + k_old_method->name_and_sig_as_C_string(), oi));
  6119. + ++oi; // advance to next old method
  6120. + break;
  6121. + default:
  6122. + ShouldNotReachHere();
  6123. + }
  6124. + }
  6125. +
  6126. + if (new_class()->size() != new_class->old_version()->size()) {
  6127. + result |= Klass::ModifyClassSize;
  6128. + }
  6129. +
  6130. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6131. + result |= Klass::ModifyInstanceSize;
  6132. + }
  6133. +
  6134. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6135. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6136. + result |= Klass::HasInstanceTransformer;
  6137. + }
  6138. +
  6139. + // (tw) Check method bodies to be able to return NoChange?
  6140. + return result;
  6141. +}
  6142. +
  6143. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6144. +
  6145. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6146. +
  6147. + private:
  6148. +
  6149. + GrowableArray<int> info;
  6150. + int curPosition;
  6151. + bool copy_backwards;
  6152. +
  6153. + public:
  6154. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6155. - if (res != JVMTI_ERROR_NONE) {
  6156. - return res;
  6157. + bool does_copy_backwards() {
  6158. + return copy_backwards;
  6159. }
  6160. - if (VerifyMergedCPBytecodes) {
  6161. - // verify what we have done during constant pool merging
  6162. - {
  6163. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6164. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6165. - }
  6166. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6167. - if (HAS_PENDING_EXCEPTION) {
  6168. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6169. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6170. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6171. - ("verify_byte_codes post merge-CP exception: '%s'",
  6172. - ex_name->as_C_string()));
  6173. - CLEAR_PENDING_EXCEPTION;
  6174. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6175. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6176. - } else {
  6177. - // tell the caller that constant pool merging screwed up
  6178. - return JVMTI_ERROR_INTERNAL;
  6179. - }
  6180. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6181. +
  6182. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6183. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6184. }
  6185. +
  6186. + info.append(base_offset);
  6187. + info.append(0);
  6188. + curPosition = base_offset;
  6189. + copy_backwards = false;
  6190. + }
  6191. +
  6192. + GrowableArray<int> &finish() {
  6193. + info.append(0);
  6194. + return info;
  6195. }
  6196. - Rewriter::rewrite(scratch_class, THREAD);
  6197. - if (!HAS_PENDING_EXCEPTION) {
  6198. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6199. + virtual void do_new_field(fieldDescriptor* fd){
  6200. + int alignment = fd->offset() - curPosition;
  6201. + if (alignment > 0) {
  6202. + // This field was aligned, so we need to make sure that we fill the gap
  6203. + fill(alignment);
  6204. + }
  6205. +
  6206. + int size = size_of_type(fd->field_type());
  6207. + fill(size);
  6208. }
  6209. - if (HAS_PENDING_EXCEPTION) {
  6210. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6211. - CLEAR_PENDING_EXCEPTION;
  6212. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6213. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6214. +
  6215. + private:
  6216. +
  6217. + void fill(int size) {
  6218. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6219. + (*info.adr_at(info.length() - 1)) -= size;
  6220. } else {
  6221. - return JVMTI_ERROR_INTERNAL;
  6222. + info.append(-size);
  6223. }
  6224. +
  6225. + curPosition += size;
  6226. }
  6227. - _scratch_classes[i] = scratch_class;
  6228. + int size_of_type(BasicType type) {
  6229. + int size = 0;
  6230. + switch(type) {
  6231. + case T_BOOLEAN:
  6232. + size = sizeof(jboolean);
  6233. + break;
  6234. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6235. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6236. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6237. - the_class->external_name(), os::available_memory() >> 10));
  6238. - }
  6239. + case T_CHAR:
  6240. + size = (sizeof(jchar));
  6241. + break;
  6242. - return JVMTI_ERROR_NONE;
  6243. -}
  6244. + case T_FLOAT:
  6245. + size = (sizeof(jfloat));
  6246. + break;
  6247. + case T_DOUBLE:
  6248. + size = (sizeof(jdouble));
  6249. + break;
  6250. -// Map old_index to new_index as needed. scratch_cp is only needed
  6251. -// for RC_TRACE() calls.
  6252. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6253. - int old_index, int new_index) {
  6254. - if (find_new_index(old_index) != 0) {
  6255. - // old_index is already mapped
  6256. - return;
  6257. - }
  6258. + case T_BYTE:
  6259. + size = (sizeof(jbyte));
  6260. + break;
  6261. - if (old_index == new_index) {
  6262. - // no mapping is needed
  6263. - return;
  6264. - }
  6265. + case T_SHORT:
  6266. + size = (sizeof(jshort));
  6267. + break;
  6268. - _index_map_p->at_put(old_index, new_index);
  6269. - _index_map_count++;
  6270. + case T_INT:
  6271. + size = (sizeof(jint));
  6272. + break;
  6273. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6274. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6275. -} // end map_index()
  6276. + case T_LONG:
  6277. + size = (sizeof(jlong));
  6278. + break;
  6279. + case T_OBJECT:
  6280. + case T_ARRAY:
  6281. + if (UseCompressedOops) {
  6282. + size = sizeof(narrowOop);
  6283. + } else {
  6284. + size = (sizeof(oop));
  6285. + }
  6286. + break;
  6287. -// Merge old_cp and scratch_cp and return the results of the merge via
  6288. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6289. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6290. -// in *merge_cp_p. Also creates a map of indices from entries in
  6291. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6292. -// entries are only created for entries in scratch_cp that occupy a
  6293. -// different location in *merged_cp_p.
  6294. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6295. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6296. - int *merge_cp_length_p, TRAPS) {
  6297. + default:
  6298. + ShouldNotReachHere();
  6299. + }
  6300. - if (merge_cp_p == NULL) {
  6301. - assert(false, "caller must provide scatch constantPool");
  6302. - return false; // robustness
  6303. - }
  6304. - if (merge_cp_length_p == NULL) {
  6305. - assert(false, "caller must provide scatch CP length");
  6306. - return false; // robustness
  6307. - }
  6308. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6309. - // but the caller might be smart so make sure we have at least
  6310. - // the minimum.
  6311. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6312. - assert(false, "merge area too small");
  6313. - return false; // robustness
  6314. - }
  6315. + assert(size > 0, "");
  6316. + return size;
  6317. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6318. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6319. - scratch_cp->length()));
  6320. + }
  6321. +
  6322. + public:
  6323. - {
  6324. - // Pass 0:
  6325. - // The old_cp is copied to *merge_cp_p; this means that any code
  6326. - // using old_cp does not have to change. This work looks like a
  6327. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6328. - // handle one special case:
  6329. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6330. - // This will make verification happy.
  6331. -
  6332. - int old_i; // index into old_cp
  6333. -
  6334. - // index zero (0) is not used in constantPools
  6335. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6336. - // leave debugging crumb
  6337. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6338. - switch (old_tag) {
  6339. - case JVM_CONSTANT_Class:
  6340. - case JVM_CONSTANT_UnresolvedClass:
  6341. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6342. - // May be resolving while calling this so do the same for
  6343. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6344. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6345. - old_cp->klass_name_at(old_i));
  6346. - break;
  6347. + virtual void do_old_field(fieldDescriptor* fd){}
  6348. - case JVM_CONSTANT_Double:
  6349. - case JVM_CONSTANT_Long:
  6350. - // just copy the entry to *merge_cp_p, but double and long take
  6351. - // two constant pool entries
  6352. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6353. - old_i++;
  6354. - break;
  6355. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6356. - default:
  6357. - // just copy the entry to *merge_cp_p
  6358. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6359. - break;
  6360. + int alignment = new_fd->offset() - curPosition;
  6361. + if (alignment > 0) {
  6362. + // This field was aligned, so we need to make sure that we fill the gap
  6363. + fill(alignment);
  6364. }
  6365. - } // end for each old_cp entry
  6366. -
  6367. - // We don't need to sanity check that *merge_cp_length_p is within
  6368. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6369. - (*merge_cp_length_p) = old_i;
  6370. - }
  6371. - // merge_cp_len should be the same as old_cp->length() at this point
  6372. - // so this trace message is really a "warm-and-breathing" message.
  6373. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6374. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6375. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6376. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6377. - int scratch_i; // index into scratch_cp
  6378. - {
  6379. - // Pass 1a:
  6380. - // Compare scratch_cp entries to the old_cp entries that we have
  6381. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6382. - // exact duplicates (matching entry at same index) so we only
  6383. - // compare entries in the common indice range.
  6384. - int increment = 1;
  6385. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6386. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6387. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6388. - case JVM_CONSTANT_Double:
  6389. - case JVM_CONSTANT_Long:
  6390. - // double and long take two constant pool entries
  6391. - increment = 2;
  6392. - break;
  6393. + int offset = old_fd->offset();
  6394. + int size = size_of_type(old_fd->field_type());
  6395. - default:
  6396. - increment = 1;
  6397. - break;
  6398. + int prevEnd = -1;
  6399. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6400. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6401. }
  6402. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6403. - scratch_i, CHECK_0);
  6404. - if (match) {
  6405. - // found a match at the same index so nothing more to do
  6406. - continue;
  6407. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6408. - *merge_cp_p, scratch_i)) {
  6409. - // The mismatch in compare_entry_to() above is because of a
  6410. - // resolved versus unresolved class entry at the same index
  6411. - // with the same string value. Since Pass 0 reverted any
  6412. - // class entries to unresolved class entries in *merge_cp_p,
  6413. - // we go with the unresolved class entry.
  6414. - continue;
  6415. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6416. - *merge_cp_p, scratch_i)) {
  6417. - // The mismatch in compare_entry_to() above is because of a
  6418. - // resolved versus unresolved string entry at the same index
  6419. - // with the same string value. We can live with whichever
  6420. - // happens to be at scratch_i in *merge_cp_p.
  6421. - continue;
  6422. - }
  6423. -
  6424. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6425. - CHECK_0);
  6426. - if (found_i != 0) {
  6427. - guarantee(found_i != scratch_i,
  6428. - "compare_entry_to() and find_matching_entry() do not agree");
  6429. -
  6430. - // Found a matching entry somewhere else in *merge_cp_p so
  6431. - // just need a mapping entry.
  6432. - map_index(scratch_cp, scratch_i, found_i);
  6433. - continue;
  6434. - }
  6435. -
  6436. - // The find_matching_entry() call above could fail to find a match
  6437. - // due to a resolved versus unresolved class or string entry situation
  6438. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6439. - // However, we would have to call is_unresolved_*_mismatch() over
  6440. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6441. - // worth the time.
  6442. -
  6443. - // No match found so we have to append this entry and any unique
  6444. - // referenced entries to *merge_cp_p.
  6445. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6446. - CHECK_0);
  6447. - }
  6448. - }
  6449. -
  6450. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6451. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6452. - *merge_cp_length_p, scratch_i, _index_map_count));
  6453. -
  6454. - if (scratch_i < scratch_cp->length()) {
  6455. - // Pass 1b:
  6456. - // old_cp is smaller than scratch_cp so there are entries in
  6457. - // scratch_cp that we have not yet processed. We take care of
  6458. - // those now.
  6459. - int increment = 1;
  6460. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6461. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6462. - case JVM_CONSTANT_Double:
  6463. - case JVM_CONSTANT_Long:
  6464. - // double and long take two constant pool entries
  6465. - increment = 2;
  6466. - break;
  6467. -
  6468. - default:
  6469. - increment = 1;
  6470. - break;
  6471. + if (prevEnd == offset) {
  6472. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6473. + } else {
  6474. + info.append(size);
  6475. + info.append(offset);
  6476. }
  6477. - int found_i =
  6478. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6479. - if (found_i != 0) {
  6480. - // Found a matching entry somewhere else in *merge_cp_p so
  6481. - // just need a mapping entry.
  6482. - map_index(scratch_cp, scratch_i, found_i);
  6483. - continue;
  6484. + if (old_fd->offset() < new_fd->offset()) {
  6485. + copy_backwards = true;
  6486. }
  6487. - // No match found so we have to append this entry and any unique
  6488. - // referenced entries to *merge_cp_p.
  6489. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6490. - CHECK_0);
  6491. + transfer_special_access_flags(old_fd, new_fd);
  6492. +
  6493. + curPosition += size;
  6494. }
  6495. + };
  6496. +
  6497. + UpdateFieldsEvolutionClosure cl(new_version);
  6498. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6499. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6500. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6501. - *merge_cp_length_p, scratch_i, _index_map_count));
  6502. + GrowableArray<int> result = cl.finish();
  6503. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6504. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6505. +
  6506. + if (RC_TRACE_ENABLED(0x00000002)) {
  6507. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6508. + new_version->klass_part()->name()->as_C_string()));
  6509. + if (cl.does_copy_backwards()) {
  6510. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6511. + }
  6512. + for (int i=0; i<result.length(); i++) {
  6513. + int curNum = result.at(i);
  6514. + if (curNum < 0) {
  6515. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6516. + } else if (curNum > 0) {
  6517. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6518. + i++;
  6519. + } else {
  6520. + RC_TRACE(0x00000002, ("\tEND"));
  6521. + }
  6522. + }
  6523. }
  6524. +}
  6525. - return true;
  6526. -} // end merge_constant_pools()
  6527. -
  6528. -
  6529. -// Merge constant pools between the_class and scratch_class and
  6530. -// potentially rewrite bytecodes in scratch_class to use the merged
  6531. -// constant pool.
  6532. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6533. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6534. - TRAPS) {
  6535. - // worst case merged constant pool length is old and new combined
  6536. - int merge_cp_length = the_class->constants()->length()
  6537. - + scratch_class->constants()->length();
  6538. -
  6539. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6540. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6541. -
  6542. - // Constant pools are not easily reused so we allocate a new one
  6543. - // each time.
  6544. - // merge_cp is created unsafe for concurrent GC processing. It
  6545. - // should be marked safe before discarding it. Even though
  6546. - // garbage, if it crosses a card boundary, it may be scanned
  6547. - // in order to find the start of the first complete object on the card.
  6548. - constantPoolHandle merge_cp(THREAD,
  6549. - oopFactory::new_constantPool(merge_cp_length,
  6550. - oopDesc::IsUnsafeConc,
  6551. - THREAD));
  6552. - int orig_length = old_cp->orig_length();
  6553. - if (orig_length == 0) {
  6554. - // This old_cp is an actual original constant pool. We save
  6555. - // the original length in the merged constant pool so that
  6556. - // merge_constant_pools() can be more efficient. If a constant
  6557. - // pool has a non-zero orig_length() value, then that constant
  6558. - // pool was created by a merge operation in RedefineClasses.
  6559. - merge_cp->set_orig_length(old_cp->length());
  6560. - } else {
  6561. - // This old_cp is a merged constant pool from a previous
  6562. - // RedefineClasses() calls so just copy the orig_length()
  6563. - // value.
  6564. - merge_cp->set_orig_length(old_cp->orig_length());
  6565. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6566. + assert(FieldType::is_obj(signature), "");
  6567. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6568. +}
  6569. +
  6570. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6571. + if (klass->klass_part()->is_redefining()) {
  6572. + klass = klass->klass_part()->old_version();
  6573. }
  6574. - ResourceMark rm(THREAD);
  6575. - _index_map_count = 0;
  6576. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6577. + // We found an instance klass!
  6578. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6579. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6580. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6581. - &merge_cp_length, THREAD);
  6582. - if (!result) {
  6583. - // The merge can fail due to memory allocation failure or due
  6584. - // to robustness checks.
  6585. - return JVMTI_ERROR_INTERNAL;
  6586. - }
  6587. -
  6588. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6589. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6590. -
  6591. - if (_index_map_count == 0) {
  6592. - // there is nothing to map between the new and merged constant pools
  6593. -
  6594. - if (old_cp->length() == scratch_cp->length()) {
  6595. - // The old and new constant pools are the same length and the
  6596. - // index map is empty. This means that the three constant pools
  6597. - // are equivalent (but not the same). Unfortunately, the new
  6598. - // constant pool has not gone through link resolution nor have
  6599. - // the new class bytecodes gone through constant pool cache
  6600. - // rewriting so we can't use the old constant pool with the new
  6601. - // class.
  6602. -
  6603. - merge_cp()->set_is_conc_safe(true);
  6604. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6605. - } else if (old_cp->length() < scratch_cp->length()) {
  6606. - // The old constant pool has fewer entries than the new constant
  6607. - // pool and the index map is empty. This means the new constant
  6608. - // pool is a superset of the old constant pool. However, the old
  6609. - // class bytecodes have already gone through constant pool cache
  6610. - // rewriting so we can't use the new constant pool with the old
  6611. - // class.
  6612. -
  6613. - merge_cp()->set_is_conc_safe(true);
  6614. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6615. - } else {
  6616. - // The old constant pool has more entries than the new constant
  6617. - // pool and the index map is empty. This means that both the old
  6618. - // and merged constant pools are supersets of the new constant
  6619. - // pool.
  6620. -
  6621. - // Replace the new constant pool with a shrunken copy of the
  6622. - // merged constant pool; the previous new constant pool will
  6623. - // get GCed.
  6624. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6625. - THREAD);
  6626. - // drop local ref to the merged constant pool
  6627. - merge_cp()->set_is_conc_safe(true);
  6628. - merge_cp = constantPoolHandle();
  6629. + class MyFieldClosure : public FieldClosure {
  6630. +
  6631. + public:
  6632. +
  6633. + GrowableArray< Pair<int, klassOop> > *_arr;
  6634. +
  6635. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6636. + _arr = arr;
  6637. }
  6638. - } else {
  6639. - if (RC_TRACE_ENABLED(0x00040000)) {
  6640. - // don't want to loop unless we are tracing
  6641. - int count = 0;
  6642. - for (int i = 1; i < _index_map_p->length(); i++) {
  6643. - int value = _index_map_p->at(i);
  6644. -
  6645. - if (value != -1) {
  6646. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6647. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6648. - count++;
  6649. +
  6650. + virtual void do_field(fieldDescriptor* fd) {
  6651. + if (fd->field_type() == T_OBJECT) {
  6652. + Symbol* signature = fd->signature();
  6653. + if (FieldType::is_obj(signature)) {
  6654. + Symbol* name = signature_to_class_name(signature);
  6655. + klassOop field_klass;
  6656. + if (is_field_dangerous(name, fd, field_klass)) {
  6657. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6658. + fd->name()->as_C_string(),
  6659. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6660. + name->as_C_string()));
  6661. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6662. + }
  6663. }
  6664. +
  6665. + // Array fields can never be a problem!
  6666. }
  6667. }
  6668. - // We have entries mapped between the new and merged constant pools
  6669. - // so we have to rewrite some constant pool references.
  6670. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6671. - return JVMTI_ERROR_INTERNAL;
  6672. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6673. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6674. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6675. + if(field_klass != NULL) {
  6676. + if (field_klass->klass_part()->is_redefining()) {
  6677. + field_klass = field_klass->klass_part()->old_version();
  6678. + }
  6679. + if (field_klass->klass_part()->has_subtype_changed()) {
  6680. + return true;
  6681. + }
  6682. + }
  6683. + return false;
  6684. }
  6685. + };
  6686. - // Replace the new constant pool with a shrunken copy of the
  6687. - // merged constant pool so now the rewritten bytecodes have
  6688. - // valid references; the previous new constant pool will get
  6689. - // GCed.
  6690. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6691. - THREAD);
  6692. - merge_cp()->set_is_conc_safe(true);
  6693. + MyFieldClosure fieldClosure(&type_check_information);
  6694. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6695. +
  6696. + if (type_check_information.length() > 0) {
  6697. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6698. + cur_instance_klass->store_type_check_information(type_check_information);
  6699. }
  6700. - assert(old_cp()->is_conc_safe(), "Just checking");
  6701. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6702. +}
  6703. - return JVMTI_ERROR_NONE;
  6704. -} // end merge_cp_and_rewrite()
  6705. +bool VM_RedefineClasses::check_field_value_types() {
  6706. + Thread *THREAD = Thread::current();
  6707. + class CheckFieldTypesClosure : public ObjectClosure {
  6708. -// Rewrite constant pool references in klass scratch_class.
  6709. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6710. - TRAPS) {
  6711. + private:
  6712. - // rewrite constant pool references in the methods:
  6713. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6714. - // propagate failure back to caller
  6715. - return false;
  6716. - }
  6717. + bool _result;
  6718. - // rewrite constant pool references in the class_annotations:
  6719. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6720. - // propagate failure back to caller
  6721. - return false;
  6722. - }
  6723. + public:
  6724. - // rewrite constant pool references in the fields_annotations:
  6725. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6726. - // propagate failure back to caller
  6727. - return false;
  6728. - }
  6729. + CheckFieldTypesClosure() {
  6730. + _result = true;
  6731. + }
  6732. - // rewrite constant pool references in the methods_annotations:
  6733. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6734. - // propagate failure back to caller
  6735. - return false;
  6736. - }
  6737. + bool result() { return _result; }
  6738. - // rewrite constant pool references in the methods_parameter_annotations:
  6739. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6740. - THREAD)) {
  6741. - // propagate failure back to caller
  6742. - return false;
  6743. + virtual void do_object(oop obj) {
  6744. +
  6745. + if (!_result) {
  6746. + return;
  6747. + }
  6748. +
  6749. + if (obj->is_objArray()) {
  6750. +
  6751. + objArrayOop array = objArrayOop(obj);
  6752. +
  6753. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6754. +
  6755. + if (element_klass->klass_part()->has_subtype_changed()) {
  6756. + int length = array->length();
  6757. + for (int i=0; i<length; i++) {
  6758. + oop element = array->obj_at(i);
  6759. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6760. + // Check subtype relationship to static type of array
  6761. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6762. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6763. + element_klass->klass_part()->name()->as_C_string(),
  6764. + i,
  6765. + element->blueprint()->name()->as_C_string()));
  6766. + _result = false;
  6767. + break;
  6768. + }
  6769. + }
  6770. + }
  6771. + }
  6772. +
  6773. + } else {
  6774. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6775. + if (cur != NULL) {
  6776. + // Type check information exists for this oop
  6777. + while ((*cur).left() != -1) {
  6778. + check_field(obj, (*cur).left(), (*cur).right());
  6779. + cur++;
  6780. + }
  6781. + }
  6782. + }
  6783. + }
  6784. +
  6785. + void check_field(oop obj, int offset, klassOop static_type) {
  6786. + oop field_value = obj->obj_field(offset);
  6787. + if (field_value != NULL) {
  6788. + // Field is not null
  6789. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6790. + // We are OK
  6791. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6792. + obj->klass()->klass_part()->name()->as_C_string(),
  6793. + static_type->klass_part()->name()->as_C_string(),
  6794. + offset,
  6795. + field_value->klass()->klass_part()->name()->as_C_string()));
  6796. + } else {
  6797. + // Failure!
  6798. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6799. + obj->klass()->klass_part()->name()->as_C_string(),
  6800. + static_type->klass_part()->name()->as_C_string(),
  6801. + offset,
  6802. + field_value->klass()->klass_part()->name()->as_C_string()));
  6803. + _result = false;
  6804. + }
  6805. + }
  6806. + }
  6807. + };
  6808. +
  6809. + CheckFieldTypesClosure myObjectClosure;
  6810. +
  6811. + // make sure that heap is parsable (fills TLABs with filler objects)
  6812. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  6813. +
  6814. + // do the iteration
  6815. + // If this operation encounters a bad object when using CMS,
  6816. + // consider using safe_object_iterate() which avoids perm gen
  6817. + // objects that may contain bad references.
  6818. + Universe::heap()->object_iterate(&myObjectClosure);
  6819. +
  6820. + // when sharing is enabled we must iterate over the shared spaces
  6821. + if (UseSharedSpaces) {
  6822. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  6823. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  6824. + gen->ro_space()->object_iterate(&myObjectClosure);
  6825. + gen->rw_space()->object_iterate(&myObjectClosure);
  6826. }
  6827. - // rewrite constant pool references in the methods_default_annotations:
  6828. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6829. - THREAD)) {
  6830. - // propagate failure back to caller
  6831. - return false;
  6832. + return myObjectClosure.result();
  6833. +}
  6834. +
  6835. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  6836. + if (k->klass_part()->is_redefining()) {
  6837. + k = k->klass_part()->old_version();
  6838. }
  6839. - return true;
  6840. -} // end rewrite_cp_refs()
  6841. + // We found an instance klass!
  6842. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  6843. + cur_instance_klass->clear_type_check_information();
  6844. +}
  6845. +void VM_RedefineClasses::update_active_methods() {
  6846. +
  6847. + RC_TRACE(0x00000002, ("Updating active methods"));
  6848. + JavaThread *java_thread = Threads::first();
  6849. + while (java_thread != NULL) {
  6850. +
  6851. + int stack_depth = 0;
  6852. + if (java_thread->has_last_Java_frame()) {
  6853. +
  6854. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  6855. +
  6856. + // vframes are resource allocated
  6857. + Thread* current_thread = Thread::current();
  6858. + ResourceMark rm(current_thread);
  6859. + HandleMark hm(current_thread);
  6860. +
  6861. + RegisterMap reg_map(java_thread);
  6862. + frame f = java_thread->last_frame();
  6863. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6864. + frame* last_entry_frame = NULL;
  6865. +
  6866. + while (vf != NULL) {
  6867. + if (vf->is_java_frame()) {
  6868. + // java frame (interpreted, compiled, ...)
  6869. + javaVFrame *jvf = javaVFrame::cast(vf);
  6870. +
  6871. + if (!(jvf->method()->is_native())) {
  6872. + int bci = jvf->bci();
  6873. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  6874. + ResourceMark rm(Thread::current());
  6875. + HandleMark hm;
  6876. + instanceKlassHandle klass(jvf->method()->method_holder());
  6877. +
  6878. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6879. +
  6880. +
  6881. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  6882. + jvf->method()->name_and_sig_as_C_string()));
  6883. +
  6884. + if (RC_TRACE_ENABLED(0x01000000)) {
  6885. + int code_size = jvf->method()->code_size();
  6886. + char *code_base_old = (char*)jvf->method()->code_base();
  6887. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  6888. + for (int i=0; i<code_size; i++) {
  6889. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  6890. + }
  6891. + jvf->method()->print_codes_on(tty);
  6892. + jvf->method()->new_version()->print_codes_on(tty);
  6893. + }
  6894. +
  6895. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  6896. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  6897. +
  6898. +
  6899. + if (RC_TRACE_ENABLED(0x01000000)) {
  6900. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  6901. + tty->print_cr("old cp");
  6902. + for (int i=0; i<cp_old->length(); i++) {
  6903. + cp_old->entry_at(i)->print(tty, i);
  6904. + }
  6905. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  6906. + tty->print_cr("new cp");
  6907. + for (int i=0; i<cp_new->length(); i++) {
  6908. + cp_new->entry_at(i)->print(tty, i);
  6909. + }
  6910. + }
  6911. -// Rewrite constant pool references in the methods.
  6912. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6913. - instanceKlassHandle scratch_class, TRAPS) {
  6914. + iframe->set_method(jvf->method()->new_version(), bci);
  6915. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  6916. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  6917. - objArrayHandle methods(THREAD, scratch_class->methods());
  6918. + }
  6919. + }
  6920. + }
  6921. + vf = vf->sender();
  6922. + }
  6923. + }
  6924. +
  6925. + // Advance to next thread
  6926. + java_thread = java_thread->next();
  6927. + }
  6928. +}
  6929. +
  6930. +void VM_RedefineClasses::method_forwarding() {
  6931. +
  6932. + int forwarding_count = 0;
  6933. + JavaThread *java_thread = Threads::first();
  6934. + while (java_thread != NULL) {
  6935. +
  6936. + int stack_depth = 0;
  6937. + if (java_thread->has_last_Java_frame()) {
  6938. +
  6939. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  6940. +
  6941. + // vframes are resource allocated
  6942. + Thread* current_thread = Thread::current();
  6943. + ResourceMark rm(current_thread);
  6944. + HandleMark hm(current_thread);
  6945. +
  6946. + RegisterMap reg_map(java_thread);
  6947. + frame f = java_thread->last_frame();
  6948. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6949. + frame* last_entry_frame = NULL;
  6950. +
  6951. + while (vf != NULL) {
  6952. + if (vf->is_java_frame()) {
  6953. + // java frame (interpreted, compiled, ...)
  6954. + javaVFrame *jvf = javaVFrame::cast(vf);
  6955. +
  6956. + if (!(jvf->method()->is_native())) {
  6957. + RC_TRACE(0x00008000, ("found method: %s",
  6958. + jvf->method()->name()->as_C_string()));
  6959. + ResourceMark rm(Thread::current());
  6960. + HandleMark hm;
  6961. + instanceKlassHandle klass(jvf->method()->method_holder());
  6962. + methodOop m = jvf->method();
  6963. + int bci = jvf->bci();
  6964. + RC_TRACE(0x00008000, ("klass redef %d",
  6965. + klass->is_redefining()));
  6966. +
  6967. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  6968. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  6969. + m->name()->as_C_string()));
  6970. +
  6971. + klassOop new_klass = klass->newest_version();
  6972. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  6973. + RC_TRACE(0x00000002, ("%d %d",
  6974. + new_method,
  6975. + new_method->constMethod()->has_code_section_table()));
  6976. +
  6977. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  6978. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  6979. + new_method->name()->as_C_string()));
  6980. + m->set_forward_method(new_method);
  6981. + if (new_method->max_locals() != m->max_locals()) {
  6982. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  6983. + }
  6984. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  6985. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  6986. + if (jvf->is_interpreted_frame()) {
  6987. + if (m->is_in_code_section(bci)) {
  6988. + // We must transfer now and cannot delay until next NOP.
  6989. + int new_bci = m->calculate_forward_bci(bci, new_method);
  6990. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  6991. + RC_TRACE(0x00000002, ("Transfering execution of %s to new method old_bci=%d new_bci=%d",
  6992. + new_method->name()->as_C_string(),
  6993. + bci,
  6994. + new_bci));
  6995. + iframe->set_method(new_method, new_bci);
  6996. + } else {
  6997. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  6998. + new_method->name()->as_C_string(),
  6999. + bci));
  7000. + }
  7001. + } else {
  7002. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7003. + new_method->name()->as_C_string()));
  7004. + }
  7005. + }
  7006. + }
  7007. + }
  7008. + }
  7009. + vf = vf->sender();
  7010. + }
  7011. + }
  7012. - if (methods.is_null() || methods->length() == 0) {
  7013. - // no methods so nothing to do
  7014. - return true;
  7015. + // Advance to next thread
  7016. + java_thread = java_thread->next();
  7017. }
  7018. - // rewrite constant pool references in the methods:
  7019. - for (int i = methods->length() - 1; i >= 0; i--) {
  7020. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7021. - methodHandle new_method;
  7022. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  7023. - if (!new_method.is_null()) {
  7024. - // the method has been replaced so save the new method version
  7025. - methods->obj_at_put(i, new_method());
  7026. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7027. + forwarding_count));
  7028. +}
  7029. +
  7030. +bool VM_RedefineClasses::check_method_stacks() {
  7031. +
  7032. + JavaThread *java_thread = Threads::first();
  7033. + while (java_thread != NULL) {
  7034. +
  7035. + int stack_depth = 0;
  7036. + if (java_thread->has_last_Java_frame()) {
  7037. +
  7038. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7039. +
  7040. + // vframes are resource allocated
  7041. + Thread* current_thread = Thread::current();
  7042. + ResourceMark rm(current_thread);
  7043. + HandleMark hm(current_thread);
  7044. +
  7045. + RegisterMap reg_map(java_thread);
  7046. + frame f = java_thread->last_frame();
  7047. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7048. + frame* last_entry_frame = NULL;
  7049. +
  7050. + while (vf != NULL) {
  7051. + if (vf->is_java_frame()) {
  7052. + // java frame (interpreted, compiled, ...)
  7053. + javaVFrame *jvf = javaVFrame::cast(vf);
  7054. +
  7055. + if (!(jvf->method()->is_native())) {
  7056. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7057. + ResourceMark rm(Thread::current());
  7058. + HandleMark hm;
  7059. + instanceKlassHandle klass(jvf->method()->method_holder());
  7060. +
  7061. + StackValueCollection *locals = jvf->locals();
  7062. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7063. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7064. +
  7065. + for (int i=0; i<locals->size(); i++) {
  7066. + StackValue *stack_value = locals->at(i);
  7067. + if (stack_value->type() == T_OBJECT) {
  7068. + Handle obj = stack_value->get_obj();
  7069. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7070. +
  7071. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7072. + bool result = false;
  7073. + methodOop method = jvf->method();
  7074. + if (method->has_localvariable_table()) {
  7075. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7076. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7077. +
  7078. + if (elem->slot == i) {
  7079. +
  7080. + // Matching index found
  7081. +
  7082. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7083. +
  7084. + // Also in range!!
  7085. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7086. + Symbol* klass_name = signature_to_class_name(signature);
  7087. +
  7088. + 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();
  7089. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7090. +
  7091. + // Field is not null
  7092. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7093. + // We are OK
  7094. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7095. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7096. + result = true;
  7097. + } else {
  7098. + // Failure!
  7099. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7100. + local_klass->klass_part()->name()->as_C_string(),
  7101. + cur->klass_part()->name()->as_C_string()));
  7102. + return false;
  7103. + }
  7104. + }
  7105. + }
  7106. +
  7107. + elem++;
  7108. + }
  7109. + } else {
  7110. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7111. + method->name_and_sig_as_C_string()));
  7112. + }
  7113. +
  7114. + if (!result) {
  7115. + return false;
  7116. + }
  7117. +
  7118. + RC_TRACE(0x00008000, ("Verifying class %s",
  7119. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7120. +
  7121. + Symbol* exception_name;
  7122. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7123. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7124. +
  7125. + Thread::current()->set_pretend_new_universe(true);
  7126. + ClassVerifier split_verifier(klass, Thread::current());
  7127. + split_verifier.verify_method(jvf->method(), Thread::current());
  7128. + exception_name = split_verifier.result();
  7129. + Thread::current()->set_pretend_new_universe(false);
  7130. +
  7131. + if (exception_name != NULL) {
  7132. +
  7133. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7134. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7135. + RC_TRACE(0x00000001, ("Exception: %s",
  7136. + exception_name->as_C_string()));
  7137. + RC_TRACE(0x00000001, ("Message: %s",
  7138. + message_buffer));
  7139. + Thread::current()->clear_pending_exception();
  7140. + return false;
  7141. + }
  7142. +
  7143. + }
  7144. + }
  7145. + }
  7146. + }
  7147. + }
  7148. + vf = vf->sender();
  7149. + }
  7150. }
  7151. +
  7152. + // Advance to next thread
  7153. + java_thread = java_thread->next();
  7154. }
  7155. return true;
  7156. }
  7157. +bool VM_RedefineClasses::check_method(methodOop method) {
  7158. +
  7159. +
  7160. + return true;
  7161. +}
  7162. -// Rewrite constant pool references in the specific method. This code
  7163. -// was adapted from Rewriter::rewrite_method().
  7164. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  7165. - methodHandle *new_method_p, TRAPS) {
  7166. +// Warning: destroys redefinition level values of klasses.
  7167. +bool VM_RedefineClasses::check_loaded_methods() {
  7168. - *new_method_p = methodHandle(); // default is no new method
  7169. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7170. - // We cache a pointer to the bytecodes here in code_base. If GC
  7171. - // moves the methodOop, then the bytecodes will also move which
  7172. - // will likely cause a crash. We create a No_Safepoint_Verifier
  7173. - // object to detect whether we pass a possible safepoint in this
  7174. - // code block.
  7175. - No_Safepoint_Verifier nsv;
  7176. + private:
  7177. +
  7178. + bool _result;
  7179. + GrowableArray<klassOop> *_dangerous_klasses;
  7180. - // Bytecodes and their length
  7181. - address code_base = method->code_base();
  7182. - int code_length = method->code_size();
  7183. + public:
  7184. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7185. + _result = true;
  7186. + _dangerous_klasses = dangerous_klasses;
  7187. + }
  7188. - int bc_length;
  7189. - for (int bci = 0; bci < code_length; bci += bc_length) {
  7190. - address bcp = code_base + bci;
  7191. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  7192. + bool result() {
  7193. + return _result;
  7194. + }
  7195. - bc_length = Bytecodes::length_for(c);
  7196. - if (bc_length == 0) {
  7197. - // More complicated bytecodes report a length of zero so
  7198. - // we have to try again a slightly different way.
  7199. - bc_length = Bytecodes::length_at(method(), bcp);
  7200. + bool is_class_dangerous(klassOop k) {
  7201. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7202. }
  7203. - assert(bc_length != 0, "impossible bytecode length");
  7204. + bool can_be_affected(instanceKlass *klass) {
  7205. - switch (c) {
  7206. - case Bytecodes::_ldc:
  7207. - {
  7208. - int cp_index = *(bcp + 1);
  7209. - int new_index = find_new_index(cp_index);
  7210. + constantPoolOop cp = klass->constants();
  7211. - if (StressLdcRewrite && new_index == 0) {
  7212. - // If we are stressing ldc -> ldc_w rewriting, then we
  7213. - // always need a new_index value.
  7214. - new_index = cp_index;
  7215. - }
  7216. - if (new_index != 0) {
  7217. - // the original index is mapped so we have more work to do
  7218. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  7219. - // The new value can still use ldc instead of ldc_w
  7220. - // unless we are trying to stress ldc -> ldc_w rewriting
  7221. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7222. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7223. - bcp, cp_index, new_index));
  7224. - *(bcp + 1) = new_index;
  7225. - } else {
  7226. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7227. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  7228. - Bytecodes::name(c), bcp, cp_index, new_index));
  7229. - // the new value needs ldc_w instead of ldc
  7230. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  7231. - bcp = (address)inst_buffer;
  7232. - // construct new instruction sequence
  7233. - *bcp = Bytecodes::_ldc_w;
  7234. - bcp++;
  7235. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  7236. - // See comment below for difference between put_Java_u2()
  7237. - // and put_native_u2().
  7238. - Bytes::put_Java_u2(bcp, new_index);
  7239. -
  7240. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  7241. - methodHandle m;
  7242. - {
  7243. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  7244. -
  7245. - // ldc is 2 bytes and ldc_w is 3 bytes
  7246. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  7247. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  7248. - guarantee(false, "insert_space_at() failed");
  7249. + Thread *THREAD = Thread::current();
  7250. + klassOop k;
  7251. + Symbol* symbol;
  7252. +
  7253. + for (int i=1; i<cp->length(); i++) {
  7254. + jbyte tag = cp->tag_at(i).value();
  7255. + switch(tag) {
  7256. + case JVM_CONSTANT_Long:
  7257. + case JVM_CONSTANT_Double:
  7258. + i++;
  7259. + break;
  7260. +
  7261. + case JVM_CONSTANT_Utf8:
  7262. + case JVM_CONSTANT_Unicode:
  7263. + case JVM_CONSTANT_Integer:
  7264. + case JVM_CONSTANT_Float:
  7265. + case JVM_CONSTANT_String:
  7266. + case JVM_CONSTANT_Fieldref:
  7267. + case JVM_CONSTANT_Methodref:
  7268. + case JVM_CONSTANT_InterfaceMethodref:
  7269. + case JVM_CONSTANT_ClassIndex:
  7270. + case JVM_CONSTANT_UnresolvedString:
  7271. + case JVM_CONSTANT_StringIndex:
  7272. + case JVM_CONSTANT_UnresolvedClassInError:
  7273. + case JVM_CONSTANT_Object:
  7274. + // do nothing
  7275. + break;
  7276. +
  7277. + case JVM_CONSTANT_Class:
  7278. + k = cp->klass_at(i, CHECK_(true));
  7279. + if (is_class_dangerous(k)) {
  7280. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7281. + klass->name()->as_C_string(),
  7282. + i,
  7283. + k->klass_part()->name()->as_C_string()));
  7284. + return true;
  7285. + }
  7286. + break;
  7287. +
  7288. + case JVM_CONSTANT_NameAndType:
  7289. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7290. + if (symbol->byte_at(0) == '(') {
  7291. + // This must be a method
  7292. + SignatureStream signatureStream(symbol);
  7293. + while (true) {
  7294. +
  7295. + if (signatureStream.is_array()) {
  7296. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7297. + if (is_type_signature_dangerous(cur_signature)) {
  7298. + return true;
  7299. + }
  7300. + } else if (signatureStream.is_object()) {
  7301. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7302. + return true;
  7303. + }
  7304. + }
  7305. +
  7306. + if (signatureStream.at_return_type()) {
  7307. + break;
  7308. + }
  7309. +
  7310. + signatureStream.next();
  7311. }
  7312. +
  7313. + } else if (is_type_signature_dangerous(symbol)) {
  7314. + return true;
  7315. }
  7316. + break;
  7317. - // return the new method so that the caller can update
  7318. - // the containing class
  7319. - *new_method_p = method = m;
  7320. - // switch our bytecode processing loop from the old method
  7321. - // to the new method
  7322. - code_base = method->code_base();
  7323. - code_length = method->code_size();
  7324. - bcp = code_base + bci;
  7325. - c = (Bytecodes::Code)(*bcp);
  7326. - bc_length = Bytecodes::length_for(c);
  7327. - assert(bc_length != 0, "sanity check");
  7328. - } // end we need ldc_w instead of ldc
  7329. - } // end if there is a mapped index
  7330. - } break;
  7331. -
  7332. - // these bytecodes have a two-byte constant pool index
  7333. - case Bytecodes::_anewarray : // fall through
  7334. - case Bytecodes::_checkcast : // fall through
  7335. - case Bytecodes::_getfield : // fall through
  7336. - case Bytecodes::_getstatic : // fall through
  7337. - case Bytecodes::_instanceof : // fall through
  7338. - case Bytecodes::_invokeinterface: // fall through
  7339. - case Bytecodes::_invokespecial : // fall through
  7340. - case Bytecodes::_invokestatic : // fall through
  7341. - case Bytecodes::_invokevirtual : // fall through
  7342. - case Bytecodes::_ldc_w : // fall through
  7343. - case Bytecodes::_ldc2_w : // fall through
  7344. - case Bytecodes::_multianewarray : // fall through
  7345. - case Bytecodes::_new : // fall through
  7346. - case Bytecodes::_putfield : // fall through
  7347. - case Bytecodes::_putstatic :
  7348. - {
  7349. - address p = bcp + 1;
  7350. - int cp_index = Bytes::get_Java_u2(p);
  7351. - int new_index = find_new_index(cp_index);
  7352. - if (new_index != 0) {
  7353. - // the original index is mapped so update w/ new value
  7354. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7355. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7356. - bcp, cp_index, new_index));
  7357. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7358. - // situation because it is reusing the constant pool index
  7359. - // location for a native index into the constantPoolCache.
  7360. - // Since we are updating the constant pool index prior to
  7361. - // verification and constantPoolCache initialization, we
  7362. - // need to keep the new index in Java byte order.
  7363. - Bytes::put_Java_u2(p, new_index);
  7364. + case JVM_CONSTANT_UnresolvedClass:
  7365. + symbol = cp->unresolved_klass_at(i);
  7366. + if (is_symbol_dangerous(symbol)) {
  7367. + return true;
  7368. + }
  7369. + break;
  7370. +
  7371. + default:
  7372. + ShouldNotReachHere();
  7373. }
  7374. - } break;
  7375. + }
  7376. +
  7377. + return false;
  7378. }
  7379. - } // end for each bytecode
  7380. -} // end rewrite_cp_refs_in_method()
  7381. + bool is_type_signature_dangerous(Symbol* signature) {
  7382. + // This must be a field type
  7383. + if (FieldType::is_obj(signature)) {
  7384. + Symbol* name = signature_to_class_name(signature);
  7385. + if (is_symbol_dangerous(name)) {
  7386. + return true;
  7387. + }
  7388. + } else if (FieldType::is_array(signature)) {
  7389. + //jint dimension;
  7390. + //Symbol* object_key;
  7391. + FieldArrayInfo fd;
  7392. + FieldType::get_array_info(signature, fd, Thread::current());
  7393. + if (is_symbol_dangerous(fd.object_key())) {
  7394. + return true;
  7395. + }
  7396. + }
  7397. + return false;
  7398. + }
  7399. +
  7400. + bool is_symbol_dangerous(Symbol* symbol) {
  7401. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7402. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7403. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7404. + i,
  7405. + symbol->as_C_string()));
  7406. + return true;
  7407. + }
  7408. + }
  7409. + return false;
  7410. + }
  7411. +
  7412. + virtual void do_object(oop obj) {
  7413. -// Rewrite constant pool references in the class_annotations field.
  7414. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7415. - instanceKlassHandle scratch_class, TRAPS) {
  7416. + if (!_result) return;
  7417. - typeArrayHandle class_annotations(THREAD,
  7418. - scratch_class->class_annotations());
  7419. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7420. - // no class_annotations so nothing to do
  7421. - return true;
  7422. + klassOop klassObj = (klassOop)obj;
  7423. + Thread *THREAD = Thread::current();
  7424. +
  7425. + // We found an instance klass!
  7426. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7427. + instanceKlassHandle handle(klassObj);
  7428. +
  7429. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7430. +
  7431. + if (!can_be_affected(klass)) {
  7432. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7433. + return;
  7434. + }
  7435. +
  7436. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7437. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7438. + _result = false;
  7439. + return;
  7440. + }
  7441. +
  7442. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7443. +
  7444. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7445. +
  7446. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7447. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7448. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7449. + //PENDING_EXCEPTION->print();
  7450. + CLEAR_PENDING_EXCEPTION;
  7451. + _result = false;
  7452. + }
  7453. +
  7454. + /*int method_count = klass->methods()->length();
  7455. + for (int i=0; i<method_count; i++) {
  7456. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7457. + if (!check_method(cur_method)) {
  7458. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7459. + }
  7460. + }*/
  7461. + }
  7462. + };
  7463. +
  7464. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7465. +
  7466. + GrowableArray<klassOop> dangerous_klasses;
  7467. + for (int i=0; i<_new_classes->length(); i++) {
  7468. + instanceKlassHandle handle = _new_classes->at(i);
  7469. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7470. + dangerous_klasses.append(handle());
  7471. + }
  7472. }
  7473. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7474. - ("class_annotations length=%d", class_annotations->length()));
  7475. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7476. + Thread::current()->set_pretend_new_universe(true);
  7477. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7478. + Thread::current()->set_pretend_new_universe(false);
  7479. - int byte_i = 0; // byte index into class_annotations
  7480. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7481. - THREAD);
  7482. +
  7483. + return checkLoadedMethodsClosure.result();
  7484. }
  7485. +bool VM_RedefineClasses::check_type_consistency() {
  7486. -// Rewrite constant pool references in an annotations typeArray. This
  7487. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7488. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7489. -//
  7490. -// annotations_typeArray {
  7491. -// u2 num_annotations;
  7492. -// annotation annotations[num_annotations];
  7493. -// }
  7494. -//
  7495. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7496. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7497. + Universe::set_verify_in_progress(true);
  7498. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7499. - // not enough room for num_annotations field
  7500. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7501. - ("length() is too small for num_annotations field"));
  7502. + SystemDictionary::classes_do(calculate_type_check_information);
  7503. + bool result = check_field_value_types();
  7504. + SystemDictionary::classes_do(clear_type_check_information);
  7505. + if (!result) {
  7506. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7507. + Universe::set_verify_in_progress(false);
  7508. + return false;
  7509. + }
  7510. +
  7511. + result = check_method_stacks();
  7512. + if (!result) {
  7513. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7514. + Universe::set_verify_in_progress(false);
  7515. return false;
  7516. }
  7517. - u2 num_annotations = Bytes::get_Java_u2((address)
  7518. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7519. - byte_i_ref += 2;
  7520. + result = check_loaded_methods();
  7521. + if (!result) {
  7522. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7523. + Universe::set_verify_in_progress(false);
  7524. + return false;
  7525. + }
  7526. +
  7527. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7528. + Universe::set_verify_in_progress(false);
  7529. + return true;
  7530. +}
  7531. +
  7532. +void VM_RedefineClasses::rollback() {
  7533. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7534. + SystemDictionary::rollback_redefinition();
  7535. +
  7536. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7537. + for (int i=0; i<_new_classes->length(); i++) {
  7538. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7539. + }
  7540. +
  7541. + for (int i=0; i<_new_classes->length(); i++) {
  7542. + instanceKlassHandle new_class = _new_classes->at(i);
  7543. + new_class->set_redefining(false);
  7544. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7545. + new_class->set_old_version(NULL);
  7546. + }
  7547. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7548. - ("num_annotations=%d", num_annotations));
  7549. +}
  7550. - int calc_num_annotations = 0;
  7551. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7552. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7553. - byte_i_ref, THREAD)) {
  7554. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7555. - ("bad annotation_struct at %d", calc_num_annotations));
  7556. - // propagate failure back to caller
  7557. - return false;
  7558. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7559. + T heap_oop = oopDesc::load_heap_oop(p);
  7560. + if (!oopDesc::is_null(heap_oop)) {
  7561. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7562. + if (obj->is_instanceKlass()) {
  7563. + klassOop klass = (klassOop)obj;
  7564. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7565. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7566. + obj = klass->klass_part()->new_version();
  7567. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7568. + }
  7569. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7570. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7571. + // java.lang.Class instances.
  7572. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7573. + if (klass_oop != NULL) {
  7574. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7575. + obj = klass_oop->new_version()->java_mirror();
  7576. + } else if (klass_oop->klass_part()->is_redefining()) {
  7577. + obj = klass_oop->java_mirror();
  7578. + }
  7579. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7580. +
  7581. +
  7582. + // FIXME: DCEVM: better implementation?
  7583. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7584. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7585. + // case we need to run write barrier to make sure card table is properly updated. This will
  7586. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7587. + if (Universe::heap()->is_in_reserved(p)) {
  7588. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7589. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7590. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7591. + CardTableRS* _rs = (CardTableRS*)rs;
  7592. + _rs->inline_write_ref_field_gc(p, obj);
  7593. + }
  7594. + }
  7595. + }
  7596. }
  7597. }
  7598. - assert(num_annotations == calc_num_annotations, "sanity check");
  7599. +}
  7600. - return true;
  7601. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7602. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7603. + markOop first_mark = first->mark();
  7604. + markOop second_mark = second->mark();
  7605. + first->set_mark(second_mark);
  7606. + second->set_mark(first_mark);
  7607. +}
  7608. +void VM_RedefineClasses::doit() {
  7609. + Thread *thread = Thread::current();
  7610. -// Rewrite constant pool references in the annotation struct portion of
  7611. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7612. -// the 2nd-edition of the VM spec:
  7613. -//
  7614. -// struct annotation {
  7615. -// u2 type_index;
  7616. -// u2 num_element_value_pairs;
  7617. -// {
  7618. -// u2 element_name_index;
  7619. -// element_value value;
  7620. -// } element_value_pairs[num_element_value_pairs];
  7621. -// }
  7622. -//
  7623. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7624. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7625. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7626. - // not enough room for smallest annotation_struct
  7627. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7628. - ("length() is too small for annotation_struct"));
  7629. - return false;
  7630. - }
  7631. + RC_TRACE(0x00000001, ("Entering doit!"));
  7632. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7633. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7634. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7635. - annotations_typeArray->byte_at_addr(
  7636. - byte_i_ref));
  7637. - byte_i_ref += 2;
  7638. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7639. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7640. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7641. - num_element_value_pairs));
  7642. + RC_TIMER_START(_timer_check_type);
  7643. - int calc_num_element_value_pairs = 0;
  7644. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7645. - calc_num_element_value_pairs++) {
  7646. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7647. - // not enough room for another element_name_index, let alone
  7648. - // the rest of another component
  7649. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7650. - ("length() is too small for element_name_index"));
  7651. - return false;
  7652. + if (!check_type_consistency()) {
  7653. + // (tw) TODO: Rollback the class redefinition
  7654. + rollback();
  7655. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7656. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7657. + RC_TIMER_STOP(_timer_check_type);
  7658. + return;
  7659. }
  7660. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7661. - annotations_typeArray, byte_i_ref,
  7662. - "mapped old element_name_index=%d", THREAD);
  7663. + RC_TIMER_STOP(_timer_check_type);
  7664. +
  7665. + } else {
  7666. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7667. + }
  7668. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7669. - ("element_name_index=%d", element_name_index));
  7670. + if (UseMethodForwardPoints) {
  7671. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7672. + method_forwarding();
  7673. + }
  7674. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7675. - byte_i_ref, THREAD)) {
  7676. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7677. - ("bad element_value at %d", calc_num_element_value_pairs));
  7678. - // propagate failure back to caller
  7679. - return false;
  7680. + if (UseSharedSpaces) {
  7681. + // Sharing is enabled so we remap the shared readonly space to
  7682. + // shared readwrite, private just in case we need to redefine
  7683. + // a shared class. We do the remap during the doit() phase of
  7684. + // the safepoint to be safer.
  7685. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7686. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7687. + _result = JVMTI_ERROR_INTERNAL;
  7688. + return;
  7689. }
  7690. - } // end for each component
  7691. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7692. - "sanity check");
  7693. + }
  7694. - return true;
  7695. -} // end rewrite_cp_refs_in_annotation_struct()
  7696. -
  7697. -
  7698. -// Rewrite a constant pool reference at the current position in
  7699. -// annotations_typeArray if needed. Returns the original constant
  7700. -// pool reference if a rewrite was not needed or the new constant
  7701. -// pool reference if a rewrite was needed.
  7702. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7703. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7704. - const char * trace_mesg, TRAPS) {
  7705. -
  7706. - address cp_index_addr = (address)
  7707. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7708. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7709. - u2 new_cp_index = find_new_index(old_cp_index);
  7710. - if (new_cp_index != 0) {
  7711. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7712. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7713. - old_cp_index = new_cp_index;
  7714. - }
  7715. - byte_i_ref += 2;
  7716. - return old_cp_index;
  7717. -}
  7718. + RC_TIMER_START(_timer_prepare_redefinition);
  7719. + for (int i = 0; i < _new_classes->length(); i++) {
  7720. + redefine_single_class(_new_classes->at(i), thread);
  7721. + }
  7722. + // Deoptimize all compiled code that depends on this class
  7723. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7724. -// Rewrite constant pool references in the element_value portion of an
  7725. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7726. -// the 2nd-edition of the VM spec:
  7727. -//
  7728. -// struct element_value {
  7729. -// u1 tag;
  7730. -// union {
  7731. -// u2 const_value_index;
  7732. -// {
  7733. -// u2 type_name_index;
  7734. -// u2 const_name_index;
  7735. -// } enum_const_value;
  7736. -// u2 class_info_index;
  7737. -// annotation annotation_value;
  7738. -// struct {
  7739. -// u2 num_values;
  7740. -// element_value values[num_values];
  7741. -// } array_value;
  7742. -// } value;
  7743. -// }
  7744. -//
  7745. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7746. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7747. + // Adjust constantpool caches and vtables for all classes
  7748. + // that reference methods of the evolved class.
  7749. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7750. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7751. - // not enough room for a tag let alone the rest of an element_value
  7752. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7753. - ("length() is too small for a tag"));
  7754. - return false;
  7755. - }
  7756. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7757. + RC_TIMER_START(_timer_redefinition);
  7758. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7759. - byte_i_ref++;
  7760. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7761. -
  7762. - switch (tag) {
  7763. - // These BaseType tag values are from Table 4.2 in VM spec:
  7764. - case 'B': // byte
  7765. - case 'C': // char
  7766. - case 'D': // double
  7767. - case 'F': // float
  7768. - case 'I': // int
  7769. - case 'J': // long
  7770. - case 'S': // short
  7771. - case 'Z': // boolean
  7772. -
  7773. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7774. - // the VM spec:
  7775. - case 's':
  7776. - {
  7777. - // For the above tag values (including the BaseType values),
  7778. - // value.const_value_index is right union field.
  7779. + class ChangePointersOopClosure : public OopClosure {
  7780. + virtual void do_oop(oop* o) {
  7781. + do_oop_work(o);
  7782. + }
  7783. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7784. - // not enough room for a const_value_index
  7785. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7786. - ("length() is too small for a const_value_index"));
  7787. - return false;
  7788. + virtual void do_oop(narrowOop* o) {
  7789. + do_oop_work(o);
  7790. }
  7791. + };
  7792. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  7793. - annotations_typeArray, byte_i_ref,
  7794. - "mapped old const_value_index=%d", THREAD);
  7795. + class ChangePointersObjectClosure : public ObjectClosure {
  7796. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7797. - ("const_value_index=%d", const_value_index));
  7798. - } break;
  7799. + private:
  7800. - case 'e':
  7801. - {
  7802. - // for the above tag value, value.enum_const_value is right union field
  7803. + OopClosure *_closure;
  7804. + bool _needs_instance_update;
  7805. + GrowableArray<oop> *_updated_oops;
  7806. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  7807. - // not enough room for a enum_const_value
  7808. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7809. - ("length() is too small for a enum_const_value"));
  7810. - return false;
  7811. - }
  7812. + public:
  7813. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7814. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  7815. - annotations_typeArray, byte_i_ref,
  7816. - "mapped old type_name_index=%d", THREAD);
  7817. + bool needs_instance_update() {
  7818. + return _needs_instance_update;
  7819. + }
  7820. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  7821. - annotations_typeArray, byte_i_ref,
  7822. - "mapped old const_name_index=%d", THREAD);
  7823. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7824. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7825. - ("type_name_index=%d const_name_index=%d", type_name_index,
  7826. - const_name_index));
  7827. - } break;
  7828. + virtual void do_object(oop obj) {
  7829. + if (!obj->is_instanceKlass()) {
  7830. + obj->oop_iterate(_closure);
  7831. +
  7832. + if (obj->blueprint()->is_redefining()) {
  7833. - case 'c':
  7834. - {
  7835. - // for the above tag value, value.class_info_index is right union field
  7836. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7837. + if (_updated_oops == NULL) {
  7838. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  7839. + }
  7840. + _updated_oops->append(obj);
  7841. + }
  7842. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7843. - // not enough room for a class_info_index
  7844. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7845. - ("length() is too small for a class_info_index"));
  7846. - return false;
  7847. - }
  7848. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7849. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  7850. - annotations_typeArray, byte_i_ref,
  7851. - "mapped old class_info_index=%d", THREAD);
  7852. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7853. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7854. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7855. - ("class_info_index=%d", class_info_index));
  7856. - } break;
  7857. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7858. + // We need an instance update => set back to old klass
  7859. + _needs_instance_update = true;
  7860. - case '@':
  7861. - // For the above tag value, value.attr_value is the right union
  7862. - // field. This is a nested annotation.
  7863. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7864. - byte_i_ref, THREAD)) {
  7865. - // propagate failure back to caller
  7866. - return false;
  7867. - }
  7868. - break;
  7869. + } else {
  7870. + MarkSweep::update_fields(obj, obj);
  7871. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7872. + }
  7873. + }
  7874. + }
  7875. - case '[':
  7876. - {
  7877. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7878. - // not enough room for a num_values field
  7879. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7880. - ("length() is too small for a num_values field"));
  7881. - return false;
  7882. - }
  7883. -
  7884. - // For the above tag value, value.array_value is the right union
  7885. - // field. This is an array of nested element_value.
  7886. - u2 num_values = Bytes::get_Java_u2((address)
  7887. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7888. - byte_i_ref += 2;
  7889. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  7890. -
  7891. - int calc_num_values = 0;
  7892. - for (; calc_num_values < num_values; calc_num_values++) {
  7893. - if (!rewrite_cp_refs_in_element_value(
  7894. - annotations_typeArray, byte_i_ref, THREAD)) {
  7895. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7896. - ("bad nested element_value at %d", calc_num_values));
  7897. - // propagate failure back to caller
  7898. - return false;
  7899. + } else {
  7900. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  7901. + if (klass->is_redefining()) {
  7902. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  7903. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  7904. + old_klass->constants()->set_pool_holder(klass->old_version());
  7905. +
  7906. + // Initialize the new class! Special static initialization that does not execute the
  7907. + // static constructor but copies static field values from the old class if name
  7908. + // and signature of a static field match.
  7909. + klass->initialize_redefined_class();
  7910. + }
  7911. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  7912. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  7913. + // idubrov: will get new version of that class
  7914. + //klass->iterate_static_fields(_closure);
  7915. }
  7916. }
  7917. - assert(num_values == calc_num_values, "sanity check");
  7918. - } break;
  7919. + };
  7920. - default:
  7921. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  7922. - return false;
  7923. - } // end decode tag field
  7924. + ChangePointersOopClosure oopClosure;
  7925. + ChangePointersObjectClosure objectClosure(&oopClosure);
  7926. - return true;
  7927. -} // end rewrite_cp_refs_in_element_value()
  7928. + {
  7929. + SharedHeap::heap()->gc_prologue(true);
  7930. + Universe::root_oops_do(&oopClosure);
  7931. + Universe::heap()->object_iterate(&objectClosure);
  7932. + SharedHeap::heap()->gc_epilogue(false);
  7933. + }
  7934. + // Swap marks to have same hashcodes
  7935. + for (int i=0; i<_new_classes->length(); i++) {
  7936. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  7937. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  7938. + }
  7939. -// Rewrite constant pool references in a fields_annotations field.
  7940. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  7941. - instanceKlassHandle scratch_class, TRAPS) {
  7942. + _updated_oops = objectClosure.updated_oops();
  7943. - objArrayHandle fields_annotations(THREAD,
  7944. - scratch_class->fields_annotations());
  7945. + if (objectClosure.needs_instance_update()){
  7946. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  7947. - // no fields_annotations so nothing to do
  7948. - return true;
  7949. + // Do a full garbage collection to update the instance sizes accordingly
  7950. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  7951. + Universe::set_redefining_gc_run(true);
  7952. + JvmtiGCMarker jgcm;
  7953. + notify_gc_begin(true);
  7954. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  7955. + notify_gc_end();
  7956. + Universe::set_redefining_gc_run(false);
  7957. + RC_TRACE(0x00000001, ("GC done!"));
  7958. }
  7959. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7960. - ("fields_annotations length=%d", fields_annotations->length()));
  7961. -
  7962. - for (int i = 0; i < fields_annotations->length(); i++) {
  7963. - typeArrayHandle field_annotations(THREAD,
  7964. - (typeArrayOop)fields_annotations->obj_at(i));
  7965. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  7966. - // this field does not have any annotations so skip it
  7967. - continue;
  7968. - }
  7969. - int byte_i = 0; // byte index into field_annotations
  7970. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  7971. - THREAD)) {
  7972. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7973. - ("bad field_annotations at %d", i));
  7974. - // propagate failure back to caller
  7975. - return false;
  7976. + if (RC_TRACE_ENABLED(0x00000001)) {
  7977. + if (_updated_oops != NULL) {
  7978. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  7979. + } else {
  7980. + RC_TRACE(0x00000001, ("No objects updated!"));
  7981. }
  7982. }
  7983. - return true;
  7984. -} // end rewrite_cp_refs_in_fields_annotations()
  7985. -
  7986. -
  7987. -// Rewrite constant pool references in a methods_annotations field.
  7988. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  7989. - instanceKlassHandle scratch_class, TRAPS) {
  7990. + // Unmark klassOops as "redefining"
  7991. + for (int i=0; i<_new_classes->length(); i++) {
  7992. + klassOop cur = _new_classes->at(i)();
  7993. + _new_classes->at(i)->set_redefining(false);
  7994. + _new_classes->at(i)->clear_update_information();
  7995. + _new_classes->at(i)->update_supers_to_newest_version();
  7996. - objArrayHandle methods_annotations(THREAD,
  7997. - scratch_class->methods_annotations());
  7998. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  7999. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  8000. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8001. - // no methods_annotations so nothing to do
  8002. - return true;
  8003. - }
  8004. -
  8005. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8006. - ("methods_annotations length=%d", methods_annotations->length()));
  8007. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  8008. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  8009. - for (int i = 0; i < methods_annotations->length(); i++) {
  8010. - typeArrayHandle method_annotations(THREAD,
  8011. - (typeArrayOop)methods_annotations->obj_at(i));
  8012. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8013. - // this method does not have any annotations so skip it
  8014. - continue;
  8015. + oop new_mirror = _new_classes->at(i)->java_mirror();
  8016. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  8017. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  8018. }
  8019. + }
  8020. - int byte_i = 0; // byte index into method_annotations
  8021. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8022. - THREAD)) {
  8023. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8024. - ("bad method_annotations at %d", i));
  8025. - // propagate failure back to caller
  8026. - return false;
  8027. - }
  8028. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  8029. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  8030. }
  8031. - return true;
  8032. -} // end rewrite_cp_refs_in_methods_annotations()
  8033. + // Disable any dependent concurrent compilations
  8034. + SystemDictionary::notice_modification();
  8035. + // Set flag indicating that some invariants are no longer true.
  8036. + // See jvmtiExport.hpp for detailed explanation.
  8037. + JvmtiExport::set_has_redefined_a_class();
  8038. -// Rewrite constant pool references in a methods_parameter_annotations
  8039. -// field. This "structure" is adapted from the
  8040. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8041. -// 4.8.17 of the 2nd-edition of the VM spec:
  8042. -//
  8043. -// methods_parameter_annotations_typeArray {
  8044. -// u1 num_parameters;
  8045. -// {
  8046. -// u2 num_annotations;
  8047. -// annotation annotations[num_annotations];
  8048. -// } parameter_annotations[num_parameters];
  8049. -// }
  8050. -//
  8051. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8052. - instanceKlassHandle scratch_class, TRAPS) {
  8053. + // Clean up caches in the compiler interface and compiler threads
  8054. + CompileBroker::cleanup_after_redefinition();
  8055. - objArrayHandle methods_parameter_annotations(THREAD,
  8056. - scratch_class->methods_parameter_annotations());
  8057. +#ifdef ASSERT
  8058. - if (methods_parameter_annotations.is_null()
  8059. - || methods_parameter_annotations->length() == 0) {
  8060. - // no methods_parameter_annotations so nothing to do
  8061. - return true;
  8062. - }
  8063. + // Universe::verify();
  8064. + // JNIHandles::verify();
  8065. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8066. - ("methods_parameter_annotations length=%d",
  8067. - methods_parameter_annotations->length()));
  8068. + SystemDictionary::classes_do(check_class, thread);
  8069. +#endif
  8070. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8071. - typeArrayHandle method_parameter_annotations(THREAD,
  8072. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8073. - if (method_parameter_annotations.is_null()
  8074. - || method_parameter_annotations->length() == 0) {
  8075. - // this method does not have any parameter annotations so skip it
  8076. - continue;
  8077. - }
  8078. + update_active_methods();
  8079. + RC_TIMER_STOP(_timer_redefinition);
  8080. - if (method_parameter_annotations->length() < 1) {
  8081. - // not enough room for a num_parameters field
  8082. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8083. - ("length() is too small for a num_parameters field at %d", i));
  8084. - return false;
  8085. - }
  8086. +}
  8087. - int byte_i = 0; // byte index into method_parameter_annotations
  8088. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  8089. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8090. - byte_i++;
  8091. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  8092. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  8093. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8094. - ("num_parameters=%d", num_parameters));
  8095. - int calc_num_parameters = 0;
  8096. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8097. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8098. - method_parameter_annotations, byte_i, THREAD)) {
  8099. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8100. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8101. - // propagate failure back to caller
  8102. - return false;
  8103. - }
  8104. + while (curArrayKlass != NULL) {
  8105. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  8106. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  8107. + curArrayKlass->update_supers_to_newest_version();
  8108. +
  8109. + curArrayKlass = NULL;
  8110. + if (higher_dimension != NULL) {
  8111. + curArrayKlass = arrayKlass::cast(higher_dimension);
  8112. }
  8113. - assert(num_parameters == calc_num_parameters, "sanity check");
  8114. }
  8115. - return true;
  8116. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8117. +}
  8118. +
  8119. +void VM_RedefineClasses::doit_epilogue() {
  8120. + RC_TIMER_START(_timer_vm_op_epilogue);
  8121. -// Rewrite constant pool references in a methods_default_annotations
  8122. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8123. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8124. -//
  8125. -// methods_default_annotations_typeArray {
  8126. -// element_value default_value;
  8127. -// }
  8128. -//
  8129. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8130. - instanceKlassHandle scratch_class, TRAPS) {
  8131. + unlock_threads();
  8132. - objArrayHandle methods_default_annotations(THREAD,
  8133. - scratch_class->methods_default_annotations());
  8134. + ResourceMark mark;
  8135. - if (methods_default_annotations.is_null()
  8136. - || methods_default_annotations->length() == 0) {
  8137. - // no methods_default_annotations so nothing to do
  8138. - return true;
  8139. - }
  8140. + VM_GC_Operation::doit_epilogue();
  8141. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  8142. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8143. - ("methods_default_annotations length=%d",
  8144. - methods_default_annotations->length()));
  8145. + GrowableArray<methodHandle> instanceTransformerMethods;
  8146. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8147. - typeArrayHandle method_default_annotations(THREAD,
  8148. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8149. - if (method_default_annotations.is_null()
  8150. - || method_default_annotations->length() == 0) {
  8151. - // this method does not have any default annotations so skip it
  8152. - continue;
  8153. + // Call static transformers
  8154. + for (int i=0; i<_new_classes->length(); i++) {
  8155. +
  8156. + instanceKlassHandle klass = _new_classes->at(i);
  8157. +
  8158. + // Transfer init state
  8159. + if (klass->old_version() != NULL) {
  8160. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  8161. + if (state > instanceKlass::linked) {
  8162. + klass->initialize(Thread::current());
  8163. + }
  8164. }
  8165. +
  8166. + // Find instance transformer method
  8167. - int byte_i = 0; // byte index into method_default_annotations
  8168. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8169. - if (!rewrite_cp_refs_in_element_value(
  8170. - method_default_annotations, byte_i, THREAD)) {
  8171. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8172. - ("bad default element_value at %d", i));
  8173. - // propagate failure back to caller
  8174. - return false;
  8175. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  8176. + klassOop cur_klass = klass();
  8177. + while (cur_klass != NULL) {
  8178. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  8179. + if (method != NULL) {
  8180. + methodHandle instanceTransformerMethod(method);
  8181. + instanceTransformerMethods.append(instanceTransformerMethod);
  8182. + break;
  8183. + } else {
  8184. + cur_klass = cur_klass->klass_part()->super();
  8185. + }
  8186. + }
  8187. + assert(cur_klass != NULL, "must have instance transformer method");
  8188. + } else {
  8189. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  8190. }
  8191. }
  8192. - return true;
  8193. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8194. + // Call instance transformers
  8195. + if (_updated_oops != NULL) {
  8196. -// Rewrite constant pool references in the method's stackmap table.
  8197. -// These "structures" are adapted from the StackMapTable_attribute that
  8198. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8199. -// (dated 2005.10.26):
  8200. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8201. -//
  8202. -// stack_map {
  8203. -// u2 number_of_entries;
  8204. -// stack_map_frame entries[number_of_entries];
  8205. -// }
  8206. -//
  8207. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8208. - methodHandle method, TRAPS) {
  8209. -
  8210. - if (!method->has_stackmap_table()) {
  8211. - return;
  8212. - }
  8213. -
  8214. - typeArrayOop stackmap_data = method->stackmap_data();
  8215. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8216. - address stackmap_end = stackmap_p + stackmap_data->length();
  8217. -
  8218. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8219. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8220. - stackmap_p += 2;
  8221. -
  8222. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8223. - ("number_of_entries=%u", number_of_entries));
  8224. -
  8225. - // walk through each stack_map_frame
  8226. - u2 calc_number_of_entries = 0;
  8227. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8228. - // The stack_map_frame structure is a u1 frame_type followed by
  8229. - // 0 or more bytes of data:
  8230. - //
  8231. - // union stack_map_frame {
  8232. - // same_frame;
  8233. - // same_locals_1_stack_item_frame;
  8234. - // same_locals_1_stack_item_frame_extended;
  8235. - // chop_frame;
  8236. - // same_frame_extended;
  8237. - // append_frame;
  8238. - // full_frame;
  8239. - // }
  8240. -
  8241. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8242. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8243. - // issues the following warning for the first if-statement below:
  8244. - //
  8245. - // "warning: comparison is always true due to limited range of data type"
  8246. - //
  8247. - u4 frame_type = *stackmap_p;
  8248. - stackmap_p++;
  8249. -
  8250. - // same_frame {
  8251. - // u1 frame_type = SAME; /* 0-63 */
  8252. - // }
  8253. - if (frame_type >= 0 && frame_type <= 63) {
  8254. - // nothing more to do for same_frame
  8255. - }
  8256. -
  8257. - // same_locals_1_stack_item_frame {
  8258. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8259. - // verification_type_info stack[1];
  8260. - // }
  8261. - else if (frame_type >= 64 && frame_type <= 127) {
  8262. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8263. - calc_number_of_entries, frame_type, THREAD);
  8264. - }
  8265. -
  8266. - // reserved for future use
  8267. - else if (frame_type >= 128 && frame_type <= 246) {
  8268. - // nothing more to do for reserved frame_types
  8269. - }
  8270. -
  8271. - // same_locals_1_stack_item_frame_extended {
  8272. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8273. - // u2 offset_delta;
  8274. - // verification_type_info stack[1];
  8275. - // }
  8276. - else if (frame_type == 247) {
  8277. - stackmap_p += 2;
  8278. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8279. - calc_number_of_entries, frame_type, THREAD);
  8280. - }
  8281. -
  8282. - // chop_frame {
  8283. - // u1 frame_type = CHOP; /* 248-250 */
  8284. - // u2 offset_delta;
  8285. - // }
  8286. - else if (frame_type >= 248 && frame_type <= 250) {
  8287. - stackmap_p += 2;
  8288. - }
  8289. -
  8290. - // same_frame_extended {
  8291. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8292. - // u2 offset_delta;
  8293. - // }
  8294. - else if (frame_type == 251) {
  8295. - stackmap_p += 2;
  8296. - }
  8297. -
  8298. - // append_frame {
  8299. - // u1 frame_type = APPEND; /* 252-254 */
  8300. - // u2 offset_delta;
  8301. - // verification_type_info locals[frame_type - 251];
  8302. - // }
  8303. - else if (frame_type >= 252 && frame_type <= 254) {
  8304. - assert(stackmap_p + 2 <= stackmap_end,
  8305. - "no room for offset_delta");
  8306. - stackmap_p += 2;
  8307. - u1 len = frame_type - 251;
  8308. - for (u1 i = 0; i < len; i++) {
  8309. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8310. - calc_number_of_entries, frame_type, THREAD);
  8311. - }
  8312. - }
  8313. -
  8314. - // full_frame {
  8315. - // u1 frame_type = FULL_FRAME; /* 255 */
  8316. - // u2 offset_delta;
  8317. - // u2 number_of_locals;
  8318. - // verification_type_info locals[number_of_locals];
  8319. - // u2 number_of_stack_items;
  8320. - // verification_type_info stack[number_of_stack_items];
  8321. - // }
  8322. - else if (frame_type == 255) {
  8323. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8324. - "no room for smallest full_frame");
  8325. - stackmap_p += 2;
  8326. -
  8327. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8328. - stackmap_p += 2;
  8329. -
  8330. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8331. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8332. - calc_number_of_entries, frame_type, THREAD);
  8333. - }
  8334. -
  8335. - // Use the largest size for the number_of_stack_items, but only get
  8336. - // the right number of bytes.
  8337. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8338. - stackmap_p += 2;
  8339. -
  8340. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8341. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8342. - calc_number_of_entries, frame_type, THREAD);
  8343. - }
  8344. - }
  8345. - } // end while there is a stack_map_frame
  8346. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8347. -} // end rewrite_cp_refs_in_stack_map_table()
  8348. -
  8349. -
  8350. -// Rewrite constant pool references in the verification type info
  8351. -// portion of the method's stackmap table. These "structures" are
  8352. -// adapted from the StackMapTable_attribute that is described in
  8353. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8354. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8355. -//
  8356. -// The verification_type_info structure is a u1 tag followed by 0 or
  8357. -// more bytes of data:
  8358. -//
  8359. -// union verification_type_info {
  8360. -// Top_variable_info;
  8361. -// Integer_variable_info;
  8362. -// Float_variable_info;
  8363. -// Long_variable_info;
  8364. -// Double_variable_info;
  8365. -// Null_variable_info;
  8366. -// UninitializedThis_variable_info;
  8367. -// Object_variable_info;
  8368. -// Uninitialized_variable_info;
  8369. -// }
  8370. -//
  8371. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8372. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8373. - u1 frame_type, TRAPS) {
  8374. -
  8375. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8376. - u1 tag = *stackmap_p_ref;
  8377. - stackmap_p_ref++;
  8378. -
  8379. - switch (tag) {
  8380. - // Top_variable_info {
  8381. - // u1 tag = ITEM_Top; /* 0 */
  8382. - // }
  8383. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8384. - case 0: // fall through
  8385. -
  8386. - // Integer_variable_info {
  8387. - // u1 tag = ITEM_Integer; /* 1 */
  8388. - // }
  8389. - case ITEM_Integer: // fall through
  8390. -
  8391. - // Float_variable_info {
  8392. - // u1 tag = ITEM_Float; /* 2 */
  8393. - // }
  8394. - case ITEM_Float: // fall through
  8395. -
  8396. - // Double_variable_info {
  8397. - // u1 tag = ITEM_Double; /* 3 */
  8398. - // }
  8399. - case ITEM_Double: // fall through
  8400. -
  8401. - // Long_variable_info {
  8402. - // u1 tag = ITEM_Long; /* 4 */
  8403. - // }
  8404. - case ITEM_Long: // fall through
  8405. -
  8406. - // Null_variable_info {
  8407. - // u1 tag = ITEM_Null; /* 5 */
  8408. - // }
  8409. - case ITEM_Null: // fall through
  8410. -
  8411. - // UninitializedThis_variable_info {
  8412. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8413. - // }
  8414. - case ITEM_UninitializedThis:
  8415. - // nothing more to do for the above tag types
  8416. - break;
  8417. + for (int i=0; i<_updated_oops->length(); i++) {
  8418. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  8419. + Handle cur(_updated_oops->at(i));
  8420. + instanceKlassHandle klass(cur->klass());
  8421. - // Object_variable_info {
  8422. - // u1 tag = ITEM_Object; /* 7 */
  8423. - // u2 cpool_index;
  8424. - // }
  8425. - case ITEM_Object:
  8426. - {
  8427. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8428. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8429. - u2 new_cp_index = find_new_index(cpool_index);
  8430. - if (new_cp_index != 0) {
  8431. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8432. - ("mapped old cpool_index=%d", cpool_index));
  8433. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8434. - cpool_index = new_cp_index;
  8435. - }
  8436. - stackmap_p_ref += 2;
  8437. -
  8438. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8439. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8440. - frame_type, cpool_index));
  8441. - } break;
  8442. -
  8443. - // Uninitialized_variable_info {
  8444. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8445. - // u2 offset;
  8446. - // }
  8447. - case ITEM_Uninitialized:
  8448. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8449. - stackmap_p_ref += 2;
  8450. - break;
  8451. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8452. - default:
  8453. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8454. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8455. - ShouldNotReachHere();
  8456. - break;
  8457. - } // end switch (tag)
  8458. -} // end rewrite_cp_refs_in_verification_type_info()
  8459. -
  8460. -
  8461. -// Change the constant pool associated with klass scratch_class to
  8462. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8463. -// are copied from scratch_cp to a smaller constant pool and the
  8464. -// smaller constant pool is associated with scratch_class.
  8465. -void VM_RedefineClasses::set_new_constant_pool(
  8466. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8467. - int scratch_cp_length, bool shrink, TRAPS) {
  8468. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  8469. -
  8470. - if (shrink) {
  8471. - // scratch_cp is a merged constant pool and has enough space for a
  8472. - // worst case merge situation. We want to associate the minimum
  8473. - // sized constant pool with the klass to save space.
  8474. - constantPoolHandle smaller_cp(THREAD,
  8475. - oopFactory::new_constantPool(scratch_cp_length,
  8476. - oopDesc::IsUnsafeConc,
  8477. - THREAD));
  8478. - // preserve orig_length() value in the smaller copy
  8479. - int orig_length = scratch_cp->orig_length();
  8480. - assert(orig_length != 0, "sanity check");
  8481. - smaller_cp->set_orig_length(orig_length);
  8482. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8483. - scratch_cp = smaller_cp;
  8484. - smaller_cp()->set_is_conc_safe(true);
  8485. - }
  8486. -
  8487. - // attach new constant pool to klass
  8488. - scratch_cp->set_pool_holder(scratch_class());
  8489. -
  8490. - // attach klass to new constant pool
  8491. - scratch_class->set_constants(scratch_cp());
  8492. -
  8493. - int i; // for portability
  8494. -
  8495. - // update each field in klass to use new constant pool indices as needed
  8496. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8497. - jshort cur_index = fs.name_index();
  8498. - jshort new_index = find_new_index(cur_index);
  8499. - if (new_index != 0) {
  8500. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8501. - ("field-name_index change: %d to %d", cur_index, new_index));
  8502. - fs.set_name_index(new_index);
  8503. - }
  8504. - cur_index = fs.signature_index();
  8505. - new_index = find_new_index(cur_index);
  8506. - if (new_index != 0) {
  8507. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8508. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8509. - fs.set_signature_index(new_index);
  8510. - }
  8511. - cur_index = fs.initval_index();
  8512. - new_index = find_new_index(cur_index);
  8513. - if (new_index != 0) {
  8514. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8515. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8516. - fs.set_initval_index(new_index);
  8517. - }
  8518. - cur_index = fs.generic_signature_index();
  8519. - new_index = find_new_index(cur_index);
  8520. - if (new_index != 0) {
  8521. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8522. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8523. - fs.set_generic_signature_index(new_index);
  8524. - }
  8525. - } // end for each field
  8526. -
  8527. - // Update constant pool indices in the inner classes info to use
  8528. - // new constant indices as needed. The inner classes info is a
  8529. - // quadruple:
  8530. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8531. - InnerClassesIterator iter(scratch_class);
  8532. - for (; !iter.done(); iter.next()) {
  8533. - int cur_index = iter.inner_class_info_index();
  8534. - if (cur_index == 0) {
  8535. - continue; // JVM spec. allows null inner class refs so skip it
  8536. - }
  8537. - int new_index = find_new_index(cur_index);
  8538. - if (new_index != 0) {
  8539. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8540. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8541. - iter.set_inner_class_info_index(new_index);
  8542. - }
  8543. - cur_index = iter.outer_class_info_index();
  8544. - new_index = find_new_index(cur_index);
  8545. - if (new_index != 0) {
  8546. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8547. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8548. - iter.set_outer_class_info_index(new_index);
  8549. - }
  8550. - cur_index = iter.inner_name_index();
  8551. - new_index = find_new_index(cur_index);
  8552. - if (new_index != 0) {
  8553. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8554. - ("inner_name change: %d to %d", cur_index, new_index));
  8555. - iter.set_inner_name_index(new_index);
  8556. - }
  8557. - } // end for each inner class
  8558. -
  8559. - // Attach each method in klass to the new constant pool and update
  8560. - // to use new constant pool indices as needed:
  8561. - objArrayHandle methods(THREAD, scratch_class->methods());
  8562. - for (i = methods->length() - 1; i >= 0; i--) {
  8563. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8564. - method->set_constants(scratch_cp());
  8565. -
  8566. - int new_index = find_new_index(method->name_index());
  8567. - if (new_index != 0) {
  8568. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8569. - ("method-name_index change: %d to %d", method->name_index(),
  8570. - new_index));
  8571. - method->set_name_index(new_index);
  8572. - }
  8573. - new_index = find_new_index(method->signature_index());
  8574. - if (new_index != 0) {
  8575. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8576. - ("method-signature_index change: %d to %d",
  8577. - method->signature_index(), new_index));
  8578. - method->set_signature_index(new_index);
  8579. - }
  8580. - new_index = find_new_index(method->generic_signature_index());
  8581. - if (new_index != 0) {
  8582. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8583. - ("method-generic_signature_index change: %d to %d",
  8584. - method->generic_signature_index(), new_index));
  8585. - method->set_generic_signature_index(new_index);
  8586. - }
  8587. -
  8588. - // Update constant pool indices in the method's checked exception
  8589. - // table to use new constant indices as needed.
  8590. - int cext_length = method->checked_exceptions_length();
  8591. - if (cext_length > 0) {
  8592. - CheckedExceptionElement * cext_table =
  8593. - method->checked_exceptions_start();
  8594. - for (int j = 0; j < cext_length; j++) {
  8595. - int cur_index = cext_table[j].class_cp_index;
  8596. - int new_index = find_new_index(cur_index);
  8597. - if (new_index != 0) {
  8598. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8599. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8600. - cext_table[j].class_cp_index = (u2)new_index;
  8601. - }
  8602. - } // end for each checked exception table entry
  8603. - } // end if there are checked exception table entries
  8604. -
  8605. - // Update each catch type index in the method's exception table
  8606. - // to use new constant pool indices as needed. The exception table
  8607. - // holds quadruple entries of the form:
  8608. - // (beg_bci, end_bci, handler_bci, klass_index)
  8609. -
  8610. - ExceptionTable ex_table(method());
  8611. - int ext_length = ex_table.length();
  8612. -
  8613. - for (int j = 0; j < ext_length; j ++) {
  8614. - int cur_index = ex_table.catch_type_index(j);
  8615. - int new_index = find_new_index(cur_index);
  8616. - if (new_index != 0) {
  8617. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8618. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8619. - ex_table.set_catch_type_index(j, new_index);
  8620. - }
  8621. - } // end for each exception table entry
  8622. -
  8623. - // Update constant pool indices in the method's local variable
  8624. - // table to use new constant indices as needed. The local variable
  8625. - // table hold sextuple entries of the form:
  8626. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8627. - int lvt_length = method->localvariable_table_length();
  8628. - if (lvt_length > 0) {
  8629. - LocalVariableTableElement * lv_table =
  8630. - method->localvariable_table_start();
  8631. - for (int j = 0; j < lvt_length; j++) {
  8632. - int cur_index = lv_table[j].name_cp_index;
  8633. - int new_index = find_new_index(cur_index);
  8634. - if (new_index != 0) {
  8635. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8636. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8637. - lv_table[j].name_cp_index = (u2)new_index;
  8638. - }
  8639. - cur_index = lv_table[j].descriptor_cp_index;
  8640. - new_index = find_new_index(cur_index);
  8641. - if (new_index != 0) {
  8642. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8643. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8644. - new_index));
  8645. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8646. - }
  8647. - cur_index = lv_table[j].signature_cp_index;
  8648. - new_index = find_new_index(cur_index);
  8649. - if (new_index != 0) {
  8650. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8651. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8652. - lv_table[j].signature_cp_index = (u2)new_index;
  8653. - }
  8654. - } // end for each local variable table entry
  8655. - } // end if there are local variable table entries
  8656. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  8657. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8658. - } // end for each method
  8659. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8660. -} // end set_new_constant_pool()
  8661. + RC_TRACE(0x00008000, ("executing transformer method"));
  8662. +
  8663. + Thread *__the_thread__ = Thread::current();
  8664. + JavaValue result(T_VOID);
  8665. + JavaCallArguments args(cur);
  8666. + JavaCalls::call(&result,
  8667. + method,
  8668. + &args,
  8669. + THREAD);
  8670. + // TODO: What to do with an exception here?
  8671. + if (HAS_PENDING_EXCEPTION) {
  8672. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  8673. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  8674. + ex_name->as_C_string()));
  8675. + CLEAR_PENDING_EXCEPTION;
  8676. + }
  8677. + }
  8678. + }
  8679. -// Unevolving classes may point to methods of the_class directly
  8680. -// from their constant pool caches, itables, and/or vtables. We
  8681. -// use the SystemDictionary::classes_do() facility and this helper
  8682. -// to fix up these pointers.
  8683. -//
  8684. -// Note: We currently don't support updating the vtable in
  8685. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8686. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8687. - oop initiating_loader, TRAPS) {
  8688. - Klass *k = k_oop->klass_part();
  8689. - if (k->oop_is_instance()) {
  8690. - HandleMark hm(THREAD);
  8691. - instanceKlass *ik = (instanceKlass *) k;
  8692. + delete _updated_oops;
  8693. + _updated_oops = NULL;
  8694. + }
  8695. - // HotSpot specific optimization! HotSpot does not currently
  8696. - // support delegation from the bootstrap class loader to a
  8697. - // user-defined class loader. This means that if the bootstrap
  8698. - // class loader is the initiating class loader, then it will also
  8699. - // be the defining class loader. This also means that classes
  8700. - // loaded by the bootstrap class loader cannot refer to classes
  8701. - // loaded by a user-defined class loader. Note: a user-defined
  8702. - // class loader can delegate to the bootstrap class loader.
  8703. - //
  8704. - // If the current class being redefined has a user-defined class
  8705. - // loader as its defining class loader, then we can skip all
  8706. - // classes loaded by the bootstrap class loader.
  8707. - bool is_user_defined =
  8708. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8709. - if (is_user_defined && ik->class_loader() == NULL) {
  8710. - return;
  8711. - }
  8712. + // Free the array of scratch classes
  8713. + delete _new_classes;
  8714. + _new_classes = NULL;
  8715. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  8716. - // This is a very busy routine. We don't want too much tracing
  8717. - // printed out.
  8718. - bool trace_name_printed = false;
  8719. -
  8720. - // Very noisy: only enable this call if you are trying to determine
  8721. - // that a specific class gets found by this routine.
  8722. - // RC_TRACE macro has an embedded ResourceMark
  8723. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8724. - // ("adjust check: name=%s", ik->external_name()));
  8725. - // trace_name_printed = true;
  8726. -
  8727. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8728. - // if one exists. We discard scratch_class and we don't keep an
  8729. - // instanceKlass around to hold obsolete methods so we don't have
  8730. - // any other instanceKlass embedded vtables to update. The vtable
  8731. - // holds the methodOops for virtual (but not final) methods.
  8732. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8733. - // ik->vtable() creates a wrapper object; rm cleans it up
  8734. - ResourceMark rm(THREAD);
  8735. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8736. - _matching_new_methods,
  8737. - _matching_methods_length,
  8738. - &trace_name_printed);
  8739. - }
  8740. -
  8741. - // If the current class has an itable and we are either redefining an
  8742. - // interface or if the current class is a subclass of the_class, then
  8743. - // we potentially have to fix the itable. If we are redefining an
  8744. - // interface, then we have to call adjust_method_entries() for
  8745. - // every instanceKlass that has an itable since there isn't a
  8746. - // subclass relationship between an interface and an instanceKlass.
  8747. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8748. - || ik->is_subclass_of(_the_class_oop))) {
  8749. - // ik->itable() creates a wrapper object; rm cleans it up
  8750. - ResourceMark rm(THREAD);
  8751. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8752. - _matching_new_methods,
  8753. - _matching_methods_length,
  8754. - &trace_name_printed);
  8755. - }
  8756. -
  8757. - // The constant pools in other classes (other_cp) can refer to
  8758. - // methods in the_class. We have to update method information in
  8759. - // other_cp's cache. If other_cp has a previous version, then we
  8760. - // have to repeat the process for each previous version. The
  8761. - // constant pool cache holds the methodOops for non-virtual
  8762. - // methods and for virtual, final methods.
  8763. - //
  8764. - // Special case: if the current class is the_class, then new_cp
  8765. - // has already been attached to the_class and old_cp has already
  8766. - // been added as a previous version. The new_cp doesn't have any
  8767. - // cached references to old methods so it doesn't need to be
  8768. - // updated. We can simply start with the previous version(s) in
  8769. - // that case.
  8770. - constantPoolHandle other_cp;
  8771. - constantPoolCacheOop cp_cache;
  8772. -
  8773. - if (k_oop != _the_class_oop) {
  8774. - // this klass' constant pool cache may need adjustment
  8775. - other_cp = constantPoolHandle(ik->constants());
  8776. - cp_cache = other_cp->cache();
  8777. - if (cp_cache != NULL) {
  8778. - cp_cache->adjust_method_entries(_matching_old_methods,
  8779. - _matching_new_methods,
  8780. - _matching_methods_length,
  8781. - &trace_name_printed);
  8782. - }
  8783. - }
  8784. - {
  8785. - ResourceMark rm(THREAD);
  8786. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  8787. - // contain a GrowableArray of handles. We have to clean up the
  8788. - // GrowableArray _after_ the PreviousVersionWalker destructor
  8789. - // has destroyed the handles.
  8790. - {
  8791. - // the previous versions' constant pool caches may need adjustment
  8792. - PreviousVersionWalker pvw(ik);
  8793. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  8794. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  8795. - other_cp = pv_info->prev_constant_pool_handle();
  8796. - cp_cache = other_cp->cache();
  8797. - if (cp_cache != NULL) {
  8798. - cp_cache->adjust_method_entries(_matching_old_methods,
  8799. - _matching_new_methods,
  8800. - _matching_methods_length,
  8801. - &trace_name_printed);
  8802. - }
  8803. - }
  8804. - } // pvw is cleaned up
  8805. - } // rm is cleaned up
  8806. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  8807. +}
  8808. +
  8809. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  8810. + // classes for primitives cannot be redefined
  8811. + if (java_lang_Class::is_primitive(klass_mirror)) {
  8812. + return false;
  8813. + }
  8814. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  8815. + // classes for arrays cannot be redefined
  8816. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  8817. + return false;
  8818. }
  8819. + return true;
  8820. }
  8821. -void VM_RedefineClasses::update_jmethod_ids() {
  8822. - for (int j = 0; j < _matching_methods_length; ++j) {
  8823. - methodOop old_method = _matching_old_methods[j];
  8824. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  8825. - if (jmid != NULL) {
  8826. - // There is a jmethodID, change it to point to the new method
  8827. - methodHandle new_method_h(_matching_new_methods[j]);
  8828. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  8829. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  8830. - "should be replaced");
  8831. - }
  8832. +#ifdef ASSERT
  8833. +
  8834. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8835. + klassOop k_oop = k_oop_latest;
  8836. + while (k_oop != NULL) {
  8837. +
  8838. + instanceKlassHandle k_handle(THREAD, k_oop);
  8839. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  8840. + k_oop = k_oop->klass_part()->old_version();
  8841. }
  8842. }
  8843. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  8844. - BitMap *emcp_methods, int * emcp_method_count_p) {
  8845. - *emcp_method_count_p = 0;
  8846. - int obsolete_count = 0;
  8847. - int old_index = 0;
  8848. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8849. - methodOop old_method = _matching_old_methods[j];
  8850. - methodOop new_method = _matching_new_methods[j];
  8851. - methodOop old_array_method;
  8852. -
  8853. - // Maintain an old_index into the _old_methods array by skipping
  8854. - // deleted methods
  8855. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8856. - != old_method) {
  8857. - ++old_index;
  8858. - }
  8859. -
  8860. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8861. - // The EMCP definition from JSR-163 requires the bytecodes to be
  8862. - // the same with the exception of constant pool indices which may
  8863. - // differ. However, the constants referred to by those indices
  8864. - // must be the same.
  8865. - //
  8866. - // We use methods_EMCP() for comparison since constant pool
  8867. - // merging can remove duplicate constant pool entries that were
  8868. - // present in the old method and removed from the rewritten new
  8869. - // method. A faster binary comparison function would consider the
  8870. - // old and new methods to be different when they are actually
  8871. - // EMCP.
  8872. - //
  8873. - // The old and new methods are EMCP and you would think that we
  8874. - // could get rid of one of them here and now and save some space.
  8875. - // However, the concept of EMCP only considers the bytecodes and
  8876. - // the constant pool entries in the comparison. Other things,
  8877. - // e.g., the line number table (LNT) or the local variable table
  8878. - // (LVT) don't count in the comparison. So the new (and EMCP)
  8879. - // method can have a new LNT that we need so we can't just
  8880. - // overwrite the new method with the old method.
  8881. - //
  8882. - // When this routine is called, we have already attached the new
  8883. - // methods to the_class so the old methods are effectively
  8884. - // overwritten. However, if an old method is still executing,
  8885. - // then the old method cannot be collected until sometime after
  8886. - // the old method call has returned. So the overwriting of old
  8887. - // methods by new methods will save us space except for those
  8888. - // (hopefully few) old methods that are still executing.
  8889. - //
  8890. - // A method refers to a constMethodOop and this presents another
  8891. - // possible avenue to space savings. The constMethodOop in the
  8892. - // new method contains possibly new attributes (LNT, LVT, etc).
  8893. - // At first glance, it seems possible to save space by replacing
  8894. - // the constMethodOop in the old method with the constMethodOop
  8895. - // from the new method. The old and new methods would share the
  8896. - // same constMethodOop and we would save the space occupied by
  8897. - // the old constMethodOop. However, the constMethodOop contains
  8898. - // a back reference to the containing method. Sharing the
  8899. - // constMethodOop between two methods could lead to confusion in
  8900. - // the code that uses the back reference. This would lead to
  8901. - // brittle code that could be broken in non-obvious ways now or
  8902. - // in the future.
  8903. - //
  8904. - // Another possibility is to copy the constMethodOop from the new
  8905. - // method to the old method and then overwrite the new method with
  8906. - // the old method. Since the constMethodOop contains the bytecodes
  8907. - // for the method embedded in the oop, this option would change
  8908. - // the bytecodes out from under any threads executing the old
  8909. - // method and make the thread's bcp invalid. Since EMCP requires
  8910. - // that the bytecodes be the same modulo constant pool indices, it
  8911. - // is straight forward to compute the correct new bcp in the new
  8912. - // constMethodOop from the old bcp in the old constMethodOop. The
  8913. - // time consuming part would be searching all the frames in all
  8914. - // of the threads to find all of the calls to the old method.
  8915. - //
  8916. - // It looks like we will have to live with the limited savings
  8917. - // that we get from effectively overwriting the old methods
  8918. - // when the new methods are attached to the_class.
  8919. -
  8920. - // track which methods are EMCP for add_previous_version() call
  8921. - emcp_methods->set_bit(old_index);
  8922. - (*emcp_method_count_p)++;
  8923. -
  8924. - // An EMCP method is _not_ obsolete. An obsolete method has a
  8925. - // different jmethodID than the current method. An EMCP method
  8926. - // has the same jmethodID as the current method. Having the
  8927. - // same jmethodID for all EMCP versions of a method allows for
  8928. - // a consistent view of the EMCP methods regardless of which
  8929. - // EMCP method you happen to have in hand. For example, a
  8930. - // breakpoint set in one EMCP method will work for all EMCP
  8931. - // versions of the method including the current one.
  8932. - } else {
  8933. - // mark obsolete methods as such
  8934. - old_method->set_is_obsolete();
  8935. - obsolete_count++;
  8936. +#endif
  8937. - // obsolete methods need a unique idnum
  8938. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  8939. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  8940. -// u2 old_num = old_method->method_idnum();
  8941. - old_method->set_method_idnum(num);
  8942. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  8943. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  8944. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  8945. +// do that, they assume that cache entry is resolved already.
  8946. +static void unpatch_bytecode(methodOop method) {
  8947. + RawBytecodeStream bcs(method);
  8948. + Bytecodes::Code code;
  8949. + Bytecodes::Code java_code;
  8950. + while (!bcs.is_last_bytecode()) {
  8951. + code = bcs.raw_next();
  8952. + address bcp = bcs.bcp();
  8953. +
  8954. + if (code == Bytecodes::_breakpoint) {
  8955. + int bci = method->bci_from(bcp);
  8956. + code = method->orig_bytecode_at(bci);
  8957. + java_code = Bytecodes::java_code(code);
  8958. + if (code != java_code &&
  8959. + (java_code == Bytecodes::_getfield ||
  8960. + java_code == Bytecodes::_putfield ||
  8961. + java_code == Bytecodes::_aload_0)) {
  8962. + // Let breakpoint table handling unpatch bytecode
  8963. + method->set_orig_bytecode_at(bci, java_code);
  8964. }
  8965. - // With tracing we try not to "yack" too much. The position of
  8966. - // this trace assumes there are fewer obsolete methods than
  8967. - // EMCP methods.
  8968. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  8969. - old_method->name()->as_C_string(),
  8970. - old_method->signature()->as_C_string()));
  8971. + } else {
  8972. + java_code = Bytecodes::java_code(code);
  8973. + if (code != java_code &&
  8974. + (java_code == Bytecodes::_getfield ||
  8975. + java_code == Bytecodes::_putfield ||
  8976. + java_code == Bytecodes::_aload_0)) {
  8977. + *bcp = java_code;
  8978. + }
  8979. + }
  8980. +
  8981. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  8982. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  8983. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  8984. + assert(code2 == Bytecodes::_fast_igetfield ||
  8985. + code2 == Bytecodes::_fast_agetfield ||
  8986. + code2 == Bytecodes::_fast_fgetfield, "");
  8987. + *(bcp + 1) = Bytecodes::java_code(code2);
  8988. }
  8989. - old_method->set_is_old();
  8990. - }
  8991. - for (int i = 0; i < _deleted_methods_length; ++i) {
  8992. - methodOop old_method = _deleted_methods[i];
  8993. -
  8994. - assert(old_method->vtable_index() < 0,
  8995. - "cannot delete methods with vtable entries");;
  8996. -
  8997. - // Mark all deleted methods as old and obsolete
  8998. - old_method->set_is_old();
  8999. - old_method->set_is_obsolete();
  9000. - ++obsolete_count;
  9001. - // With tracing we try not to "yack" too much. The position of
  9002. - // this trace assumes there are fewer obsolete methods than
  9003. - // EMCP methods.
  9004. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9005. - old_method->name()->as_C_string(),
  9006. - old_method->signature()->as_C_string()));
  9007. - }
  9008. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9009. - "sanity check");
  9010. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9011. - obsolete_count));
  9012. + }
  9013. }
  9014. -// This internal class transfers the native function registration from old methods
  9015. -// to new methods. It is designed to handle both the simple case of unchanged
  9016. -// native methods and the complex cases of native method prefixes being added and/or
  9017. -// removed.
  9018. -// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  9019. -//
  9020. -// This class is used after the new methods have been installed in "the_class".
  9021. -//
  9022. -// So, for example, the following must be handled. Where 'm' is a method and
  9023. -// a number followed by an underscore is a prefix.
  9024. -//
  9025. -// Old Name New Name
  9026. -// Simple transfer to new method m -> m
  9027. -// Add prefix m -> 1_m
  9028. -// Remove prefix 1_m -> m
  9029. -// Simultaneous add of prefixes m -> 3_2_1_m
  9030. -// Simultaneous removal of prefixes 3_2_1_m -> m
  9031. -// Simultaneous add and remove 1_m -> 2_m
  9032. -// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9033. +// Unevolving classes may point to old methods directly
  9034. +// from their constant pool caches, itables, and/or vtables. We
  9035. +// use the SystemDictionary::classes_do() facility and this helper
  9036. +// to fix up these pointers. Additional field offsets and vtable indices
  9037. +// in the constant pool cache entries are fixed.
  9038. //
  9039. -class TransferNativeFunctionRegistration {
  9040. - private:
  9041. - instanceKlassHandle the_class;
  9042. - int prefix_count;
  9043. - char** prefixes;
  9044. +// Note: We currently don't support updating the vtable in
  9045. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9046. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9047. + klassOop k_oop = k_oop_latest;
  9048. + while (k_oop != NULL) {
  9049. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9050. +/*
  9051. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9052. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9053. - // Recursively search the binary tree of possibly prefixed method names.
  9054. - // Iteration could be used if all agents were well behaved. Full tree walk is
  9055. - // more resilent to agents not cleaning up intermediate methods.
  9056. - // Branch at each depth in the binary tree is:
  9057. - // (1) without the prefix.
  9058. - // (2) with the prefix.
  9059. - // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9060. - methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9061. - Symbol* signature) {
  9062. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9063. - if (name_symbol != NULL) {
  9064. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9065. - if (method != NULL) {
  9066. - // Even if prefixed, intermediate methods must exist.
  9067. - if (method->is_native()) {
  9068. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9069. - return method;
  9070. - }
  9071. - if (depth < prefix_count) {
  9072. - // Try applying further prefixes (other than this one).
  9073. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9074. - if (method != NULL) {
  9075. - return method; // found
  9076. - }
  9077. + for (int i=0; i<_matching_methods_length; i++) {
  9078. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9079. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9080. + }*/
  9081. - // Try adding this prefix to the method name and see if it matches
  9082. - // another method name.
  9083. - char* prefix = prefixes[depth];
  9084. - size_t prefix_len = strlen(prefix);
  9085. - size_t trial_len = name_len + prefix_len;
  9086. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9087. - strcpy(trial_name_str, prefix);
  9088. - strcat(trial_name_str, name_str);
  9089. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9090. - signature);
  9091. - if (method != NULL) {
  9092. - // If found along this branch, it was prefixed, mark as such
  9093. - method->set_is_prefixed_native();
  9094. - return method; // found
  9095. - }
  9096. - }
  9097. - }
  9098. - }
  9099. - return NULL; // This whole branch bore nothing
  9100. - }
  9101. + Klass *k = k_oop->klass_part();
  9102. + if (k->oop_is_instance()) {
  9103. + HandleMark hm(THREAD);
  9104. + instanceKlass *ik = (instanceKlass *) k;
  9105. - // Return the method name with old prefixes stripped away.
  9106. - char* method_name_without_prefixes(methodOop method) {
  9107. - Symbol* name = method->name();
  9108. - char* name_str = name->as_utf8();
  9109. + constantPoolHandle other_cp;
  9110. + constantPoolCacheOop cp_cache;
  9111. - // Old prefixing may be defunct, strip prefixes, if any.
  9112. - for (int i = prefix_count-1; i >= 0; i--) {
  9113. - char* prefix = prefixes[i];
  9114. - size_t prefix_len = strlen(prefix);
  9115. - if (strncmp(prefix, name_str, prefix_len) == 0) {
  9116. - name_str += prefix_len;
  9117. - }
  9118. - }
  9119. - return name_str;
  9120. - }
  9121. + other_cp = constantPoolHandle(ik->constants());
  9122. - // Strip any prefixes off the old native method, then try to find a
  9123. - // (possibly prefixed) new native that matches it.
  9124. - methodOop strip_and_search_for_new_native(methodOop method) {
  9125. - ResourceMark rm;
  9126. - char* name_str = method_name_without_prefixes(method);
  9127. - return search_prefix_name_space(0, name_str, strlen(name_str),
  9128. - method->signature());
  9129. - }
  9130. + for (int i=0; i<other_cp->length(); i++) {
  9131. + if (other_cp->tag_at(i).is_klass()) {
  9132. + klassOop klass = other_cp->klass_at(i, THREAD);
  9133. + if (klass->klass_part()->new_version() != NULL) {
  9134. - public:
  9135. + // (tw) TODO: check why/if this is necessary
  9136. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9137. + }
  9138. + klass = other_cp->klass_at(i, THREAD);
  9139. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9140. + }
  9141. + }
  9142. - // Construct a native method transfer processor for this class.
  9143. - TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9144. - assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  9145. + cp_cache = other_cp->cache();
  9146. - the_class = _the_class;
  9147. - prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  9148. + if (cp_cache != NULL) {
  9149. + cp_cache->adjust_entries(NULL,
  9150. + NULL,
  9151. + 0);
  9152. + }
  9153. +
  9154. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9155. + if (RewriteBytecodes) {
  9156. + ik->methods_do(unpatch_bytecode);
  9157. + }
  9158. + }
  9159. + k_oop = k_oop->klass_part()->old_version();
  9160. }
  9161. +}
  9162. - // Attempt to transfer any of the old or deleted methods that are native
  9163. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  9164. - for (int j = 0; j < methods_length; j++) {
  9165. - methodOop old_method = old_methods[j];
  9166. +void VM_RedefineClasses::update_jmethod_ids() {
  9167. + for (int j = 0; j < _matching_methods_length; ++j) {
  9168. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9169. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9170. +
  9171. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9172. + if (old_method->new_version() != NULL && jmid == NULL) {
  9173. + // (tw) Have to create jmethodID in this case
  9174. + jmid = old_method->jmethod_id();
  9175. + }
  9176. +
  9177. + if (jmid != NULL) {
  9178. + // There is a jmethodID, change it to point to the new method
  9179. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9180. + if (old_method->new_version() == NULL) {
  9181. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9182. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9183. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9184. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9185. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9186. + } else {
  9187. + jmethodID mid = new_method_h->jmethod_id();
  9188. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9189. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9190. - if (old_method->is_native() && old_method->has_native_function()) {
  9191. - methodOop new_method = strip_and_search_for_new_native(old_method);
  9192. - if (new_method != NULL) {
  9193. - // Actually set the native function in the new method.
  9194. - // Redefine does not send events (except CFLH), certainly not this
  9195. - // behind the scenes re-registration.
  9196. - new_method->set_native_function(old_method->native_function(),
  9197. - !methodOopDesc::native_bind_event_is_interesting);
  9198. - }
  9199. }
  9200. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9201. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9202. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9203. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9204. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9205. +
  9206. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9207. }
  9208. }
  9209. -};
  9210. -
  9211. -// Don't lose the association between a native method and its JNI function.
  9212. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  9213. - TransferNativeFunctionRegistration transfer(the_class);
  9214. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  9215. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  9216. }
  9217. +
  9218. // Deoptimize all compiled code that depends on this class.
  9219. //
  9220. // If the can_redefine_classes capability is obtained in the onload
  9221. @@ -2964,7 +2677,10 @@ void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9222. // All dependencies have been recorded from startup or this is a second or
  9223. // subsequent use of RedefineClasses
  9224. - if (JvmtiExport::all_dependencies_are_recorded()) {
  9225. +
  9226. + // For now deopt all
  9227. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9228. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9229. Universe::flush_evol_dependents_on(k_h);
  9230. } else {
  9231. CodeCache::mark_all_nmethods_for_deoptimization();
  9232. @@ -2987,10 +2703,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9233. methodOop old_method;
  9234. methodOop new_method;
  9235. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9236. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9237. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  9238. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9239. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9240. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9241. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9242. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9243. _matching_methods_length = 0;
  9244. _deleted_methods_length = 0;
  9245. @@ -3005,36 +2721,36 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9246. }
  9247. // New method at the end
  9248. new_method = (methodOop) _new_methods->obj_at(nj);
  9249. - _added_methods[_added_methods_length++] = new_method;
  9250. + _added_methods[_added_methods_length++] = nj;
  9251. ++nj;
  9252. } else if (nj >= _new_methods->length()) {
  9253. // Old method, at the end, is deleted
  9254. old_method = (methodOop) _old_methods->obj_at(oj);
  9255. - _deleted_methods[_deleted_methods_length++] = old_method;
  9256. + _deleted_methods[_deleted_methods_length++] = oj;
  9257. ++oj;
  9258. } else {
  9259. old_method = (methodOop) _old_methods->obj_at(oj);
  9260. new_method = (methodOop) _new_methods->obj_at(nj);
  9261. if (old_method->name() == new_method->name()) {
  9262. if (old_method->signature() == new_method->signature()) {
  9263. - _matching_old_methods[_matching_methods_length ] = old_method;
  9264. - _matching_new_methods[_matching_methods_length++] = new_method;
  9265. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9266. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9267. ++nj;
  9268. ++oj;
  9269. } else {
  9270. // added overloaded have already been moved to the end,
  9271. // so this is a deleted overloaded method
  9272. - _deleted_methods[_deleted_methods_length++] = old_method;
  9273. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9274. ++oj;
  9275. }
  9276. } else { // names don't match
  9277. if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9278. // new method
  9279. - _added_methods[_added_methods_length++] = new_method;
  9280. + _added_methods[_added_methods_length++] = nj;//new_method;
  9281. ++nj;
  9282. } else {
  9283. // deleted method
  9284. - _deleted_methods[_deleted_methods_length++] = old_method;
  9285. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9286. ++oj;
  9287. }
  9288. }
  9289. @@ -3042,6 +2758,8 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9290. }
  9291. assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9292. assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9293. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9294. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9295. }
  9296. @@ -3049,287 +2767,184 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9297. // Install the redefinition of a class:
  9298. // - house keeping (flushing breakpoints and caches, deoptimizing
  9299. // dependent compiled code)
  9300. -// - replacing parts in the_class with parts from scratch_class
  9301. -// - adding a weak reference to track the obsolete but interesting
  9302. -// parts of the_class
  9303. // - adjusting constant pool caches and vtables in other classes
  9304. -// that refer to methods in the_class. These adjustments use the
  9305. -// SystemDictionary::classes_do() facility which only allows
  9306. -// a helper method to be specified. The interesting parameters
  9307. -// that we would like to pass to the helper method are saved in
  9308. -// static global fields in the VM operation.
  9309. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  9310. - instanceKlassHandle scratch_class, TRAPS) {
  9311. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9312. +
  9313. + ResourceMark rm(THREAD);
  9314. - RC_TIMER_START(_timer_rsc_phase1);
  9315. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9316. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9317. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  9318. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  9319. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  9320. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9321. +#ifndef JVMTI_KERNEL
  9322. // Remove all breakpoints in methods of this class
  9323. JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9324. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  9325. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9326. +#endif // !JVMTI_KERNEL
  9327. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  9328. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9329. // We are redefining java.lang.reflect.Method. Method.invoke() is
  9330. // cached and users of the cache care about each active version of
  9331. // the method so we have to track this previous version.
  9332. // Do this before methods get switched
  9333. Universe::reflect_invoke_cache()->add_previous_version(
  9334. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9335. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9336. }
  9337. - // Deoptimize all compiled code that depends on this class
  9338. - flush_dependent_code(the_class, THREAD);
  9339. -
  9340. - _old_methods = the_class->methods();
  9341. - _new_methods = scratch_class->methods();
  9342. - _the_class_oop = the_class_oop;
  9343. + _old_methods = the_old_class->methods();
  9344. + _new_methods = the_new_class->methods();
  9345. + _the_class_oop = the_old_class();
  9346. compute_added_deleted_matching_methods();
  9347. - update_jmethod_ids();
  9348. -
  9349. - // Attach new constant pool to the original klass. The original
  9350. - // klass still refers to the old constant pool (for now).
  9351. - scratch_class->constants()->set_pool_holder(the_class());
  9352. -
  9353. -#if 0
  9354. - // In theory, with constant pool merging in place we should be able
  9355. - // to save space by using the new, merged constant pool in place of
  9356. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  9357. - // the klass version we are replacing now and any constant pool(s) in
  9358. - // previous versions of klass. Nice theory, doesn't work in practice.
  9359. - // When this code is enabled, even simple programs throw NullPointer
  9360. - // exceptions. I'm guessing that this is caused by some constant pool
  9361. - // cache difference between the new, merged constant pool and the
  9362. - // constant pool that was just being used by the klass. I'm keeping
  9363. - // this code around to archive the idea, but the code has to remain
  9364. - // disabled for now.
  9365. -
  9366. - // Attach each old method to the new constant pool. This can be
  9367. - // done here since we are past the bytecode verification and
  9368. - // constant pool optimization phases.
  9369. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  9370. - methodOop method = (methodOop)_old_methods->obj_at(i);
  9371. - method->set_constants(scratch_class->constants());
  9372. - }
  9373. -
  9374. - {
  9375. - // walk all previous versions of the klass
  9376. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  9377. - PreviousVersionWalker pvw(ik);
  9378. - instanceKlassHandle ikh;
  9379. - do {
  9380. - ikh = pvw.next_previous_version();
  9381. - if (!ikh.is_null()) {
  9382. - ik = ikh();
  9383. -
  9384. - // attach previous version of klass to the new constant pool
  9385. - ik->set_constants(scratch_class->constants());
  9386. -
  9387. - // Attach each method in the previous version of klass to the
  9388. - // new constant pool
  9389. - objArrayOop prev_methods = ik->methods();
  9390. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  9391. - methodOop method = (methodOop)prev_methods->obj_at(i);
  9392. - method->set_constants(scratch_class->constants());
  9393. - }
  9394. - }
  9395. - } while (!ikh.is_null());
  9396. - }
  9397. -#endif
  9398. -
  9399. - // Replace methods and constantpool
  9400. - the_class->set_methods(_new_methods);
  9401. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  9402. - // and to be able to undo operation easily.
  9403. -
  9404. - constantPoolOop old_constants = the_class->constants();
  9405. - the_class->set_constants(scratch_class->constants());
  9406. - scratch_class->set_constants(old_constants); // See the previous comment.
  9407. -#if 0
  9408. - // We are swapping the guts of "the new class" with the guts of "the
  9409. - // class". Since the old constant pool has just been attached to "the
  9410. - // new class", it seems logical to set the pool holder in the old
  9411. - // constant pool also. However, doing this will change the observable
  9412. - // class hierarchy for any old methods that are still executing. A
  9413. - // method can query the identity of its "holder" and this query uses
  9414. - // the method's constant pool link to find the holder. The change in
  9415. - // holding class from "the class" to "the new class" can confuse
  9416. - // things.
  9417. - //
  9418. - // Setting the old constant pool's holder will also cause
  9419. - // verification done during vtable initialization below to fail.
  9420. - // During vtable initialization, the vtable's class is verified to be
  9421. - // a subtype of the method's holder. The vtable's class is "the
  9422. - // class" and the method's holder is gotten from the constant pool
  9423. - // link in the method itself. For "the class"'s directly implemented
  9424. - // methods, the method holder is "the class" itself (as gotten from
  9425. - // the new constant pool). The check works fine in this case. The
  9426. - // check also works fine for methods inherited from super classes.
  9427. - //
  9428. - // Miranda methods are a little more complicated. A miranda method is
  9429. - // provided by an interface when the class implementing the interface
  9430. - // does not provide its own method. These interfaces are implemented
  9431. - // internally as an instanceKlass. These special instanceKlasses
  9432. - // share the constant pool of the class that "implements" the
  9433. - // interface. By sharing the constant pool, the method holder of a
  9434. - // miranda method is the class that "implements" the interface. In a
  9435. - // non-redefine situation, the subtype check works fine. However, if
  9436. - // the old constant pool's pool holder is modified, then the check
  9437. - // fails because there is no class hierarchy relationship between the
  9438. - // vtable's class and "the new class".
  9439. -
  9440. - old_constants->set_pool_holder(scratch_class());
  9441. -#endif
  9442. // track which methods are EMCP for add_previous_version() call below
  9443. - BitMap emcp_methods(_old_methods->length());
  9444. +
  9445. + // (tw) TODO: Check if we need the concept of EMCP?
  9446. + BitMap emcp_methods(_old_methods->length());
  9447. int emcp_method_count = 0;
  9448. emcp_methods.clear(); // clears 0..(length() - 1)
  9449. +
  9450. + // We need to mark methods as old!!
  9451. check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9452. - transfer_old_native_function_registrations(the_class);
  9453. -
  9454. - // The class file bytes from before any retransformable agents mucked
  9455. - // with them was cached on the scratch class, move to the_class.
  9456. - // Note: we still want to do this if nothing needed caching since it
  9457. - // should get cleared in the_class too.
  9458. - if (the_class->get_cached_class_file_bytes() == 0) {
  9459. - // the_class doesn't have a cache yet so copy it
  9460. - the_class->set_cached_class_file(
  9461. - scratch_class->get_cached_class_file_bytes(),
  9462. - scratch_class->get_cached_class_file_len());
  9463. - }
  9464. -#ifndef PRODUCT
  9465. - else {
  9466. - assert(the_class->get_cached_class_file_bytes() ==
  9467. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  9468. - assert(the_class->get_cached_class_file_len() ==
  9469. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  9470. - }
  9471. -#endif
  9472. -
  9473. - // Replace inner_classes
  9474. - typeArrayOop old_inner_classes = the_class->inner_classes();
  9475. - the_class->set_inner_classes(scratch_class->inner_classes());
  9476. - scratch_class->set_inner_classes(old_inner_classes);
  9477. -
  9478. - // Initialize the vtable and interface table after
  9479. - // methods have been rewritten
  9480. - {
  9481. - ResourceMark rm(THREAD);
  9482. - // no exception should happen here since we explicitly
  9483. - // do not check loader constraints.
  9484. - // compare_and_normalize_class_versions has already checked:
  9485. - // - classloaders unchanged, signatures unchanged
  9486. - // - all instanceKlasses for redefined classes reused & contents updated
  9487. - the_class->vtable()->initialize_vtable(false, THREAD);
  9488. - the_class->itable()->initialize_itable(false, THREAD);
  9489. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  9490. - }
  9491. -
  9492. - // Leave arrays of jmethodIDs and itable index cache unchanged
  9493. -
  9494. - // Copy the "source file name" attribute from new class version
  9495. - the_class->set_source_file_name(scratch_class->source_file_name());
  9496. -
  9497. - // Copy the "source debug extension" attribute from new class version
  9498. - the_class->set_source_debug_extension(
  9499. - scratch_class->source_debug_extension(),
  9500. - scratch_class->source_debug_extension() == NULL ? 0 :
  9501. - (int)strlen(scratch_class->source_debug_extension()));
  9502. -
  9503. - // Use of javac -g could be different in the old and the new
  9504. - if (scratch_class->access_flags().has_localvariable_table() !=
  9505. - the_class->access_flags().has_localvariable_table()) {
  9506. -
  9507. - AccessFlags flags = the_class->access_flags();
  9508. - if (scratch_class->access_flags().has_localvariable_table()) {
  9509. - flags.set_has_localvariable_table();
  9510. - } else {
  9511. - flags.clear_has_localvariable_table();
  9512. - }
  9513. - the_class->set_access_flags(flags);
  9514. - }
  9515. -
  9516. - // Replace class annotation fields values
  9517. - typeArrayOop old_class_annotations = the_class->class_annotations();
  9518. - the_class->set_class_annotations(scratch_class->class_annotations());
  9519. - scratch_class->set_class_annotations(old_class_annotations);
  9520. -
  9521. - // Replace fields annotation fields values
  9522. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  9523. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  9524. - scratch_class->set_fields_annotations(old_fields_annotations);
  9525. -
  9526. - // Replace methods annotation fields values
  9527. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  9528. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  9529. - scratch_class->set_methods_annotations(old_methods_annotations);
  9530. -
  9531. - // Replace methods parameter annotation fields values
  9532. - objArrayOop old_methods_parameter_annotations =
  9533. - the_class->methods_parameter_annotations();
  9534. - the_class->set_methods_parameter_annotations(
  9535. - scratch_class->methods_parameter_annotations());
  9536. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  9537. -
  9538. - // Replace methods default annotation fields values
  9539. - objArrayOop old_methods_default_annotations =
  9540. - the_class->methods_default_annotations();
  9541. - the_class->set_methods_default_annotations(
  9542. - scratch_class->methods_default_annotations());
  9543. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  9544. -
  9545. - // Replace minor version number of class file
  9546. - u2 old_minor_version = the_class->minor_version();
  9547. - the_class->set_minor_version(scratch_class->minor_version());
  9548. - scratch_class->set_minor_version(old_minor_version);
  9549. -
  9550. - // Replace major version number of class file
  9551. - u2 old_major_version = the_class->major_version();
  9552. - the_class->set_major_version(scratch_class->major_version());
  9553. - scratch_class->set_major_version(old_major_version);
  9554. -
  9555. - // Replace CP indexes for class and name+type of enclosing method
  9556. - u2 old_class_idx = the_class->enclosing_method_class_index();
  9557. - u2 old_method_idx = the_class->enclosing_method_method_index();
  9558. - the_class->set_enclosing_method_indices(
  9559. - scratch_class->enclosing_method_class_index(),
  9560. - scratch_class->enclosing_method_method_index());
  9561. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  9562. + update_jmethod_ids();
  9563. // keep track of previous versions of this class
  9564. - the_class->add_previous_version(scratch_class, &emcp_methods,
  9565. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9566. emcp_method_count);
  9567. - RC_TIMER_STOP(_timer_rsc_phase1);
  9568. - RC_TIMER_START(_timer_rsc_phase2);
  9569. + // TODO:
  9570. + transfer_old_native_function_registrations(the_old_class);
  9571. - // Adjust constantpool caches and vtables for all classes
  9572. - // that reference methods of the evolved class.
  9573. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  9574. - if (the_class->oop_map_cache() != NULL) {
  9575. - // Flush references to any obsolete methods from the oop map cache
  9576. - // so that obsolete methods are not pinned.
  9577. - the_class->oop_map_cache()->flush_obsolete_entries();
  9578. +#ifdef ASSERT
  9579. +
  9580. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9581. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9582. +
  9583. + //JNIHandles::verify();
  9584. +
  9585. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9586. +
  9587. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9588. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9589. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9590. +
  9591. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9592. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9593. }
  9594. + _old_methods->verify();
  9595. + _new_methods->verify();
  9596. +
  9597. + the_new_class->vtable()->verify(tty);
  9598. + the_old_class->vtable()->verify(tty);
  9599. +
  9600. +#endif
  9601. +
  9602. // increment the classRedefinedCount field in the_class and in any
  9603. // direct and indirect subclasses of the_class
  9604. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  9605. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9606. +
  9607. +}
  9608. +
  9609. +
  9610. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9611. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9612. + *emcp_method_count_p = 0;
  9613. + int obsolete_count = 0;
  9614. + int old_index = 0;
  9615. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9616. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9617. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9618. + methodOop old_array_method;
  9619. +
  9620. + // Maintain an old_index into the _old_methods array by skipping
  9621. + // deleted methods
  9622. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9623. + != old_method) {
  9624. + ++old_index;
  9625. + }
  9626. +
  9627. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9628. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9629. + // the same with the exception of constant pool indices which may
  9630. + // differ. However, the constants referred to by those indices
  9631. + // must be the same.
  9632. + //
  9633. + // We use methods_EMCP() for comparison since constant pool
  9634. + // merging can remove duplicate constant pool entries that were
  9635. + // present in the old method and removed from the rewritten new
  9636. + // method. A faster binary comparison function would consider the
  9637. + // old and new methods to be different when they are actually
  9638. + // EMCP.
  9639. +
  9640. + // track which methods are EMCP for add_previous_version() call
  9641. + emcp_methods->set_bit(old_index);
  9642. + (*emcp_method_count_p)++;
  9643. +
  9644. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9645. + // different jmethodID than the current method. An EMCP method
  9646. + // has the same jmethodID as the current method. Having the
  9647. + // same jmethodID for all EMCP versions of a method allows for
  9648. + // a consistent view of the EMCP methods regardless of which
  9649. + // EMCP method you happen to have in hand. For example, a
  9650. + // breakpoint set in one EMCP method will work for all EMCP
  9651. + // versions of the method including the current one.
  9652. +
  9653. + old_method->set_new_version(new_method);
  9654. + new_method->set_old_version(old_method);
  9655. +
  9656. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9657. +
  9658. + // Transfer breakpoints
  9659. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9660. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9661. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9662. + RC_TRACE(0x00000002, ("%d / %d",
  9663. + bp->match(old_method), bp->match(new_method)));
  9664. + if (bp->match(old_method)) {
  9665. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9666. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9667. + new_method->set_breakpoint(bp->bci());
  9668. + }
  9669. + }
  9670. +
  9671. +
  9672. - // RC_TRACE macro has an embedded ResourceMark
  9673. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  9674. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  9675. - the_class->external_name(),
  9676. - java_lang_Class::classRedefinedCount(the_class_mirror),
  9677. - os::available_memory() >> 10));
  9678. + } else {
  9679. + // mark obsolete methods as such
  9680. + old_method->set_is_obsolete();
  9681. + obsolete_count++;
  9682. +
  9683. + // With tracing we try not to "yack" too much. The position of
  9684. + // this trace assumes there are fewer obsolete methods than
  9685. + // EMCP methods.
  9686. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9687. + old_method->name()->as_C_string(),
  9688. + old_method->signature()->as_C_string()));
  9689. + }
  9690. + old_method->set_is_old();
  9691. + }
  9692. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9693. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9694. - RC_TIMER_STOP(_timer_rsc_phase2);
  9695. -} // end redefine_single_class()
  9696. + //assert(old_method->vtable_index() < 0,
  9697. + // "cannot delete methods with vtable entries");;
  9698. + // Mark all deleted methods as old and obsolete
  9699. + old_method->set_is_old();
  9700. + old_method->set_is_obsolete();
  9701. + ++obsolete_count;
  9702. + // With tracing we try not to "yack" too much. The position of
  9703. + // this trace assumes there are fewer obsolete methods than
  9704. + // EMCP methods.
  9705. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9706. + old_method->name()->as_C_string(),
  9707. + old_method->signature()->as_C_string()));
  9708. + }
  9709. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9710. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9711. +}
  9712. // Increment the classRedefinedCount field in the specific instanceKlass
  9713. // and in all direct and indirect subclasses.
  9714. @@ -3338,134 +2953,324 @@ void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9715. klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9716. int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9717. java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9718. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9719. +}
  9720. +
  9721. +#ifndef PRODUCT
  9722. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9723. + Klass *k = k_oop->klass_part();
  9724. + if (k->oop_is_instance()) {
  9725. + HandleMark hm(THREAD);
  9726. + instanceKlass *ik = (instanceKlass *) k;
  9727. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9728. +
  9729. + if (ik->vtable_length() > 0) {
  9730. + ResourceMark rm(THREAD);
  9731. + if (!ik->vtable()->check_no_old_entries()) {
  9732. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9733. + k_oop->size()));
  9734. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9735. + ik->signature_name()));
  9736. + assert(false, "OLD method found");
  9737. + }
  9738. - if (class_oop != _the_class_oop) {
  9739. - // _the_class_oop count is printed at end of redefine_single_class()
  9740. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  9741. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  9742. + ik->vtable()->verify(tty, true);
  9743. + }
  9744. }
  9745. +}
  9746. +
  9747. +#endif
  9748. +
  9749. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9750. +{
  9751. + assert(original_klasses != NULL && result != NULL, "");
  9752. + this->_original_klasses = original_klasses;
  9753. + this->_result = result;
  9754. + SystemDictionary::classes_do(this);
  9755. +}
  9756. - for (Klass *subk = ik->subklass(); subk != NULL;
  9757. - subk = subk->next_sibling()) {
  9758. - if (subk->oop_is_instance()) {
  9759. - // Only update instanceKlasses
  9760. - instanceKlass *subik = (instanceKlass*)subk;
  9761. - // recursively do subclasses of the current subclass
  9762. - increment_class_counter(subik, THREAD);
  9763. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9764. +{
  9765. + klassOop klass = (klassOop)obj;
  9766. + assert(!_result->contains(klass), "must not occur more than once!");
  9767. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9768. +
  9769. + for(int i=0; i<_original_klasses->length(); i++) {
  9770. + instanceKlassHandle cur = _original_klasses->at(i);
  9771. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9772. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9773. + _result->append(klass);
  9774. + break;
  9775. }
  9776. }
  9777. }
  9778. -void VM_RedefineClasses::check_class(klassOop k_oop,
  9779. - oop initiating_loader, TRAPS) {
  9780. - Klass *k = k_oop->klass_part();
  9781. - if (k->oop_is_instance()) {
  9782. - HandleMark hm(THREAD);
  9783. - instanceKlass *ik = (instanceKlass *) k;
  9784. - bool no_old_methods = true; // be optimistic
  9785. - ResourceMark rm(THREAD);
  9786. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9787. +{
  9788. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9789. - // a vtable should never contain old or obsolete methods
  9790. - if (ik->vtable_length() > 0 &&
  9791. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  9792. - if (RC_TRACE_ENABLED(0x00004000)) {
  9793. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9794. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  9795. - " -- OLD or OBSOLETE method found -- class: %s",
  9796. - ik->signature_name()));
  9797. - ik->vtable()->dump_vtable();
  9798. - }
  9799. - no_old_methods = false;
  9800. - }
  9801. -
  9802. - // an itable should never contain old or obsolete methods
  9803. - if (ik->itable_length() > 0 &&
  9804. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  9805. - if (RC_TRACE_ENABLED(0x00004000)) {
  9806. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9807. - ("klassItable::check_no_old_or_obsolete_entries failure"
  9808. - " -- OLD or OBSOLETE method found -- class: %s",
  9809. - ik->signature_name()));
  9810. - ik->itable()->dump_itable();
  9811. - }
  9812. - no_old_methods = false;
  9813. - }
  9814. -
  9815. - // the constant pool cache should never contain old or obsolete methods
  9816. - if (ik->constants() != NULL &&
  9817. - ik->constants()->cache() != NULL &&
  9818. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  9819. - if (RC_TRACE_ENABLED(0x00004000)) {
  9820. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9821. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  9822. - " -- OLD or OBSOLETE method found -- class: %s",
  9823. - ik->signature_name()));
  9824. - ik->constants()->cache()->dump_cache();
  9825. - }
  9826. - no_old_methods = false;
  9827. - }
  9828. -
  9829. - if (!no_old_methods) {
  9830. - if (RC_TRACE_ENABLED(0x00004000)) {
  9831. - dump_methods();
  9832. - } else {
  9833. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  9834. - "to see more info about the following guarantee() failure.");
  9835. + for (int i=0; i<class_count; i++) {
  9836. +
  9837. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9838. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9839. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9840. + Handle the_class_loader(THREAD, the_class->class_loader());
  9841. + Handle protection_domain(THREAD, the_class->protection_domain());
  9842. +
  9843. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9844. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9845. + ClassFileParser cfp(&st);
  9846. +
  9847. + GrowableArray<Symbol*> symbolArr;
  9848. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9849. + the_class->name()->as_C_string()));
  9850. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9851. +
  9852. + for (int j=0; j<symbolArr.length(); j++) {
  9853. + Symbol* sym = symbolArr.at(j);
  9854. +
  9855. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9856. +
  9857. + for (int k=0; k<arr->length(); k++) {
  9858. + klassOop curOop = arr->at(k)();
  9859. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9860. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9861. + RC_TRACE(0x00000002, ("Found class to link"));
  9862. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9863. + break;
  9864. + }
  9865. + }
  9866. + }
  9867. + }
  9868. +
  9869. +
  9870. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9871. +
  9872. + for (int i=0; i<affected->length(); i++) {
  9873. +
  9874. + instanceKlassHandle klass = affected->at(i);
  9875. +
  9876. + klassOop superKlass = klass->super();
  9877. + if (affected->contains(superKlass)) {
  9878. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9879. + }
  9880. +
  9881. + objArrayOop superInterfaces = klass->local_interfaces();
  9882. + for (int j=0; j<superInterfaces->length(); j++) {
  9883. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9884. + if (arr->contains(interfaceKlass)) {
  9885. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9886. + }
  9887. + }
  9888. + }
  9889. +
  9890. + if (RC_TRACE_ENABLED(0x00000002)) {
  9891. + RC_TRACE(0x00000002, ("Identified links: "));
  9892. + for (int i=0; i<links->length(); i++) {
  9893. + RC_TRACE(0x00000002, ("%s to %s",
  9894. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9895. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9896. + }
  9897. + }
  9898. +
  9899. + for (int i=0; i<arr->length(); i++) {
  9900. +
  9901. + int j;
  9902. + for (j=i; j<arr->length(); j++) {
  9903. +
  9904. + int k;
  9905. + for (k=0; k<links->length(); k++) {
  9906. +
  9907. + klassOop k1 = links->adr_at(k)->right();
  9908. + klassOop k2 = arr->at(j)();
  9909. + if (k1 == k2) {
  9910. + break;
  9911. + }
  9912. + }
  9913. +
  9914. + if (k == links->length()) {
  9915. + break;
  9916. }
  9917. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  9918. + }
  9919. +
  9920. + if (j == arr->length()) {
  9921. + // circle detected
  9922. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9923. + }
  9924. +
  9925. + for (int k=0; k<links->length(); k++) {
  9926. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9927. + links->at_put(k, links->at(links->length() - 1));
  9928. + links->remove_at(links->length() - 1);
  9929. + k--;
  9930. + }
  9931. + }
  9932. +
  9933. + instanceKlassHandle tmp = arr->at(j);
  9934. + arr->at_put(j, arr->at(i));
  9935. + arr->at_put(i, tmp);
  9936. + }
  9937. +
  9938. + return JVMTI_ERROR_NONE;
  9939. +}
  9940. +
  9941. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9942. +
  9943. + if (_updated_oops != NULL) {
  9944. + for (int i=0; i<_updated_oops->length(); i++) {
  9945. + closure->do_oop(_updated_oops->adr_at(i));
  9946. }
  9947. }
  9948. }
  9949. -void VM_RedefineClasses::dump_methods() {
  9950. - int j;
  9951. - RC_TRACE(0x00004000, ("_old_methods --"));
  9952. - for (j = 0; j < _old_methods->length(); ++j) {
  9953. - methodOop m = (methodOop) _old_methods->obj_at(j);
  9954. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  9955. - m->access_flags().print_on(tty);
  9956. - tty->print(" -- ");
  9957. - m->print_name(tty);
  9958. - tty->cr();
  9959. - }
  9960. - RC_TRACE(0x00004000, ("_new_methods --"));
  9961. - for (j = 0; j < _new_methods->length(); ++j) {
  9962. - methodOop m = (methodOop) _new_methods->obj_at(j);
  9963. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  9964. - m->access_flags().print_on(tty);
  9965. - tty->print(" -- ");
  9966. - m->print_name(tty);
  9967. - tty->cr();
  9968. - }
  9969. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  9970. - for (j = 0; j < _matching_methods_length; ++j) {
  9971. - methodOop m = _matching_old_methods[j];
  9972. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  9973. - m->access_flags().print_on(tty);
  9974. - tty->print(" -- ");
  9975. - m->print_name(tty);
  9976. - tty->cr();
  9977. - m = _matching_new_methods[j];
  9978. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  9979. - m->access_flags().print_on(tty);
  9980. - tty->cr();
  9981. - }
  9982. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  9983. - for (j = 0; j < _deleted_methods_length; ++j) {
  9984. - methodOop m = _deleted_methods[j];
  9985. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  9986. - m->access_flags().print_on(tty);
  9987. - tty->print(" -- ");
  9988. - m->print_name(tty);
  9989. - tty->cr();
  9990. - }
  9991. - RC_TRACE(0x00004000, ("_added_methods --"));
  9992. - for (j = 0; j < _added_methods_length; ++j) {
  9993. - methodOop m = _added_methods[j];
  9994. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  9995. - m->access_flags().print_on(tty);
  9996. - tty->print(" -- ");
  9997. - m->print_name(tty);
  9998. - tty->cr();
  9999. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  10000. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  10001. + to->set_is_field_access_watched(from->is_field_access_watched());
  10002. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  10003. + RC_TRACE(0x00000002, ("Transfered watch for field %s",
  10004. + from->name()->as_C_string()));
  10005. + }
  10006. + update_klass_field_access_flag(to);
  10007. +}
  10008. +
  10009. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  10010. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  10011. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  10012. + fi->set_access_flags(fd->access_flags().as_short());
  10013. +}
  10014. +
  10015. +
  10016. +// This internal class transfers the native function registration from old methods
  10017. +// to new methods. It is designed to handle both the simple case of unchanged
  10018. +// native methods and the complex cases of native method prefixes being added and/or
  10019. +// removed.
  10020. +// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  10021. +//
  10022. +// This class is used after the new methods have been installed in "the_class".
  10023. +//
  10024. +// So, for example, the following must be handled. Where 'm' is a method and
  10025. +// a number followed by an underscore is a prefix.
  10026. +//
  10027. +// Old Name New Name
  10028. +// Simple transfer to new method m -> m
  10029. +// Add prefix m -> 1_m
  10030. +// Remove prefix 1_m -> m
  10031. +// Simultaneous add of prefixes m -> 3_2_1_m
  10032. +// Simultaneous removal of prefixes 3_2_1_m -> m
  10033. +// Simultaneous add and remove 1_m -> 2_m
  10034. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  10035. +//
  10036. +class TransferNativeFunctionRegistration {
  10037. +private:
  10038. + instanceKlassHandle the_class;
  10039. + int prefix_count;
  10040. + char** prefixes;
  10041. +
  10042. + // Recursively search the binary tree of possibly prefixed method names.
  10043. + // Iteration could be used if all agents were well behaved. Full tree walk is
  10044. + // more resilent to agents not cleaning up intermediate methods.
  10045. + // Branch at each depth in the binary tree is:
  10046. + // (1) without the prefix.
  10047. + // (2) with the prefix.
  10048. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  10049. + methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  10050. + Symbol* signature) {
  10051. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10052. + if (name_symbol != NULL) {
  10053. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10054. + if (method != NULL) {
  10055. + // Even if prefixed, intermediate methods must exist.
  10056. + if (method->is_native()) {
  10057. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10058. + return method;
  10059. + }
  10060. + if (depth < prefix_count) {
  10061. + // Try applying further prefixes (other than this one).
  10062. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10063. + if (method != NULL) {
  10064. + return method; // found
  10065. + }
  10066. +
  10067. + // Try adding this prefix to the method name and see if it matches
  10068. + // another method name.
  10069. + char* prefix = prefixes[depth];
  10070. + size_t prefix_len = strlen(prefix);
  10071. + size_t trial_len = name_len + prefix_len;
  10072. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10073. + strcpy(trial_name_str, prefix);
  10074. + strcat(trial_name_str, name_str);
  10075. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10076. + signature);
  10077. + if (method != NULL) {
  10078. + // If found along this branch, it was prefixed, mark as such
  10079. + method->set_is_prefixed_native();
  10080. + return method; // found
  10081. + }
  10082. + }
  10083. + }
  10084. + }
  10085. + return NULL; // This whole branch bore nothing
  10086. + }
  10087. +
  10088. + // Return the method name with old prefixes stripped away.
  10089. + char* method_name_without_prefixes(methodOop method) {
  10090. + Symbol* name = method->name();
  10091. + char* name_str = name->as_utf8();
  10092. +
  10093. + // Old prefixing may be defunct, strip prefixes, if any.
  10094. + for (int i = prefix_count-1; i >= 0; i--) {
  10095. + char* prefix = prefixes[i];
  10096. + size_t prefix_len = strlen(prefix);
  10097. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  10098. + name_str += prefix_len;
  10099. + }
  10100. + }
  10101. + return name_str;
  10102. + }
  10103. +
  10104. + // Strip any prefixes off the old native method, then try to find a
  10105. + // (possibly prefixed) new native that matches it.
  10106. + methodOop strip_and_search_for_new_native(methodOop method) {
  10107. + ResourceMark rm;
  10108. + char* name_str = method_name_without_prefixes(method);
  10109. + return search_prefix_name_space(0, name_str, strlen(name_str),
  10110. + method->signature());
  10111. + }
  10112. +
  10113. +public:
  10114. +
  10115. + // Construct a native method transfer processor for this class.
  10116. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10117. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  10118. +
  10119. + the_class = _the_class;
  10120. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  10121. + }
  10122. +
  10123. + // Attempt to transfer any of the old or deleted methods that are native
  10124. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10125. + for (int j = 0; j < methods_length; j++) {
  10126. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10127. +
  10128. + if (old_method->is_native() && old_method->has_native_function()) {
  10129. + methodOop new_method = strip_and_search_for_new_native(old_method);
  10130. + if (new_method != NULL) {
  10131. + // Actually set the native function in the new method.
  10132. + // Redefine does not send events (except CFLH), certainly not this
  10133. + // behind the scenes re-registration.
  10134. + new_method->set_native_function(old_method->native_function(),
  10135. + !methodOopDesc::native_bind_event_is_interesting);
  10136. +
  10137. + RC_TRACE(0x00008000, ("Transfering native function for method %s", old_method->name()->as_C_string()));
  10138. + }
  10139. + }
  10140. + }
  10141. }
  10142. +};
  10143. +
  10144. +// Don't lose the association between a native method and its JNI function.
  10145. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10146. + TransferNativeFunctionRegistration transfer(old_klass);
  10147. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10148. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10149. }
  10150. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10151. index 671f2ae..88fdbac 100644
  10152. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10153. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10154. @@ -1,26 +1,29 @@
  10155. /*
  10156. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10157. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10158. - *
  10159. - * This code is free software; you can redistribute it and/or modify it
  10160. - * under the terms of the GNU General Public License version 2 only, as
  10161. - * published by the Free Software Foundation.
  10162. - *
  10163. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10164. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10165. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10166. - * version 2 for more details (a copy is included in the LICENSE file that
  10167. - * accompanied this code).
  10168. - *
  10169. - * You should have received a copy of the GNU General Public License version
  10170. - * 2 along with this work; if not, write to the Free Software Foundation,
  10171. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10172. - *
  10173. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10174. - * or visit www.oracle.com if you need additional information or have any
  10175. - * questions.
  10176. - *
  10177. - */
  10178. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10179. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10180. +*
  10181. +* This code is free software; you can redistribute it and/or modify it
  10182. +* under the terms of the GNU General Public License version 2 only, as
  10183. +* published by the Free Software Foundation.
  10184. +*
  10185. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10186. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10187. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10188. +* version 2 for more details (a copy is included in the LICENSE file that
  10189. +* accompanied this code).
  10190. +*
  10191. +* You should have received a copy of the GNU General Public License version
  10192. +* 2 along with this work; if not, write to the Free Software Foundation,
  10193. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10194. +*
  10195. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10196. +* or visit www.oracle.com if you need additional information or have any
  10197. +* questions.
  10198. +*
  10199. +*/
  10200. +
  10201. +// New version that allows arbitrary changes to already loaded classes.
  10202. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10203. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10204. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10205. @@ -32,331 +35,28 @@
  10206. #include "oops/objArrayOop.hpp"
  10207. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10208. #include "runtime/vm_operations.hpp"
  10209. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10210. -// Introduction:
  10211. -//
  10212. -// The RedefineClasses() API is used to change the definition of one or
  10213. -// more classes. While the API supports redefining more than one class
  10214. -// in a single call, in general, the API is discussed in the context of
  10215. -// changing the definition of a single current class to a single new
  10216. -// class. For clarity, the current class is will always be called
  10217. -// "the_class" and the new class will always be called "scratch_class".
  10218. -//
  10219. -// The name "the_class" is used because there is only one structure
  10220. -// that represents a specific class; redefinition does not replace the
  10221. -// structure, but instead replaces parts of the structure. The name
  10222. -// "scratch_class" is used because the structure that represents the
  10223. -// new definition of a specific class is simply used to carry around
  10224. -// the parts of the new definition until they are used to replace the
  10225. -// appropriate parts in the_class. Once redefinition of a class is
  10226. -// complete, scratch_class is thrown away.
  10227. -//
  10228. -//
  10229. -// Implementation Overview:
  10230. -//
  10231. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10232. -// does the real work. The work is split in varying degrees between
  10233. -// doit_prologue(), doit() and doit_epilogue().
  10234. -//
  10235. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10236. -// safepoint. It does parameter verification and loads scratch_class
  10237. -// which involves:
  10238. -// - parsing the incoming class definition using the_class' class
  10239. -// loader and security context
  10240. -// - linking scratch_class
  10241. -// - merging constant pools and rewriting bytecodes as needed
  10242. -// for the merged constant pool
  10243. -// - verifying the bytecodes in scratch_class
  10244. -// - setting up the constant pool cache and rewriting bytecodes
  10245. -// as needed to use the cache
  10246. -// - finally, scratch_class is compared to the_class to verify
  10247. -// that it is a valid replacement class
  10248. -// - if everything is good, then scratch_class is saved in an
  10249. -// instance field in the VM operation for the doit() call
  10250. -//
  10251. -// Note: A JavaThread must do the above work.
  10252. -//
  10253. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10254. -// the new class definition(s) which involves:
  10255. -// - retrieving the scratch_class from the instance field in the
  10256. -// VM operation
  10257. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10258. -// dependent compiled code)
  10259. -// - replacing parts in the_class with parts from scratch_class
  10260. -// - adding weak reference(s) to track the obsolete but interesting
  10261. -// parts of the_class
  10262. -// - adjusting constant pool caches and vtables in other classes
  10263. -// that refer to methods in the_class. These adjustments use the
  10264. -// SystemDictionary::classes_do() facility which only allows
  10265. -// a helper method to be specified. The interesting parameters
  10266. -// that we would like to pass to the helper method are saved in
  10267. -// static global fields in the VM operation.
  10268. -// - telling the SystemDictionary to notice our changes
  10269. -//
  10270. -// Note: the above work must be done by the VMThread to be safe.
  10271. -//
  10272. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10273. -// is finished and the safepoint is done. It simply cleans up
  10274. -// memory allocated in doit_prologue() and used in doit().
  10275. -//
  10276. -//
  10277. -// Constant Pool Details:
  10278. -//
  10279. -// When the_class is redefined, we cannot just replace the constant
  10280. -// pool in the_class with the constant pool from scratch_class because
  10281. -// that could confuse obsolete methods that may still be running.
  10282. -// Instead, the constant pool from the_class, old_cp, is merged with
  10283. -// the constant pool from scratch_class, scratch_cp. The resulting
  10284. -// constant pool, merge_cp, replaces old_cp in the_class.
  10285. -//
  10286. -// The key part of any merging algorithm is the entry comparison
  10287. -// function so we have to know the types of entries in a constant pool
  10288. -// in order to merge two of them together. Constant pools can contain
  10289. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10290. -// is not presently used so we only have to worry about the other 11
  10291. -// entry types. For the purposes of constant pool merging, it is
  10292. -// helpful to know that the 11 entry types fall into 3 different
  10293. -// subtypes: "direct", "indirect" and "double-indirect".
  10294. -//
  10295. -// Direct CP entries contain data and do not contain references to
  10296. -// other CP entries. The following are direct CP entries:
  10297. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10298. -//
  10299. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10300. -// and no other data. The following are indirect CP entries:
  10301. -// JVM_CONSTANT_{Class,NameAndType,String}
  10302. -//
  10303. -// Double-indirect CP entries contain two references to indirect CP
  10304. -// entries and no other data. The following are double-indirect CP
  10305. -// entries:
  10306. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10307. -//
  10308. -// When comparing entries between two constant pools, the entry types
  10309. -// are compared first and if they match, then further comparisons are
  10310. -// made depending on the entry subtype. Comparing direct CP entries is
  10311. -// simply a matter of comparing the data associated with each entry.
  10312. -// Comparing both indirect and double-indirect CP entries requires
  10313. -// recursion.
  10314. -//
  10315. -// Fortunately, the recursive combinations are limited because indirect
  10316. -// CP entries can only refer to direct CP entries and double-indirect
  10317. -// CP entries can only refer to indirect CP entries. The following is
  10318. -// an example illustration of the deepest set of indirections needed to
  10319. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10320. -//
  10321. -// JVM_CONSTANT_Fieldref {
  10322. -// class_index => JVM_CONSTANT_Class {
  10323. -// name_index => JVM_CONSTANT_Utf8 {
  10324. -// <data-1>
  10325. -// }
  10326. -// }
  10327. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10328. -// name_index => JVM_CONSTANT_Utf8 {
  10329. -// <data-2>
  10330. -// }
  10331. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10332. -// <data-3>
  10333. -// }
  10334. -// }
  10335. -// }
  10336. -//
  10337. -// The above illustration is not a data structure definition for any
  10338. -// computer language. The curly braces ('{' and '}') are meant to
  10339. -// delimit the context of the "fields" in the CP entry types shown.
  10340. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10341. -// "=>", e.g., the class_index is used to indirectly reference a
  10342. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10343. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10344. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10345. -// have to do a total of 5 indirections just to get to the CP entries
  10346. -// that contain the interesting pieces of data and then we have to
  10347. -// fetch the three pieces of data. This means we have to do a total of
  10348. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10349. -// entries.
  10350. -//
  10351. -// Here is the indirection, data and dereference count for each entry
  10352. -// type:
  10353. -//
  10354. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10355. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10356. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10357. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10358. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10359. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10360. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10361. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10362. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10363. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10364. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10365. -//
  10366. -// So different subtypes of CP entries require different amounts of
  10367. -// work for a proper comparison.
  10368. -//
  10369. -// Now that we've talked about the different entry types and how to
  10370. -// compare them we need to get back to merging. This is not a merge in
  10371. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10372. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10373. -// preserving entry order. Next we append all the unique entries from
  10374. -// scratch_cp to merge_cp and we track the index changes from the
  10375. -// location in scratch_cp to the possibly new location in merge_cp.
  10376. -// When we are done, any obsolete code that is still running that
  10377. -// uses old_cp should not be able to observe any difference if it
  10378. -// were to use merge_cp. As for the new code in scratch_class, it is
  10379. -// modified to use the appropriate index values in merge_cp before it
  10380. -// is used to replace the code in the_class.
  10381. -//
  10382. -// There is one small complication in copying the entries from old_cp
  10383. -// to merge_cp. Two of the CP entry types are special in that they are
  10384. -// lazily resolved. Before explaining the copying complication, we need
  10385. -// to digress into CP entry resolution.
  10386. -//
  10387. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10388. -// the class file, but are not stored in memory as such until they are
  10389. -// resolved. The entries are not resolved unless they are used because
  10390. -// resolution is expensive. During class file parsing the entries are
  10391. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10392. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10393. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10394. -// have been parsed, but the index values in the entries have not been
  10395. -// validated. After the entire constant pool has been parsed, the index
  10396. -// values can be validated and then the entries are converted into
  10397. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10398. -// entries. During this conversion process, the UTF8 values that are
  10399. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10400. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10401. -// entries are modified to refer to the Symbol*s. This optimization
  10402. -// eliminates one level of indirection for those two CP entry types and
  10403. -// gets the entries ready for verification. During class file parsing
  10404. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10405. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10406. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10407. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10408. -// entries.
  10409. -//
  10410. -// Now we can get back to the copying complication. When we copy
  10411. -// entries from old_cp to merge_cp, we have to revert any
  10412. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10413. -// or verification will fail.
  10414. -//
  10415. -// It is important to explicitly state that the merging algorithm
  10416. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10417. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10418. -// entries in the merge_cp. This is done both to make verification
  10419. -// happy and to avoid adding more brittleness between RedefineClasses
  10420. -// and the constant pool cache. By allowing the constant pool cache
  10421. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10422. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10423. -// about those algorithms in RedefineClasses.
  10424. -//
  10425. -// Appending unique entries from scratch_cp to merge_cp is straight
  10426. -// forward for direct CP entries and most indirect CP entries. For the
  10427. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10428. -// indirect CP entry types, the presence of more than one piece of
  10429. -// interesting data makes appending the entries more complicated.
  10430. -//
  10431. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10432. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10433. -// If the index in scratch_cp is different than the destination index
  10434. -// in merge_cp, then the change in index value is tracked.
  10435. -//
  10436. -// Note: the above discussion for the direct CP entries also applies
  10437. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10438. -//
  10439. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10440. -// one data element at the end of the recursion, we know that we have
  10441. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10442. -// unique then it is appended to merge_cp before the current entry.
  10443. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10444. -// is updated to refer to the duplicate entry in merge_cp before it is
  10445. -// appended to merge_cp. Again, any changes in index values are tracked
  10446. -// as needed.
  10447. -//
  10448. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10449. -// types is theoretical. Since those entry types have already been
  10450. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10451. -// they are handled as direct CP entries.
  10452. -//
  10453. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10454. -// data elements at the end of the recursions, we know that we have
  10455. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10456. -// entries are appended to merge_cp before the current entry. For any
  10457. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10458. -// updated to refer to the duplicate entry in merge_cp before it is
  10459. -// appended to merge_cp. Again, any changes in index values are tracked
  10460. -// as needed.
  10461. -//
  10462. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10463. -// types, since there are two indirect CP entries and three data
  10464. -// elements at the end of the recursions, we know that we have between
  10465. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10466. -// above for an example of all six entries. The uniqueness algorithm
  10467. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10468. -// covered above. Any unique entries are appended to merge_cp before
  10469. -// the current entry. For any entries that are not unique, the current
  10470. -// entry is updated to refer to the duplicate entry in merge_cp before
  10471. -// it is appended to merge_cp. Again, any changes in index values are
  10472. -// tracked as needed.
  10473. -//
  10474. -//
  10475. -// Other Details:
  10476. -//
  10477. -// Details for other parts of RedefineClasses need to be written.
  10478. -// This is a placeholder section.
  10479. -//
  10480. -//
  10481. -// Open Issues (in no particular order):
  10482. -//
  10483. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10484. -//
  10485. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10486. -// domain since the initial version. This has been changed to pass
  10487. -// the_class->protection_domain(). This change has been tested with
  10488. -// all NSK tests and nothing broke, but what will adding it now break
  10489. -// in ways that we don't test?
  10490. -//
  10491. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10492. -// (indirect) use of the Relocator class that the max instruction
  10493. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10494. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10495. -// what it does to the bytecodes. More investigation is needed.
  10496. -//
  10497. -// - java.lang.Object methods can be called on arrays. This is
  10498. -// implemented via the arrayKlassOop vtable which we don't
  10499. -// update. For example, if we redefine java.lang.Object.toString(),
  10500. -// then the new version of the method will not be called for array
  10501. -// objects.
  10502. -//
  10503. -// - How do we know if redefine_single_class() and the guts of
  10504. -// instanceKlass are out of sync? I don't think this can be
  10505. -// automated, but we should probably order the work in
  10506. -// redefine_single_class() to match the order of field
  10507. -// definitions in instanceKlass. We also need to add some
  10508. -// comments about keeping things in sync.
  10509. -//
  10510. -// - set_new_constant_pool() is huge and we should consider refactoring
  10511. -// it into smaller chunks of work.
  10512. -//
  10513. -// - The exception table update code in set_new_constant_pool() defines
  10514. -// const values that are also defined in a local context elsewhere.
  10515. -// The same literal values are also used in elsewhere. We need to
  10516. -// coordinate a cleanup of these constants with Runtime.
  10517. -//
  10518. -
  10519. -class VM_RedefineClasses: public VM_Operation {
  10520. +#define RC_ABORT(error) { _result = error; return false; }
  10521. +
  10522. +class VM_RedefineClasses: public VM_GC_Operation {
  10523. private:
  10524. +
  10525. // These static fields are needed by SystemDictionary::classes_do()
  10526. // facility and the adjust_cpool_cache_and_vtable() helper:
  10527. static objArrayOop _old_methods;
  10528. static objArrayOop _new_methods;
  10529. - static methodOop* _matching_old_methods;
  10530. - static methodOop* _matching_new_methods;
  10531. - static methodOop* _deleted_methods;
  10532. - static methodOop* _added_methods;
  10533. + static int* _matching_old_methods;
  10534. + static int* _matching_new_methods;
  10535. + static int* _deleted_methods;
  10536. + static int* _added_methods;
  10537. static int _matching_methods_length;
  10538. static int _deleted_methods_length;
  10539. static int _added_methods_length;
  10540. static klassOop _the_class_oop;
  10541. + static int _revision_number;
  10542. +
  10543. // The instance fields are used to pass information from
  10544. // doit_prologue() to doit() and doit_epilogue().
  10545. jint _class_count;
  10546. @@ -370,36 +70,29 @@ class VM_RedefineClasses: public VM_Operation {
  10547. // _index_map_p contains any entries.
  10548. int _index_map_count;
  10549. intArray * _index_map_p;
  10550. - // ptr to _class_count scratch_classes
  10551. - instanceKlassHandle * _scratch_classes;
  10552. - jvmtiError _res;
  10553. + GrowableArray<instanceKlassHandle>* _new_classes;
  10554. + GrowableArray<oop>* _updated_oops;
  10555. + jvmtiError _result;
  10556. + int _max_redefinition_flags;
  10557. // Performance measurement support. These timers do not cover all
  10558. // the work done for JVM/TI RedefineClasses() but they do cover
  10559. // the heavy lifting.
  10560. - elapsedTimer _timer_rsc_phase1;
  10561. - elapsedTimer _timer_rsc_phase2;
  10562. - elapsedTimer _timer_vm_op_prologue;
  10563. -
  10564. - // These routines are roughly in call order unless otherwise noted.
  10565. -
  10566. - // Load the caller's new class definition(s) into _scratch_classes.
  10567. - // Constant pool merging work is done here as needed. Also calls
  10568. - // compare_and_normalize_class_versions() to verify the class
  10569. - // definition(s).
  10570. + elapsedTimer _timer_total;
  10571. + elapsedTimer _timer_prologue;
  10572. + elapsedTimer _timer_class_linking;
  10573. + elapsedTimer _timer_class_loading;
  10574. + elapsedTimer _timer_check_type;
  10575. + elapsedTimer _timer_prepare_redefinition;
  10576. + elapsedTimer _timer_wait_for_locks;
  10577. + elapsedTimer _timer_redefinition;
  10578. + elapsedTimer _timer_vm_op_epilogue;
  10579. +
  10580. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  10581. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  10582. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  10583. jvmtiError load_new_class_versions(TRAPS);
  10584. - // Verify that the caller provided class definition(s) that meet
  10585. - // the restrictions of RedefineClasses. Normalize the order of
  10586. - // overloaded methods as needed.
  10587. - jvmtiError compare_and_normalize_class_versions(
  10588. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  10589. -
  10590. - // Swap annotations[i] with annotations[j]
  10591. - // Used by compare_and_normalize_class_versions() when normalizing
  10592. - // overloaded methods or changing idnum as when adding or deleting methods.
  10593. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  10594. -
  10595. // Figure out which new methods match old methods in name and signature,
  10596. // which methods have been added, and which are no longer present
  10597. void compute_added_deleted_matching_methods();
  10598. @@ -407,95 +100,100 @@ class VM_RedefineClasses: public VM_Operation {
  10599. // Change jmethodIDs to point to the new methods
  10600. void update_jmethod_ids();
  10601. - // In addition to marking methods as obsolete, this routine
  10602. - // records which methods are EMCP (Equivalent Module Constant
  10603. - // Pool) in the emcp_methods BitMap and returns the number of
  10604. - // EMCP methods via emcp_method_count_p. This information is
  10605. - // used when information about the previous version of the_class
  10606. - // is squirreled away.
  10607. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  10608. - int * emcp_method_count_p);
  10609. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10610. + class FindAffectedKlassesClosure : public ObjectClosure {
  10611. - // Unevolving classes may point to methods of the_class directly
  10612. - // from their constant pool caches, itables, and/or vtables. We
  10613. - // use the SystemDictionary::classes_do() facility and this helper
  10614. - // to fix up these pointers.
  10615. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  10616. + private:
  10617. + GrowableArray<instanceKlassHandle> *_original_klasses;
  10618. + GrowableArray<instanceKlassHandle> *_result;
  10619. +
  10620. + public:
  10621. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  10622. +
  10623. + virtual void do_object(oop obj);
  10624. + };
  10625. +
  10626. +
  10627. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  10628. // Install the redefinition of a class
  10629. - void redefine_single_class(jclass the_jclass,
  10630. - instanceKlassHandle scratch_class, TRAPS);
  10631. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  10632. // Increment the classRedefinedCount field in the specific instanceKlass
  10633. // and in all direct and indirect subclasses.
  10634. void increment_class_counter(instanceKlass *ik, TRAPS);
  10635. - // Support for constant pool merging (these routines are in alpha
  10636. - // order):
  10637. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  10638. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10639. - int find_new_index(int old_index);
  10640. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  10641. - constantPoolHandle cp2, int index2);
  10642. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  10643. - constantPoolHandle cp2, int index2);
  10644. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  10645. - bool merge_constant_pools(constantPoolHandle old_cp,
  10646. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  10647. - int *merge_cp_length_p, TRAPS);
  10648. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  10649. - instanceKlassHandle scratch_class, TRAPS);
  10650. - u2 rewrite_cp_ref_in_annotation_data(
  10651. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  10652. - const char * trace_mesg, TRAPS);
  10653. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  10654. - bool rewrite_cp_refs_in_annotation_struct(
  10655. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10656. - bool rewrite_cp_refs_in_annotations_typeArray(
  10657. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  10658. - bool rewrite_cp_refs_in_class_annotations(
  10659. - instanceKlassHandle scratch_class, TRAPS);
  10660. - bool rewrite_cp_refs_in_element_value(
  10661. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10662. - bool rewrite_cp_refs_in_fields_annotations(
  10663. - instanceKlassHandle scratch_class, TRAPS);
  10664. - void rewrite_cp_refs_in_method(methodHandle method,
  10665. - methodHandle * new_method_p, TRAPS);
  10666. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  10667. - bool rewrite_cp_refs_in_methods_annotations(
  10668. - instanceKlassHandle scratch_class, TRAPS);
  10669. - bool rewrite_cp_refs_in_methods_default_annotations(
  10670. - instanceKlassHandle scratch_class, TRAPS);
  10671. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  10672. - instanceKlassHandle scratch_class, TRAPS);
  10673. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  10674. - void rewrite_cp_refs_in_verification_type_info(
  10675. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  10676. - u1 frame_size, TRAPS);
  10677. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  10678. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  10679. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  10680. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  10681. - static void dump_methods();
  10682. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  10683. +
  10684. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  10685. +
  10686. +#ifdef ASSERT
  10687. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  10688. +#endif
  10689. +
  10690. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  10691. + void calculate_instance_update_information(klassOop new_version);
  10692. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  10693. +
  10694. + static void calculate_type_check_information(klassOop k);
  10695. + static void clear_type_check_information(klassOop k);
  10696. public:
  10697. - VM_RedefineClasses(jint class_count,
  10698. - const jvmtiClassDefinition *class_defs,
  10699. - JvmtiClassLoadKind class_load_kind);
  10700. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  10701. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  10702. + virtual ~VM_RedefineClasses();
  10703. +
  10704. + bool check_arguments();
  10705. bool doit_prologue();
  10706. void doit();
  10707. void doit_epilogue();
  10708. + void rollback();
  10709. - bool allow_nested_vm_operations() const { return true; }
  10710. - jvmtiError check_error() { return _res; }
  10711. + jvmtiError check_exception() const;
  10712. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  10713. + bool skip_operation() const { return false; }
  10714. + bool allow_nested_vm_operations() const { return true; }
  10715. + jvmtiError check_error() { return _result; }
  10716. +
  10717. + void update_active_methods();
  10718. +
  10719. + // Checks for type consistency after hierarchy change
  10720. + bool check_type_consistency();
  10721. + void calculate_type_check_information();
  10722. + bool check_field_value_types();
  10723. + void clear_type_check_information();
  10724. + bool check_method_stacks();
  10725. + bool check_loaded_methods();
  10726. + bool check_method(methodOop method);
  10727. + static Symbol* signature_to_class_name(Symbol* signature);
  10728. +
  10729. + void method_forwarding();
  10730. +
  10731. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  10732. // Modifiable test must be shared between IsModifiableClass query
  10733. // and redefine implementation
  10734. static bool is_modifiable_class(oop klass_mirror);
  10735. +
  10736. + // Method used during garbage collection, the VM operation must iterate over all oops.
  10737. + void oops_do(OopClosure* f);
  10738. +
  10739. + // Utility methods for transfering field access flags
  10740. +
  10741. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  10742. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  10743. +
  10744. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10745. +
  10746. + void lock_threads();
  10747. + void unlock_threads();
  10748. +
  10749. + template <class T> static void do_oop_work(T* p);
  10750. +
  10751. + static void swap_marks(oop first, oop second);
  10752. +
  10753. };
  10754. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10755. +
  10756. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  10757. index 60eaf97..07bb6e3 100644
  10758. --- a/src/share/vm/prims/methodComparator.cpp
  10759. +++ b/src/share/vm/prims/methodComparator.cpp
  10760. @@ -65,6 +65,7 @@ bool MethodComparator::methods_EMCP(methodOop old_method, methodOop new_method)
  10761. if (! args_same(c_old, c_new))
  10762. return false;
  10763. }
  10764. +
  10765. return true;
  10766. }
  10767. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  10768. index 41fc42d..53b3e0c 100644
  10769. --- a/src/share/vm/prims/nativeLookup.cpp
  10770. +++ b/src/share/vm/prims/nativeLookup.cpp
  10771. @@ -35,6 +35,7 @@
  10772. #include "oops/symbol.hpp"
  10773. #include "prims/jvm_misc.hpp"
  10774. #include "prims/nativeLookup.hpp"
  10775. +#include "prims/jvmtiRedefineClasses.hpp"
  10776. #include "runtime/arguments.hpp"
  10777. #include "runtime/handles.inline.hpp"
  10778. #include "runtime/javaCalls.hpp"
  10779. @@ -53,7 +54,6 @@
  10780. # include "os_bsd.inline.hpp"
  10781. #endif
  10782. -
  10783. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  10784. char* bytes = (char*)name->bytes() + begin;
  10785. char* end_bytes = (char*)name->bytes() + end;
  10786. @@ -138,6 +138,40 @@ static JNINativeMethod lookup_special_native_methods[] = {
  10787. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  10788. };
  10789. +// Helper function to call redefineClasses from Java Code
  10790. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  10791. + ResourceMark rm(THREAD);
  10792. +
  10793. + JavaThread* current_thread = JavaThread::current();
  10794. + jbyte* bytecodes = NULL;
  10795. + const int class_count = 1;
  10796. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  10797. +
  10798. + {
  10799. + ThreadToNativeFromVM ttnfv(thread);
  10800. + jboolean is_copy = JNI_FALSE;
  10801. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  10802. + class_definitions[0].klass = target;
  10803. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  10804. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  10805. + }
  10806. +
  10807. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  10808. + VMThread::execute(&op);
  10809. + int result = op.check_error();
  10810. +
  10811. + {
  10812. + ThreadToNativeFromVM ttnfv(thread);
  10813. + if (env->ExceptionOccurred()) {
  10814. + return -1;
  10815. + }
  10816. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  10817. + }
  10818. +
  10819. + return result;
  10820. +JVM_END
  10821. +
  10822. +
  10823. static address lookup_special_native(char* jni_name) {
  10824. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  10825. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  10826. @@ -177,6 +211,9 @@ address NativeLookup::lookup_style(methodHandle method, char* pure_name, const c
  10827. return entry;
  10828. }
  10829. }
  10830. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  10831. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  10832. + }
  10833. // Otherwise call static method findNative in ClassLoader
  10834. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  10835. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  10836. index 22d450b..d7bf297 100644
  10837. --- a/src/share/vm/runtime/arguments.cpp
  10838. +++ b/src/share/vm/runtime/arguments.cpp
  10839. @@ -1792,6 +1792,15 @@ bool Arguments::check_gc_consistency() {
  10840. status = false;
  10841. }
  10842. + // (tw) Must use serial GC
  10843. + if (!UseSerialGC && i >= 1) {
  10844. + jio_fprintf(defaultStream::error_stream(),
  10845. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  10846. + status = false;
  10847. + } else {
  10848. + UseSerialGC = true;
  10849. + }
  10850. +
  10851. return status;
  10852. }
  10853. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  10854. index 2b767d4..bcea3be 100644
  10855. --- a/src/share/vm/runtime/deoptimization.cpp
  10856. +++ b/src/share/vm/runtime/deoptimization.cpp
  10857. @@ -599,6 +599,38 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
  10858. // Cleanup thread deopt data
  10859. cleanup_deopt_info(thread, array);
  10860. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  10861. + {
  10862. + ResourceMark res_mark;
  10863. +
  10864. + // Verify that the just-unpacked frames match the interpreter's
  10865. + // notions of expression stack and locals
  10866. + vframeArray* cur_array = thread->vframe_array_last();
  10867. + RegisterMap rm(thread, false);
  10868. + rm.set_include_argument_oops(false);
  10869. + for (int i = 0; i < cur_array->frames(); i++) {
  10870. + vframeArrayElement* el = cur_array->element(i);
  10871. + frame* frame = el->iframe();
  10872. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  10873. + RegisterMap reg_map(thread);
  10874. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  10875. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  10876. + methodOop method = iframe->method();
  10877. + int bci = iframe->bci();
  10878. + method = method->newest_version();
  10879. + iframe->set_method(method, bci);
  10880. +
  10881. + methodOop forward_method = method->forward_method();
  10882. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  10883. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  10884. + if (TraceRedefineClasses >= 2) {
  10885. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  10886. + }
  10887. + iframe->set_method(forward_method, new_bci);
  10888. + }
  10889. + }
  10890. + }
  10891. +
  10892. #ifndef PRODUCT
  10893. if (VerifyStack) {
  10894. ResourceMark res_mark;
  10895. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  10896. index 32d02d6..bbb6c47 100644
  10897. --- a/src/share/vm/runtime/frame.cpp
  10898. +++ b/src/share/vm/runtime/frame.cpp
  10899. @@ -407,6 +407,12 @@ void frame::interpreter_frame_set_method(methodOop method) {
  10900. *interpreter_frame_method_addr() = method;
  10901. }
  10902. +// (tw) Sets constant pool cache oop
  10903. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  10904. + assert(is_interpreted_frame(), "interpreted frame expected");
  10905. + *interpreter_frame_cache_addr() = cp;
  10906. +}
  10907. +
  10908. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  10909. assert(is_interpreted_frame(), "Not an interpreted frame");
  10910. if (ProfileInterpreter) {
  10911. @@ -422,19 +428,27 @@ void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  10912. // The bcx was just converted from bci to bcp.
  10913. // Convert the mdx in parallel.
  10914. methodDataOop mdo = interpreter_frame_method()->method_data();
  10915. - assert(mdo != NULL, "");
  10916. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10917. - address mdp = mdo->di_to_dp(mdi);
  10918. - interpreter_frame_set_mdx((intptr_t)mdp);
  10919. + if (mdo == NULL) {
  10920. + interpreter_frame_set_mdx(0);
  10921. + } else {
  10922. + assert(mdo != NULL, "");
  10923. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10924. + address mdp = mdo->di_to_dp(mdi);
  10925. + interpreter_frame_set_mdx((intptr_t)mdp);
  10926. + }
  10927. }
  10928. } else {
  10929. if (is_now_bci) {
  10930. // The bcx was just converted from bcp to bci.
  10931. // Convert the mdx in parallel.
  10932. methodDataOop mdo = interpreter_frame_method()->method_data();
  10933. - assert(mdo != NULL, "");
  10934. - int mdi = mdo->dp_to_di((address)mdx);
  10935. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10936. + if (mdo == NULL) {
  10937. + interpreter_frame_set_mdx(0);
  10938. + } else {
  10939. + assert(mdo != NULL, "");
  10940. + int mdi = mdo->dp_to_di((address)mdx);
  10941. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10942. + }
  10943. }
  10944. }
  10945. }
  10946. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  10947. index 9c7bb72..04a6595 100644
  10948. --- a/src/share/vm/runtime/frame.hpp
  10949. +++ b/src/share/vm/runtime/frame.hpp
  10950. @@ -346,6 +346,7 @@ class frame VALUE_OBJ_CLASS_SPEC {
  10951. // Method & constant pool cache
  10952. methodOop interpreter_frame_method() const;
  10953. void interpreter_frame_set_method(methodOop method);
  10954. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  10955. methodOop* interpreter_frame_method_addr() const;
  10956. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  10957. #ifdef PPC
  10958. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  10959. index 8df7220..634c589 100644
  10960. --- a/src/share/vm/runtime/globals.hpp
  10961. +++ b/src/share/vm/runtime/globals.hpp
  10962. @@ -1227,9 +1227,23 @@ class CommandLineFlags {
  10963. product(bool, StressLdcRewrite, false, \
  10964. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  10965. \
  10966. + product(bool, UseMethodForwardPoints, false, \
  10967. + "Use method forward points") \
  10968. + \
  10969. + product(intx, MethodForwardPointsMaxLocals, 300, \
  10970. + "Maximum number of locals in forwarding method") \
  10971. + \
  10972. + product(intx, MethodForwardPointsMaxStack, 300, \
  10973. + "Maximum number of stack slots in forwarding method") \
  10974. + \
  10975. product(intx, TraceRedefineClasses, 0, \
  10976. "Trace level for JVMTI RedefineClasses") \
  10977. \
  10978. + product(bool, TimeRedefineClasses, false, \
  10979. + "Measure timing for JVMTI RedefineClasses") \
  10980. + \
  10981. + product(bool, AllowAdvancedClassRedefinition, true, \
  10982. + "Allow advanced class redefinition beyond swapping method bodies")\
  10983. develop(bool, StressMethodComparator, false, \
  10984. "run the MethodComparator on all loaded methods") \
  10985. \
  10986. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  10987. index 2875ee0..61fd8fe 100644
  10988. --- a/src/share/vm/runtime/interfaceSupport.hpp
  10989. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  10990. @@ -296,7 +296,7 @@ class ThreadToNativeFromVM : public ThreadStateTransition {
  10991. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  10992. // We are leaving the VM at this point and going directly to native code.
  10993. // Block, if we are in the middle of a safepoint synchronization.
  10994. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  10995. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  10996. thread->frame_anchor()->make_walkable(thread);
  10997. trans_and_fence(_thread_in_vm, _thread_in_native);
  10998. // Check for pending. async. exceptions or suspends.
  10999. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11000. index edbba98..4a27925 100644
  11001. --- a/src/share/vm/runtime/javaCalls.cpp
  11002. +++ b/src/share/vm/runtime/javaCalls.cpp
  11003. @@ -60,7 +60,7 @@ JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, Ja
  11004. bool clear_pending_exception = true;
  11005. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11006. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11007. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11008. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11009. _result = result;
  11010. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11011. index 3cbcaca..30839d7 100644
  11012. --- a/src/share/vm/runtime/jniHandles.cpp
  11013. +++ b/src/share/vm/runtime/jniHandles.cpp
  11014. @@ -112,6 +112,10 @@ jobject JNIHandles::make_weak_global(Handle obj) {
  11015. }
  11016. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11017. + if (mh->newest_version() != mh()) {
  11018. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11019. + return (jmethodID) make_weak_global(mh_new);
  11020. + }
  11021. return (jmethodID) make_weak_global(mh);
  11022. }
  11023. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11024. index 2095237..c541434 100644
  11025. --- a/src/share/vm/runtime/mutex.cpp
  11026. +++ b/src/share/vm/runtime/mutex.cpp
  11027. @@ -1227,7 +1227,7 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
  11028. // in increasing rank order (modulo any native ranks)
  11029. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11030. if (tmp->next() != NULL) {
  11031. - assert(tmp->rank() == Mutex::native ||
  11032. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11033. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11034. }
  11035. }
  11036. @@ -1247,7 +1247,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
  11037. // in increasing rank order (modulo any native ranks)
  11038. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11039. if (tmp->next() != NULL) {
  11040. - assert(tmp->rank() == Mutex::native ||
  11041. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11042. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11043. }
  11044. }
  11045. @@ -1310,6 +1310,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
  11046. // already hold Terminator_lock - may happen because of periodic safepoints
  11047. if (this->rank() != Mutex::native &&
  11048. this->rank() != Mutex::suspend_resume &&
  11049. + this->rank() != Mutex::redefine_classes &&
  11050. locks != NULL && locks->rank() <= this->rank() &&
  11051. !SafepointSynchronize::is_at_safepoint() &&
  11052. this != Interrupt_lock &&
  11053. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11054. index 7d2cd82..11eb32e 100644
  11055. --- a/src/share/vm/runtime/mutex.hpp
  11056. +++ b/src/share/vm/runtime/mutex.hpp
  11057. @@ -109,7 +109,8 @@ class Monitor : public CHeapObj<mtInternal> {
  11058. barrier = safepoint + 1,
  11059. nonleaf = barrier + 1,
  11060. max_nonleaf = nonleaf + 900,
  11061. - native = max_nonleaf + 1
  11062. + native = max_nonleaf + 1,
  11063. + redefine_classes = native + 1
  11064. };
  11065. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11066. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11067. index a6b2106..758e87f 100644
  11068. --- a/src/share/vm/runtime/mutexLocker.cpp
  11069. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11070. @@ -49,6 +49,7 @@
  11071. // Consider using GCC's __read_mostly.
  11072. Mutex* Patching_lock = NULL;
  11073. +Mutex* RedefineClasses_lock = NULL;
  11074. Monitor* SystemDictionary_lock = NULL;
  11075. Mutex* PackageTable_lock = NULL;
  11076. Mutex* CompiledIC_lock = NULL;
  11077. @@ -90,6 +91,7 @@ Mutex* Shared_SATB_Q_lock = NULL;
  11078. Mutex* DirtyCardQ_FL_lock = NULL;
  11079. Monitor* DirtyCardQ_CBL_mon = NULL;
  11080. Mutex* Shared_DirtyCardQ_lock = NULL;
  11081. +Monitor* RedefinitionSync_lock = NULL;
  11082. Mutex* ParGCRareEvent_lock = NULL;
  11083. Mutex* EvacFailureStack_lock = NULL;
  11084. Mutex* DerivedPointerTableGC_lock = NULL;
  11085. @@ -205,6 +207,7 @@ void mutex_init() {
  11086. def(HotCardCache_lock , Mutex , special , true );
  11087. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11088. }
  11089. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11090. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11091. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11092. def(CodeCache_lock , Mutex , special, true );
  11093. @@ -279,6 +282,7 @@ void mutex_init() {
  11094. def(Debug2_lock , Mutex , nonleaf+4, true );
  11095. def(Debug3_lock , Mutex , nonleaf+4, true );
  11096. def(CompileThread_lock , Monitor, nonleaf+5, false );
  11097. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11098. def(JfrMsg_lock , Monitor, leaf, true);
  11099. def(JfrBuffer_lock , Mutex, nonleaf+1, true);
  11100. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11101. index 40008bb..72f8ce0 100644
  11102. --- a/src/share/vm/runtime/mutexLocker.hpp
  11103. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11104. @@ -43,6 +43,8 @@
  11105. // Mutexes used in the VM.
  11106. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11107. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11108. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11109. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11110. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11111. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11112. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11113. index cd009ed..a53ad09 100644
  11114. --- a/src/share/vm/runtime/reflection.cpp
  11115. +++ b/src/share/vm/runtime/reflection.cpp
  11116. @@ -468,7 +468,8 @@ bool Reflection::verify_class_access(klassOop current_class, klassOop new_class,
  11117. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11118. if ( JDK_Version::is_gte_jdk14x_version()
  11119. && UseNewReflection
  11120. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11121. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11122. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11123. return true;
  11124. }
  11125. @@ -519,6 +520,12 @@ bool Reflection::verify_field_access(klassOop current_class,
  11126. AccessFlags access,
  11127. bool classloader_only,
  11128. bool protected_restriction) {
  11129. +
  11130. + // (tw) Decide accessibility based on active version
  11131. + if (current_class != NULL) {
  11132. + current_class = current_class->klass_part()->active_version();
  11133. + }
  11134. +
  11135. // Verify that current_class can access a field of field_class, where that
  11136. // field's access bits are "access". We assume that we've already verified
  11137. // that current_class can access field_class.
  11138. @@ -560,7 +567,8 @@ bool Reflection::verify_field_access(klassOop current_class,
  11139. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11140. if ( JDK_Version::is_gte_jdk14x_version()
  11141. && UseNewReflection
  11142. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11143. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11144. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11145. return true;
  11146. }
  11147. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11148. index 709d783..e0e19b1 100644
  11149. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11150. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11151. @@ -1137,7 +1137,20 @@ methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
  11152. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11153. int retry_count = 0;
  11154. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11155. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11156. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11157. +
  11158. + // DCEVM: If we are executing an old method, this is OK!
  11159. + {
  11160. + ResourceMark rm(thread);
  11161. + RegisterMap cbl_map(thread, false);
  11162. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11163. +
  11164. + CodeBlob* caller_cb = caller_frame.cb();
  11165. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11166. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11167. + if (caller_nm->method()->is_old()) break;
  11168. + }
  11169. +
  11170. // If has a pending exception then there is no need to re-try to
  11171. // resolve this method.
  11172. // If the method has been redefined, we need to try again.
  11173. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11174. index ae28b65..7d0d809 100644
  11175. --- a/src/share/vm/runtime/thread.cpp
  11176. +++ b/src/share/vm/runtime/thread.cpp
  11177. @@ -216,6 +216,8 @@ Thread::Thread() {
  11178. set_self_raw_id(0);
  11179. set_lgrp_id(-1);
  11180. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11181. +
  11182. // allocated data structures
  11183. set_osthread(NULL);
  11184. set_resource_area(new (mtThread)ResourceArea());
  11185. @@ -249,6 +251,7 @@ Thread::Thread() {
  11186. omFreeProvision = 32 ;
  11187. omInUseList = NULL ;
  11188. omInUseCount = 0 ;
  11189. + _pretend_new_universe = false;
  11190. #ifdef ASSERT
  11191. _visited_for_critical_count = false;
  11192. @@ -884,6 +887,15 @@ bool Thread::owns_locks_but_compiled_lock() const {
  11193. return false;
  11194. }
  11195. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11196. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11197. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11198. + return true;
  11199. + }
  11200. + }
  11201. + return false;
  11202. +}
  11203. +
  11204. #endif
  11205. @@ -1637,7 +1649,7 @@ void JavaThread::run() {
  11206. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11207. assert(JavaThread::current() == this, "sanity check");
  11208. - assert(!Thread::current()->owns_locks(), "sanity check");
  11209. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11210. DTRACE_THREAD_PROBE(start, this);
  11211. @@ -3193,7 +3205,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  11212. // Create a CompilerThread
  11213. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11214. -: JavaThread(&compiler_thread_entry) {
  11215. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11216. _env = NULL;
  11217. _log = NULL;
  11218. _task = NULL;
  11219. @@ -3201,6 +3213,7 @@ CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11220. _counters = counters;
  11221. _buffer_blob = NULL;
  11222. _scanned_nmethod = NULL;
  11223. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11224. #ifndef PRODUCT
  11225. _ideal_graph_printer = NULL;
  11226. @@ -3230,6 +3243,7 @@ int Threads::_number_of_threads = 0;
  11227. int Threads::_number_of_non_daemon_threads = 0;
  11228. int Threads::_return_code = 0;
  11229. size_t JavaThread::_stack_size_at_create = 0;
  11230. +bool Threads::_wait_at_instrumentation_entry = false;
  11231. // All JavaThreads
  11232. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11233. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11234. index 774bd27..4ca4502 100644
  11235. --- a/src/share/vm/runtime/thread.hpp
  11236. +++ b/src/share/vm/runtime/thread.hpp
  11237. @@ -203,11 +203,14 @@ class Thread: public ThreadShadow {
  11238. void enter_signal_handler() { _num_nested_signal++; }
  11239. void leave_signal_handler() { _num_nested_signal--; }
  11240. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11241. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11242. private:
  11243. // Debug tracing
  11244. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11245. + Mutex* _redefine_classes_mutex;
  11246. +
  11247. // Active_handles points to a block of handles
  11248. JNIHandleBlock* _active_handles;
  11249. @@ -530,10 +533,15 @@ public:
  11250. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11251. int _lgrp_id;
  11252. +
  11253. + bool _pretend_new_universe;
  11254. +
  11255. public:
  11256. // Stack overflow support
  11257. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11258. + 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; } }
  11259. + bool pretend_new_universe() { return _pretend_new_universe; }
  11260. void set_stack_base(address base) { _stack_base = base; }
  11261. size_t stack_size() const { return _stack_size; }
  11262. void set_stack_size(size_t size) { _stack_size = size; }
  11263. @@ -570,6 +578,7 @@ public:
  11264. void print_owned_locks() const { print_owned_locks_on(tty); }
  11265. Monitor* owned_locks() const { return _owned_locks; }
  11266. bool owns_locks() const { return owned_locks() != NULL; }
  11267. + bool owns_locks_but_redefine_classes_lock() const;
  11268. bool owns_locks_but_compiled_lock() const;
  11269. // Deadlock detection
  11270. @@ -1793,6 +1802,8 @@ class CompilerThread : public JavaThread {
  11271. CompileTask* _task;
  11272. CompileQueue* _queue;
  11273. BufferBlob* _buffer_blob;
  11274. + bool _should_bailout;
  11275. + Mutex* _compilation_mutex;
  11276. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11277. @@ -1802,12 +1813,16 @@ class CompilerThread : public JavaThread {
  11278. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11279. + bool should_bailout() const { return _should_bailout; }
  11280. + void set_should_bailout(bool b) { _should_bailout = false; }
  11281. +
  11282. bool is_Compiler_thread() const { return true; }
  11283. // Hide this compiler thread from external view.
  11284. bool is_hidden_from_external_view() const { return true; }
  11285. CompileQueue* queue() { return _queue; }
  11286. CompilerCounters* counters() { return _counters; }
  11287. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11288. // Get/set the thread's compilation environment.
  11289. ciEnv* env() { return _env; }
  11290. @@ -1862,6 +1877,7 @@ class Threads: AllStatic {
  11291. static int _number_of_threads;
  11292. static int _number_of_non_daemon_threads;
  11293. static int _return_code;
  11294. + static bool _wait_at_instrumentation_entry;
  11295. public:
  11296. // Thread management
  11297. @@ -1873,6 +1889,9 @@ class Threads: AllStatic {
  11298. static JavaThread* first() { return _thread_list; }
  11299. static void threads_do(ThreadClosure* tc);
  11300. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11301. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11302. +
  11303. // Initializes the vm and creates the vm thread
  11304. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11305. static void convert_vm_init_libraries_to_agents();
  11306. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11307. index 09e324f..d47ffef 100644
  11308. --- a/src/share/vm/runtime/vframe.cpp
  11309. +++ b/src/share/vm/runtime/vframe.cpp
  11310. @@ -253,6 +253,46 @@ methodOop interpretedVFrame::method() const {
  11311. return fr().interpreter_frame_method();
  11312. }
  11313. +// (tw) Sets interpreter frame method.
  11314. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11315. + methodOop old_method = fr().interpreter_frame_method();
  11316. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11317. + if (old_method == new_method) return;
  11318. + u_char *old_bcp = bcp();
  11319. + int old_bci = bci();
  11320. + fr().interpreter_frame_set_method(new_method);
  11321. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11322. + u_char *new_bcp = new_method->code_base() + new_bci;
  11323. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11324. +
  11325. + set_bcp(new_bcp);
  11326. +
  11327. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11328. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11329. +
  11330. + switch (code) {
  11331. + case Bytecodes::_invokevirtual :
  11332. + case Bytecodes::_invokespecial :
  11333. + case Bytecodes::_invokestatic :
  11334. + case Bytecodes::_invokeinterface: {
  11335. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11336. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11337. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11338. + break;
  11339. + }
  11340. +
  11341. + case Bytecodes::_invokedynamic: {
  11342. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11343. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11344. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11345. + break;
  11346. + }
  11347. + }
  11348. +
  11349. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11350. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11351. +}
  11352. +
  11353. StackValueCollection* interpretedVFrame::locals() const {
  11354. int length = method()->max_locals();
  11355. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11356. index badfea5..edbc5c7 100644
  11357. --- a/src/share/vm/runtime/vframe.hpp
  11358. +++ b/src/share/vm/runtime/vframe.hpp
  11359. @@ -163,6 +163,7 @@ class interpretedVFrame: public javaVFrame {
  11360. StackValueCollection* locals() const;
  11361. StackValueCollection* expressions() const;
  11362. GrowableArray<MonitorInfo*>* monitors() const;
  11363. + void set_method(methodOop method, int new_bci);
  11364. void set_locals(StackValueCollection* values) const;
  11365. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11366. index 7643670..036ab64 100644
  11367. --- a/src/share/vm/runtime/vmThread.cpp
  11368. +++ b/src/share/vm/runtime/vmThread.cpp
  11369. @@ -691,6 +691,10 @@ void VMThread::execute(VM_Operation* op) {
  11370. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11371. Thread::oops_do(f, cf);
  11372. _vm_queue->oops_do(f);
  11373. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11374. + if (_cur_vm_operation != NULL) {
  11375. + _cur_vm_operation->oops_do(f);
  11376. + }
  11377. }
  11378. //------------------------------------------------------------------------------------------------------------------
  11379. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11380. index 03f254d..c9e0efc 100644
  11381. --- a/src/share/vm/utilities/exceptions.cpp
  11382. +++ b/src/share/vm/utilities/exceptions.cpp
  11383. @@ -254,6 +254,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11384. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11385. assert(!thread->has_pending_exception(), "already has exception");
  11386. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11387. + Thread::current()->set_pretend_new_universe(false);
  11388. Handle h_exception;
  11389. // Resolve exception klass
  11390. @@ -285,6 +287,7 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11391. h_exception = Handle(thread, thread->pending_exception());
  11392. thread->clear_pending_exception();
  11393. }
  11394. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11395. return h_exception;
  11396. }
  11397. @@ -295,6 +298,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11398. Symbol* signature, JavaCallArguments *args,
  11399. Handle h_cause,
  11400. Handle h_loader, Handle h_protection_domain) {
  11401. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11402. + Thread::current()->set_pretend_new_universe(false);
  11403. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11404. // Future: object initializer should take a cause argument
  11405. @@ -317,6 +322,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11406. h_exception = Handle(thread, thread->pending_exception());
  11407. thread->clear_pending_exception();
  11408. }
  11409. +
  11410. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11411. return h_exception;
  11412. }
  11413. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11414. index 2a6d6b8..4b6927f 100644
  11415. --- a/src/share/vm/utilities/growableArray.hpp
  11416. +++ b/src/share/vm/utilities/growableArray.hpp
  11417. @@ -145,6 +145,33 @@ class GenericGrowableArray : public ResourceObj {
  11418. assert(on_stack(), "fast ResourceObj path only");
  11419. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11420. }
  11421. +
  11422. +};
  11423. +
  11424. +template<class E, class F> class Pair : public StackObj
  11425. +{
  11426. +private:
  11427. + E _left;
  11428. + F _right;
  11429. +
  11430. +public:
  11431. +
  11432. + Pair() {
  11433. +
  11434. + }
  11435. +
  11436. + Pair(E left, F right) {
  11437. + this->_left = left;
  11438. + this->_right = right;
  11439. + }
  11440. +
  11441. + E left() {
  11442. + return _left;
  11443. + }
  11444. +
  11445. + F right() {
  11446. + return _right;
  11447. + }
  11448. };
  11449. template<class E> class GrowableArray : public GenericGrowableArray {