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-jdk7u60-b09.patch 504KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382
  1. diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make
  2. index 3de1dea..8bf7f94 100644
  3. --- a/make/bsd/makefiles/gcc.make
  4. +++ b/make/bsd/makefiles/gcc.make
  5. @@ -117,7 +117,10 @@
  6. CFLAGS += -fno-rtti
  7. CFLAGS += -fno-exceptions
  8. CFLAGS += -pthread
  9. -CFLAGS += -fcheck-new
  10. +## well, strictly speaking we should check for clang not Darwin
  11. +ifneq ($(OS_VENDOR), Darwin)
  12. + CFLAGS += -fcheck-new
  13. +endif
  14. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  15. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  16. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  17. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  18. index fc19edc..d2cddd3 100644
  19. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  20. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  21. @@ -2109,6 +2109,22 @@
  22. // resolve first time through
  23. address entry;
  24. switch (bytecode()) {
  25. + case Bytecodes::_fast_agetfield : // fall through
  26. + case Bytecodes::_fast_bgetfield : // fall through
  27. + case Bytecodes::_fast_cgetfield : // fall through
  28. + case Bytecodes::_fast_dgetfield : // fall through
  29. + case Bytecodes::_fast_fgetfield : // fall through
  30. + case Bytecodes::_fast_igetfield : // fall through
  31. + case Bytecodes::_fast_lgetfield : // fall through
  32. + case Bytecodes::_fast_sgetfield : // fall through
  33. + case Bytecodes::_fast_aputfield : // fall through
  34. + case Bytecodes::_fast_bputfield : // fall through
  35. + case Bytecodes::_fast_cputfield : // fall through
  36. + case Bytecodes::_fast_dputfield : // fall through
  37. + case Bytecodes::_fast_fputfield : // fall through
  38. + case Bytecodes::_fast_iputfield : // fall through
  39. + case Bytecodes::_fast_lputfield : // fall through
  40. + case Bytecodes::_fast_sputfield : // fall through
  41. case Bytecodes::_getstatic : // fall through
  42. case Bytecodes::_putstatic : // fall through
  43. case Bytecodes::_getfield : // fall through
  44. @@ -2211,6 +2227,7 @@
  45. // Correct values of the cache and index registers are preserved.
  46. void TemplateTable::jvmti_post_field_access(Register cache,
  47. Register index,
  48. + int byte_no,
  49. bool is_static,
  50. bool has_tos) {
  51. if (JvmtiExport::can_post_field_access()) {
  52. @@ -2237,7 +2254,11 @@
  53. // cache: cache entry pointer
  54. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  55. rax, cache);
  56. - __ get_cache_and_index_at_bcp(cache, index, 1);
  57. +
  58. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  59. + __ restore_bcp();
  60. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  61. +
  62. __ bind(L1);
  63. }
  64. }
  65. @@ -2258,7 +2279,7 @@
  66. const Register flags = rax;
  67. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  68. - jvmti_post_field_access(cache, index, is_static, false);
  69. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  70. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  71. if (!is_static) pop_and_check_object(obj);
  72. @@ -2393,7 +2414,7 @@
  73. // The registers cache and index expected to be set before call.
  74. // The function may destroy various registers, just not the cache and index registers.
  75. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  76. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  77. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  78. @@ -2451,7 +2472,11 @@
  79. // rcx: jvalue object on the stack
  80. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  81. rbx, rax, rcx);
  82. - __ get_cache_and_index_at_bcp(cache, index, 1);
  83. +
  84. + // (tw) Redefinition might have occured => reresolve the cp entry.
  85. + __ restore_bcp();
  86. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  87. +
  88. __ bind(L1);
  89. }
  90. }
  91. @@ -2467,7 +2492,7 @@
  92. const Register flags = rax;
  93. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  94. - jvmti_post_field_mod(cache, index, is_static);
  95. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  96. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  97. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  98. @@ -2818,6 +2843,11 @@
  99. // rcx: cache entry pointer
  100. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  101. __ pop_ptr(rax); // restore object pointer
  102. +
  103. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  104. + __ restore_bcp();
  105. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  106. +
  107. __ bind(L1);
  108. }
  109. @@ -3008,6 +3038,26 @@
  110. __ bind(notFinal);
  111. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  112. + Label notOld;
  113. + __ movl(rax, flags);
  114. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  115. + __ jcc(Assembler::zero, notOld);
  116. +
  117. + // Need a null check here!
  118. + __ null_check(recv);
  119. +
  120. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  121. + // DCEVM: TODO: Check if we can improve performance by inlining.
  122. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  123. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  124. +
  125. + // profile this call
  126. + __ profile_final_call(rax);
  127. + __ jump_from_interpreted(method, rdx);
  128. +
  129. + __ bind(notOld);
  130. +
  131. // get receiver klass
  132. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  133. __ load_klass(rax, recv);
  134. @@ -3093,6 +3143,31 @@
  135. invokevirtual_helper(rbx, rcx, rdx);
  136. __ bind(notMethod);
  137. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  138. + //__ movl(rax, rdx);
  139. + Label notOld;
  140. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  141. + __ jcc(Assembler::zero, notOld);
  142. +
  143. + // Get receiver klass into rdx - also a null check
  144. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  145. + __ verify_oop(rdx);
  146. +
  147. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  148. + // DCEVM: TODO: Check if we can improve performance by inlining.
  149. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  150. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  151. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  152. +
  153. + // DCEVM: TODO: Check if resolved method could be null.
  154. +
  155. + // profile this call
  156. + __ profile_virtual_call(rdx, rsi, rdi);
  157. +
  158. + __ jump_from_interpreted(rbx, rdx);
  159. +
  160. + __ bind(notOld);
  161. +
  162. // Get receiver klass into rdx - also a null check
  163. __ restore_locals(); // restore rdi
  164. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  165. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  166. index 932ee97..67bb710 100644
  167. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  168. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  169. @@ -2151,6 +2151,22 @@
  170. // resolve first time through
  171. address entry;
  172. switch (bytecode()) {
  173. + case Bytecodes::_fast_agetfield : // fall through
  174. + case Bytecodes::_fast_bgetfield : // fall through
  175. + case Bytecodes::_fast_cgetfield : // fall through
  176. + case Bytecodes::_fast_dgetfield : // fall through
  177. + case Bytecodes::_fast_fgetfield : // fall through
  178. + case Bytecodes::_fast_igetfield : // fall through
  179. + case Bytecodes::_fast_lgetfield : // fall through
  180. + case Bytecodes::_fast_sgetfield : // fall through
  181. + case Bytecodes::_fast_aputfield : // fall through
  182. + case Bytecodes::_fast_bputfield : // fall through
  183. + case Bytecodes::_fast_cputfield : // fall through
  184. + case Bytecodes::_fast_dputfield : // fall through
  185. + case Bytecodes::_fast_fputfield : // fall through
  186. + case Bytecodes::_fast_iputfield : // fall through
  187. + case Bytecodes::_fast_lputfield : // fall through
  188. + case Bytecodes::_fast_sputfield : // fall through
  189. case Bytecodes::_getstatic:
  190. case Bytecodes::_putstatic:
  191. case Bytecodes::_getfield:
  192. @@ -2267,7 +2283,7 @@
  193. // The registers cache and index expected to be set before call.
  194. // Correct values of the cache and index registers are preserved.
  195. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  196. - bool is_static, bool has_tos) {
  197. + int byte_no, bool is_static, bool has_tos) {
  198. // do the JVMTI work here to avoid disturbing the register state below
  199. // We use c_rarg registers here because we want to use the register used in
  200. // the call to the VM
  201. @@ -2298,7 +2314,11 @@
  202. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  203. InterpreterRuntime::post_field_access),
  204. c_rarg1, c_rarg2, c_rarg3);
  205. - __ get_cache_and_index_at_bcp(cache, index, 1);
  206. +
  207. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  208. + __ restore_bcp();
  209. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  210. +
  211. __ bind(L1);
  212. }
  213. }
  214. @@ -2320,7 +2340,7 @@
  215. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  216. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  217. - jvmti_post_field_access(cache, index, is_static, false);
  218. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  219. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  220. if (!is_static) {
  221. @@ -2455,7 +2475,7 @@
  222. // The registers cache and index expected to be set before call.
  223. // The function may destroy various registers, just not the cache and index registers.
  224. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  225. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  226. transition(vtos, vtos);
  227. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  228. @@ -2507,7 +2527,11 @@
  229. CAST_FROM_FN_PTR(address,
  230. InterpreterRuntime::post_field_modification),
  231. c_rarg1, c_rarg2, c_rarg3);
  232. - __ get_cache_and_index_at_bcp(cache, index, 1);
  233. +
  234. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  235. + __ restore_bcp();
  236. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  237. +
  238. __ bind(L1);
  239. }
  240. }
  241. @@ -2523,7 +2547,7 @@
  242. const Register bc = c_rarg3;
  243. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  244. - jvmti_post_field_mod(cache, index, is_static);
  245. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  246. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  247. // [jk] not needed currently
  248. @@ -2837,6 +2861,11 @@
  249. InterpreterRuntime::post_field_access),
  250. c_rarg1, c_rarg2);
  251. __ pop_ptr(rax); // restore object pointer
  252. +
  253. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  254. + __ restore_bcp();
  255. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  256. +
  257. __ bind(L1);
  258. }
  259. @@ -3073,6 +3102,26 @@
  260. __ bind(notFinal);
  261. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  262. + Label notOld;
  263. + __ movl(rax, flags);
  264. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  265. + __ jcc(Assembler::zero, notOld);
  266. +
  267. + // Need a null check here!
  268. + __ null_check(recv);
  269. +
  270. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  271. + // DCEVM: TODO: Check if we can improve performance by inlining.
  272. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  273. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  274. +
  275. + // profile this call
  276. + __ profile_final_call(rax);
  277. + __ jump_from_interpreted(method, rdx);
  278. +
  279. + __ bind(notOld);
  280. +
  281. // get receiver klass
  282. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  283. __ load_klass(rax, recv);
  284. @@ -3156,6 +3205,35 @@
  285. invokevirtual_helper(rbx, rcx, rdx);
  286. __ bind(notMethod);
  287. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  288. + Label notOld;
  289. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  290. + __ jcc(Assembler::zero, notOld);
  291. +
  292. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  293. + // DCEVM: TODO: Check if we can improve performance by inlining.
  294. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  295. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  296. + // DCEVM: FIXME: What exactly should we store here?
  297. + __ push(rcx); // destroyed by Linux arguments passing conventions
  298. + __ movptr(r14, rcx);
  299. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  300. + __ pop(rcx);
  301. +
  302. + // Get receiver klass into rdx - also a null check
  303. + __ restore_locals(); // restore r14
  304. + __ load_klass(rdx, rcx);
  305. + __ verify_oop(rdx);
  306. +
  307. + // DCEVM: TODO: Check if resolved method could be null.
  308. +
  309. + // profile this call
  310. + __ profile_virtual_call(rdx, r13, r14);
  311. +
  312. + __ jump_from_interpreted(rbx, rdx);
  313. +
  314. + __ bind(notOld);
  315. +
  316. // Get receiver klass into rdx - also a null check
  317. __ restore_locals(); // restore r14
  318. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  319. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  320. index 9a8ca61..196ab25 100644
  321. --- a/src/share/vm/c1/c1_Compilation.hpp
  322. +++ b/src/share/vm/c1/c1_Compilation.hpp
  323. @@ -242,8 +242,8 @@
  324. #define BAILOUT(msg) { bailout(msg); return; }
  325. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  326. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  327. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  328. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  329. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  330. class InstructionMark: public StackObj {
  331. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  332. index e20db5d..57f37db 100644
  333. --- a/src/share/vm/ci/ciEnv.cpp
  334. +++ b/src/share/vm/ci/ciEnv.cpp
  335. @@ -1172,3 +1172,11 @@
  336. // If memory is low, we stop compiling methods.
  337. record_method_not_compilable("out of memory");
  338. }
  339. +
  340. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  341. +void ciEnv::cleanup_after_redefinition() {
  342. +
  343. + if (_factory != NULL) {
  344. + _factory->cleanup_after_redefinition();
  345. + }
  346. +}
  347. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  348. index 103e532..abe2e37 100644
  349. --- a/src/share/vm/ci/ciEnv.hpp
  350. +++ b/src/share/vm/ci/ciEnv.hpp
  351. @@ -417,6 +417,8 @@
  352. void record_failure(const char* reason);
  353. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  354. void record_out_of_memory_failure();
  355. +
  356. + void cleanup_after_redefinition();
  357. };
  358. #endif // SHARE_VM_CI_CIENV_HPP
  359. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  360. index e0ab96b..36efef4 100644
  361. --- a/src/share/vm/ci/ciObjectFactory.cpp
  362. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  363. @@ -296,6 +296,11 @@
  364. // into the table. We need to recompute our index.
  365. index = find(keyHandle(), _ci_objects);
  366. }
  367. +
  368. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  369. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  370. + return _ci_objects->at(index);
  371. + }
  372. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  373. insert(index, new_object, _ci_objects);
  374. return new_object;
  375. @@ -764,3 +769,50 @@
  376. _unloaded_instances->length(),
  377. _unloaded_klasses->length());
  378. }
  379. +
  380. +// DCEVM: Resoring the ciObject arrays after class redefinition
  381. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  382. +
  383. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  384. + oop last = NULL;
  385. + for (int j = 0; j< objects->length(); j++) {
  386. + oop o = objects->at(j)->get_oop();
  387. + if (last >= o) {
  388. + int cur_last_index = j - 1;
  389. + oop cur_last = last;
  390. + while (cur_last >= o) {
  391. +
  392. + // Swap the two objects to guarantee ordering
  393. + ciObject *tmp = objects->at(cur_last_index);
  394. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  395. + objects->at_put(cur_last_index + 1, tmp);
  396. +
  397. + // Decrement index to move one step to the left
  398. + cur_last_index--;
  399. + if (cur_last_index < 0) {
  400. + break;
  401. + }
  402. + cur_last = objects->at(cur_last_index)->get_oop();
  403. + }
  404. + } else {
  405. + assert(last < o, "out of order");
  406. + last = o;
  407. + }
  408. + }
  409. +
  410. +#ifdef ASSERT
  411. + if (CIObjectFactoryVerify) {
  412. + oop last = NULL;
  413. + for (int j = 0; j< objects->length(); j++) {
  414. + oop o = objects->at(j)->get_oop();
  415. + assert(last < o, "out of order");
  416. + last = o;
  417. + }
  418. + }
  419. +#endif // ASSERT
  420. +}
  421. +
  422. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  423. +void ciObjectFactory::cleanup_after_redefinition() {
  424. + sort_ci_objects(_ci_objects);
  425. +}
  426. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  427. index 26cc2c3..855a4ac 100644
  428. --- a/src/share/vm/ci/ciObjectFactory.hpp
  429. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  430. @@ -38,6 +38,7 @@
  431. class ciObjectFactory : public ResourceObj {
  432. friend class VMStructs;
  433. friend class ciEnv;
  434. + friend class CompileBroker;
  435. private:
  436. static volatile bool _initialized;
  437. @@ -137,6 +138,11 @@
  438. void print_contents();
  439. void print();
  440. +
  441. +private:
  442. +
  443. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  444. + void cleanup_after_redefinition();
  445. };
  446. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  447. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  448. index 2f41d2b..6e362d9 100644
  449. --- a/src/share/vm/classfile/classFileParser.cpp
  450. +++ b/src/share/vm/classfile/classFileParser.cpp
  451. @@ -795,6 +795,7 @@
  452. Handle class_loader,
  453. Handle protection_domain,
  454. Symbol* class_name,
  455. + KlassHandle old_klass,
  456. TRAPS) {
  457. ClassFileStream* cfs = stream();
  458. assert(length > 0, "only called for length>0");
  459. @@ -813,6 +814,9 @@
  460. interface_index, CHECK_(nullHandle));
  461. if (cp->tag_at(interface_index).is_klass()) {
  462. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  463. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  464. + interf = KlassHandle(THREAD, interf->newest_version());
  465. + }
  466. } else {
  467. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  468. @@ -825,6 +829,9 @@
  469. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  470. unresolved_klass, class_loader, protection_domain,
  471. false, CHECK_(nullHandle));
  472. + if (!old_klass.is_null()) {
  473. + k = k->klass_part()->newest_version();
  474. + }
  475. interf = KlassHandle(THREAD, k);
  476. }
  477. @@ -1912,6 +1919,8 @@
  478. int runtime_invisible_parameter_annotations_length = 0;
  479. u1* annotation_default = NULL;
  480. int annotation_default_length = 0;
  481. + u2 code_section_table_length;
  482. + typeArrayHandle code_section_table;
  483. // Parse code and exceptions attribute
  484. u2 method_attributes_count = cfs->get_u2_fast();
  485. @@ -2081,6 +2090,24 @@
  486. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  487. stackmap_data = typeArrayHandle(THREAD, sm);
  488. parsed_stackmap_attribute = true;
  489. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  490. + int length = code_attribute_length;
  491. + int value_count = length / sizeof(u2);
  492. + int line_count = length / 3;
  493. + if (TraceRedefineClasses >= 3) {
  494. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  495. + }
  496. + code_section_table_length = value_count;
  497. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  498. + code_section_table->set_length(value_count);
  499. +
  500. + for (int i = 0; i < value_count; ++i) {
  501. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  502. + code_section_table->short_at_put(i, value);
  503. + if (TraceRedefineClasses >= 4) {
  504. + tty->print_cr("Code section table at %d: %d", i, value);
  505. + }
  506. + }
  507. } else {
  508. // Skip unknown attributes
  509. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  510. @@ -2206,6 +2233,18 @@
  511. }
  512. #endif
  513. + // DCEVM: TODO: Get a different solution for the problem of method forward
  514. + // points and variable sized interpreter frames.
  515. + if (UseMethodForwardPoints) {
  516. + if (max_stack > MethodForwardPointsMaxStack) {
  517. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  518. + }
  519. + if (max_locals > MethodForwardPointsMaxLocals) {
  520. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  521. + }
  522. + max_stack = MethodForwardPointsMaxStack;
  523. + max_locals = MethodForwardPointsMaxLocals;
  524. + }
  525. // Fill in code attribute information
  526. m->set_max_stack(max_stack);
  527. m->set_max_locals(max_locals);
  528. @@ -2218,6 +2257,8 @@
  529. * sure that the oops can pass verification when this field is set.
  530. */
  531. m->constMethod()->set_stackmap_data(stackmap_data());
  532. +
  533. + m->constMethod()->set_code_section_table(code_section_table());
  534. // Copy byte codes
  535. m->set_code(code_start);
  536. @@ -2792,6 +2833,15 @@
  537. "Invalid Deprecated classfile attribute length %u in class file %s",
  538. attribute_length, CHECK);
  539. }
  540. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  541. + // DCEVM: Check for deleted field attribute
  542. + _field_redefinition_policy = cfs->get_u1_fast();
  543. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  544. + // DCEVM: Check for deleted static field attribute
  545. + _static_field_redefinition_policy = cfs->get_u1_fast();
  546. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  547. + // DCEVM: Check for deleted method attribute
  548. + _method_redefinition_policy = cfs->get_u1_fast();
  549. } else if (_major_version >= JAVA_1_5_VERSION) {
  550. if (tag == vmSymbols::tag_signature()) {
  551. if (attribute_length != 2) {
  552. @@ -2895,6 +2945,17 @@
  553. }
  554. k->set_inner_classes(_inner_classes());
  555. k->set_class_annotations(_annotations());
  556. +
  557. +
  558. + if (_field_redefinition_policy != 0xff) {
  559. + k->set_field_redefinition_policy(_field_redefinition_policy);
  560. + }
  561. + if (_static_field_redefinition_policy != 0xff) {
  562. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  563. + }
  564. + if (_method_redefinition_policy != 0xff) {
  565. + k->set_method_redefinition_policy(_method_redefinition_policy);
  566. + }
  567. }
  568. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  569. @@ -2918,9 +2979,126 @@
  570. }
  571. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  572. +// them in a growable array.
  573. +void ClassFileParser::findSuperSymbols(Symbol* name,
  574. + Handle class_loader,
  575. + Handle protection_domain,
  576. + KlassHandle old_klass,
  577. + GrowableArray<Symbol*> &handles,
  578. + TRAPS) {
  579. +
  580. + _cp_patches = NULL;
  581. + // So that JVMTI can cache class file in the state before retransformable agents
  582. + // have modified it
  583. + unsigned char *cached_class_file_bytes = NULL;
  584. +
  585. + ClassFileStream* cfs = stream();
  586. +
  587. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  588. +
  589. + instanceKlassHandle nullHandle;
  590. +
  591. + // Save the class file name for easier error message printing.
  592. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  593. +
  594. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  595. + // Magic value
  596. + u4 magic = cfs->get_u4_fast();
  597. + if (magic != JAVA_CLASSFILE_MAGIC) {
  598. + // Invalid class file!
  599. + return;
  600. + }
  601. +
  602. + // Version numbers
  603. + u2 minor_version = cfs->get_u2_fast();
  604. + u2 major_version = cfs->get_u2_fast();
  605. +
  606. + // Check version numbers - we check this even with verifier off
  607. + if (!is_supported_version(major_version, minor_version)) {
  608. +
  609. + // Unsupported version!
  610. + return;
  611. + }
  612. +
  613. + _major_version = major_version;
  614. + _minor_version = minor_version;
  615. +
  616. +
  617. + // Check if verification needs to be relaxed for this class file
  618. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  619. + _relax_verify = Verifier::relax_verify_for(class_loader());
  620. + _need_verify = false;
  621. +
  622. + // Constant pool
  623. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  624. + int cp_size = cp->length();
  625. +
  626. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  627. +
  628. + // Access flags
  629. + AccessFlags access_flags;
  630. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  631. +
  632. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  633. + // Set abstract bit for old class files for backward compatibility
  634. + flags |= JVM_ACC_ABSTRACT;
  635. + }
  636. + access_flags.set_flags(flags);
  637. +
  638. + // This class and superclass
  639. + instanceKlassHandle super_klass;
  640. + u2 this_class_index = cfs->get_u2_fast();
  641. + check_property(
  642. + valid_cp_range(this_class_index, cp_size) &&
  643. + cp->tag_at(this_class_index).is_unresolved_klass(),
  644. + "Invalid this class index %u in constant pool in class file %s",
  645. + this_class_index, CHECK);
  646. +
  647. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  648. + assert(class_name != NULL, "class_name can't be null");
  649. +
  650. + // Update _class_name which could be null previously to be class_name
  651. + _class_name = class_name;
  652. +
  653. + // DCEVM: DO NOT release all handles when parsing is done
  654. + {// HandleMark hm(THREAD);
  655. +
  656. + // Checks if name in class file matches requested name
  657. + if (name != NULL && class_name != name) {
  658. + return;
  659. + }
  660. +
  661. + u2 super_class_index = cfs->get_u2_fast();
  662. +
  663. + if (super_class_index != 0) {
  664. + Symbol* super_class = cp->klass_name_at(super_class_index);
  665. + handles.append(super_class);
  666. + } else {
  667. + // DCEVM: This redefinition must be for the Object class.
  668. + }
  669. +
  670. + // Interfaces
  671. + u2 itfs_len = cfs->get_u2_fast();
  672. + objArrayHandle local_interfaces;
  673. + if (itfs_len == 0) {
  674. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  675. + } else {
  676. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  677. + }
  678. +
  679. + for (int i=0; i<local_interfaces->length(); i++) {
  680. + oop o = local_interfaces->obj_at(i);
  681. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  682. + handles.append(interface_handle);
  683. + }
  684. + }
  685. +}
  686. +
  687. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  688. Handle class_loader,
  689. Handle protection_domain,
  690. + KlassHandle old_klass,
  691. KlassHandle host_klass,
  692. GrowableArray<Handle>* cp_patches,
  693. TempNewSymbol& parsed_name,
  694. @@ -2971,10 +3149,13 @@
  695. unsigned char* ptr = cfs->buffer();
  696. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  697. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  698. + Thread::current()->set_pretend_new_universe(false);
  699. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  700. &ptr, &end_ptr,
  701. &cached_class_file_bytes,
  702. &cached_class_file_length);
  703. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  704. if (ptr != cfs->buffer()) {
  705. // JVMTI agent has modified class file data.
  706. @@ -3130,7 +3311,11 @@
  707. // However, make sure it is not an array type.
  708. bool is_array = false;
  709. if (cp->tag_at(super_class_index).is_klass()) {
  710. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  711. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  712. + if (!old_klass.is_null()) {
  713. + resolved_klass = resolved_klass->klass_part()->newest_version();
  714. + }
  715. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  716. if (_need_verify)
  717. is_array = super_klass->oop_is_array();
  718. } else if (_need_verify) {
  719. @@ -3148,7 +3333,7 @@
  720. if (itfs_len == 0) {
  721. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  722. } else {
  723. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  724. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  725. }
  726. u2 java_fields_count = 0;
  727. @@ -3202,7 +3387,9 @@
  728. protection_domain,
  729. true,
  730. CHECK_(nullHandle));
  731. -
  732. + if (!old_klass.is_null()) {
  733. + k = k->klass_part()->newest_version();
  734. + }
  735. KlassHandle kh (THREAD, k);
  736. super_klass = instanceKlassHandle(THREAD, kh());
  737. }
  738. @@ -3591,6 +3778,19 @@
  739. rt = REF_NONE;
  740. } else {
  741. rt = super_klass->reference_type();
  742. +
  743. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  744. + if (name == vmSymbols::java_lang_ref_Reference()) {
  745. + rt = REF_OTHER;
  746. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  747. + rt = REF_SOFT;
  748. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  749. + rt = REF_WEAK;
  750. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  751. + rt = REF_FINAL;
  752. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  753. + rt = REF_PHANTOM;
  754. + }
  755. }
  756. // We can now create the basic klassOop for this klass
  757. @@ -3691,7 +3891,7 @@
  758. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  759. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  760. - set_precomputed_flags(this_klass);
  761. + set_precomputed_flags(this_klass, old_klass);
  762. // reinitialize modifiers, using the InnerClasses attribute
  763. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  764. @@ -3713,6 +3913,10 @@
  765. // Allocate mirror and initialize static fields
  766. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  767. +
  768. + if (rt == REF_OTHER) {
  769. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  770. + }
  771. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  772. false /* not shared class */);
  773. @@ -3856,7 +4060,7 @@
  774. }
  775. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  776. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  777. klassOop super = k->super();
  778. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  779. @@ -3864,7 +4068,9 @@
  780. if (!_has_empty_finalizer) {
  781. if (_has_finalizer ||
  782. (super != NULL && super->klass_part()->has_finalizer())) {
  783. - k->set_has_finalizer();
  784. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  785. + k->set_has_finalizer();
  786. + }
  787. }
  788. }
  789. @@ -3880,7 +4086,7 @@
  790. // Check if this klass supports the java.lang.Cloneable interface
  791. if (SystemDictionary::Cloneable_klass_loaded()) {
  792. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  793. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  794. k->set_is_cloneable();
  795. }
  796. }
  797. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  798. index 314ec5e..a35bf67 100644
  799. --- a/src/share/vm/classfile/classFileParser.hpp
  800. +++ b/src/share/vm/classfile/classFileParser.hpp
  801. @@ -64,6 +64,9 @@
  802. int _sde_length;
  803. typeArrayHandle _inner_classes;
  804. typeArrayHandle _annotations;
  805. + u1 _field_redefinition_policy;
  806. + u1 _static_field_redefinition_policy;
  807. + u1 _method_redefinition_policy;
  808. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  809. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  810. @@ -151,6 +154,7 @@
  811. Handle class_loader,
  812. Handle protection_domain,
  813. Symbol* class_name,
  814. + KlassHandle old_klass,
  815. TRAPS);
  816. // Field parsing
  817. @@ -237,7 +241,7 @@
  818. unsigned int nonstatic_oop_map_count,
  819. int* nonstatic_oop_offsets,
  820. unsigned int* nonstatic_oop_counts);
  821. - void set_precomputed_flags(instanceKlassHandle k);
  822. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  823. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  824. objArrayHandle local_ifs, TRAPS);
  825. @@ -337,7 +341,12 @@
  826. public:
  827. // Constructor
  828. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  829. + ClassFileParser(ClassFileStream* st) {
  830. + set_stream(st);
  831. + _field_redefinition_policy = 0xff;
  832. + _static_field_redefinition_policy = 0xff;
  833. + _method_redefinition_policy = 0xff;
  834. + }
  835. // Parse .class file and return new klassOop. The klassOop is not hooked up
  836. // to the system dictionary or any other structures, so a .class file can
  837. @@ -349,21 +358,33 @@
  838. instanceKlassHandle parseClassFile(Symbol* name,
  839. Handle class_loader,
  840. Handle protection_domain,
  841. + KlassHandle old_klass,
  842. TempNewSymbol& parsed_name,
  843. bool verify,
  844. TRAPS) {
  845. KlassHandle no_host_klass;
  846. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  847. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  848. }
  849. instanceKlassHandle parseClassFile(Symbol* name,
  850. Handle class_loader,
  851. Handle protection_domain,
  852. + KlassHandle old_klass,
  853. KlassHandle host_klass,
  854. GrowableArray<Handle>* cp_patches,
  855. TempNewSymbol& parsed_name,
  856. bool verify,
  857. TRAPS);
  858. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  859. +
  860. + // DCEVM: Creates symbol handles for the super class and the interfaces
  861. + void findSuperSymbols(Symbol* name,
  862. + Handle class_loader,
  863. + Handle protection_domain,
  864. + KlassHandle old_klass,
  865. + GrowableArray<Symbol*> &handles,
  866. + TRAPS);
  867. +
  868. // Verifier checks
  869. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  870. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  871. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  872. index a2e61a4..450e19f 100644
  873. --- a/src/share/vm/classfile/classLoader.cpp
  874. +++ b/src/share/vm/classfile/classLoader.cpp
  875. @@ -915,6 +915,7 @@
  876. instanceKlassHandle result = parser.parseClassFile(h_name,
  877. class_loader,
  878. protection_domain,
  879. + KlassHandle(),
  880. parsed_name,
  881. false,
  882. CHECK_(h));
  883. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  884. index 78e76cc..ee21f3a 100644
  885. --- a/src/share/vm/classfile/dictionary.cpp
  886. +++ b/src/share/vm/classfile/dictionary.cpp
  887. @@ -326,6 +326,21 @@
  888. }
  889. }
  890. +
  891. +// DCEVM: Just the classes from defining class loaders
  892. +void Dictionary::classes_do(ObjectClosure *closure) {
  893. + for (int index = 0; index < table_size(); index++) {
  894. + for (DictionaryEntry* probe = bucket(index);
  895. + probe != NULL;
  896. + probe = probe->next()) {
  897. + klassOop k = probe->klass();
  898. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  899. + closure->do_object(k);
  900. + }
  901. + }
  902. + }
  903. +}
  904. +
  905. // Added for initialize_itable_for_klass to handle exceptions
  906. // Just the classes from defining class loaders
  907. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  908. @@ -433,6 +448,33 @@
  909. add_entry(index, entry);
  910. }
  911. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  912. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  913. +
  914. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  915. + bool found = false;
  916. + for (int index = 0; index < table_size(); index++) {
  917. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  918. + if (entry->klass() == old_class()) {
  919. + entry->set_literal(k());
  920. + found = true;
  921. + }
  922. + }
  923. + }
  924. +
  925. + return found;
  926. +}
  927. +
  928. +// DCEVM: Undo previous updates to the system dictionary
  929. +void Dictionary::rollback_redefinition() {
  930. + for (int index = 0; index < table_size(); index++) {
  931. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  932. + if (entry->klass()->klass_part()->is_redefining()) {
  933. + entry->set_literal(entry->klass()->klass_part()->old_version());
  934. + }
  935. + }
  936. + }
  937. +}
  938. // This routine does not lock the system dictionary.
  939. //
  940. @@ -459,12 +501,22 @@
  941. return NULL;
  942. }
  943. +// DCEVM: return old version if we are not in the new universe?
  944. +klassOop Dictionary::intercept_for_version(klassOop k) {
  945. + if (k == NULL) return k;
  946. +
  947. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  948. + return k->klass_part()->old_version();
  949. + }
  950. +
  951. + return k;
  952. +}
  953. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  954. Handle loader, Handle protection_domain, TRAPS) {
  955. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  956. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  957. - return entry->klass();
  958. + return intercept_for_version(entry->klass());
  959. } else {
  960. return NULL;
  961. }
  962. @@ -477,7 +529,7 @@
  963. assert (index == index_for(name, loader), "incorrect index?");
  964. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  965. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  966. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  967. }
  968. @@ -489,7 +541,7 @@
  969. assert (index == index_for(name, Handle()), "incorrect index?");
  970. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  971. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  972. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  973. }
  974. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  975. index bd33760..186d0eb 100644
  976. --- a/src/share/vm/classfile/dictionary.hpp
  977. +++ b/src/share/vm/classfile/dictionary.hpp
  978. @@ -73,6 +73,10 @@
  979. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  980. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  981. +
  982. + void rollback_redefinition();
  983. +
  984. klassOop find_class(int index, unsigned int hash,
  985. Symbol* name, Handle loader);
  986. @@ -89,6 +93,7 @@
  987. void classes_do(void f(klassOop, TRAPS), TRAPS);
  988. void classes_do(void f(klassOop, oop));
  989. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  990. + void classes_do(ObjectClosure *closure);
  991. void methods_do(void f(methodOop));
  992. @@ -105,6 +110,7 @@
  993. bool do_unloading(BoolObjectClosure* is_alive);
  994. // Protection domains
  995. + static klassOop intercept_for_version(klassOop k);
  996. klassOop find(int index, unsigned int hash, Symbol* name,
  997. Handle loader, Handle protection_domain, TRAPS);
  998. bool is_valid_protection_domain(int index, unsigned int hash,
  999. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  1000. index 7dd5f1b..9c7d8eb 100644
  1001. --- a/src/share/vm/classfile/javaClasses.cpp
  1002. +++ b/src/share/vm/classfile/javaClasses.cpp
  1003. @@ -1798,7 +1798,7 @@
  1004. klassOop klass = SystemDictionary::reflect_Method_klass();
  1005. // This class is eagerly initialized during VM initialization, since we keep a refence
  1006. // to one of the methods
  1007. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1008. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1009. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1010. }
  1011. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1012. index 36d1cec..a6de98e 100644
  1013. --- a/src/share/vm/classfile/javaClasses.hpp
  1014. +++ b/src/share/vm/classfile/javaClasses.hpp
  1015. @@ -213,7 +213,6 @@
  1016. class java_lang_Class : AllStatic {
  1017. friend class VMStructs;
  1018. -
  1019. private:
  1020. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1021. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1022. index 8650cd9..965cce2 100644
  1023. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1024. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1025. @@ -449,7 +449,7 @@
  1026. if (k != NULL) {
  1027. // We found the class in the system dictionary, so we should
  1028. // make sure that the klassOop matches what we already have.
  1029. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1030. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1031. } else {
  1032. // If we don't find the class in the system dictionary, it
  1033. // has to be in the placeholders table.
  1034. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1035. index d01b2c4..1ad80f7 100644
  1036. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1037. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1038. @@ -106,7 +106,7 @@
  1039. klassOop klass() { return literal(); }
  1040. klassOop* klass_addr() { return literal_addr(); }
  1041. - void set_klass(klassOop k) { set_literal(k); }
  1042. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1043. LoaderConstraintEntry* next() {
  1044. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1045. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1046. index 4899d32..365aeda 100644
  1047. --- a/src/share/vm/classfile/systemDictionary.cpp
  1048. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1049. @@ -157,6 +157,7 @@
  1050. // can return a null klass
  1051. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1052. }
  1053. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1054. return klass;
  1055. }
  1056. @@ -199,7 +200,8 @@
  1057. // Forwards to resolve_instance_class_or_null
  1058. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1059. - assert(!THREAD->is_Compiler_thread(),
  1060. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1061. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1062. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1063. class_name->as_C_string(),
  1064. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1065. @@ -961,6 +963,7 @@
  1066. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1067. class_loader,
  1068. protection_domain,
  1069. + KlassHandle(),
  1070. host_klass,
  1071. cp_patches,
  1072. parsed_name,
  1073. @@ -1022,7 +1025,14 @@
  1074. Handle protection_domain,
  1075. ClassFileStream* st,
  1076. bool verify,
  1077. + KlassHandle old_class,
  1078. TRAPS) {
  1079. + bool redefine_classes_locked = false;
  1080. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1081. + Thread::current()->redefine_classes_mutex()->lock();
  1082. + redefine_classes_locked = true;
  1083. + }
  1084. +
  1085. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1086. // or all classloaders with UnsyncloadClass do not acquire lock here
  1087. bool DoObjectLock = true;
  1088. @@ -1050,9 +1060,14 @@
  1089. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1090. class_loader,
  1091. protection_domain,
  1092. + old_class,
  1093. parsed_name,
  1094. verify,
  1095. THREAD);
  1096. + if (!old_class.is_null() && !k.is_null()) {
  1097. + k->set_redefining(true);
  1098. + k->set_old_version(old_class());
  1099. + }
  1100. const char* pkg = "java/";
  1101. if (!HAS_PENDING_EXCEPTION &&
  1102. @@ -1087,11 +1102,16 @@
  1103. // Add class just loaded
  1104. // If a class loader supports parallel classloading handle parallel define requests
  1105. // find_or_define_instance_class may return a different instanceKlass
  1106. - if (is_parallelCapable(class_loader)) {
  1107. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1108. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1109. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1110. } else {
  1111. - define_instance_class(k, THREAD);
  1112. + define_instance_class(k, old_class, THREAD);
  1113. }
  1114. + }
  1115. +
  1116. + if (redefine_classes_locked) {
  1117. + Thread::current()->redefine_classes_mutex()->unlock();
  1118. }
  1119. // If parsing the class file or define_instance_class failed, we
  1120. @@ -1122,7 +1142,7 @@
  1121. MutexLocker mu(SystemDictionary_lock, THREAD);
  1122. klassOop check = find_class(parsed_name, class_loader);
  1123. - assert(check == k(), "should be present in the dictionary");
  1124. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1125. klassOop check2 = find_class(h_name, h_loader);
  1126. assert(check == check2, "name inconsistancy in SystemDictionary");
  1127. @@ -1349,7 +1369,11 @@
  1128. }
  1129. }
  1130. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1131. +void SystemDictionary::rollback_redefinition() {
  1132. + dictionary()->rollback_redefinition();
  1133. +}
  1134. +
  1135. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1136. Handle class_loader_h(THREAD, k->class_loader());
  1137. @@ -1376,13 +1400,23 @@
  1138. Symbol* name_h = k->name();
  1139. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1140. int d_index = dictionary()->hash_to_index(d_hash);
  1141. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1142. +
  1143. + // DCEVM: Update version of the klassOop in the system dictionary
  1144. + // TODO: Check for thread safety!
  1145. + if (!old_class.is_null()) {
  1146. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1147. + assert (ok, "must have found old class and updated!");
  1148. + }
  1149. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1150. +
  1151. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1152. // Register class just loaded with class loader (placed in Vector)
  1153. // Note we do this before updating the dictionary, as this can
  1154. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1155. // class in the dictionary and will not update the class hierarchy).
  1156. - if (k->class_loader() != NULL) {
  1157. + // (tw) Only register if not redefining a class.
  1158. + if (k->class_loader() != NULL && old_class.is_null()) {
  1159. methodHandle m(THREAD, Universe::loader_addClass_method());
  1160. JavaValue result(T_VOID);
  1161. JavaCallArguments args(class_loader_h);
  1162. @@ -1408,8 +1442,9 @@
  1163. }
  1164. k->eager_initialize(THREAD);
  1165. + // (tw) Only notify jvmti if not redefining a class.
  1166. // notify jvmti
  1167. - if (JvmtiExport::should_post_class_load()) {
  1168. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1169. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1170. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1171. @@ -1482,7 +1517,7 @@
  1172. }
  1173. }
  1174. - define_instance_class(k, THREAD);
  1175. + define_instance_class(k, KlassHandle(), THREAD);
  1176. Handle linkage_exception = Handle(); // null handle
  1177. @@ -1613,6 +1648,14 @@
  1178. Universe::flush_dependents_on(k);
  1179. }
  1180. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1181. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1182. + assert(k.not_null(), "just checking");
  1183. +
  1184. + k->remove_from_sibling_list();
  1185. +
  1186. + // TODO: Remove from interfaces.
  1187. +}
  1188. // ----------------------------------------------------------------------------
  1189. // GC support
  1190. @@ -1702,6 +1745,24 @@
  1191. }
  1192. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1193. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1194. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1195. + f->do_oop((oop*) &_well_known_klasses[k]);
  1196. + }
  1197. +
  1198. + {
  1199. + for (int i = 0; i < T_VOID+1; i++) {
  1200. + if (_box_klasses[i] != NULL) {
  1201. + assert(i >= T_BOOLEAN, "checking");
  1202. + f->do_oop((oop*) &_box_klasses[i]);
  1203. + }
  1204. + }
  1205. + }
  1206. +
  1207. + // TODO: Check if we need to call FilterFieldsMap
  1208. +}
  1209. +
  1210. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1211. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1212. f->do_oop((oop*) &_well_known_klasses[k]);
  1213. @@ -1732,6 +1793,11 @@
  1214. // Don't iterate over placeholders
  1215. void SystemDictionary::classes_do(void f(klassOop)) {
  1216. dictionary()->classes_do(f);
  1217. +}
  1218. +
  1219. +// (tw) Iterate over all classes in the dictionary.
  1220. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1221. + dictionary()->classes_do(closure);
  1222. }
  1223. // Added for initialize_itable_for_klass
  1224. @@ -1870,7 +1936,9 @@
  1225. // Preload ref klasses and set reference types
  1226. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1227. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1228. +
  1229. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1230. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1231. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1232. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1233. @@ -1956,7 +2024,11 @@
  1234. // also holds array classes
  1235. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1236. - if ((defining == true) || (k() != check)) {
  1237. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1238. + ResourceMark rm(Thread::current());
  1239. + tty->print_cr("(%d / %d) (%s/%s)", k->revision_number(), check->klass_part()->revision_number(), k->name()->as_C_string(), check->klass_part()->name()->as_C_string());
  1240. + k()->print();
  1241. + check->print();
  1242. linkage_error = "loader (instance of %s): attempted duplicate class "
  1243. "definition for name: \"%s\"";
  1244. } else {
  1245. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1246. index 324d53d..0c600ae 100644
  1247. --- a/src/share/vm/classfile/systemDictionary.hpp
  1248. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1249. @@ -269,7 +269,7 @@
  1250. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1251. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1252. Handle protection_domain,
  1253. - ClassFileStream* st, bool verify, TRAPS);
  1254. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1255. // Lookup an already loaded class. If not found NULL is returned.
  1256. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1257. @@ -310,6 +310,8 @@
  1258. // Iterate over all klasses in dictionary
  1259. // Just the classes from defining class loaders
  1260. static void classes_do(void f(klassOop));
  1261. + static void classes_do(ObjectClosure *closure);
  1262. + static void preloaded_classes_do(OopClosure *closure);
  1263. // Added for initialize_itable_for_klass to handle exceptions
  1264. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1265. // All classes, and their class loaders
  1266. @@ -415,6 +417,8 @@
  1267. int limit = (int)end_id + 1;
  1268. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1269. }
  1270. +
  1271. + static void rollback_redefinition();
  1272. public:
  1273. #define WK_KLASS_DECLARE(name, symbol, option) \
  1274. @@ -597,11 +601,11 @@
  1275. // after waiting, but before reentering SystemDictionary_lock
  1276. // to preserve lock order semantics.
  1277. static void double_lock_wait(Handle lockObject, TRAPS);
  1278. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1279. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1280. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1281. Handle class_loader,
  1282. instanceKlassHandle k, TRAPS);
  1283. - static instanceKlassHandle load_shared_class(Symbol* class_name,
  1284. + static instanceKlassHandle load_shared_class(Symbol* class_name, // after waiting, but before reentering SystemDictionary_lock,
  1285. Handle class_loader, TRAPS);
  1286. static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
  1287. Handle class_loader, TRAPS);
  1288. @@ -616,12 +620,16 @@
  1289. // Setup link to hierarchy
  1290. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1291. +public:
  1292. + // Remove link to hierarchy
  1293. + static void remove_from_hierarchy(instanceKlassHandle k);
  1294. +
  1295. +private:
  1296. // event based tracing
  1297. static void post_class_load_event(const Ticks& start_time, instanceKlassHandle k,
  1298. Handle initiating_loader);
  1299. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1300. -private:
  1301. // We pass in the hashtable index so we can calculate it outside of
  1302. // the SystemDictionary_lock.
  1303. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1304. index da188bb..53455df 100644
  1305. --- a/src/share/vm/classfile/verifier.cpp
  1306. +++ b/src/share/vm/classfile/verifier.cpp
  1307. @@ -106,7 +106,7 @@
  1308. return !need_verify;
  1309. }
  1310. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1311. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1312. HandleMark hm;
  1313. ResourceMark rm(THREAD);
  1314. @@ -117,7 +117,8 @@
  1315. const char* klassName = klass->external_name();
  1316. bool can_failover = FailOverToOldVerifier &&
  1317. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1318. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1319. + may_use_old_verifier;
  1320. // If the class should be verified, first see if we can use the split
  1321. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1322. @@ -138,6 +139,7 @@
  1323. tty->print_cr(
  1324. "Fail over class verification to old verifier for: %s", klassName);
  1325. }
  1326. + assert(may_use_old_verifier, "");
  1327. exception_name = inference_verify(
  1328. klass, message_buffer, message_buffer_len, THREAD);
  1329. }
  1330. @@ -145,6 +147,7 @@
  1331. exception_message = split_verifier.exception_message();
  1332. }
  1333. } else {
  1334. + assert(may_use_old_verifier, "");
  1335. exception_name = inference_verify(
  1336. klass, message_buffer, message_buffer_len, THREAD);
  1337. }
  1338. @@ -159,6 +162,9 @@
  1339. }
  1340. tty->print_cr("End class verification for: %s", klassName);
  1341. }
  1342. + } else if (TraceClassInitialization) {
  1343. + // (tw) Output not verified classes
  1344. + tty->print_cr("Class %s was not verified", klassName);
  1345. }
  1346. if (HAS_PENDING_EXCEPTION) {
  1347. @@ -210,7 +216,7 @@
  1348. // NOTE: this is called too early in the bootstrapping process to be
  1349. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1350. (refl_magic_klass == NULL ||
  1351. - !klass->is_subtype_of(refl_magic_klass) ||
  1352. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1353. VerifyReflectionBytecodes)
  1354. );
  1355. }
  1356. @@ -517,7 +523,7 @@
  1357. ClassVerifier::ClassVerifier(
  1358. instanceKlassHandle klass, TRAPS)
  1359. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1360. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1361. _this_type = VerificationType::reference_type(klass->name());
  1362. // Create list to hold symbols in reference area.
  1363. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1364. @@ -547,7 +553,7 @@
  1365. _klass->external_name());
  1366. }
  1367. - objArrayHandle methods(THREAD, _klass->methods());
  1368. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1369. int num_methods = methods->length();
  1370. for (int index = 0; index < num_methods; index++) {
  1371. @@ -2444,7 +2450,10 @@
  1372. VerificationType stack_object_type =
  1373. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1374. if (current_type() != stack_object_type) {
  1375. - assert(cp->cache() == NULL, "not rewritten yet");
  1376. +
  1377. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1378. + //assert(cp->cache() == NULL, "not rewritten yet");
  1379. +
  1380. Symbol* ref_class_name =
  1381. cp->klass_name_at(cp->klass_ref_index_at(index));
  1382. // See the comments in verify_field_instructions() for
  1383. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1384. index 4457f4a..b1b96f2 100644
  1385. --- a/src/share/vm/classfile/verifier.hpp
  1386. +++ b/src/share/vm/classfile/verifier.hpp
  1387. @@ -47,7 +47,7 @@
  1388. * Otherwise, no exception is thrown and the return indicates the
  1389. * error.
  1390. */
  1391. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1392. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1393. // Return false if the class is loaded by the bootstrap loader,
  1394. // or if defineClass was called requesting skipping verification
  1395. @@ -256,7 +256,10 @@
  1396. ErrorContext _error_context; // contains information about an error
  1397. +public:
  1398. void verify_method(methodHandle method, TRAPS);
  1399. +
  1400. +private:
  1401. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1402. void verify_exception_handler_table(u4 code_length, char* code_data,
  1403. int& min, int& max, TRAPS);
  1404. @@ -329,6 +332,7 @@
  1405. VerificationType object_type() const;
  1406. + instanceKlassHandle _klass_to_verify;
  1407. instanceKlassHandle _klass; // the class being verified
  1408. methodHandle _method; // current method being verified
  1409. VerificationType _this_type; // the verification type of the current class
  1410. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1411. index 5b773da..b20086b 100644
  1412. --- a/src/share/vm/classfile/vmSymbols.hpp
  1413. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1414. @@ -138,6 +138,10 @@
  1415. template(tag_annotation_default, "AnnotationDefault") \
  1416. template(tag_enclosing_method, "EnclosingMethod") \
  1417. template(tag_bootstrap_methods, "BootstrapMethods") \
  1418. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1419. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1420. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1421. + template(tag_code_sections, "CodeSections") \
  1422. \
  1423. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1424. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1425. @@ -379,6 +383,10 @@
  1426. template(oop_size_name, "oop_size") \
  1427. template(static_oop_field_count_name, "static_oop_field_count") \
  1428. \
  1429. + /* mutator in case of class redefinition */ \
  1430. + template(static_transformer_name, "$staticTransformer") \
  1431. + template(transformer_name, "$transformer") \
  1432. + \
  1433. /* non-intrinsic name/signature pairs: */ \
  1434. template(register_method_name, "register") \
  1435. do_alias(register_method_signature, object_void_signature) \
  1436. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1437. index 0feca89..cfa1958 100644
  1438. --- a/src/share/vm/compiler/compileBroker.cpp
  1439. +++ b/src/share/vm/compiler/compileBroker.cpp
  1440. @@ -1181,6 +1181,14 @@
  1441. int comp_level,
  1442. methodHandle hot_method, int hot_count,
  1443. const char* comment, Thread* THREAD) {
  1444. + JavaThread* thread = JavaThread::current();
  1445. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1446. + return NULL; // FIXME: DCEVM: should we do something else?
  1447. + }
  1448. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1449. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1450. + }
  1451. +
  1452. // make sure arguments make sense
  1453. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1454. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1455. @@ -1260,6 +1268,7 @@
  1456. }
  1457. // RedefineClasses() has replaced this method; just return
  1458. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1459. if (method->is_old()) {
  1460. return NULL;
  1461. }
  1462. @@ -1592,6 +1601,8 @@
  1463. // Never compile a method if breakpoints are present in it
  1464. if (method()->number_of_breakpoints() == 0) {
  1465. + thread->compilation_mutex()->lock();
  1466. + thread->set_should_bailout(false);
  1467. // Compile the method.
  1468. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1469. #ifdef COMPILER1
  1470. @@ -1615,6 +1626,7 @@
  1471. // After compilation is disabled, remove remaining methods from queue
  1472. method->clear_queued_for_compilation();
  1473. }
  1474. + thread->compilation_mutex()->unlock();
  1475. }
  1476. }
  1477. }
  1478. @@ -2164,3 +2176,15 @@
  1479. st->cr();
  1480. #endif
  1481. }
  1482. +
  1483. +// (tw) Clean up compiler interface after a class redefinition step
  1484. +void CompileBroker::cleanup_after_redefinition() {
  1485. + int num_threads = _method_threads->length();
  1486. +
  1487. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1488. + for (int i=0; i<num_threads; i++) {
  1489. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1490. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1491. + }
  1492. + }
  1493. +}
  1494. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1495. index 29f2b22..37989d1 100644
  1496. --- a/src/share/vm/compiler/compileBroker.hpp
  1497. +++ b/src/share/vm/compiler/compileBroker.hpp
  1498. @@ -408,6 +408,7 @@
  1499. static void print_compiler_threads_on(outputStream* st);
  1500. + static void cleanup_after_redefinition();
  1501. static int get_total_compile_count() { return _total_compile_count; }
  1502. static int get_total_bailout_count() { return _total_bailout_count; }
  1503. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1504. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1505. index b0c9ec8..b3298e0 100644
  1506. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1507. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1508. @@ -162,6 +162,13 @@
  1509. }
  1510. }
  1511. +
  1512. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1513. + CompactPoint* cp, HeapWord* compact_top) {
  1514. + ShouldNotReachHere();
  1515. + return NULL;
  1516. +}
  1517. +
  1518. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1519. // update the block offset table. Removed initialize_threshold call because
  1520. // CFLS does not use a block offset array for contiguous spaces.
  1521. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1522. index 3b7bb9a..de7e54b 100644
  1523. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1524. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1525. @@ -149,6 +149,7 @@
  1526. // Support for compacting cms
  1527. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1528. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1529. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1530. // Initialization helpers.
  1531. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1532. index 29841d8..a13a35d 100644
  1533. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1534. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1535. @@ -32,6 +32,8 @@
  1536. #include "oops/objArrayKlass.inline.hpp"
  1537. #include "oops/oop.inline.hpp"
  1538. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1539. +
  1540. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1541. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1542. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1543. @@ -357,3 +359,86 @@
  1544. }
  1545. #endif
  1546. +
  1547. +// (tw) Copy the rescued objects to their destination address after compaction.
  1548. +void MarkSweep::copy_rescued_objects_back() {
  1549. +
  1550. + if (_rescued_oops != NULL) {
  1551. +
  1552. + for (int i=0; i<_rescued_oops->length(); i++) {
  1553. + oop rescued_obj = _rescued_oops->at(i);
  1554. +
  1555. + int size = rescued_obj->size();
  1556. + oop new_obj = rescued_obj->forwardee();
  1557. +
  1558. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1559. + MarkSweep::update_fields(rescued_obj, new_obj);
  1560. + } else {
  1561. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1562. + }
  1563. +
  1564. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1565. +
  1566. + new_obj->init_mark();
  1567. + assert(new_obj->is_oop(), "must be a valid oop");
  1568. + }
  1569. + _rescued_oops->clear();
  1570. + _rescued_oops = NULL;
  1571. + }
  1572. +}
  1573. +
  1574. +// (tw) Update instances of a class whose fields changed.
  1575. +void MarkSweep::update_fields(oop q, oop new_location) {
  1576. +
  1577. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1578. +
  1579. + klassOop old_klass_oop = q->klass();
  1580. + klassOop new_klass_oop = q->blueprint()->new_version();
  1581. +
  1582. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1583. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1584. +
  1585. + int size = q->size_given_klass(old_klass);
  1586. + int new_size = q->size_given_klass(new_klass);
  1587. +
  1588. + oop tmp_obj = q;
  1589. +
  1590. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1591. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1592. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1593. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1594. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1595. + }
  1596. + }
  1597. +
  1598. + int *cur = new_klass_oop->klass_part()->update_information();
  1599. +
  1600. + tmp_obj->set_klass_no_check(new_klass_oop);
  1601. +
  1602. + if (cur == NULL) {
  1603. + assert(size == new_size, "just checking");
  1604. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1605. + } else {
  1606. + int destOffset = 0;
  1607. + while (*cur != 0) {
  1608. + if (*cur > 0) {
  1609. + int size = *cur;
  1610. + cur++;
  1611. + int offset = *cur;
  1612. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1613. + destOffset += size;
  1614. + cur++;
  1615. + } else {
  1616. + assert(*cur < 0, "");
  1617. + int skip = -*cur;
  1618. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1619. + destOffset += skip;
  1620. + cur++;
  1621. + }
  1622. + }
  1623. + }
  1624. +
  1625. + if (tmp_obj != q) {
  1626. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1627. + }
  1628. +}
  1629. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1630. index eb8252c..b96a677 100644
  1631. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1632. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1633. @@ -117,7 +117,11 @@
  1634. friend class AdjustPointerClosure;
  1635. friend class KeepAliveClosure;
  1636. friend class VM_MarkSweep;
  1637. + friend class GenMarkSweep;
  1638. friend void marksweep_init();
  1639. +
  1640. +public:
  1641. + static GrowableArray<oop>* _rescued_oops;
  1642. //
  1643. // Vars
  1644. @@ -208,6 +212,8 @@
  1645. template <class T> static inline void mark_and_push(T* p);
  1646. static inline void push_objarray(oop obj, size_t index);
  1647. + static void copy_rescued_objects_back();
  1648. + static void update_fields(oop q, oop new_location);
  1649. static void follow_stack(); // Empty marking stack.
  1650. static void preserve_mark(oop p, markOop mark);
  1651. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1652. index 1a1af1b..94972f0 100644
  1653. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1654. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1655. @@ -402,7 +402,7 @@
  1656. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1657. assert(h_exception->is_oop(), "just checking");
  1658. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1659. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1660. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1661. if (ExitVMOnVerifyError) vm_exit(-1);
  1662. ShouldNotReachHere();
  1663. }
  1664. @@ -656,6 +656,82 @@
  1665. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1666. IRT_END
  1667. +// (tw) Correctly resolve method when running old code.
  1668. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1669. + {
  1670. + MonitorLockerEx ml(RedefinitionSync_lock);
  1671. + while (Threads::wait_at_instrumentation_entry()) {
  1672. + ml.wait();
  1673. + }
  1674. + }
  1675. + frame f = last_frame(thread);
  1676. + methodOop m = f.interpreter_frame_method();
  1677. + methodOop forward_method = m->forward_method();
  1678. + if (forward_method != NULL) {
  1679. + int bci = f.interpreter_frame_bci();
  1680. +
  1681. + if (TraceRedefineClasses >= 3) {
  1682. + tty->print_cr("Executing NOP in method %s at bci %d %d", m->name()->as_C_string(), bci, m->is_in_code_section(bci + 1));
  1683. + }
  1684. +
  1685. + int next_bci = bci - 1;
  1686. + // First try bci before NOP.
  1687. + if (!m->is_in_code_section(next_bci)) {
  1688. + // Try bci after NOP.
  1689. + next_bci = bci + 1;
  1690. + if (!m->is_in_code_section(next_bci)) return;
  1691. + }
  1692. +
  1693. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1694. + if (TraceRedefineClasses >= 2) {
  1695. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1696. + }
  1697. + RegisterMap reg_map(thread);
  1698. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1699. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1700. + iframe->set_method(forward_method, new_bci - 1);
  1701. + }
  1702. +IRT_END
  1703. +
  1704. +// (tw) Correctly resolve method when running old code.
  1705. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1706. + // extract receiver from the outgoing argument list if necessary
  1707. + Handle receiver(thread, receiverOop);
  1708. +
  1709. + // TODO: Check for invokeinterface!
  1710. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1711. +
  1712. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1713. + klassOop klass = receiverOop->klass();
  1714. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1715. + klass = klass->klass_part()->old_version();
  1716. + }
  1717. +
  1718. + // TODO: Check for correctness if different vtable indices in different versions?
  1719. +
  1720. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1721. + thread->set_vm_result(method);
  1722. +IRT_END
  1723. +
  1724. +// Correctly resolve interface method when running old code.
  1725. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1726. +
  1727. + // extract receiver from the outgoing argument list if necessary
  1728. + Handle receiver(thread, receiverOop);
  1729. +
  1730. + // TODO: Check for invokeinterface!
  1731. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1732. +
  1733. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1734. + klassOop klass = receiverOop->klass();
  1735. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1736. + klass = klass->klass_part()->old_version();
  1737. + }
  1738. +
  1739. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1740. + thread->set_vm_result(method);
  1741. +IRT_END
  1742. +
  1743. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1744. // extract receiver from the outgoing argument list if necessary
  1745. Handle receiver(thread, NULL);
  1746. @@ -684,6 +760,10 @@
  1747. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1748. int retry_count = 0;
  1749. while (info.resolved_method()->is_old()) {
  1750. + // (tw) If we are executing an old method, this is OK!
  1751. + if (method(thread)->is_old()) {
  1752. + break;
  1753. + }
  1754. // It is very unlikely that method is redefined more than 100 times
  1755. // in the middle of resolve. If it is looping here more than 100 times
  1756. // means then there could be a bug here.
  1757. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1758. index 6d5f13a..50fa219 100644
  1759. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1760. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1761. @@ -141,6 +141,9 @@
  1762. static void post_method_entry(JavaThread *thread);
  1763. static void post_method_exit (JavaThread *thread);
  1764. static int interpreter_contains(address pc);
  1765. + static void forward_method(JavaThread *thread);
  1766. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1767. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1768. // Native signature handlers
  1769. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1770. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1771. index b17f405..6acf287 100644
  1772. --- a/src/share/vm/interpreter/linkResolver.cpp
  1773. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1774. @@ -153,8 +153,8 @@
  1775. // Klass resolution
  1776. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1777. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1778. - sel_klass->as_klassOop(),
  1779. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1780. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1781. true)) {
  1782. ResourceMark rm(THREAD);
  1783. Exceptions::fthrow(
  1784. @@ -338,7 +338,7 @@
  1785. // We'll check for the method name first, as that's most likely
  1786. // to be false (so we'll short-circuit out of these tests).
  1787. if (sel_method->name() == vmSymbols::clone_name() &&
  1788. - sel_klass() == SystemDictionary::Object_klass() &&
  1789. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1790. resolved_klass->oop_is_array()) {
  1791. // We need to change "protected" to "public".
  1792. assert(flags.is_protected(), "clone not protected?");
  1793. @@ -404,6 +404,156 @@
  1794. }
  1795. }
  1796. +
  1797. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1798. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1799. +
  1800. + // Interface method lookup?
  1801. + if (is_interface) {
  1802. +
  1803. + // lookup method in this interface or its super, java.lang.Object
  1804. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1805. +
  1806. + if (resolved_method.is_null()) {
  1807. + // lookup method in all the super-interfaces
  1808. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1809. + }
  1810. +
  1811. + // Other methods
  1812. + } else {
  1813. + Handle nested_exception;
  1814. +
  1815. + // 2. lookup method in resolved klass and its super klasses
  1816. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1817. +
  1818. + if (resolved_method.is_null()) { // not found in the class hierarchy
  1819. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1820. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1821. +
  1822. + if (resolved_method.is_null()) {
  1823. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1824. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1825. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1826. + if (HAS_PENDING_EXCEPTION) {
  1827. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1828. + CLEAR_PENDING_EXCEPTION;
  1829. + }
  1830. + }
  1831. + }
  1832. + }
  1833. +}
  1834. +
  1835. +void LinkResolver::lookup_correct_field(fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static) {
  1836. +
  1837. + // First attempt unversioned
  1838. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1839. +
  1840. +
  1841. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1842. +
  1843. + // 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).
  1844. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1845. + if (is_static) {
  1846. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1847. + }
  1848. +
  1849. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1850. +
  1851. + if (redefinition_policy != Klass::DynamicCheck) {
  1852. +
  1853. + if (redefinition_policy == Klass::AccessOldMembers) {
  1854. + // Forget looked up fields
  1855. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1856. + }
  1857. +
  1858. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1859. +
  1860. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1861. +
  1862. + // Select correct version for resolved klass.
  1863. + find_correct_resolved_klass(resolved_klass, current_klass);
  1864. +
  1865. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1866. +
  1867. + // FIXME: idubrov
  1868. + //if (sel_klass.is_null()) {
  1869. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1870. + //} else {
  1871. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1872. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1873. + //}
  1874. + }
  1875. + }
  1876. + }
  1877. +}
  1878. +
  1879. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1880. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1881. +
  1882. + // First attempt unversioned
  1883. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1884. +
  1885. + // (tw) Are we in an old method that wants to see a different view on the world?
  1886. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1887. +
  1888. + // 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).
  1889. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1890. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1891. +
  1892. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1893. +
  1894. + // We do not throw the exception
  1895. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1896. + // Forget any new member lookup
  1897. + resolved_method = methodHandle(THREAD, NULL);
  1898. + }
  1899. +
  1900. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1901. +
  1902. + if (resolved_method.is_null()) {
  1903. +
  1904. + // Select correct version for resolved klass.
  1905. + find_correct_resolved_klass(resolved_klass, current_klass);
  1906. +
  1907. + // Now do the lookup in a second attempt with a different resolved klass.
  1908. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1909. +
  1910. + // FIXME: idubrov
  1911. + //IF_TRACE_RC2 {
  1912. + // ResourceMark rm(THREAD);
  1913. + // if (resolved_method.is_null()) {
  1914. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1915. + // } else {
  1916. + // assert(resolved_method->is_old(), "must be old method!");
  1917. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1918. + // }
  1919. + //}
  1920. + }
  1921. + }
  1922. + }
  1923. +
  1924. + if (resolved_method.is_null()) {
  1925. + // no method found
  1926. + ResourceMark rm(THREAD);
  1927. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1928. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1929. + method_name,
  1930. + method_signature));
  1931. + }
  1932. +}
  1933. +
  1934. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1935. + int current_klass_revision = current_klass->revision_number();
  1936. + int resolved_klass_revision = resolved_klass->revision_number();
  1937. + // FIXME: idubrov
  1938. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1939. +
  1940. + while (resolved_klass->revision_number() > current_klass_revision) {
  1941. + assert(resolved_klass->old_version(), "must have old version");
  1942. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1943. + }
  1944. +}
  1945. +
  1946. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1947. Symbol* method_name, Symbol* method_signature,
  1948. KlassHandle current_klass, bool check_access, TRAPS) {
  1949. @@ -416,35 +566,8 @@
  1950. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1951. }
  1952. - Handle nested_exception;
  1953. -
  1954. - // 2. lookup method in resolved klass and its super klasses
  1955. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1956. -
  1957. - if (resolved_method.is_null()) { // not found in the class hierarchy
  1958. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1959. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1960. -
  1961. - if (resolved_method.is_null()) {
  1962. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1963. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1964. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1965. - if (HAS_PENDING_EXCEPTION) {
  1966. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1967. - CLEAR_PENDING_EXCEPTION;
  1968. - }
  1969. - }
  1970. -
  1971. - if (resolved_method.is_null()) {
  1972. - // 4. method lookup failed
  1973. - ResourceMark rm(THREAD);
  1974. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1975. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1976. - method_name,
  1977. - method_signature),
  1978. - nested_exception);
  1979. - }
  1980. - }
  1981. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1982. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1983. // 5. check if method is concrete
  1984. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1985. @@ -512,20 +635,7 @@
  1986. }
  1987. // lookup method in this interface or its super, java.lang.Object
  1988. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1989. -
  1990. - if (resolved_method.is_null()) {
  1991. - // lookup method in all the super-interfaces
  1992. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1993. - if (resolved_method.is_null()) {
  1994. - // no method found
  1995. - ResourceMark rm(THREAD);
  1996. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1997. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1998. - method_name,
  1999. - method_signature));
  2000. - }
  2001. - }
  2002. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  2003. if (check_access) {
  2004. HandleMark hm(THREAD);
  2005. @@ -612,9 +722,14 @@
  2006. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  2007. }
  2008. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  2009. +
  2010. // Resolve instance field
  2011. fieldDescriptor fd; // find_field initializes fd if found
  2012. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  2013. +
  2014. + KlassHandle sel_klass;
  2015. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  2016. +
  2017. // check if field exists; i.e., if a klass containing the field def has been selected
  2018. if (sel_klass.is_null()){
  2019. ResourceMark rm(THREAD);
  2020. @@ -622,7 +737,6 @@
  2021. }
  2022. // check access
  2023. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  2024. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  2025. // check for errors
  2026. @@ -634,7 +748,7 @@
  2027. }
  2028. // Final fields can only be accessed from its own class.
  2029. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  2030. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2031. THROW(vmSymbols::java_lang_IllegalAccessError());
  2032. }
  2033. @@ -839,7 +953,7 @@
  2034. bool check_access, bool check_null_and_abstract, TRAPS) {
  2035. methodHandle resolved_method;
  2036. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2037. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2038. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2039. }
  2040. // throws linktime exceptions
  2041. @@ -869,6 +983,7 @@
  2042. KlassHandle resolved_klass,
  2043. Handle recv,
  2044. KlassHandle recv_klass,
  2045. + KlassHandle current_klass,
  2046. bool check_null_and_abstract,
  2047. TRAPS) {
  2048. @@ -917,7 +1032,40 @@
  2049. // recv_klass might be an arrayKlassOop but all vtables start at
  2050. // the same place. The cast is to avoid virtual call and assertion.
  2051. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2052. +
  2053. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2054. + // have anything in common, as the receiver type could've been hotswapped.
  2055. + // Does not always work (method could be resolved with correct dynamic type and later
  2056. + // be called at the same place with a wrong dynamic type).
  2057. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2058. +
  2059. + // The vTable must be based on the view of the world of the resolved method
  2060. + klassOop method_holder = resolved_method->method_holder();
  2061. +
  2062. + if (method_holder->klass_part()->new_version() != NULL) {
  2063. + // We are executing in old code
  2064. + // FIXME: idubrov
  2065. + //TRACE_RC2("Calling a method in old code");
  2066. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2067. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2068. + }
  2069. + }
  2070. +
  2071. + if (inst->is_subtype_of(method_holder)) {
  2072. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2073. + } else {
  2074. +
  2075. + tty->print_cr("Failure:");
  2076. + inst->as_klassOop()->print();
  2077. + inst->super()->print();
  2078. + juint off = inst->super_check_offset();
  2079. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2080. + sup->print();
  2081. + method_holder->print();
  2082. +
  2083. + bool b = inst->is_subtype_of(method_holder);
  2084. + 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!");
  2085. + }
  2086. }
  2087. }
  2088. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2089. index dfd74f9..cf6e44a 100644
  2090. --- a/src/share/vm/interpreter/linkResolver.hpp
  2091. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2092. @@ -110,7 +110,11 @@
  2093. // It does all necessary link-time checks & throws exceptions if necessary.
  2094. class LinkResolver: AllStatic {
  2095. - private:
  2096. +private:
  2097. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2098. + 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);
  2099. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2100. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2101. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2102. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2103. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2104. @@ -133,7 +137,7 @@
  2105. 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);
  2106. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2107. - 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);
  2108. + 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);
  2109. 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);
  2110. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2111. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2112. index 17e9f26..e77500f 100644
  2113. --- a/src/share/vm/interpreter/templateTable.hpp
  2114. +++ b/src/share/vm/interpreter/templateTable.hpp
  2115. @@ -329,8 +329,8 @@
  2116. static void shouldnotreachhere();
  2117. // jvmti support
  2118. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2119. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2120. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2121. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2122. static void jvmti_post_fast_field_mod();
  2123. // debugging of TemplateGenerator
  2124. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2125. index 76e18d8..6af7c14 100644
  2126. --- a/src/share/vm/memory/genMarkSweep.cpp
  2127. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2128. @@ -421,6 +421,7 @@
  2129. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2130. // here (perm_gen first rather than last), so we tell the validate code
  2131. // to use a higher index (saved from phase2) when verifying perm_gen.
  2132. + assert(_rescued_oops == NULL, "must be empty before processing");
  2133. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2134. Generation* pg = gch->perm_gen();
  2135. @@ -433,10 +434,14 @@
  2136. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2137. + MarkSweep::copy_rescued_objects_back();
  2138. +
  2139. GenCompactClosure blk;
  2140. gch->generation_iterate(&blk, true);
  2141. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2142. + MarkSweep::copy_rescued_objects_back();
  2143. +
  2144. pg->post_compact(); // Shared spaces verification.
  2145. }
  2146. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2147. index 350f583..59faad1 100644
  2148. --- a/src/share/vm/memory/permGen.cpp
  2149. +++ b/src/share/vm/memory/permGen.cpp
  2150. @@ -57,7 +57,12 @@
  2151. for (;;) {
  2152. {
  2153. - MutexLocker ml(Heap_lock);
  2154. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2155. + Monitor *lock = Heap_lock;
  2156. + if (SafepointSynchronize::is_at_safepoint()) {
  2157. + lock = NULL;
  2158. + }
  2159. + MutexLockerEx ml(lock);
  2160. if ((obj = gen->allocate(size, false)) != NULL) {
  2161. return obj;
  2162. }
  2163. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2164. index f97bc34..9b20d08 100644
  2165. --- a/src/share/vm/memory/space.cpp
  2166. +++ b/src/share/vm/memory/space.cpp
  2167. @@ -378,6 +378,31 @@
  2168. _compaction_top = bottom();
  2169. }
  2170. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2171. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2172. +CompactPoint* cp, HeapWord* compact_top) {
  2173. + // First check if we should switch compaction space
  2174. + assert(this == cp->space, "'this' should be current compaction space.");
  2175. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2176. + while (size > compaction_max_size) {
  2177. + // switch to next compaction space
  2178. + cp->space->set_compaction_top(compact_top);
  2179. + cp->space = cp->space->next_compaction_space();
  2180. + if (cp->space == NULL) {
  2181. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2182. + assert(cp->gen != NULL, "compaction must succeed");
  2183. + cp->space = cp->gen->first_compaction_space();
  2184. + assert(cp->space != NULL, "generation must have a first compaction space");
  2185. + }
  2186. + compact_top = cp->space->bottom();
  2187. + cp->space->set_compaction_top(compact_top);
  2188. + cp->threshold = cp->space->initialize_threshold();
  2189. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2190. + }
  2191. +
  2192. + return compact_top;
  2193. +}
  2194. +
  2195. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2196. CompactPoint* cp, HeapWord* compact_top) {
  2197. // q is alive
  2198. @@ -401,7 +426,7 @@
  2199. }
  2200. // store the forwarding pointer into the mark word
  2201. - if ((HeapWord*)q != compact_top) {
  2202. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2203. q->forward_to(oop(compact_top));
  2204. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2205. } else {
  2206. @@ -449,7 +474,208 @@
  2207. // Faster object search.
  2208. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2209. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2210. + if (!Universe::is_redefining_gc_run()) {
  2211. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2212. + return;
  2213. + }
  2214. +
  2215. + /* Compute the new addresses for the live objects and store it in the mark
  2216. + * Used by universe::mark_sweep_phase2()
  2217. + */
  2218. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2219. +
  2220. + /* We're sure to be here before any objects are compacted into this
  2221. + * space, so this is a good time to initialize this:
  2222. + */
  2223. + set_compaction_top(bottom());
  2224. +
  2225. + if (cp->space == NULL) {
  2226. + assert(cp->gen != NULL, "need a generation");
  2227. + assert(cp->threshold == NULL, "just checking");
  2228. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2229. + cp->space = cp->gen->first_compaction_space();
  2230. + compact_top = cp->space->bottom();
  2231. + cp->space->set_compaction_top(compact_top);
  2232. + cp->threshold = cp->space->initialize_threshold();
  2233. + } else {
  2234. + compact_top = cp->space->compaction_top();
  2235. + }
  2236. +
  2237. + /* We allow some amount of garbage towards the bottom of the space, so
  2238. + * we don't start compacting before there is a significant gain to be made.
  2239. + * Occasionally, we want to ensure a full compaction, which is determined
  2240. + * by the MarkSweepAlwaysCompactCount parameter.
  2241. + */
  2242. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2243. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2244. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2245. +
  2246. + size_t allowed_deadspace = 0;
  2247. + if (skip_dead) {
  2248. + int ratio = (int)allowed_dead_ratio();
  2249. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2250. + }
  2251. +
  2252. + HeapWord* q = bottom();
  2253. + HeapWord* t = end();
  2254. +
  2255. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2256. + live object. */
  2257. + HeapWord* first_dead = end();/* The first dead object. */
  2258. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2259. + first header of preceding free area. */
  2260. + _first_dead = first_dead;
  2261. +
  2262. + const intx interval = PrefetchScanIntervalInBytes;
  2263. +
  2264. + while (q < t) {
  2265. + assert(!block_is_obj(q) ||
  2266. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2267. + oop(q)->mark()->has_bias_pattern(),
  2268. + "these are the only valid states during a mark sweep");
  2269. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2270. + /* prefetch beyond q */
  2271. + Prefetch::write(q, interval);
  2272. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2273. + size_t size = block_size(q);
  2274. +
  2275. + // DCEVM: begin
  2276. + //////////////////////////////////////////////////////////////////////////
  2277. + size_t forward_size = size;
  2278. +
  2279. + // Compute the forward sizes and leave out objects whose position could
  2280. + // possibly overlap other objects.
  2281. +
  2282. + // DCEVM: There is a new version of the class of q => different size
  2283. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2284. +
  2285. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2286. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2287. + forward_size = new_size;
  2288. + }
  2289. +
  2290. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2291. +
  2292. + bool rescueing = false;
  2293. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2294. + if (MarkSweep::_rescued_oops == NULL) {
  2295. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2296. + }
  2297. + // FIXME: idubrov
  2298. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2299. + MarkSweep::_rescued_oops->append(oop(q));
  2300. + } else {
  2301. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2302. + }
  2303. +
  2304. + if ((size != forward_size || rescueing) && q < first_dead) {
  2305. + // (tw) This object moves => first_dead must be set to here!
  2306. + first_dead = q;
  2307. + }
  2308. + //////////////////////////////////////////////////////////////////////////
  2309. + q += size;
  2310. + end_of_live = q;
  2311. + } else {
  2312. + /* run over all the contiguous dead objects */
  2313. + HeapWord* end = q;
  2314. + do {
  2315. + /* prefetch beyond end */
  2316. + Prefetch::write(end, interval);
  2317. + end += block_size(end);
  2318. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2319. +
  2320. + /* see if we might want to pretend this object is alive so that
  2321. + * we don't have to compact quite as often.
  2322. + */
  2323. + if (allowed_deadspace > 0 && q == compact_top) {
  2324. + size_t sz = pointer_delta(end, q);
  2325. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2326. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2327. + q = end;
  2328. + end_of_live = end;
  2329. + continue;
  2330. + }
  2331. + }
  2332. +
  2333. + /* otherwise, it really is a free region. */
  2334. +
  2335. + /* for the previous LiveRange, record the end of the live objects. */
  2336. + if (liveRange) {
  2337. + liveRange->set_end(q);
  2338. + }
  2339. +
  2340. + /* record the current LiveRange object.
  2341. + * liveRange->start() is overlaid on the mark word.
  2342. + */
  2343. + liveRange = (LiveRange*)q;
  2344. + liveRange->set_start(end);
  2345. + liveRange->set_end(end);
  2346. +
  2347. + /* see if this is the first dead region. */
  2348. + if (q < first_dead) {
  2349. + first_dead = q;
  2350. + }
  2351. +
  2352. + /* move on to the next object */
  2353. + q = end;
  2354. + }
  2355. + }
  2356. +
  2357. + //////////////////////////////////////////////////////////////////////////
  2358. + // Compute the forwarding addresses for the objects that need to be
  2359. + // rescued.
  2360. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2361. + if (MarkSweep::_rescued_oops != NULL) {
  2362. + // FIXME: idubrov
  2363. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2364. +
  2365. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2366. + oop q = MarkSweep::_rescued_oops->at(i);
  2367. +
  2368. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2369. + size_t size = block_size((HeapWord*)q);
  2370. +
  2371. + size_t forward_size = size;
  2372. +
  2373. + // (tw) There is a new version of the class of q => different size
  2374. + if (oop(q)->blueprint()->new_version() != NULL) {
  2375. +
  2376. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2377. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2378. + forward_size = new_size;
  2379. + }
  2380. +
  2381. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2382. + assert(compact_top <= t, "must not write over end of space!");
  2383. + }
  2384. + MarkSweep::_rescued_oops->clear();
  2385. + MarkSweep::_rescued_oops = NULL;
  2386. + }
  2387. + //////////////////////////////////////////////////////////////////////////
  2388. +
  2389. + assert(q == t, "just checking");
  2390. + if (liveRange != NULL) {
  2391. + liveRange->set_end(q);
  2392. + }
  2393. + _end_of_live = end_of_live;
  2394. + if (end_of_live < first_dead) {
  2395. + first_dead = end_of_live;
  2396. + }
  2397. + _first_dead = first_dead;
  2398. +
  2399. +// FIXME: idubrov
  2400. +// if (_first_dead > top()) {
  2401. +// _first_dead = top();
  2402. +// }
  2403. +//
  2404. +// if (_end_of_live > top()) {
  2405. +// _end_of_live = top();
  2406. +// }
  2407. + assert(_first_dead <= top(), "Must be smaller equal");
  2408. + assert(_end_of_live <= top(), "Must be smaller equal");
  2409. +
  2410. + /* save the compaction_top of the compaction space. */
  2411. + cp->space->set_compaction_top(compact_top);
  2412. }
  2413. void Space::adjust_pointers() {
  2414. @@ -490,17 +716,313 @@
  2415. assert(q == t, "just checking");
  2416. }
  2417. +
  2418. +#ifdef ASSERT
  2419. +
  2420. +int CompactibleSpace::space_index(oop obj) {
  2421. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2422. +
  2423. + if (heap->is_in_permanent(obj)) {
  2424. + return -1;
  2425. + }
  2426. +
  2427. + int index = 0;
  2428. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2429. + Generation* gen = heap->get_gen(i);
  2430. + CompactibleSpace* space = gen->first_compaction_space();
  2431. + while (space != NULL) {
  2432. + if (space->is_in_reserved(obj)) {
  2433. + return index;
  2434. + }
  2435. + space = space->next_compaction_space();
  2436. + index++;
  2437. + }
  2438. + }
  2439. +
  2440. + tty->print_cr("could not compute space_index for %08xh", obj);
  2441. + index = 0;
  2442. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2443. + Generation* gen = heap->get_gen(i);
  2444. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2445. +
  2446. + CompactibleSpace* space = gen->first_compaction_space();
  2447. + while (space != NULL) {
  2448. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2449. + space = space->next_compaction_space();
  2450. + index++;
  2451. + }
  2452. + }
  2453. +
  2454. + ShouldNotReachHere();
  2455. + return 0;
  2456. +}
  2457. +#endif
  2458. +
  2459. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2460. +
  2461. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2462. +
  2463. + if (old_obj->is_perm()) {
  2464. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2465. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2466. + return true;
  2467. + }
  2468. + }
  2469. +
  2470. + int size = old_obj->size();
  2471. + int original_size = size;
  2472. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2473. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2474. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2475. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2476. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2477. + }
  2478. +
  2479. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2480. +
  2481. + if (is_in_reserved(new_obj)) {
  2482. + // Old and new address are in same space, so just compare the address.
  2483. + // Must rescue if object moves towards the top of the space.
  2484. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2485. + return normalComparison;
  2486. +
  2487. + } else {
  2488. +
  2489. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2490. +
  2491. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2492. + if (tenured_gen->is_in_reserved(new_obj)) {
  2493. + // Must never rescue when moving from the new into the old generation.
  2494. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2495. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2496. + return false;
  2497. +
  2498. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2499. + // Must always rescue when moving from the old into the new generation.
  2500. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2501. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2502. + return true;
  2503. +
  2504. + } else {
  2505. + // In the new generation, eden is located before the from space, so a
  2506. + // simple pointer comparison is sufficient.
  2507. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2508. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2509. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2510. + return normalComparison;
  2511. + }
  2512. + }
  2513. +}
  2514. +
  2515. +oop CompactibleSpace::rescue(oop old_obj) {
  2516. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2517. +
  2518. + int size = old_obj->size();
  2519. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2520. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2521. +
  2522. + if (MarkSweep::_rescued_oops == NULL) {
  2523. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2524. + }
  2525. +
  2526. + MarkSweep::_rescued_oops->append(rescued_obj);
  2527. + return rescued_obj;
  2528. +}
  2529. +
  2530. void CompactibleSpace::adjust_pointers() {
  2531. // Check first is there is any work to do.
  2532. if (used() == 0) {
  2533. return; // Nothing to do.
  2534. }
  2535. + /* adjust all the interior pointers to point at the new locations of objects
  2536. + * Used by MarkSweep::mark_sweep_phase3() */
  2537. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2538. + HeapWord* q = bottom();
  2539. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2540. +
  2541. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2542. +
  2543. + debug_only(HeapWord* prev_q = NULL);
  2544. + debug_only(HeapWord* prev_prev_q = NULL);
  2545. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2546. + if (q < t && _first_dead > q &&
  2547. + !oop(q)->is_gc_marked()) {
  2548. + /* we have a chunk of the space which hasn't moved and we've
  2549. + * reinitialized the mark word during the previous pass, so we can't
  2550. + * use is_gc_marked for the traversal. */
  2551. + HeapWord* end = _first_dead;
  2552. +
  2553. + while (q < end) {
  2554. + /* I originally tried to conjoin "block_start(q) == q" to the
  2555. + * assertion below, but that doesn't work, because you can't
  2556. + * accurately traverse previous objects to get to the current one
  2557. + * after their pointers (including pointers into permGen) have been
  2558. + * updated, until the actual compaction is done. dld, 4/00 */
  2559. + assert(block_is_obj(q),
  2560. + "should be at block boundaries, and should be looking at objs");
  2561. +
  2562. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2563. +
  2564. + /* point all the oops to the new location */
  2565. + size_t size = oop(q)->adjust_pointers();
  2566. + size = adjust_obj_size(size);
  2567. +
  2568. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2569. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2570. +
  2571. + debug_only(prev_prev_prev_q = prev_prev_q);
  2572. + debug_only(prev_prev_q = prev_q);
  2573. + debug_only(prev_q = q);
  2574. + q += size;
  2575. + }
  2576. +
  2577. + // (tw) first_dead can be live object!
  2578. + q = _first_dead;
  2579. +
  2580. +// if (_first_dead == t) {
  2581. +// q = t;
  2582. +// } else {
  2583. +// /* $$$ This is funky. Using this to read the previously written
  2584. +// * LiveRange. See also use below. */
  2585. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2586. +// }
  2587. + }
  2588. +
  2589. + const intx interval = PrefetchScanIntervalInBytes;
  2590. +
  2591. + debug_only(prev_q = NULL);
  2592. + debug_only(prev_prev_q = NULL);
  2593. + debug_only(prev_prev_prev_q = NULL);
  2594. + while (q < t) {
  2595. + /* prefetch beyond q */
  2596. + Prefetch::write(q, interval);
  2597. + if (oop(q)->is_gc_marked()) {
  2598. + /* q is alive */
  2599. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2600. + /* point all the oops to the new location */
  2601. + size_t size = oop(q)->adjust_pointers();
  2602. + size = adjust_obj_size(size);
  2603. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2604. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2605. + debug_only(prev_prev_prev_q = prev_prev_q);
  2606. + debug_only(prev_prev_q = prev_q);
  2607. + debug_only(prev_q = q);
  2608. + q += size;
  2609. + } else {
  2610. + /* q is not a live object, so its mark should point at the next
  2611. + * live object */
  2612. + debug_only(prev_prev_prev_q = prev_prev_q);
  2613. + debug_only(prev_prev_q = prev_q);
  2614. + debug_only(prev_q = q);
  2615. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2616. + assert(q > prev_q, "we should be moving forward through memory");
  2617. + }
  2618. + }
  2619. +
  2620. + assert(q == t, "just checking");
  2621. }
  2622. void CompactibleSpace::compact() {
  2623. - SCAN_AND_COMPACT(obj_size);
  2624. +
  2625. + if(!Universe::is_redefining_gc_run()) {
  2626. + SCAN_AND_COMPACT(obj_size);
  2627. + return;
  2628. + }
  2629. +
  2630. + /* Copy all live objects to their new location
  2631. + * Used by MarkSweep::mark_sweep_phase4() */
  2632. +
  2633. + HeapWord* q = bottom();
  2634. + HeapWord* const t = _end_of_live;
  2635. + debug_only(HeapWord* prev_q = NULL);
  2636. +
  2637. + if (q < t && _first_dead > q &&
  2638. + !oop(q)->is_gc_marked()) {
  2639. + debug_only(
  2640. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2641. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2642. + * the traversal. */
  2643. + HeapWord* const end = _first_dead;
  2644. +
  2645. + while (q < end) {
  2646. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2647. + assert(!oop(q)->is_gc_marked(),
  2648. + "should be unmarked (special dense prefix handling)");
  2649. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2650. + debug_only(prev_q = q);
  2651. + q += size;
  2652. + }
  2653. + ) /* debug_only */
  2654. + // (tw) first_dead can be live object!
  2655. + q = _first_dead;
  2656. +
  2657. + //if (_first_dead == t) {
  2658. + // q = t;
  2659. + //} else {
  2660. + ///* $$$ Funky */
  2661. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2662. + //}
  2663. + }
  2664. +
  2665. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2666. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2667. + while (q < t) {
  2668. + if (!oop(q)->is_gc_marked()) {
  2669. + /* mark is pointer to next marked oop */
  2670. + debug_only(prev_q = q);
  2671. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2672. + assert(q > prev_q, "we should be moving forward through memory");
  2673. + } else {
  2674. + /* prefetch beyond q */
  2675. + Prefetch::read(q, scan_interval);
  2676. +
  2677. + /* size and destination */
  2678. + size_t size = obj_size(q);
  2679. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2680. +
  2681. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2682. + oop dest_obj = rescue(oop(q));
  2683. + debug_only(Copy::fill_to_words(q, size, 0));
  2684. + } else {
  2685. +
  2686. + /* prefetch beyond compaction_top */
  2687. + Prefetch::write(compaction_top, copy_interval);
  2688. +
  2689. + /* copy object and reinit its mark */
  2690. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2691. + compaction_top));
  2692. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2693. +
  2694. + if (oop(q)->blueprint()->new_version() != NULL) {
  2695. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2696. + } else {
  2697. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2698. + }
  2699. + oop(compaction_top)->init_mark();
  2700. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2701. + }
  2702. +
  2703. + debug_only(prev_q = q);
  2704. + q += size;
  2705. + }
  2706. + }
  2707. +
  2708. + /* Let's remember if we were empty before we did the compaction. */
  2709. + bool was_empty = used_region().is_empty();
  2710. + /* Reset space after compaction is complete */
  2711. + reset_after_compaction();
  2712. + /* We do this clear, below, since it has overloaded meanings for some */
  2713. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2714. + /* compacted into will have had their offset table thresholds updated */
  2715. + /* continuously, but those that weren't need to have their thresholds */
  2716. + /* re-initialized. Also mangles unused area for debugging. */
  2717. + if (used_region().is_empty()) {
  2718. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2719. + } else {
  2720. + if (ZapUnusedHeapArea) mangle_unused_area();
  2721. + }
  2722. +
  2723. + //SCAN_AND_COMPACT(obj_size);
  2724. }
  2725. void Space::print_short() const { print_short_on(tty); }
  2726. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2727. index ef2f2c6..b54d470 100644
  2728. --- a/src/share/vm/memory/space.hpp
  2729. +++ b/src/share/vm/memory/space.hpp
  2730. @@ -445,6 +445,9 @@
  2731. // indicates when the next such action should be taken.
  2732. virtual void prepare_for_compaction(CompactPoint* cp);
  2733. // MarkSweep support phase3
  2734. + DEBUG_ONLY(int space_index(oop obj));
  2735. + bool must_rescue(oop old_obj, oop new_obj);
  2736. + oop rescue(oop old_obj);
  2737. virtual void adjust_pointers();
  2738. // MarkSweep support phase4
  2739. virtual void compact();
  2740. @@ -475,6 +478,10 @@
  2741. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2742. HeapWord* compact_top);
  2743. + // (tw)
  2744. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2745. + HeapWord* compact_top);
  2746. +
  2747. // Return a size with adjusments as required of the space.
  2748. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2749. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2750. index 4030d9d..da9a186 100644
  2751. --- a/src/share/vm/memory/universe.cpp
  2752. +++ b/src/share/vm/memory/universe.cpp
  2753. @@ -100,6 +100,8 @@
  2754. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2755. #endif
  2756. +bool Universe::_is_redefining_gc_run = false;
  2757. +
  2758. // Known objects
  2759. klassOop Universe::_boolArrayKlassObj = NULL;
  2760. klassOop Universe::_byteArrayKlassObj = NULL;
  2761. @@ -204,6 +206,38 @@
  2762. f(systemObjArrayKlassObj());
  2763. }
  2764. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2765. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2766. +
  2767. + class AlwaysTrueClosure: public BoolObjectClosure {
  2768. + public:
  2769. + void do_object(oop p) { ShouldNotReachHere(); }
  2770. + bool do_object_b(oop p) { return true; }
  2771. + };
  2772. + AlwaysTrueClosure always_true;
  2773. +
  2774. + // General strong roots
  2775. + Universe::oops_do(oopClosure);
  2776. + JNIHandles::oops_do(oopClosure);
  2777. + Threads::oops_do(oopClosure, NULL);
  2778. + ObjectSynchronizer::oops_do(oopClosure);
  2779. + FlatProfiler::oops_do(oopClosure);
  2780. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2781. + JvmtiExport::oops_do(oopClosure);
  2782. + // SO_AllClasses
  2783. + SystemDictionary::oops_do(oopClosure);
  2784. +
  2785. + // Now adjust pointers in remaining weak roots. (All of which should
  2786. + // have been cleared if they pointed to non-surviving objects.)
  2787. + // Global (weak) JNI handles
  2788. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2789. +
  2790. + CodeCache::oops_do(oopClosure);
  2791. + StringTable::oops_do(oopClosure);
  2792. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2793. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2794. +}
  2795. +
  2796. void Universe::oops_do(OopClosure* f, bool do_all) {
  2797. f->do_oop((oop*) &_int_mirror);
  2798. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2799. index 50fcb62..afb6b33 100644
  2800. --- a/src/share/vm/memory/universe.hpp
  2801. +++ b/src/share/vm/memory/universe.hpp
  2802. @@ -127,6 +127,8 @@
  2803. friend class SystemDictionary;
  2804. friend class VMStructs;
  2805. friend class CompactingPermGenGen;
  2806. + friend class Space;
  2807. + friend class ContiguousSpace;
  2808. friend class VM_PopulateDumpSharedSpace;
  2809. friend jint universe_init();
  2810. @@ -258,7 +260,18 @@
  2811. static void compute_verify_oop_data();
  2812. + static bool _is_redefining_gc_run;
  2813. +
  2814. public:
  2815. +
  2816. + static bool is_redefining_gc_run() {
  2817. + return _is_redefining_gc_run;
  2818. + }
  2819. +
  2820. + static void set_redefining_gc_run(bool b) {
  2821. + _is_redefining_gc_run = b;
  2822. + }
  2823. +
  2824. // Known classes in the VM
  2825. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2826. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2827. @@ -403,6 +416,8 @@
  2828. // Iteration
  2829. + static void root_oops_do(OopClosure *f);
  2830. +
  2831. // Apply "f" to the addresses of all the direct heap pointers maintained
  2832. // as static fields of "Universe".
  2833. static void oops_do(OopClosure* f, bool do_all = false);
  2834. @@ -419,6 +434,7 @@
  2835. // Debugging
  2836. static bool verify_in_progress() { return _verify_in_progress; }
  2837. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2838. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  2839. static void verify(const char* prefix, bool silent = VerifySilently) {
  2840. verify(VerifyOption_Default, prefix, silent);
  2841. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2842. index 4aa1155..2738ea9 100644
  2843. --- a/src/share/vm/oops/arrayKlass.cpp
  2844. +++ b/src/share/vm/oops/arrayKlass.cpp
  2845. @@ -129,9 +129,9 @@
  2846. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2847. // An array is a subtype of Serializable, Clonable, and Object
  2848. - return k == SystemDictionary::Object_klass()
  2849. - || k == SystemDictionary::Cloneable_klass()
  2850. - || k == SystemDictionary::Serializable_klass();
  2851. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2852. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2853. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2854. }
  2855. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2856. index e74811f..be3fe7d 100644
  2857. --- a/src/share/vm/oops/constMethodKlass.cpp
  2858. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2859. @@ -102,6 +102,7 @@
  2860. constMethodOop cm = constMethodOop(obj);
  2861. MarkSweep::mark_and_push(cm->adr_constants());
  2862. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2863. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2864. // Performance tweak: We skip iterating over the klass pointer since we
  2865. // know that Universe::constMethodKlassObj never moves.
  2866. }
  2867. @@ -113,6 +114,7 @@
  2868. constMethodOop cm_oop = constMethodOop(obj);
  2869. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2870. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2871. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2872. // Performance tweak: We skip iterating over the klass pointer since we
  2873. // know that Universe::constMethodKlassObj never moves.
  2874. }
  2875. @@ -123,6 +125,7 @@
  2876. constMethodOop cm = constMethodOop(obj);
  2877. blk->do_oop(cm->adr_constants());
  2878. blk->do_oop(cm->adr_stackmap_data());
  2879. + blk->do_oop(cm->adr_code_section_table());
  2880. // Get size before changing pointers.
  2881. // Don't call size() or oop_size() since that is a virtual call.
  2882. int size = cm->object_size();
  2883. @@ -138,6 +141,8 @@
  2884. if (mr.contains(adr)) blk->do_oop(adr);
  2885. adr = cm->adr_stackmap_data();
  2886. if (mr.contains(adr)) blk->do_oop(adr);
  2887. + adr = cm->adr_code_section_table();
  2888. + if (mr.contains(adr)) blk->do_oop(adr);
  2889. // Get size before changing pointers.
  2890. // Don't call size() or oop_size() since that is a virtual call.
  2891. int size = cm->object_size();
  2892. @@ -152,6 +157,7 @@
  2893. constMethodOop cm = constMethodOop(obj);
  2894. MarkSweep::adjust_pointer(cm->adr_constants());
  2895. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2896. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2897. // Get size before changing pointers.
  2898. // Don't call size() or oop_size() since that is a virtual call.
  2899. int size = cm->object_size();
  2900. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2901. index 549192b..5cea5c4 100644
  2902. --- a/src/share/vm/oops/constMethodOop.hpp
  2903. +++ b/src/share/vm/oops/constMethodOop.hpp
  2904. @@ -129,7 +129,7 @@
  2905. public:
  2906. oop* oop_block_beg() const { return adr_constants(); }
  2907. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2908. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2909. private:
  2910. //
  2911. @@ -140,6 +140,9 @@
  2912. // Raw stackmap data for the method
  2913. typeArrayOop _stackmap_data;
  2914. +
  2915. + // (tw) Table mapping code sections for method forward points.
  2916. + typeArrayOop _code_section_table;
  2917. //
  2918. // End of the oop block.
  2919. @@ -194,6 +197,28 @@
  2920. oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
  2921. }
  2922. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2923. +
  2924. + // code section table
  2925. + typeArrayOop code_section_table() const { return _code_section_table; }
  2926. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2927. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2928. + static const int ValuesPerCodeSectionEntry = 3;
  2929. + int code_section_entries() const {
  2930. + if (!has_code_section_table()) return 0;
  2931. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2932. + }
  2933. +
  2934. + int code_section_new_index_at(int index) const {
  2935. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2936. + }
  2937. +
  2938. + int code_section_original_index_at(int index) const {
  2939. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2940. + }
  2941. +
  2942. + int code_section_length_at(int index) const {
  2943. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2944. + }
  2945. void init_fingerprint() {
  2946. const uint64_t initval = CONST64(0x8000000000000000);
  2947. @@ -301,6 +326,7 @@
  2948. // Garbage collection support
  2949. oop* adr_constants() const { return (oop*)&_constants; }
  2950. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2951. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2952. bool is_conc_safe() { return _is_conc_safe; }
  2953. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2954. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2955. index ad62921..f39f202 100644
  2956. --- a/src/share/vm/oops/cpCacheOop.cpp
  2957. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2958. @@ -37,9 +37,15 @@
  2959. // Implememtation of ConstantPoolCacheEntry
  2960. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2961. + _flags = other->_flags; // flags
  2962. +}
  2963. +
  2964. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2965. assert(0 < index && index < 0x10000, "sanity check");
  2966. _indices = index;
  2967. + _f1 = NULL;
  2968. + _f2 = 0;
  2969. assert(constant_pool_index() == index, "");
  2970. }
  2971. @@ -162,7 +168,8 @@
  2972. int vtable_index) {
  2973. assert(!is_secondary_entry(), "");
  2974. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2975. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2976. + // (tw) No longer valid assert
  2977. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2978. int byte_no = -1;
  2979. bool change_to_virtual = false;
  2980. @@ -183,6 +190,7 @@
  2981. set_method_flags(as_TosState(method->result_type()),
  2982. ( 1 << is_vfinal_shift) |
  2983. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2984. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2985. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2986. method()->size_of_parameters());
  2987. set_f2_as_vfinal_method(method());
  2988. @@ -190,9 +198,13 @@
  2989. assert(vtable_index >= 0, "valid index");
  2990. assert(!method->is_final_method(), "sanity");
  2991. set_method_flags(as_TosState(method->result_type()),
  2992. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2993. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2994. method()->size_of_parameters());
  2995. set_f2(vtable_index);
  2996. +
  2997. + // (tw) save method holder in f1 for virtual calls
  2998. + set_f1(method());
  2999. }
  3000. byte_no = 2;
  3001. break;
  3002. @@ -206,7 +218,8 @@
  3003. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  3004. set_method_flags(as_TosState(method->result_type()),
  3005. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  3006. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  3007. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3008. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3009. method()->size_of_parameters());
  3010. set_f1(method());
  3011. byte_no = 1;
  3012. @@ -259,7 +272,7 @@
  3013. set_f1(interf);
  3014. set_f2(index);
  3015. set_method_flags(as_TosState(method->result_type()),
  3016. - 0, // no option bits
  3017. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3018. method()->size_of_parameters());
  3019. set_bytecode_1(Bytecodes::_invokeinterface);
  3020. }
  3021. @@ -520,27 +533,12 @@
  3022. // If this constantPoolCacheEntry refers to old_method then update it
  3023. // to refer to new_method.
  3024. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3025. - methodOop new_method, bool * trace_name_printed) {
  3026. + methodOop new_method) {
  3027. if (is_vfinal()) {
  3028. - // virtual and final so _f2 contains method ptr instead of vtable index
  3029. - if (f2_as_vfinal_method() == old_method) {
  3030. - // match old_method so need an update
  3031. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3032. - _f2 = (intptr_t)new_method;
  3033. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3034. - if (!(*trace_name_printed)) {
  3035. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3036. - RC_TRACE_MESG(("adjust: name=%s",
  3037. - Klass::cast(old_method->method_holder())->external_name()));
  3038. - *trace_name_printed = true;
  3039. - }
  3040. - // RC_TRACE macro has an embedded ResourceMark
  3041. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3042. - new_method->name()->as_C_string(),
  3043. - new_method->signature()->as_C_string()));
  3044. - }
  3045. -
  3046. + // virtual and final so f2() contains method ptr instead of vtable index
  3047. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3048. + initialize_entry(constant_pool_index());
  3049. return true;
  3050. }
  3051. @@ -548,82 +546,25 @@
  3052. return false;
  3053. }
  3054. - if ((oop)_f1 == NULL) {
  3055. - // NULL f1() means this is a virtual entry so bail out
  3056. - // We are assuming that the vtable index does not need change.
  3057. + // (tw) check how to update interface methods!
  3058. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3059. +
  3060. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3061. + initialize_entry(constant_pool_index());
  3062. + return true;
  3063. + }
  3064. +
  3065. return false;
  3066. }
  3067. if ((oop)_f1 == old_method) {
  3068. _f1 = new_method;
  3069. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3070. - if (!(*trace_name_printed)) {
  3071. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3072. - RC_TRACE_MESG(("adjust: name=%s",
  3073. - Klass::cast(old_method->method_holder())->external_name()));
  3074. - *trace_name_printed = true;
  3075. - }
  3076. - // RC_TRACE macro has an embedded ResourceMark
  3077. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3078. - new_method->name()->as_C_string(),
  3079. - new_method->signature()->as_C_string()));
  3080. - }
  3081. -
  3082. return true;
  3083. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3084. + initialize_entry(constant_pool_index());
  3085. }
  3086. return false;
  3087. -}
  3088. -
  3089. -// a constant pool cache entry should never contain old or obsolete methods
  3090. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3091. - if (is_vfinal()) {
  3092. - // virtual and final so _f2 contains method ptr instead of vtable index
  3093. - methodOop m = (methodOop)_f2;
  3094. - // Return false if _f2 refers to an old or an obsolete method.
  3095. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3096. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3097. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3098. - // _f1 == NULL || !_f1->is_method() are OK here
  3099. - return true;
  3100. - }
  3101. -
  3102. - methodOop m = (methodOop)_f1;
  3103. - // return false if _f1 refers to an old or an obsolete method
  3104. - return (!m->is_old() && !m->is_obsolete());
  3105. -}
  3106. -
  3107. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3108. - if (!is_method_entry()) {
  3109. - // not a method entry so not interesting by default
  3110. - return false;
  3111. - }
  3112. -
  3113. - methodOop m = NULL;
  3114. - if (is_vfinal()) {
  3115. - // virtual and final so _f2 contains method ptr instead of vtable index
  3116. - m = f2_as_vfinal_method();
  3117. - } else if (is_f1_null()) {
  3118. - // NULL _f1 means this is a virtual entry so also not interesting
  3119. - return false;
  3120. - } else {
  3121. - oop f1 = _f1; // _f1 is volatile
  3122. - if (!f1->is_method()) {
  3123. - // _f1 can also contain a klassOop for an interface
  3124. - return false;
  3125. - }
  3126. - m = f1_as_method();
  3127. - }
  3128. -
  3129. - assert(m != NULL && m->is_method(), "sanity check");
  3130. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3131. - // robustness for above sanity checks or method is not in
  3132. - // the interesting class
  3133. - return false;
  3134. - }
  3135. -
  3136. - // the method is in the interesting class so the entry is interesting
  3137. - return true;
  3138. }
  3139. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3140. @@ -663,60 +604,18 @@
  3141. }
  3142. }
  3143. -// RedefineClasses() API support:
  3144. -// If any entry of this constantPoolCache points to any of
  3145. -// old_methods, replace it with the corresponding new_method.
  3146. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3147. - int methods_length, bool * trace_name_printed) {
  3148. -
  3149. - if (methods_length == 0) {
  3150. - // nothing to do if there are no methods
  3151. - return;
  3152. - }
  3153. -
  3154. - // get shorthand for the interesting class
  3155. - klassOop old_holder = old_methods[0]->method_holder();
  3156. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3157. + int methods_length) {
  3158. for (int i = 0; i < length(); i++) {
  3159. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3160. - // skip uninteresting methods
  3161. - continue;
  3162. - }
  3163. -
  3164. - // The constantPoolCache contains entries for several different
  3165. - // things, but we only care about methods. In fact, we only care
  3166. - // about methods in the same class as the one that contains the
  3167. - // old_methods. At this point, we have an interesting entry.
  3168. -
  3169. - for (int j = 0; j < methods_length; j++) {
  3170. - methodOop old_method = old_methods[j];
  3171. - methodOop new_method = new_methods[j];
  3172. -
  3173. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3174. - trace_name_printed)) {
  3175. - // current old_method matched this entry and we updated it so
  3176. - // break out and get to the next interesting entry if there one
  3177. - break;
  3178. - }
  3179. + if (entry_at(i)->is_field_entry()) {
  3180. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3181. + // point to changed fields
  3182. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3183. + } else if(entry_at(i)->is_method_entry()) {
  3184. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3185. }
  3186. }
  3187. }
  3188. -// the constant pool cache should never contain old or obsolete methods
  3189. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3190. - for (int i = 1; i < length(); i++) {
  3191. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3192. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3193. - return false;
  3194. - }
  3195. - }
  3196. - return true;
  3197. -}
  3198. -void constantPoolCacheOopDesc::dump_cache() {
  3199. - for (int i = 1; i < length(); i++) {
  3200. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3201. - entry_at(i)->print(tty, i);
  3202. - }
  3203. - }
  3204. -}
  3205. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3206. index ef26775..6f37d81 100644
  3207. --- a/src/share/vm/oops/cpCacheOop.hpp
  3208. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3209. @@ -136,7 +136,8 @@
  3210. void set_bytecode_2(Bytecodes::Code code);
  3211. void set_f1(oop f1) {
  3212. oop existing_f1 = _f1; // read once
  3213. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3214. + // (tw) need to relax assertion for redefinition
  3215. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3216. oop_store(&_f1, f1);
  3217. }
  3218. void release_set_f1(oop f1);
  3219. @@ -167,6 +168,7 @@
  3220. tos_state_mask = right_n_bits(tos_state_bits),
  3221. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3222. // misc. option bits; can be any bit position in [16..27]
  3223. + is_old_method_shift = 19,
  3224. is_vfinal_shift = 20,
  3225. is_volatile_shift = 21,
  3226. is_final_shift = 22,
  3227. @@ -199,6 +201,8 @@
  3228. // Initialization
  3229. void initialize_entry(int original_index); // initialize primary entry
  3230. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3231. +
  3232. + void copy_from(ConstantPoolCacheEntry *other);
  3233. void set_field( // sets entry to resolved field state
  3234. Bytecodes::Code get_code, // the bytecode used for reading the field
  3235. @@ -361,10 +365,7 @@
  3236. // trace_name_printed is set to true if the current call has
  3237. // printed the klass name so that other routines in the adjust_*
  3238. // group don't print the klass name.
  3239. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3240. - bool * trace_name_printed);
  3241. - bool check_no_old_or_obsolete_entries();
  3242. - bool is_interesting_method_entry(klassOop k);
  3243. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3244. // Debugging & Printing
  3245. void print (outputStream* st, int index) const;
  3246. @@ -485,16 +486,9 @@
  3247. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3248. }
  3249. - // RedefineClasses() API support:
  3250. - // If any entry of this constantPoolCache points to any of
  3251. - // old_methods, replace it with the corresponding new_method.
  3252. - // trace_name_printed is set to true if the current call has
  3253. - // printed the klass name so that other routines in the adjust_*
  3254. - // group don't print the klass name.
  3255. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3256. - int methods_length, bool * trace_name_printed);
  3257. - bool check_no_old_or_obsolete_entries();
  3258. - void dump_cache();
  3259. + // (tw) Update method and field references
  3260. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3261. + int methods_length);
  3262. };
  3263. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3264. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3265. index a775b02..749458f 100644
  3266. --- a/src/share/vm/oops/instanceKlass.cpp
  3267. +++ b/src/share/vm/oops/instanceKlass.cpp
  3268. @@ -250,12 +250,118 @@
  3269. }
  3270. +void instanceKlass::initialize_redefined_class() {
  3271. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3272. + name()->as_C_string()));
  3273. +
  3274. + assert(!is_initialized(), "");
  3275. + assert(this->old_version() != NULL, "");
  3276. + assert(is_linked(), "must be linked before");
  3277. +
  3278. +
  3279. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3280. + class UpdateStaticFieldClosure : public FieldClosure {
  3281. +
  3282. + private:
  3283. + instanceKlassHandle this_oop;
  3284. +
  3285. + public:
  3286. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3287. + this->this_oop = this_oop;
  3288. + }
  3289. +
  3290. + virtual void do_field(fieldDescriptor* fd) {
  3291. + fieldDescriptor result;
  3292. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3293. +
  3294. + if (found && result.is_static()) {
  3295. + int old_offset = result.offset();
  3296. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3297. +
  3298. + oop new_location = this_oop()->java_mirror();
  3299. + oop old_location = this_oop->old_version()->java_mirror();
  3300. + int offset = fd->offset();
  3301. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3302. + fd->name()->as_C_string(), old_offset, offset));
  3303. +
  3304. + oop cur_oop;
  3305. +
  3306. + switch(result.field_type()) {
  3307. +
  3308. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3309. +
  3310. + case T_BOOLEAN:
  3311. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3312. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3313. + break;
  3314. +
  3315. + case T_CHAR:
  3316. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3317. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3318. + break;
  3319. +
  3320. + case T_FLOAT:
  3321. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3322. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3323. + break;
  3324. +
  3325. + case T_DOUBLE:
  3326. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3327. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3328. + break;
  3329. +
  3330. + case T_BYTE:
  3331. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3332. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3333. + break;
  3334. +
  3335. + case T_SHORT:
  3336. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3337. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3338. + break;
  3339. +
  3340. + case T_INT:
  3341. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3342. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3343. + break;
  3344. +
  3345. + case T_LONG:
  3346. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3347. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3348. + break;
  3349. +
  3350. + case T_OBJECT:
  3351. + case T_ARRAY:
  3352. + cur_oop = old_location->obj_field(old_offset);
  3353. + new_location->obj_field_put_raw(offset, cur_oop);
  3354. + old_location->obj_field_put_raw(old_offset, NULL);
  3355. + break;
  3356. +
  3357. + default:
  3358. + ShouldNotReachHere();
  3359. + }
  3360. + } else {
  3361. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3362. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3363. + // field not found
  3364. + // (tw) TODO: Probably this call is not necessary here!
  3365. + // FIXME: idubrov
  3366. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3367. + }
  3368. + }
  3369. + };
  3370. +
  3371. + UpdateStaticFieldClosure cl(this_oop);
  3372. + this->do_local_static_fields(&cl);
  3373. +}
  3374. +
  3375. +
  3376. bool instanceKlass::verify_code(
  3377. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3378. // 1) Verify the bytecodes
  3379. Verifier::Mode mode =
  3380. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3381. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3382. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3383. }
  3384. @@ -362,7 +468,13 @@
  3385. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3386. jt->get_thread_stat()->perf_timers_addr(),
  3387. PerfClassTraceTime::CLASS_VERIFY);
  3388. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3389. + if (this_oop->is_redefining()) {
  3390. + Thread::current()->set_pretend_new_universe(true);
  3391. + }
  3392. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3393. + if (this_oop->is_redefining()) {
  3394. + Thread::current()->set_pretend_new_universe(false);
  3395. + }
  3396. if (!verify_ok) {
  3397. return false;
  3398. }
  3399. @@ -400,7 +512,8 @@
  3400. }
  3401. #endif
  3402. this_oop->set_init_state(linked);
  3403. - if (JvmtiExport::should_post_class_prepare()) {
  3404. + // (tw) Must check for old version in order to prevent infinite loops.
  3405. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3406. Thread *thread = THREAD;
  3407. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3408. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3409. @@ -673,6 +786,18 @@
  3410. return false;
  3411. }
  3412. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3413. + k = k->klass_part()->newest_version();
  3414. + if (this->newest_version() == k) return true;
  3415. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3416. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3417. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3418. + return true;
  3419. + }
  3420. + }
  3421. + return false;
  3422. +}
  3423. +
  3424. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3425. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3426. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3427. @@ -801,7 +926,25 @@
  3428. }
  3429. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3430. +
  3431. + ResourceMark rm(THREAD);
  3432. methodHandle h_method(THREAD, this_oop->class_initializer());
  3433. +
  3434. + if (this_oop->revision_number() != -1){
  3435. + methodOop m = NULL;
  3436. + if (AllowAdvancedClassRedefinition) {
  3437. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3438. + }
  3439. + methodHandle method(m);
  3440. + if (method() != NULL && method()->is_static()) {
  3441. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3442. + h_method = method;
  3443. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3444. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3445. + return;
  3446. + }
  3447. + }
  3448. +
  3449. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3450. if (TraceClassInitialization) {
  3451. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3452. @@ -949,6 +1092,137 @@
  3453. }
  3454. }
  3455. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3456. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3457. + for (int i=0; i<values.length(); i++) {
  3458. + arr[i] = values.at(i);
  3459. + }
  3460. + set_update_information(arr);
  3461. +}
  3462. +
  3463. +void instanceKlass::clear_update_information() {
  3464. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3465. + set_update_information(NULL);
  3466. +}
  3467. +
  3468. +typedef Pair<int, klassOop> typeInfoPair;
  3469. +
  3470. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3471. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3472. + for (int i=0; i<values.length(); i++) {
  3473. + arr[i] = values.at(i);
  3474. + }
  3475. + set_type_check_information(arr);
  3476. +}
  3477. +
  3478. +void instanceKlass::clear_type_check_information() {
  3479. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3480. + set_type_check_information(NULL);
  3481. +}
  3482. +
  3483. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3484. +
  3485. + assert (old_version() != NULL, "must have old version!");
  3486. +
  3487. + klassOop old_klass_oop = old_version();
  3488. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3489. + instanceKlass *new_klass = this;
  3490. +
  3491. + fieldDescriptor fd;
  3492. + fieldDescriptor old_fd;
  3493. +
  3494. + instanceKlass *cur_new_klass = new_klass;
  3495. + klassOop cur_new_klass_oop = this->as_klassOop();
  3496. +
  3497. + if (_fields_not_changed) {
  3498. +
  3499. + class MyFieldClosure : public FieldClosure {
  3500. +
  3501. + FieldEvolutionClosure *_cl;
  3502. + public:
  3503. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3504. + virtual void do_field(fieldDescriptor* fd) {
  3505. + _cl->do_changed_field(fd, fd);
  3506. + }
  3507. + };
  3508. +
  3509. + MyFieldClosure mfc(cl);
  3510. + do_nonstatic_fields(&mfc);
  3511. + } else {
  3512. +
  3513. + _fields_not_changed = true;
  3514. + GrowableArray<fieldDescriptor> fds;
  3515. + while (true) {
  3516. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3517. + fd.initialize(cur_new_klass_oop, fs.index());
  3518. + if (fd.is_static()) {
  3519. + continue;
  3520. + }
  3521. + fds.append(fd);
  3522. + }
  3523. +
  3524. + if (cur_new_klass->super() != NULL) {
  3525. + cur_new_klass_oop = cur_new_klass->super();
  3526. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3527. + } else {
  3528. + break;
  3529. + }
  3530. + }
  3531. +
  3532. + GrowableArray<fieldDescriptor> sortedFds;
  3533. + while (fds.length() > 0) {
  3534. + int minOffset = 0x7fffffff;
  3535. + int minIndex = -1;
  3536. + for (int i=0; i<fds.length(); i++) {
  3537. + int curOffset = fds.adr_at(i)->offset();
  3538. + if (curOffset < minOffset) {
  3539. + minOffset = curOffset;
  3540. + minIndex = i;
  3541. + }
  3542. + }
  3543. +
  3544. + sortedFds.append(fds.at(minIndex));
  3545. + fds.remove_at(minIndex);
  3546. + }
  3547. +
  3548. +
  3549. + for (int i=0; i<sortedFds.length(); i++) {
  3550. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3551. +
  3552. + char found = 0;
  3553. + instanceKlass *cur_old_klass = old_klass;
  3554. + klassOop cur_old_klass_oop = old_klass_oop;
  3555. + while (true) {
  3556. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3557. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3558. + if (old_fd.is_static()) {
  3559. + continue;
  3560. + }
  3561. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3562. + found = 1;
  3563. + break;
  3564. + }
  3565. + }
  3566. + if (!found && cur_old_klass->super()) {
  3567. + cur_old_klass_oop = cur_old_klass->super();
  3568. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3569. + } else {
  3570. + break;
  3571. + }
  3572. + }
  3573. +
  3574. + if (found) {
  3575. + if (old_fd.offset() != fd.offset()) {
  3576. + _fields_not_changed = false;
  3577. + }
  3578. + cl->do_changed_field(&old_fd, &fd);
  3579. + } else {
  3580. + _fields_not_changed = false;
  3581. + cl->do_new_field(&fd);
  3582. + }
  3583. + }
  3584. + }
  3585. +}
  3586. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3587. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3588. @@ -1368,6 +1642,20 @@
  3589. return id;
  3590. }
  3591. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3592. + size_t idnum = (size_t)method->method_idnum();
  3593. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3594. + size_t length; // length assigned as debugging crumb
  3595. + jmethodID id = NULL;
  3596. + if (jmeths != NULL && // If there is a cache
  3597. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3598. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3599. + return true;
  3600. + }
  3601. +
  3602. + return false;
  3603. +}
  3604. +
  3605. // Cache an itable index
  3606. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3607. @@ -1527,6 +1815,13 @@
  3608. last = b;
  3609. b = b->next();
  3610. }
  3611. +
  3612. + // (tw) Hack as dependencies get wrong version of klassOop
  3613. + if(this->old_version() != NULL) {
  3614. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3615. + return;
  3616. + }
  3617. +
  3618. #ifdef ASSERT
  3619. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3620. nm->print();
  3621. @@ -2417,6 +2712,9 @@
  3622. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3623. st->print(BULLET"fake entry for mirror: ");
  3624. mirrored_klass->print_value_on(st);
  3625. + if (mirrored_klass != NULL) {
  3626. + 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());
  3627. + }
  3628. st->cr();
  3629. st->print(BULLET"fake entry resolved_constructor: ");
  3630. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3631. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3632. index bb613b0..71f0083 100644
  3633. --- a/src/share/vm/oops/instanceKlass.hpp
  3634. +++ b/src/share/vm/oops/instanceKlass.hpp
  3635. @@ -102,6 +102,22 @@
  3636. virtual void do_field(fieldDescriptor* fd) = 0;
  3637. };
  3638. +// (tw) Iterates over the fields of the old and new class
  3639. +class FieldEvolutionClosure : public StackObj {
  3640. +public:
  3641. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3642. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3643. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3644. +};
  3645. +
  3646. +// (tw) Iterates over the methods of the old and new class
  3647. +class MethodEvolutionClosure : public StackObj {
  3648. +public:
  3649. + virtual void do_new_method(methodOop oop) = 0;
  3650. + virtual void do_old_method(methodOop oop) = 0;
  3651. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3652. +};
  3653. +
  3654. #ifndef PRODUCT
  3655. // Print fields.
  3656. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3657. @@ -287,6 +303,11 @@
  3658. // _idnum_allocated_count.
  3659. u1 _init_state; // state of class
  3660. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3661. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3662. + // information is cached.
  3663. + bool _fields_not_changed;
  3664. +
  3665. u1 _reference_type; // reference type
  3666. // embedded Java vtable follows here
  3667. @@ -454,6 +475,7 @@
  3668. // initialization (virtuals from Klass)
  3669. bool should_be_initialized() const; // means that initialize should be called
  3670. void initialize(TRAPS);
  3671. + void initialize_redefined_class();
  3672. void link_class(TRAPS);
  3673. bool link_class_or_fail(TRAPS); // returns false on failure
  3674. void unlink_class();
  3675. @@ -631,6 +653,7 @@
  3676. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3677. size_t *length_p, jmethodID* id_p);
  3678. jmethodID jmethod_id_or_null(methodOop method);
  3679. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3680. // cached itable index support
  3681. void set_cached_itable_index(size_t idnum, int index);
  3682. @@ -713,6 +736,7 @@
  3683. // subclass/subinterface checks
  3684. bool implements_interface(klassOop k) const;
  3685. + bool implements_interface_any_version(klassOop k) const;
  3686. // Access to the implementor of an interface.
  3687. klassOop implementor() const
  3688. @@ -762,6 +786,12 @@
  3689. void do_local_static_fields(FieldClosure* cl);
  3690. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3691. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3692. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3693. + void store_update_information(GrowableArray<int> &values);
  3694. + void clear_update_information();
  3695. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3696. + void clear_type_check_information();
  3697. +
  3698. void methods_do(void f(methodOop method));
  3699. void array_klasses_do(void f(klassOop k));
  3700. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3701. index 8e7dc12..63d6dc4 100644
  3702. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3703. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3704. @@ -480,6 +480,28 @@
  3705. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3706. klassKlass::oop_print_on(obj, st);
  3707. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3708. +
  3709. + st->print(BULLET"revision: %d", ik->revision_number());
  3710. +
  3711. + if (ik->new_version() != NULL) {
  3712. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3713. + }
  3714. +
  3715. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3716. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3717. + }
  3718. +
  3719. + if (ik->old_version() != NULL) {
  3720. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3721. + }
  3722. +
  3723. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3724. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3725. + }
  3726. +
  3727. + st->cr();
  3728. +
  3729. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3730. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3731. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3732. @@ -663,7 +685,7 @@
  3733. }
  3734. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3735. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3736. - guarantee(sib->super() == super, "siblings should have same superklass");
  3737. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3738. sib = sib->next_sibling();
  3739. }
  3740. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3741. index 7db4f03..1171487 100644
  3742. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3743. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3744. @@ -455,10 +455,13 @@
  3745. instanceKlass* ik = instanceKlass::cast(k);
  3746. // Check that we have the right class
  3747. - debug_only(static bool first_time = true);
  3748. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3749. - "Invalid update of maps");
  3750. - debug_only(first_time = false);
  3751. +
  3752. + // (tw) Asserts no longer valid for class redefinition
  3753. + // debug_only(static bool first_time = true);
  3754. +
  3755. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3756. + // "Invalid update of maps");
  3757. + //debug_only(first_time = false);
  3758. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3759. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3760. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3761. index 596d5ad..767588c 100644
  3762. --- a/src/share/vm/oops/klass.cpp
  3763. +++ b/src/share/vm/oops/klass.cpp
  3764. @@ -55,6 +55,26 @@
  3765. return false;
  3766. }
  3767. +void Klass::update_supers_to_newest_version() {
  3768. +
  3769. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3770. +
  3771. + for (uint i=0; i<primary_super_limit(); i++) {
  3772. + klassOop cur = _primary_supers[i];
  3773. + if (cur != NULL) {
  3774. + _primary_supers[i] = cur->klass_part()->newest_version();
  3775. + }
  3776. + }
  3777. +
  3778. + // Scan the array-of-objects
  3779. + int cnt = secondary_supers()->length();
  3780. + for (int i = 0; i < cnt; i++) {
  3781. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3782. + if (cur != NULL) {
  3783. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3784. + }
  3785. + }
  3786. +}
  3787. bool Klass::search_secondary_supers(klassOop k) const {
  3788. // Put some extra logic here out-of-line, before the search proper.
  3789. // This cuts down the size of the inline method.
  3790. @@ -161,6 +181,16 @@
  3791. kl->set_alloc_size(0);
  3792. TRACE_INIT_ID(kl);
  3793. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3794. + kl->set_redefining(false);
  3795. + kl->set_new_version(NULL);
  3796. + kl->set_old_version(NULL);
  3797. + kl->set_redefinition_index(-1);
  3798. + kl->set_revision_number(-1);
  3799. + kl->set_field_redefinition_policy(DynamicCheck);
  3800. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3801. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3802. +
  3803. kl->set_prototype_header(markOopDesc::prototype());
  3804. kl->set_biased_lock_revocation_count(0);
  3805. kl->set_last_biased_lock_bulk_revocation_time(0);
  3806. @@ -232,7 +262,7 @@
  3807. set_super(NULL);
  3808. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3809. assert(super_depth() == 0, "Object must already be initialized properly");
  3810. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3811. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3812. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3813. "initialize this only once to a non-trivial value");
  3814. set_super(k);
  3815. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3816. index bcbd4e7..d086b5d 100644
  3817. --- a/src/share/vm/oops/klass.hpp
  3818. +++ b/src/share/vm/oops/klass.hpp
  3819. @@ -170,6 +170,7 @@
  3820. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3821. };
  3822. +template<class L, class R> class Pair;
  3823. class Klass : public Klass_vtbl {
  3824. friend class VMStructs;
  3825. @@ -222,6 +223,39 @@
  3826. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3827. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3828. + // (tw) Different class redefinition flags of code evolution.
  3829. + enum RedefinitionFlags {
  3830. +
  3831. + // This class is not redefined at all!
  3832. + NoRedefinition,
  3833. +
  3834. + // There are changes to the class meta data.
  3835. + ModifyClass = 1,
  3836. +
  3837. + // The size of the class meta data changes.
  3838. + ModifyClassSize = ModifyClass << 1,
  3839. +
  3840. + // There are change to the instance format.
  3841. + ModifyInstances = ModifyClassSize << 1,
  3842. +
  3843. + // The size of instances changes.
  3844. + ModifyInstanceSize = ModifyInstances << 1,
  3845. +
  3846. + // A super type of this class is removed.
  3847. + RemoveSuperType = ModifyInstanceSize << 1,
  3848. +
  3849. + // This class (or one of its super classes) has an instance transformer method.
  3850. + HasInstanceTransformer = RemoveSuperType << 1,
  3851. + };
  3852. +
  3853. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3854. + enum RedefinitionPolicy {
  3855. + StaticCheck,
  3856. + DynamicCheck,
  3857. + AccessDeletedMembers,
  3858. + AccessOldMembers
  3859. + };
  3860. +
  3861. protected:
  3862. //
  3863. // The oop block. All oop fields must be declared here and only oop fields
  3864. @@ -241,6 +275,10 @@
  3865. oop _java_mirror;
  3866. // Superclass
  3867. klassOop _super;
  3868. + // Old class
  3869. + klassOop _old_version;
  3870. + // New class
  3871. + klassOop _new_version;
  3872. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3873. klassOop _subklass;
  3874. // Sibling link (or NULL); links all subklasses of a klass
  3875. @@ -252,6 +290,19 @@
  3876. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3877. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3878. +
  3879. + // (tw) Non-oop fields for enhanced class redefinition
  3880. + jint _revision_number; // The revision number for redefined classes
  3881. + jint _redefinition_index; // Index of this class when performing the redefinition
  3882. + bool _subtype_changed;
  3883. + int _redefinition_flags; // Level of class redefinition
  3884. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3885. + int * _update_information; // Update information
  3886. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3887. + char _method_redefinition_policy;
  3888. + char _field_redefinition_policy;
  3889. + char _static_field_redefinition_policy;
  3890. + bool _is_redefining;
  3891. #ifndef PRODUCT
  3892. int _verify_count; // to avoid redundant verifies
  3893. @@ -300,6 +351,99 @@
  3894. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3895. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3896. +
  3897. + // BEGIN class redefinition utilities
  3898. +
  3899. + // double links between new and old version of a class
  3900. + klassOop old_version() const { return _old_version; }
  3901. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3902. + klassOop new_version() const { return _new_version; }
  3903. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3904. +
  3905. + // A subtype of this class is no longer a subtype
  3906. + bool has_subtype_changed() const { return _subtype_changed; }
  3907. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3908. + _subtype_changed = b; }
  3909. + // state of being redefined
  3910. + int redefinition_index() const { return _redefinition_index; }
  3911. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3912. + void set_redefining(bool b) { _is_redefining = b; }
  3913. + bool is_redefining() const { return _is_redefining; }
  3914. + int redefinition_flags() const { return _redefinition_flags; }
  3915. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3916. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3917. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3918. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3919. +
  3920. + // update information
  3921. + int *update_information() const { return _update_information; }
  3922. + void set_update_information(int *info) { _update_information = info; }
  3923. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3924. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3925. +
  3926. + bool is_same_or_older_version(klassOop klass) const {
  3927. + if (Klass::cast(klass) == this) { return true; }
  3928. + else if (_old_version == NULL) { return false; }
  3929. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3930. + }
  3931. +
  3932. + // Revision number for redefined classes, -1 for originally loaded classes
  3933. + jint revision_number() const {
  3934. + return _revision_number;
  3935. + }
  3936. +
  3937. + bool was_redefined() const {
  3938. + return _revision_number != -1;
  3939. + }
  3940. +
  3941. + void set_revision_number(jint number) {
  3942. + _revision_number = number;
  3943. + }
  3944. +
  3945. + char method_redefinition_policy() {
  3946. + return _method_redefinition_policy;
  3947. + }
  3948. +
  3949. + void set_method_redefinition_policy(char v) {
  3950. + _method_redefinition_policy = v;
  3951. + }
  3952. +
  3953. + char field_redefinition_policy() {
  3954. + return _field_redefinition_policy;
  3955. + }
  3956. +
  3957. + void set_field_redefinition_policy(char v) {
  3958. + _field_redefinition_policy = v;
  3959. + }
  3960. +
  3961. + char static_field_redefinition_policy() {
  3962. + return _static_field_redefinition_policy;
  3963. + }
  3964. +
  3965. + void set_static_field_redefinition_policy(char v) {
  3966. + _static_field_redefinition_policy = v;
  3967. + }
  3968. +
  3969. + klassOop oldest_version() const {
  3970. + if (_old_version == NULL) { return this->as_klassOop(); }
  3971. + else { return _old_version->klass_part()->oldest_version(); };
  3972. + }
  3973. +
  3974. + klassOop newest_version() const {
  3975. + if (_new_version == NULL) { return this->as_klassOop(); }
  3976. + else { return _new_version->klass_part()->newest_version(); };
  3977. + }
  3978. +
  3979. + klassOop active_version() const {
  3980. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3981. + else { return _new_version->klass_part()->active_version(); };
  3982. + }
  3983. +
  3984. + bool is_newest_version() const {
  3985. + return _new_version == NULL;
  3986. + }
  3987. +
  3988. + // END class redefinition utilities
  3989. objArrayOop secondary_supers() const { return _secondary_supers; }
  3990. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3991. @@ -361,6 +505,8 @@
  3992. void set_next_sibling(klassOop s);
  3993. oop* adr_super() const { return (oop*)&_super; }
  3994. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3995. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3996. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3997. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3998. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3999. @@ -490,6 +636,7 @@
  4000. return search_secondary_supers(k);
  4001. }
  4002. }
  4003. + void update_supers_to_newest_version();
  4004. bool search_secondary_supers(klassOop k) const;
  4005. // Find LCA in class hierarchy
  4006. @@ -816,6 +963,8 @@
  4007. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  4008. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  4009. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  4010. #endif // SHARE_VM_OOPS_KLASS_HPP
  4011. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  4012. index 06809d5..9c08f32 100644
  4013. --- a/src/share/vm/oops/klassKlass.cpp
  4014. +++ b/src/share/vm/oops/klassKlass.cpp
  4015. @@ -68,6 +68,8 @@
  4016. Klass* k = Klass::cast(klassOop(obj));
  4017. // If we are alive it is valid to keep our superclass and subtype caches alive
  4018. MarkSweep::mark_and_push(k->adr_super());
  4019. + MarkSweep::mark_and_push(k->adr_old_version());
  4020. + MarkSweep::mark_and_push(k->adr_new_version());
  4021. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4022. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  4023. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4024. @@ -87,6 +89,8 @@
  4025. Klass* k = Klass::cast(klassOop(obj));
  4026. // If we are alive it is valid to keep our superclass and subtype caches alive
  4027. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4028. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4029. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4030. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4031. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4032. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4033. @@ -106,6 +110,8 @@
  4034. int size = oop_size(obj);
  4035. Klass* k = Klass::cast(klassOop(obj));
  4036. blk->do_oop(k->adr_super());
  4037. + blk->do_oop(k->adr_old_version());
  4038. + blk->do_oop(k->adr_new_version());
  4039. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4040. blk->do_oop(k->adr_primary_supers()+i);
  4041. blk->do_oop(k->adr_secondary_super_cache());
  4042. @@ -134,6 +140,10 @@
  4043. oop* adr;
  4044. adr = k->adr_super();
  4045. if (mr.contains(adr)) blk->do_oop(adr);
  4046. + adr = k->adr_old_version();
  4047. + if (mr.contains(adr)) blk->do_oop(adr);
  4048. + adr = k->adr_new_version();
  4049. + if (mr.contains(adr)) blk->do_oop(adr);
  4050. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4051. adr = k->adr_primary_supers()+i;
  4052. if (mr.contains(adr)) blk->do_oop(adr);
  4053. @@ -147,6 +157,8 @@
  4054. // The following are "weak links" in the perm gen and are
  4055. // treated specially in a later phase of a perm gen collection.
  4056. assert(oop(k)->is_perm(), "should be in perm");
  4057. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4058. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4059. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4060. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4061. if (blk->should_remember_klasses()
  4062. @@ -167,6 +179,8 @@
  4063. Klass* k = Klass::cast(klassOop(obj));
  4064. MarkSweep::adjust_pointer(k->adr_super());
  4065. + MarkSweep::adjust_pointer(k->adr_new_version());
  4066. + MarkSweep::adjust_pointer(k->adr_old_version());
  4067. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4068. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4069. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4070. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4071. index f212fc5..9731a9c 100644
  4072. --- a/src/share/vm/oops/klassOop.hpp
  4073. +++ b/src/share/vm/oops/klassOop.hpp
  4074. @@ -41,8 +41,10 @@
  4075. // returns the Klass part containing dispatching behavior
  4076. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4077. - // Convenience wrapper
  4078. + // Convenience wrappers
  4079. inline oop java_mirror() const;
  4080. + inline klassOop old_version() const;
  4081. + inline klassOop new_version() const;
  4082. private:
  4083. // These have no implementation since klassOop should never be accessed in this fashion
  4084. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4085. index 94e2e04..09d3088 100644
  4086. --- a/src/share/vm/oops/klassVtable.cpp
  4087. +++ b/src/share/vm/oops/klassVtable.cpp
  4088. @@ -97,7 +97,8 @@
  4089. vtable_length = Universe::base_vtable_size();
  4090. }
  4091. - if (super == NULL && !Universe::is_bootstrapping() &&
  4092. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4093. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4094. vtable_length != Universe::base_vtable_size()) {
  4095. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4096. // only way this should happen is from
  4097. @@ -107,9 +108,9 @@
  4098. vtable_length = Universe::base_vtable_size();
  4099. }
  4100. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4101. - "bad vtable size for class Object");
  4102. + "bad vtable size for class Object");*/
  4103. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4104. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4105. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4106. }
  4107. int klassVtable::index_of(methodOop m, int len) const {
  4108. @@ -655,20 +656,6 @@
  4109. }
  4110. }
  4111. return true;
  4112. -}
  4113. -
  4114. -void klassVtable::dump_vtable() {
  4115. - tty->print_cr("vtable dump --");
  4116. - for (int i = 0; i < length(); i++) {
  4117. - methodOop m = unchecked_method_at(i);
  4118. - if (m != NULL) {
  4119. - tty->print(" (%5d) ", i);
  4120. - m->access_flags().print_on(tty);
  4121. - tty->print(" -- ");
  4122. - m->print_name(tty);
  4123. - tty->cr();
  4124. - }
  4125. - }
  4126. }
  4127. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4128. @@ -1241,6 +1228,7 @@
  4129. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4130. vtableEntry* vte = &vt->table()[index];
  4131. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4132. if (vte->method()->name() != table()[index].method()->name() ||
  4133. vte->method()->signature() != table()[index].method()->signature()) {
  4134. fatal("mismatched name/signature of vtable entries");
  4135. @@ -1260,6 +1248,8 @@
  4136. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4137. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4138. + // (tw) TODO: Check: Does not hold?
  4139. + if (method() != NULL) {
  4140. assert(method() != NULL, "must have set method");
  4141. method()->verify();
  4142. // we sub_type, because it could be a miranda method
  4143. @@ -1267,7 +1257,13 @@
  4144. #ifndef PRODUCT
  4145. print();
  4146. #endif
  4147. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4148. + klassOop first_klass = vt->klass()();
  4149. + klassOop second_klass = method()->method_holder();
  4150. + // (tw) the following fatal does not work for old versions of classes
  4151. + if (first_klass->klass_part()->is_newest_version()) {
  4152. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4153. + }
  4154. + }
  4155. }
  4156. }
  4157. @@ -1275,7 +1271,7 @@
  4158. void vtableEntry::print() {
  4159. ResourceMark rm;
  4160. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4161. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4162. if (Verbose) {
  4163. tty->print("m %#lx ", (address)method());
  4164. }
  4165. @@ -1342,6 +1338,33 @@
  4166. tty->print_cr("%6d bytes total", total);
  4167. }
  4168. +bool klassVtable::check_no_old_entries() {
  4169. + // Check that there really is no entry
  4170. + for (int i = 0; i < length(); i++) {
  4171. + methodOop m = unchecked_method_at(i);
  4172. + if (m != NULL) {
  4173. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4174. + return false;
  4175. + }
  4176. + }
  4177. + }
  4178. + return true;
  4179. +}
  4180. +
  4181. +void klassVtable::dump_vtable() {
  4182. + tty->print_cr("vtable dump --");
  4183. + for (int i = 0; i < length(); i++) {
  4184. + methodOop m = unchecked_method_at(i);
  4185. + if (m != NULL) {
  4186. + tty->print(" (%5d) ", i);
  4187. + m->access_flags().print_on(tty);
  4188. + tty->print(" -- ");
  4189. + m->print_name(tty);
  4190. + tty->cr();
  4191. + }
  4192. + }
  4193. +}
  4194. +
  4195. int klassItable::_total_classes; // Total no. of classes with itables
  4196. long klassItable::_total_size; // Total no. of bytes used for itables
  4197. diff --git a/src/share/vm/oops/klassVtable.hpp b/src/share/vm/oops/klassVtable.hpp
  4198. index 405b0c7..0c8d2f7 100644
  4199. --- a/src/share/vm/oops/klassVtable.hpp
  4200. +++ b/src/share/vm/oops/klassVtable.hpp
  4201. @@ -100,6 +100,7 @@
  4202. int methods_length, bool * trace_name_printed);
  4203. bool check_no_old_or_obsolete_entries();
  4204. void dump_vtable();
  4205. + bool check_no_old_entries();
  4206. // Garbage collection
  4207. void oop_follow_contents();
  4208. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4209. index 75d0b09..f1b7d2f 100644
  4210. --- a/src/share/vm/oops/methodKlass.cpp
  4211. +++ b/src/share/vm/oops/methodKlass.cpp
  4212. @@ -93,6 +93,10 @@
  4213. m->set_adapter_entry(NULL);
  4214. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4215. + m->set_forward_method(NULL);
  4216. + m->set_new_version(NULL);
  4217. + m->set_old_version(NULL);
  4218. +
  4219. if (access_flags.is_native()) {
  4220. m->clear_native_function();
  4221. m->set_signature_handler(NULL);
  4222. @@ -122,6 +126,9 @@
  4223. // Performance tweak: We skip iterating over the klass pointer since we
  4224. // know that Universe::methodKlassObj never moves.
  4225. MarkSweep::mark_and_push(m->adr_constMethod());
  4226. + MarkSweep::mark_and_push(m->adr_forward_method());
  4227. + MarkSweep::mark_and_push(m->adr_new_version());
  4228. + MarkSweep::mark_and_push(m->adr_old_version());
  4229. if (m->method_data() != NULL) {
  4230. MarkSweep::mark_and_push(m->adr_method_data());
  4231. }
  4232. @@ -135,6 +142,9 @@
  4233. // Performance tweak: We skip iterating over the klass pointer since we
  4234. // know that Universe::methodKlassObj never moves.
  4235. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4236. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4237. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4238. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4239. #ifdef COMPILER2
  4240. if (m->method_data() != NULL) {
  4241. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4242. @@ -152,6 +162,9 @@
  4243. // Performance tweak: We skip iterating over the klass pointer since we
  4244. // know that Universe::methodKlassObj never moves
  4245. blk->do_oop(m->adr_constMethod());
  4246. + blk->do_oop(m->adr_forward_method());
  4247. + blk->do_oop(m->adr_new_version());
  4248. + blk->do_oop(m->adr_old_version());
  4249. if (m->method_data() != NULL) {
  4250. blk->do_oop(m->adr_method_data());
  4251. }
  4252. @@ -170,6 +183,12 @@
  4253. oop* adr;
  4254. adr = m->adr_constMethod();
  4255. if (mr.contains(adr)) blk->do_oop(adr);
  4256. + adr = m->adr_new_version();
  4257. + if (mr.contains(adr)) blk->do_oop(adr);
  4258. + adr = m->adr_forward_method();
  4259. + if (mr.contains(adr)) blk->do_oop(adr);
  4260. + adr = m->adr_old_version();
  4261. + if (mr.contains(adr)) blk->do_oop(adr);
  4262. if (m->method_data() != NULL) {
  4263. adr = m->adr_method_data();
  4264. if (mr.contains(adr)) blk->do_oop(adr);
  4265. @@ -187,6 +206,9 @@
  4266. // Performance tweak: We skip iterating over the klass pointer since we
  4267. // know that Universe::methodKlassObj never moves.
  4268. MarkSweep::adjust_pointer(m->adr_constMethod());
  4269. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4270. + MarkSweep::adjust_pointer(m->adr_new_version());
  4271. + MarkSweep::adjust_pointer(m->adr_old_version());
  4272. if (m->method_data() != NULL) {
  4273. MarkSweep::adjust_pointer(m->adr_method_data());
  4274. }
  4275. @@ -202,6 +224,9 @@
  4276. assert(obj->is_method(), "should be method");
  4277. methodOop m = methodOop(obj);
  4278. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4279. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4280. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4281. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4282. #ifdef COMPILER2
  4283. if (m->method_data() != NULL) {
  4284. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4285. @@ -222,7 +247,18 @@
  4286. methodOop m = methodOop(obj);
  4287. // get the effect of PrintOopAddress, always, for methods:
  4288. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4289. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4290. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4291. +
  4292. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4293. + st->print(" (old)");
  4294. + }
  4295. + st->cr();
  4296. +
  4297. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4298. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4299. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4300. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4301. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4302. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4303. m->constants()->print_value_on(st); st->cr();
  4304. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4305. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4306. index 4f59d3a..5cdf147 100644
  4307. --- a/src/share/vm/oops/methodOop.cpp
  4308. +++ b/src/share/vm/oops/methodOop.cpp
  4309. @@ -328,6 +328,70 @@
  4310. }
  4311. +bool methodOopDesc::is_in_code_section(int bci) {
  4312. + // There is no table => every bci is in the code section table.
  4313. + if (!constMethod()->has_code_section_table()) return true;
  4314. +
  4315. + constMethodOop m = constMethod();
  4316. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4317. + u2 new_index = m->code_section_new_index_at(i);
  4318. + u2 length = m->code_section_length_at(i);
  4319. + if (bci >= new_index && bci < new_index + length) {
  4320. + // We are in a specified code section.
  4321. + return true;
  4322. + }
  4323. + }
  4324. +
  4325. + return false;
  4326. +}
  4327. +
  4328. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4329. + int original_bci = -1;
  4330. + if (constMethod()->has_code_section_table()) {
  4331. + assert(is_in_code_section(bci), "can only forward in section");
  4332. + // First calculate back to original bci.
  4333. + constMethodOop m = constMethod();
  4334. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4335. + u2 new_index = m->code_section_new_index_at(i);
  4336. + u2 original_index = m->code_section_original_index_at(i);
  4337. + u2 length = m->code_section_length_at(i);
  4338. + if (bci >= new_index && bci < new_index + length) {
  4339. + // We are in a specified code section.
  4340. + original_bci = bci - new_index + original_index;
  4341. + break;
  4342. + }
  4343. + }
  4344. + assert (original_bci != -1, "must have been in code section");
  4345. + } else {
  4346. + // No code sections specified => we are in an original method.
  4347. + original_bci = bci;
  4348. + }
  4349. +
  4350. + // We know the original bci => match to new method.
  4351. + int new_bci = -1;
  4352. + if (new_method->constMethod()->has_code_section_table()) {
  4353. + // Map to new bci.
  4354. + constMethodOop m = new_method->constMethod();
  4355. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4356. + u2 new_index = m->code_section_new_index_at(i);
  4357. + u2 original_index = m->code_section_original_index_at(i);
  4358. + u2 length = m->code_section_length_at(i);
  4359. + if (original_bci >= original_index && original_bci < original_index + length) {
  4360. + new_bci = original_bci - original_index + new_index;
  4361. + break;
  4362. + }
  4363. + }
  4364. + assert (new_bci != -1, "must have found new code section");
  4365. +
  4366. + } else {
  4367. + // We are in an original method.
  4368. + new_bci = original_bci;
  4369. + }
  4370. +
  4371. + return new_bci;
  4372. +}
  4373. +
  4374. +
  4375. int methodOopDesc::extra_stack_words() {
  4376. // not an inline function, to avoid a header dependency on Interpreter
  4377. return extra_stack_entries() * Interpreter::stackElementSize;
  4378. @@ -1061,6 +1125,9 @@
  4379. // Reset correct method/const method, method size, and parameter info
  4380. newm->set_constMethod(newcm);
  4381. + newm->set_forward_method(newm->forward_method());
  4382. + newm->set_new_version(newm->new_version());
  4383. + newm->set_old_version(newm->old_version());
  4384. newm->constMethod()->set_code_size(new_code_length);
  4385. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4386. newm->set_method_size(new_method_size);
  4387. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4388. index 486e106..11e52bb 100644
  4389. --- a/src/share/vm/oops/methodOop.hpp
  4390. +++ b/src/share/vm/oops/methodOop.hpp
  4391. @@ -114,6 +114,11 @@
  4392. AccessFlags _access_flags; // Access flags
  4393. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4394. // note: can have vtables with >2**16 elements (because of inheritance)
  4395. + // (tw) Newer version of method available?
  4396. + methodOop _forward_method;
  4397. + methodOop _new_version;
  4398. + methodOop _old_version;
  4399. +
  4400. #ifdef CC_INTERP
  4401. int _result_index; // C++ interpreter needs for converting results to/from stack
  4402. #endif
  4403. @@ -174,6 +179,32 @@
  4404. Symbol* name() const { return constants()->symbol_at(name_index()); }
  4405. int name_index() const { return constMethod()->name_index(); }
  4406. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4407. +
  4408. + methodOop forward_method() const {return _forward_method; }
  4409. + void set_forward_method(methodOop m) { _forward_method = m; }
  4410. + bool has_forward_method() const { return forward_method() != NULL; }
  4411. + methodOop new_version() const {return _new_version; }
  4412. + void set_new_version(methodOop m) { _new_version = m; }
  4413. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4414. +
  4415. + methodOop old_version() const {return _old_version; };
  4416. + void set_old_version(methodOop m) {
  4417. + if (m == NULL) {
  4418. + _old_version = NULL;
  4419. + return;
  4420. + }
  4421. +
  4422. + assert(_old_version == NULL, "may only be set once");
  4423. + assert(this->code_size() == m->code_size(), "must have same code length");
  4424. + _old_version = m;
  4425. + }
  4426. +
  4427. + methodOop oldest_version() const {
  4428. + if(_old_version == NULL) return (methodOop)this;
  4429. + else {
  4430. + return old_version()->oldest_version();
  4431. + }
  4432. + }
  4433. // signature
  4434. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4435. @@ -670,6 +701,10 @@
  4436. // Inline cache support
  4437. void cleanup_inline_caches();
  4438. + // (tw) Method forwarding support.
  4439. + bool is_in_code_section(int bci);
  4440. + int calculate_forward_bci(int bci, methodOop new_method);
  4441. +
  4442. // Find if klass for method is loaded
  4443. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4444. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4445. @@ -734,6 +769,9 @@
  4446. // Garbage collection support
  4447. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4448. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4449. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4450. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4451. oop* adr_method_data() const { return (oop*)&_method_data; }
  4452. };
  4453. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4454. index 5982c88..4873fca 100644
  4455. --- a/src/share/vm/oops/oop.hpp
  4456. +++ b/src/share/vm/oops/oop.hpp
  4457. @@ -95,6 +95,7 @@
  4458. narrowOop* compressed_klass_addr();
  4459. void set_klass(klassOop k);
  4460. + void set_klass_no_check(klassOop k);
  4461. // For klass field compression
  4462. int klass_gap() const;
  4463. @@ -135,6 +136,7 @@
  4464. bool is_array() const;
  4465. bool is_objArray() const;
  4466. bool is_klass() const;
  4467. + bool is_instanceKlass() const;
  4468. bool is_thread() const;
  4469. bool is_method() const;
  4470. bool is_constMethod() const;
  4471. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4472. index f4eb2f7..0acb346 100644
  4473. --- a/src/share/vm/oops/oop.inline.hpp
  4474. +++ b/src/share/vm/oops/oop.inline.hpp
  4475. @@ -123,6 +123,14 @@
  4476. }
  4477. }
  4478. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4479. + if (UseCompressedOops) {
  4480. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4481. + } else {
  4482. + oop_store_without_check(klass_addr(), (oop) k);
  4483. + }
  4484. +}
  4485. +
  4486. inline int oopDesc::klass_gap() const {
  4487. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4488. }
  4489. @@ -156,6 +164,7 @@
  4490. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4491. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4492. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4493. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4494. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4495. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4496. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4497. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4498. index 8d82439..0e95b14 100644
  4499. --- a/src/share/vm/prims/jni.cpp
  4500. +++ b/src/share/vm/prims/jni.cpp
  4501. @@ -406,7 +406,7 @@
  4502. }
  4503. }
  4504. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4505. - Handle(), &st, true,
  4506. + Handle(), &st, true, KlassHandle(),
  4507. CHECK_NULL);
  4508. if (TraceClassResolution && k != NULL) {
  4509. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4510. index 7dcd968..d59052f 100644
  4511. --- a/src/share/vm/prims/jvm.cpp
  4512. +++ b/src/share/vm/prims/jvm.cpp
  4513. @@ -872,7 +872,7 @@
  4514. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4515. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4516. protection_domain, &st,
  4517. - verify != 0,
  4518. + verify != 0, KlassHandle(),
  4519. CHECK_NULL);
  4520. if (TraceClassResolution && k != NULL) {
  4521. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4522. index 4ac6b82..30b8e84 100644
  4523. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4524. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4525. @@ -290,7 +290,10 @@
  4526. class_definitions[index].klass = jcls;
  4527. }
  4528. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4529. - VMThread::execute(&op);
  4530. + {
  4531. + MutexLocker sd_mutex(RedefineClasses_lock);
  4532. + VMThread::execute(&op);
  4533. + }
  4534. return (op.check_error());
  4535. } /* end RetransformClasses */
  4536. @@ -299,9 +302,12 @@
  4537. // class_definitions - pre-checked for NULL
  4538. jvmtiError
  4539. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4540. -//TODO: add locking
  4541. +
  4542. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4543. - VMThread::execute(&op);
  4544. + {
  4545. + MutexLocker sd_mutex(RedefineClasses_lock);
  4546. + VMThread::execute(&op);
  4547. + }
  4548. return (op.check_error());
  4549. } /* end RedefineClasses */
  4550. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4551. index ec8ede3..2bd5983 100644
  4552. --- a/src/share/vm/prims/jvmtiExport.cpp
  4553. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4554. @@ -2296,7 +2296,7 @@
  4555. // iterate over any code blob descriptors collected and post a
  4556. // DYNAMIC_CODE_GENERATED event to the profiler.
  4557. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4558. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4559. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4560. // iterate over any code blob descriptors that we collected
  4561. if (_code_blobs != NULL) {
  4562. for (int i=0; i<_code_blobs->length(); i++) {
  4563. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4564. index d3fa140..f4f8b57 100644
  4565. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4566. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4567. @@ -286,6 +286,8 @@
  4568. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4569. ((methodOopDesc*)_method->*meth_act)(_bci);
  4570. + // DCEVM: TODO: Check how we can implement this differently here!
  4571. +
  4572. // add/remove breakpoint to/from versions of the method that
  4573. // are EMCP. Directly or transitively obsolete methods are
  4574. // not saved in the PreviousVersionInfo.
  4575. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4576. index 606be1c..ef4f380 100644
  4577. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4578. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4579. @@ -1,5 +1,5 @@
  4580. /*
  4581. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  4582. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4583. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4584. *
  4585. * This code is free software; you can redistribute it and/or modify it
  4586. @@ -30,581 +30,637 @@
  4587. #include "interpreter/rewriter.hpp"
  4588. #include "memory/gcLocker.hpp"
  4589. #include "memory/universe.inline.hpp"
  4590. -#include "oops/fieldStreams.hpp"
  4591. +#include "memory/cardTableRS.hpp"
  4592. #include "oops/klassVtable.hpp"
  4593. +#include "oops/fieldStreams.hpp"
  4594. #include "prims/jvmtiImpl.hpp"
  4595. #include "prims/jvmtiRedefineClasses.hpp"
  4596. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4597. #include "prims/methodComparator.hpp"
  4598. -#include "prims/methodHandles.hpp"
  4599. #include "runtime/deoptimization.hpp"
  4600. #include "runtime/relocator.hpp"
  4601. #include "utilities/bitMap.inline.hpp"
  4602. +#include "compiler/compileBroker.hpp"
  4603. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4604. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4605. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4606. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4607. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4608. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4609. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4610. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4611. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4612. +int* VM_RedefineClasses::_added_methods = NULL;
  4613. int VM_RedefineClasses::_matching_methods_length = 0;
  4614. int VM_RedefineClasses::_deleted_methods_length = 0;
  4615. int VM_RedefineClasses::_added_methods_length = 0;
  4616. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4617. +// Holds the revision number of the current class redefinition
  4618. +int VM_RedefineClasses::_revision_number = -1;
  4619. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4620. - const jvmtiClassDefinition *class_defs,
  4621. - JvmtiClassLoadKind class_load_kind) {
  4622. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4623. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4624. + RC_TIMER_START(_timer_total);
  4625. _class_count = class_count;
  4626. _class_defs = class_defs;
  4627. _class_load_kind = class_load_kind;
  4628. - _res = JVMTI_ERROR_NONE;
  4629. + _updated_oops = NULL;
  4630. + _result = JVMTI_ERROR_NONE;
  4631. }
  4632. -bool VM_RedefineClasses::doit_prologue() {
  4633. - if (_class_count == 0) {
  4634. - _res = JVMTI_ERROR_NONE;
  4635. - return false;
  4636. +VM_RedefineClasses::~VM_RedefineClasses() {
  4637. + {
  4638. + MonitorLockerEx ml(RedefinitionSync_lock);
  4639. + Threads::set_wait_at_instrumentation_entry(false);
  4640. + ml.notify_all();
  4641. }
  4642. - if (_class_defs == NULL) {
  4643. - _res = JVMTI_ERROR_NULL_POINTER;
  4644. - return false;
  4645. +
  4646. + unlock_threads();
  4647. + RC_TIMER_STOP(_timer_total);
  4648. +
  4649. + if (TimeRedefineClasses) {
  4650. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4651. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4652. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4653. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4654. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4655. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4656. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4657. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4658. + tty->print_cr("------------------------------------------------------------------");
  4659. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4660. }
  4661. - for (int i = 0; i < _class_count; i++) {
  4662. - if (_class_defs[i].klass == NULL) {
  4663. - _res = JVMTI_ERROR_INVALID_CLASS;
  4664. - return false;
  4665. - }
  4666. - if (_class_defs[i].class_byte_count == 0) {
  4667. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4668. - return false;
  4669. - }
  4670. - if (_class_defs[i].class_bytes == NULL) {
  4671. - _res = JVMTI_ERROR_NULL_POINTER;
  4672. - return false;
  4673. +}
  4674. +
  4675. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4676. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4677. +
  4678. + // Create array with all classes for which the redefine command was given
  4679. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4680. + for (int i=0; i<_class_count; i++) {
  4681. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4682. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4683. + klasses_to_redefine.append(klass_handle);
  4684. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4685. + }
  4686. +
  4687. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4688. + GrowableArray<instanceKlassHandle> affected_classes;
  4689. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4690. +
  4691. + // Trace affected classes
  4692. + if (RC_TRACE_ENABLED(0x00000001)) {
  4693. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4694. + affected_classes.length()));
  4695. + for (int i=0; i<affected_classes.length(); i++) {
  4696. + RC_TRACE(0x00000001, ("%s",
  4697. + affected_classes.at(i)->name()->as_C_string()));
  4698. }
  4699. }
  4700. - // Start timer after all the sanity checks; not quite accurate, but
  4701. - // better than adding a bunch of stop() calls.
  4702. - RC_TIMER_START(_timer_vm_op_prologue);
  4703. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4704. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4705. + all_affected_klasses->appendAll(&affected_classes);
  4706. +
  4707. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4708. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4709. + if (RC_TRACE_ENABLED(0x00000001)) {
  4710. + RC_TRACE(0x00000001, ("Redefine order: "));
  4711. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4712. + RC_TRACE(0x00000001, ("%s",
  4713. + all_affected_klasses->at(i)->name()->as_C_string()));
  4714. + }
  4715. + }
  4716. +
  4717. + return result;
  4718. +}
  4719. +
  4720. +// Searches for the class bytes of the given class and returns them as a byte array.
  4721. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4722. +
  4723. + *not_changed = false;
  4724. +
  4725. + // Search for the index in the redefinition array that corresponds to the current class
  4726. + int j;
  4727. + for (j=0; j<_class_count; j++) {
  4728. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4729. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4730. + if (the_class_oop == the_class()) {
  4731. + break;
  4732. + }
  4733. + }
  4734. +
  4735. + if (j == _class_count) {
  4736. +
  4737. + *not_changed = true;
  4738. +
  4739. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4740. + // so the user did not specify a different bytecode for that class.
  4741. +
  4742. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4743. + // not cached, we need to reconstitute the class file from VM representation
  4744. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4745. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4746. +
  4747. + JvmtiClassFileReconstituter reconstituter(the_class);
  4748. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4749. + return reconstituter.get_error();
  4750. + }
  4751. +
  4752. + *class_byte_count = (jint)reconstituter.class_file_size();
  4753. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4754. +
  4755. + } else {
  4756. +
  4757. + // it is cached, get it from the cache
  4758. + *class_byte_count = the_class->get_cached_class_file_len();
  4759. + *class_bytes = the_class->get_cached_class_file_bytes();
  4760. + }
  4761. +
  4762. + } else {
  4763. +
  4764. + // Redefine with bytecodes at index j
  4765. + *class_bytes = _class_defs[j].class_bytes;
  4766. + *class_byte_count = _class_defs[j].class_byte_count;
  4767. + }
  4768. +
  4769. + return JVMTI_ERROR_NONE;
  4770. +}
  4771. +
  4772. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4773. +bool VM_RedefineClasses::doit_prologue() {
  4774. +
  4775. + _revision_number++;
  4776. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4777. +
  4778. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4779. + RC_TIMER_START(_timer_prologue);
  4780. +
  4781. + if (!check_arguments()) {
  4782. + RC_TIMER_STOP(_timer_prologue);
  4783. + return false;
  4784. + }
  4785. // We first load new class versions in the prologue, because somewhere down the
  4786. // call chain it is required that the current thread is a Java thread.
  4787. - _res = load_new_class_versions(Thread::current());
  4788. - if (_res != JVMTI_ERROR_NONE) {
  4789. - // Free os::malloc allocated memory in load_new_class_version.
  4790. - os::free(_scratch_classes);
  4791. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4792. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4793. + _result = load_new_class_versions(Thread::current());
  4794. +
  4795. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4796. + if (_result != JVMTI_ERROR_NONE) {
  4797. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4798. + delete _new_classes;
  4799. + _new_classes = NULL;
  4800. + RC_TIMER_STOP(_timer_prologue);
  4801. return false;
  4802. }
  4803. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4804. + RC_TRACE(0x00000001, ("nearly finished"));
  4805. + VM_GC_Operation::doit_prologue();
  4806. + RC_TIMER_STOP(_timer_prologue);
  4807. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4808. return true;
  4809. }
  4810. -void VM_RedefineClasses::doit() {
  4811. - Thread *thread = Thread::current();
  4812. +// Checks basic properties of the arguments of the redefinition command.
  4813. +bool VM_RedefineClasses::check_arguments() {
  4814. - if (UseSharedSpaces) {
  4815. - // Sharing is enabled so we remap the shared readonly space to
  4816. - // shared readwrite, private just in case we need to redefine
  4817. - // a shared class. We do the remap during the doit() phase of
  4818. - // the safepoint to be safer.
  4819. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4820. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4821. - ("failed to remap shared readonly space to readwrite, private"));
  4822. - _res = JVMTI_ERROR_INTERNAL;
  4823. - return;
  4824. - }
  4825. - }
  4826. -
  4827. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4828. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4829. for (int i = 0; i < _class_count; i++) {
  4830. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4831. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4832. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4833. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4834. }
  4835. - // Disable any dependent concurrent compilations
  4836. - SystemDictionary::notice_modification();
  4837. - // Set flag indicating that some invariants are no longer true.
  4838. - // See jvmtiExport.hpp for detailed explanation.
  4839. - JvmtiExport::set_has_redefined_a_class();
  4840. -
  4841. -// check_class() is optionally called for product bits, but is
  4842. -// always called for non-product bits.
  4843. -#ifdef PRODUCT
  4844. - if (RC_TRACE_ENABLED(0x00004000)) {
  4845. -#endif
  4846. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4847. - SystemDictionary::classes_do(check_class, thread);
  4848. -#ifdef PRODUCT
  4849. - }
  4850. -#endif
  4851. -}
  4852. -
  4853. -void VM_RedefineClasses::doit_epilogue() {
  4854. - // Free os::malloc allocated memory.
  4855. - // The memory allocated in redefine will be free'ed in next VM operation.
  4856. - os::free(_scratch_classes);
  4857. -
  4858. - if (RC_TRACE_ENABLED(0x00000004)) {
  4859. - // Used to have separate timers for "doit" and "all", but the timer
  4860. - // overhead skewed the measurements.
  4861. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4862. - _timer_rsc_phase2.milliseconds();
  4863. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4864. -
  4865. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4866. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4867. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4868. - RC_TRACE(0x00000004,
  4869. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4870. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4871. - }
  4872. -}
  4873. -
  4874. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4875. - // classes for primitives cannot be redefined
  4876. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4877. - return false;
  4878. - }
  4879. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4880. - // classes for arrays cannot be redefined
  4881. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4882. - return false;
  4883. - }
  4884. return true;
  4885. }
  4886. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4887. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4888. -// direct CP entries, there is just the current entry to append. For
  4889. -// indirect and double-indirect CP entries, there are zero or more
  4890. -// referenced CP entries along with the current entry to append.
  4891. -// Indirect and double-indirect CP entries are handled by recursive
  4892. -// calls to append_entry() as needed. The referenced CP entries are
  4893. -// always appended to *merge_cp_p before the referee CP entry. These
  4894. -// referenced CP entries may already exist in *merge_cp_p in which case
  4895. -// there is nothing extra to append and only the current entry is
  4896. -// appended.
  4897. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4898. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4899. - TRAPS) {
  4900. +jvmtiError VM_RedefineClasses::check_exception() const {
  4901. + Thread* THREAD = Thread::current();
  4902. + if (HAS_PENDING_EXCEPTION) {
  4903. - // append is different depending on entry tag type
  4904. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4905. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4906. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4907. + ex_name->as_C_string()));
  4908. + if (TraceRedefineClasses >= 1) {
  4909. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4910. + tty->print_cr("");
  4911. + }
  4912. + CLEAR_PENDING_EXCEPTION;
  4913. - // The old verifier is implemented outside the VM. It loads classes,
  4914. - // but does not resolve constant pool entries directly so we never
  4915. - // see Class entries here with the old verifier. Similarly the old
  4916. - // verifier does not like Class entries in the input constant pool.
  4917. - // The split-verifier is implemented in the VM so it can optionally
  4918. - // and directly resolve constant pool entries to load classes. The
  4919. - // split-verifier can accept either Class entries or UnresolvedClass
  4920. - // entries in the input constant pool. We revert the appended copy
  4921. - // back to UnresolvedClass so that either verifier will be happy
  4922. - // with the constant pool entry.
  4923. - case JVM_CONSTANT_Class:
  4924. - {
  4925. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4926. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4927. - scratch_cp->klass_name_at(scratch_i));
  4928. -
  4929. - if (scratch_i != *merge_cp_length_p) {
  4930. - // The new entry in *merge_cp_p is at a different index than
  4931. - // the new entry in scratch_cp so we need to map the index values.
  4932. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4933. - }
  4934. - (*merge_cp_length_p)++;
  4935. - } break;
  4936. -
  4937. - // these are direct CP entries so they can be directly appended,
  4938. - // but double and long take two constant pool entries
  4939. - case JVM_CONSTANT_Double: // fall through
  4940. - case JVM_CONSTANT_Long:
  4941. - {
  4942. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4943. - THREAD);
  4944. -
  4945. - if (scratch_i != *merge_cp_length_p) {
  4946. - // The new entry in *merge_cp_p is at a different index than
  4947. - // the new entry in scratch_cp so we need to map the index values.
  4948. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4949. - }
  4950. - (*merge_cp_length_p) += 2;
  4951. - } break;
  4952. -
  4953. - // these are direct CP entries so they can be directly appended
  4954. - case JVM_CONSTANT_Float: // fall through
  4955. - case JVM_CONSTANT_Integer: // fall through
  4956. - case JVM_CONSTANT_Utf8: // fall through
  4957. -
  4958. - // This was an indirect CP entry, but it has been changed into
  4959. - // an interned string so this entry can be directly appended.
  4960. - case JVM_CONSTANT_String: // fall through
  4961. -
  4962. - // These were indirect CP entries, but they have been changed into
  4963. - // Symbol*s so these entries can be directly appended.
  4964. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4965. - case JVM_CONSTANT_UnresolvedString:
  4966. - {
  4967. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4968. - THREAD);
  4969. -
  4970. - if (scratch_i != *merge_cp_length_p) {
  4971. - // The new entry in *merge_cp_p is at a different index than
  4972. - // the new entry in scratch_cp so we need to map the index values.
  4973. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4974. - }
  4975. - (*merge_cp_length_p)++;
  4976. - } break;
  4977. -
  4978. - // this is an indirect CP entry so it needs special handling
  4979. - case JVM_CONSTANT_NameAndType:
  4980. - {
  4981. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4982. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  4983. - merge_cp_length_p, THREAD);
  4984. -
  4985. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  4986. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  4987. - merge_cp_p, merge_cp_length_p,
  4988. - THREAD);
  4989. -
  4990. - // If the referenced entries already exist in *merge_cp_p, then
  4991. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  4992. - // In that case, all we are appending is the current entry.
  4993. - if (new_name_ref_i != name_ref_i) {
  4994. - RC_TRACE(0x00080000,
  4995. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  4996. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  4997. - }
  4998. - if (new_signature_ref_i != signature_ref_i) {
  4999. - RC_TRACE(0x00080000,
  5000. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5001. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5002. - }
  5003. -
  5004. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5005. - new_name_ref_i, new_signature_ref_i);
  5006. - if (scratch_i != *merge_cp_length_p) {
  5007. - // The new entry in *merge_cp_p is at a different index than
  5008. - // the new entry in scratch_cp so we need to map the index values.
  5009. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5010. - }
  5011. - (*merge_cp_length_p)++;
  5012. - } break;
  5013. -
  5014. - // this is a double-indirect CP entry so it needs special handling
  5015. - case JVM_CONSTANT_Fieldref: // fall through
  5016. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5017. - case JVM_CONSTANT_Methodref:
  5018. - {
  5019. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5020. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  5021. - merge_cp_p, merge_cp_length_p, THREAD);
  5022. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5023. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  5024. - merge_cp_p, merge_cp_length_p, THREAD);
  5025. -
  5026. - const char *entry_name;
  5027. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5028. - case JVM_CONSTANT_Fieldref:
  5029. - entry_name = "Fieldref";
  5030. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5031. - new_name_and_type_ref_i);
  5032. - break;
  5033. - case JVM_CONSTANT_InterfaceMethodref:
  5034. - entry_name = "IFMethodref";
  5035. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5036. - new_klass_ref_i, new_name_and_type_ref_i);
  5037. - break;
  5038. - case JVM_CONSTANT_Methodref:
  5039. - entry_name = "Methodref";
  5040. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5041. - new_name_and_type_ref_i);
  5042. - break;
  5043. - default:
  5044. - guarantee(false, "bad switch");
  5045. - break;
  5046. - }
  5047. -
  5048. - if (klass_ref_i != new_klass_ref_i) {
  5049. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5050. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5051. - }
  5052. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5053. - RC_TRACE(0x00080000,
  5054. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5055. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5056. - new_name_and_type_ref_i));
  5057. - }
  5058. -
  5059. - if (scratch_i != *merge_cp_length_p) {
  5060. - // The new entry in *merge_cp_p is at a different index than
  5061. - // the new entry in scratch_cp so we need to map the index values.
  5062. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5063. - }
  5064. - (*merge_cp_length_p)++;
  5065. - } break;
  5066. -
  5067. - // this is an indirect CP entry so it needs special handling
  5068. - case JVM_CONSTANT_MethodType:
  5069. - {
  5070. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  5071. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5072. - merge_cp_length_p, THREAD);
  5073. - if (new_ref_i != ref_i) {
  5074. - RC_TRACE(0x00080000,
  5075. - ("MethodType entry@%d ref_index change: %d to %d",
  5076. - *merge_cp_length_p, ref_i, new_ref_i));
  5077. - }
  5078. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  5079. - if (scratch_i != *merge_cp_length_p) {
  5080. - // The new entry in *merge_cp_p is at a different index than
  5081. - // the new entry in scratch_cp so we need to map the index values.
  5082. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5083. - }
  5084. - (*merge_cp_length_p)++;
  5085. - } break;
  5086. -
  5087. - // this is an indirect CP entry so it needs special handling
  5088. - case JVM_CONSTANT_MethodHandle:
  5089. - {
  5090. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  5091. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  5092. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5093. - merge_cp_length_p, THREAD);
  5094. - if (new_ref_i != ref_i) {
  5095. - RC_TRACE(0x00080000,
  5096. - ("MethodHandle entry@%d ref_index change: %d to %d",
  5097. - *merge_cp_length_p, ref_i, new_ref_i));
  5098. - }
  5099. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  5100. - if (scratch_i != *merge_cp_length_p) {
  5101. - // The new entry in *merge_cp_p is at a different index than
  5102. - // the new entry in scratch_cp so we need to map the index values.
  5103. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5104. - }
  5105. - (*merge_cp_length_p)++;
  5106. - } break;
  5107. -
  5108. - // this is an indirect CP entry so it needs special handling
  5109. - case JVM_CONSTANT_InvokeDynamic:
  5110. - {
  5111. - // Index of the bootstrap specifier in the operands array
  5112. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  5113. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  5114. - merge_cp_length_p, THREAD);
  5115. - // The bootstrap method NameAndType_info index
  5116. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  5117. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5118. - merge_cp_length_p, THREAD);
  5119. - if (new_bs_i != old_bs_i) {
  5120. - RC_TRACE(0x00080000,
  5121. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  5122. - *merge_cp_length_p, old_bs_i, new_bs_i));
  5123. - }
  5124. - if (new_ref_i != old_ref_i) {
  5125. - RC_TRACE(0x00080000,
  5126. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  5127. - *merge_cp_length_p, old_ref_i, new_ref_i));
  5128. - }
  5129. -
  5130. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  5131. - if (scratch_i != *merge_cp_length_p) {
  5132. - // The new entry in *merge_cp_p is at a different index than
  5133. - // the new entry in scratch_cp so we need to map the index values.
  5134. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5135. - }
  5136. - (*merge_cp_length_p)++;
  5137. - } break;
  5138. -
  5139. - // At this stage, Class or UnresolvedClass could be here, but not
  5140. - // ClassIndex
  5141. - case JVM_CONSTANT_ClassIndex: // fall through
  5142. -
  5143. - // Invalid is used as the tag for the second constant pool entry
  5144. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5145. - // not be seen by itself.
  5146. - case JVM_CONSTANT_Invalid: // fall through
  5147. -
  5148. - // At this stage, String or UnresolvedString could be here, but not
  5149. - // StringIndex
  5150. - case JVM_CONSTANT_StringIndex: // fall through
  5151. -
  5152. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5153. - // here
  5154. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5155. -
  5156. - default:
  5157. - {
  5158. - // leave a breadcrumb
  5159. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5160. - ShouldNotReachHere();
  5161. - } break;
  5162. - } // end switch tag value
  5163. -} // end append_entry()
  5164. -
  5165. -
  5166. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  5167. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5168. -
  5169. - int new_ref_i = ref_i;
  5170. - bool match = (ref_i < *merge_cp_length_p) &&
  5171. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  5172. -
  5173. - if (!match) {
  5174. - // forward reference in *merge_cp_p or not a direct match
  5175. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  5176. - if (found_i != 0) {
  5177. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  5178. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  5179. - new_ref_i = found_i;
  5180. - map_index(scratch_cp, ref_i, found_i);
  5181. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5182. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5183. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5184. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5185. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5186. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5187. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5188. + // The message will be "XXX (wrong name: YYY)"
  5189. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  5190. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5191. + return JVMTI_ERROR_OUT_OF_MEMORY;
  5192. } else {
  5193. - // no match found so we have to append this entry to *merge_cp_p
  5194. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  5195. - // The above call to append_entry() can only append one entry
  5196. - // so the post call query of *merge_cp_length_p is only for
  5197. - // the sake of consistency.
  5198. - new_ref_i = *merge_cp_length_p - 1;
  5199. + // Just in case more exceptions can be thrown..
  5200. + return JVMTI_ERROR_FAILS_VERIFICATION;
  5201. }
  5202. }
  5203. - return new_ref_i;
  5204. -} // end find_or_append_indirect_entry()
  5205. -
  5206. -
  5207. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  5208. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  5209. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  5210. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  5211. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5212. -
  5213. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  5214. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5215. - merge_cp_length_p, THREAD);
  5216. - if (new_ref_i != old_ref_i) {
  5217. - RC_TRACE(0x00080000,
  5218. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  5219. - _operands_cur_length, old_ref_i, new_ref_i));
  5220. - }
  5221. -
  5222. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  5223. - int new_bs_i = _operands_cur_length;
  5224. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  5225. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  5226. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  5227. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  5228. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  5229. -
  5230. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  5231. - merge_ops->short_at_put(new_base++, new_ref_i);
  5232. - merge_ops->short_at_put(new_base++, argc);
  5233. -
  5234. - for (int i = 0; i < argc; i++) {
  5235. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  5236. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  5237. - merge_cp_length_p, THREAD);
  5238. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  5239. - if (new_arg_ref_i != old_arg_ref_i) {
  5240. - RC_TRACE(0x00080000,
  5241. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  5242. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  5243. - }
  5244. - }
  5245. - if (old_bs_i != _operands_cur_length) {
  5246. - // The bootstrap specifier in *merge_cp_p is at a different index than
  5247. - // that in scratch_cp so we need to map the index values.
  5248. - map_operand_index(old_bs_i, new_bs_i);
  5249. - }
  5250. - _operands_cur_length++;
  5251. -} // end append_operand()
  5252. -
  5253. -
  5254. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  5255. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5256. -
  5257. - int new_bs_i = old_bs_i; // bootstrap specifier index
  5258. - bool match = (old_bs_i < _operands_cur_length) &&
  5259. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  5260. -
  5261. - if (!match) {
  5262. - // forward reference in *merge_cp_p or not a direct match
  5263. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  5264. - _operands_cur_length, THREAD);
  5265. - if (found_i != -1) {
  5266. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  5267. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  5268. - new_bs_i = found_i;
  5269. - map_operand_index(old_bs_i, found_i);
  5270. - } else {
  5271. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  5272. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  5273. - new_bs_i = _operands_cur_length - 1;
  5274. - }
  5275. - }
  5276. - return new_bs_i;
  5277. -} // end find_or_append_operand()
  5278. -
  5279. -
  5280. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  5281. - if (merge_cp->operands() == NULL) {
  5282. - return;
  5283. - }
  5284. - // Shrink the merge_cp operands
  5285. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  5286. -
  5287. - if (RC_TRACE_ENABLED(0x00040000)) {
  5288. - // don't want to loop unless we are tracing
  5289. - int count = 0;
  5290. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  5291. - int value = _operands_index_map_p->at(i);
  5292. - if (value != -1) {
  5293. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5294. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  5295. - count++;
  5296. - }
  5297. - }
  5298. - }
  5299. - // Clean-up
  5300. - _operands_index_map_p = NULL;
  5301. - _operands_cur_length = 0;
  5302. - _operands_index_map_count = 0;
  5303. -} // end finalize_operands_merge()
  5304. -
  5305. -
  5306. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5307. - typeArrayOop save;
  5308. -
  5309. - save = scratch_class->get_method_annotations_of(i);
  5310. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5311. - scratch_class->set_method_annotations_of(j, save);
  5312. -
  5313. - save = scratch_class->get_method_parameter_annotations_of(i);
  5314. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5315. - scratch_class->set_method_parameter_annotations_of(j, save);
  5316. -
  5317. - save = scratch_class->get_method_default_annotations_of(i);
  5318. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5319. - scratch_class->set_method_default_annotations_of(j, save);
  5320. + return JVMTI_ERROR_NONE;
  5321. }
  5322. +// Loads all new class versions and stores the instanceKlass handles in an array.
  5323. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5324. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5325. - instanceKlassHandle the_class,
  5326. - instanceKlassHandle scratch_class) {
  5327. + ResourceMark rm(THREAD);
  5328. +
  5329. + RC_TRACE(0x00000001, ("==================================================================="));
  5330. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  5331. + _class_count));
  5332. +
  5333. + // Retrieve an array of all classes that need to be redefined
  5334. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  5335. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  5336. + if (err != JVMTI_ERROR_NONE) {
  5337. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  5338. + (int)err));
  5339. + return err;
  5340. + }
  5341. +
  5342. +
  5343. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5344. +
  5345. + _max_redefinition_flags = Klass::NoRedefinition;
  5346. + jvmtiError result = JVMTI_ERROR_NONE;
  5347. +
  5348. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5349. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  5350. + i+1, all_affected_klasses.length()));
  5351. +
  5352. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5353. + RC_TRACE(0x00000002, ("name=%s",
  5354. + the_class->name()->as_C_string()));
  5355. +
  5356. + the_class->link_class(THREAD);
  5357. + result = check_exception();
  5358. + if (result != JVMTI_ERROR_NONE) break;
  5359. +
  5360. + // Find new class bytes
  5361. + const unsigned char* class_bytes;
  5362. + jint class_byte_count;
  5363. + jvmtiError error;
  5364. + jboolean not_changed;
  5365. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  5366. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  5367. + (int)error));
  5368. + result = error;
  5369. + break;
  5370. + }
  5371. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  5372. +
  5373. +
  5374. + // Set redefined class handle in JvmtiThreadState class.
  5375. + // This redefined class is sent to agent event handler for class file
  5376. + // load hook event.
  5377. + state->set_class_being_redefined(&the_class, _class_load_kind);
  5378. +
  5379. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  5380. +
  5381. + RC_TIMER_STOP(_timer_prologue);
  5382. + RC_TIMER_START(_timer_class_loading);
  5383. +
  5384. +
  5385. + // Parse the stream.
  5386. + Handle the_class_loader(THREAD, the_class->class_loader());
  5387. + Handle protection_domain(THREAD, the_class->protection_domain());
  5388. + Symbol* the_class_sym = the_class->name();
  5389. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  5390. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  5391. + the_class_loader,
  5392. + protection_domain,
  5393. + &st,
  5394. + true,
  5395. + the_class,
  5396. + THREAD));
  5397. +
  5398. + not_changed = false;
  5399. +
  5400. + RC_TIMER_STOP(_timer_class_loading);
  5401. + RC_TIMER_START(_timer_prologue);
  5402. +
  5403. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  5404. + // Clear class_being_redefined just to be sure.
  5405. + state->clear_class_being_redefined();
  5406. +
  5407. + result = check_exception();
  5408. + if (result != JVMTI_ERROR_NONE) break;
  5409. +
  5410. +#ifdef ASSERT
  5411. +
  5412. + assert(new_class() != NULL, "Class could not be loaded!");
  5413. + assert(new_class() != the_class(), "must be different");
  5414. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5415. +
  5416. +
  5417. + objArrayOop k_interfaces = new_class->local_interfaces();
  5418. + for (int j=0; j<k_interfaces->length(); j++) {
  5419. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5420. + }
  5421. +
  5422. + if (!THREAD->is_Compiler_thread()) {
  5423. +
  5424. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5425. + the_class->name()->as_C_string(),
  5426. + (address)(the_class->class_loader()),
  5427. + (address)(the_class->protection_domain())));
  5428. + // If we are on the compiler thread, we must not try to resolve a class.
  5429. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5430. +
  5431. + if (systemLookup != NULL) {
  5432. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5433. +
  5434. +
  5435. + Klass *subklass = new_class()->klass_part()->subklass();
  5436. + while (subklass != NULL) {
  5437. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5438. + subklass = subklass->next_sibling();
  5439. + }
  5440. + } else {
  5441. + // This can happen for reflection generated classes.. ?
  5442. + CLEAR_PENDING_EXCEPTION;
  5443. + }
  5444. + }
  5445. +
  5446. +#endif
  5447. +
  5448. + if (RC_TRACE_ENABLED(0x00000001)) {
  5449. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5450. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5451. + new_class->name()->as_C_string(),
  5452. + new_class->layout_helper(),
  5453. + the_class->layout_helper()));
  5454. + }
  5455. + }
  5456. +
  5457. + // Set the new version of the class
  5458. + new_class->set_revision_number(_revision_number);
  5459. + new_class->set_redefinition_index(i);
  5460. + the_class->set_new_version(new_class());
  5461. + _new_classes->append(new_class);
  5462. +
  5463. + assert(new_class->new_version() == NULL, "");
  5464. +
  5465. + int redefinition_flags = Klass::NoRedefinition;
  5466. +
  5467. + if (not_changed) {
  5468. + redefinition_flags = Klass::NoRedefinition;
  5469. + } else if (AllowAdvancedClassRedefinition) {
  5470. + redefinition_flags = calculate_redefinition_flags(new_class);
  5471. + } else {
  5472. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5473. + if (allowed != JVMTI_ERROR_NONE) {
  5474. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5475. + result = allowed;
  5476. + break;
  5477. + }
  5478. + redefinition_flags = Klass::ModifyClass;
  5479. + }
  5480. +
  5481. + if (new_class->super() != NULL) {
  5482. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5483. + }
  5484. +
  5485. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5486. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5487. + }
  5488. +
  5489. + new_class->set_redefinition_flags(redefinition_flags);
  5490. +
  5491. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5492. +
  5493. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5494. + // TODO: Check if watch access flags of static fields are updated correctly.
  5495. + calculate_instance_update_information(_new_classes->at(i)());
  5496. + } else {
  5497. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5498. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5499. +
  5500. + fieldDescriptor fd_new;
  5501. + fieldDescriptor fd_old;
  5502. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5503. + fd_new.initialize(new_class(), fs.index());
  5504. + fd_old.initialize(new_class->old_version(), fs.index());
  5505. + transfer_special_access_flags(&fd_old, &fd_new);
  5506. + }
  5507. + }
  5508. +
  5509. + if (RC_TRACE_ENABLED(0x00000008)) {
  5510. + if (new_class->super() != NULL) {
  5511. + RC_TRACE(0x00000008, ("Super class is %s",
  5512. + new_class->super()->klass_part()->name()->as_C_string()));
  5513. + }
  5514. + }
  5515. +
  5516. +#ifdef ASSERT
  5517. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5518. +
  5519. + the_class->vtable()->verify(tty);
  5520. + new_class->vtable()->verify(tty);
  5521. +#endif
  5522. +
  5523. + RC_TRACE(0x00000002, ("Verification done!"));
  5524. +
  5525. + if (i == all_affected_klasses.length() - 1) {
  5526. +
  5527. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5528. +
  5529. + RC_TIMER_STOP(_timer_prologue);
  5530. + lock_threads();
  5531. + RC_TIMER_START(_timer_prologue);
  5532. +
  5533. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5534. +
  5535. + klassOop initial_klass = all_affected_klasses.at(j)();
  5536. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5537. + Klass *cur_klass = initial_subklass;
  5538. + while(cur_klass != NULL) {
  5539. +
  5540. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5541. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5542. + if (!all_affected_klasses.contains(handle)) {
  5543. +
  5544. + int k = i + 1;
  5545. + for (; k<all_affected_klasses.length(); k++) {
  5546. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5547. + break;
  5548. + }
  5549. + }
  5550. + all_affected_klasses.insert_before(k, handle);
  5551. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5552. + cur_klass->name()->as_C_string()));
  5553. + }
  5554. + }
  5555. +
  5556. + cur_klass = cur_klass->next_sibling();
  5557. + }
  5558. + }
  5559. +
  5560. + int new_count = all_affected_klasses.length() - 1 - i;
  5561. + if (new_count != 0) {
  5562. +
  5563. + unlock_threads();
  5564. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5565. + new_count));
  5566. + }
  5567. + }
  5568. + }
  5569. +
  5570. + if (result != JVMTI_ERROR_NONE) {
  5571. + rollback();
  5572. + return result;
  5573. + }
  5574. +
  5575. + RC_TIMER_STOP(_timer_prologue);
  5576. + RC_TIMER_START(_timer_class_linking);
  5577. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5578. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5579. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5580. + instanceKlassHandle new_class(the_class->new_version());
  5581. +
  5582. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5583. + i,
  5584. + all_affected_klasses.length(),
  5585. + the_class->name()->as_C_string()));
  5586. + new_class->link_class(THREAD);
  5587. +
  5588. + result = check_exception();
  5589. + if (result != JVMTI_ERROR_NONE) break;
  5590. + }
  5591. + RC_TIMER_STOP(_timer_class_linking);
  5592. + RC_TIMER_START(_timer_prologue);
  5593. +
  5594. + if (result != JVMTI_ERROR_NONE) {
  5595. + rollback();
  5596. + return result;
  5597. + }
  5598. +
  5599. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5600. +
  5601. +#ifdef ASSERT
  5602. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5603. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5604. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5605. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5606. + assert(new_version->new_version() == NULL, "Must be newest version");
  5607. +
  5608. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5609. + new_version()->print();
  5610. + new_version->super()->print();
  5611. + }
  5612. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5613. + }
  5614. +
  5615. + SystemDictionary::classes_do(check_class, THREAD);
  5616. +
  5617. +#endif
  5618. +
  5619. + RC_TRACE(0x00000001, ("Finished verification!"));
  5620. + return JVMTI_ERROR_NONE;
  5621. +}
  5622. +
  5623. +void VM_RedefineClasses::lock_threads() {
  5624. +
  5625. + RC_TIMER_START(_timer_wait_for_locks);
  5626. +
  5627. +
  5628. + JavaThread *javaThread = Threads::first();
  5629. + while (javaThread != NULL) {
  5630. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5631. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5632. + compilerThread->set_should_bailout(true);
  5633. + }
  5634. + javaThread = javaThread->next();
  5635. + }
  5636. +
  5637. + int cnt = 0;
  5638. + javaThread = Threads::first();
  5639. + while (javaThread != NULL) {
  5640. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5641. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5642. + compilerThread->compilation_mutex()->lock();
  5643. + cnt++;
  5644. + }
  5645. + javaThread = javaThread->next();
  5646. + }
  5647. +
  5648. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5649. +
  5650. + cnt = 0;
  5651. + javaThread = Threads::first();
  5652. + while (javaThread != NULL) {
  5653. + if (javaThread != Thread::current()) {
  5654. + javaThread->redefine_classes_mutex()->lock();
  5655. + }
  5656. + javaThread = javaThread->next();
  5657. + }
  5658. +
  5659. +
  5660. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5661. +
  5662. + RC_TIMER_STOP(_timer_wait_for_locks);
  5663. +}
  5664. +
  5665. +void VM_RedefineClasses::unlock_threads() {
  5666. +
  5667. + int cnt = 0;
  5668. + JavaThread *javaThread = Threads::first();
  5669. + Thread *thread = Thread::current();
  5670. + while (javaThread != NULL) {
  5671. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5672. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5673. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5674. + compilerThread->compilation_mutex()->unlock();
  5675. + cnt++;
  5676. + }
  5677. + }
  5678. + javaThread = javaThread->next();
  5679. + }
  5680. +
  5681. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5682. +
  5683. + cnt = 0;
  5684. + javaThread = Threads::first();
  5685. + while (javaThread != NULL) {
  5686. + if (javaThread != Thread::current()) {
  5687. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5688. + javaThread->redefine_classes_mutex()->unlock();
  5689. + }
  5690. + }
  5691. + javaThread = javaThread->next();
  5692. + }
  5693. +
  5694. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5695. +}
  5696. +
  5697. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5698. +
  5699. +
  5700. +
  5701. + // Compatibility mode => check for unsupported modification
  5702. +
  5703. +
  5704. + assert(scratch_class->old_version() != NULL, "must have old version");
  5705. + instanceKlassHandle the_class(scratch_class->old_version());
  5706. +
  5707. int i;
  5708. // Check superclasses, or rather their names, since superclasses themselves can be
  5709. // requested to replace.
  5710. // Check for NULL superclass first since this might be java.lang.Object
  5711. if (the_class->super() != scratch_class->super() &&
  5712. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5713. - Klass::cast(the_class->super())->name() !=
  5714. - Klass::cast(scratch_class->super())->name())) {
  5715. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5716. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5717. + Klass::cast(the_class->super())->name() !=
  5718. + Klass::cast(scratch_class->super())->name())) {
  5719. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5720. }
  5721. // Check if the number, names and order of directly implemented interfaces are the same.
  5722. @@ -622,8 +678,8 @@
  5723. }
  5724. for (i = 0; i < n_intfs; i++) {
  5725. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5726. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5727. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5728. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5729. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5730. }
  5731. }
  5732. @@ -772,12 +828,8 @@
  5733. idnum_owner->set_method_idnum(new_num);
  5734. }
  5735. k_new_method->set_method_idnum(old_num);
  5736. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5737. }
  5738. }
  5739. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5740. - k_new_method->name_and_sig_as_C_string(), ni,
  5741. - k_old_method->name_and_sig_as_C_string(), oi));
  5742. // advance to next pair of methods
  5743. ++oi;
  5744. ++ni;
  5745. @@ -786,11 +838,11 @@
  5746. // method added, see if it is OK
  5747. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5748. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5749. - // hack: private should be treated as final, but alas
  5750. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5751. - ) {
  5752. - // new methods must be private
  5753. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5754. + // hack: private should be treated as final, but alas
  5755. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5756. + ) {
  5757. + // new methods must be private
  5758. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5759. }
  5760. {
  5761. u2 num = the_class->next_method_idnum();
  5762. @@ -805,24 +857,19 @@
  5763. idnum_owner->set_method_idnum(new_num);
  5764. }
  5765. k_new_method->set_method_idnum(num);
  5766. - swap_all_method_annotations(new_num, num, scratch_class);
  5767. }
  5768. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5769. - k_new_method->name_and_sig_as_C_string(), ni));
  5770. ++ni; // advance to next new method
  5771. break;
  5772. case deleted:
  5773. // method deleted, see if it is OK
  5774. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5775. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5776. - // hack: private should be treated as final, but alas
  5777. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5778. - ) {
  5779. - // deleted methods must be private
  5780. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5781. + // hack: private should be treated as final, but alas
  5782. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5783. + ) {
  5784. + // deleted methods must be private
  5785. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5786. }
  5787. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5788. - k_old_method->name_and_sig_as_C_string(), oi));
  5789. ++oi; // advance to next old method
  5790. break;
  5791. default:
  5792. @@ -833,2120 +880,2265 @@
  5793. return JVMTI_ERROR_NONE;
  5794. }
  5795. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5796. -// Find new constant pool index value for old constant pool index value
  5797. -// by seaching the index map. Returns zero (0) if there is no mapped
  5798. -// value for the old constant pool index.
  5799. -int VM_RedefineClasses::find_new_index(int old_index) {
  5800. - if (_index_map_count == 0) {
  5801. - // map is empty so nothing can be found
  5802. - return 0;
  5803. + int result = Klass::NoRedefinition;
  5804. +
  5805. +
  5806. +
  5807. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5808. + new_class->name()->as_C_string()));
  5809. +
  5810. + assert(new_class->old_version() != NULL, "must have old version");
  5811. + instanceKlassHandle the_class(new_class->old_version());
  5812. +
  5813. + // Check whether class is in the error init state.
  5814. + if (the_class->is_in_error_state()) {
  5815. + // TBD #5057930: special error code is needed in 1.6
  5816. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5817. }
  5818. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5819. - // The old_index is out of range so it is not mapped. This should
  5820. - // not happen in regular constant pool merging use, but it can
  5821. - // happen if a corrupt annotation is processed.
  5822. - return 0;
  5823. - }
  5824. + int i;
  5825. - int value = _index_map_p->at(old_index);
  5826. - if (value == -1) {
  5827. - // the old_index is not mapped
  5828. - return 0;
  5829. - }
  5830. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5831. + // Check superclasses
  5832. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5833. + if (the_class->super() != new_class->super()) {
  5834. + // Super class changed
  5835. - return value;
  5836. -} // end find_new_index()
  5837. + klassOop cur_klass = the_class->super();
  5838. + while (cur_klass != NULL) {
  5839. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5840. + RC_TRACE(0x00000002, ("Removed super class %s",
  5841. + cur_klass->klass_part()->name()->as_C_string()));
  5842. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5843. -
  5844. -// Find new bootstrap specifier index value for old bootstrap specifier index
  5845. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  5846. -// value for the old bootstrap specifier index.
  5847. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  5848. - if (_operands_index_map_count == 0) {
  5849. - // map is empty so nothing can be found
  5850. - return -1;
  5851. - }
  5852. -
  5853. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  5854. - // The old_index is out of range so it is not mapped.
  5855. - // This should not happen in regular constant pool merging use.
  5856. - return -1;
  5857. - }
  5858. -
  5859. - int value = _operands_index_map_p->at(old_index);
  5860. -
  5861. - return value;
  5862. -} // end find_new_operand_index()
  5863. -
  5864. -
  5865. -// Returns true if the current mismatch is due to a resolved/unresolved
  5866. -// class pair. Otherwise, returns false.
  5867. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5868. - int index1, constantPoolHandle cp2, int index2) {
  5869. -
  5870. - jbyte t1 = cp1->tag_at(index1).value();
  5871. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5872. - return false; // wrong entry type; not our special case
  5873. - }
  5874. -
  5875. - jbyte t2 = cp2->tag_at(index2).value();
  5876. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5877. - return false; // wrong entry type; not our special case
  5878. - }
  5879. -
  5880. - if (t1 == t2) {
  5881. - return false; // not a mismatch; not our special case
  5882. - }
  5883. -
  5884. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5885. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5886. - if (strcmp(s1, s2) != 0) {
  5887. - return false; // strings don't match; not our special case
  5888. - }
  5889. -
  5890. - return true; // made it through the gauntlet; this is our special case
  5891. -} // end is_unresolved_class_mismatch()
  5892. -
  5893. -
  5894. -// Returns true if the current mismatch is due to a resolved/unresolved
  5895. -// string pair. Otherwise, returns false.
  5896. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5897. - int index1, constantPoolHandle cp2, int index2) {
  5898. -
  5899. - jbyte t1 = cp1->tag_at(index1).value();
  5900. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5901. - return false; // wrong entry type; not our special case
  5902. - }
  5903. -
  5904. - jbyte t2 = cp2->tag_at(index2).value();
  5905. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5906. - return false; // wrong entry type; not our special case
  5907. - }
  5908. -
  5909. - if (t1 == t2) {
  5910. - return false; // not a mismatch; not our special case
  5911. - }
  5912. -
  5913. - char *s1 = cp1->string_at_noresolve(index1);
  5914. - char *s2 = cp2->string_at_noresolve(index2);
  5915. - if (strcmp(s1, s2) != 0) {
  5916. - return false; // strings don't match; not our special case
  5917. - }
  5918. -
  5919. - return true; // made it through the gauntlet; this is our special case
  5920. -} // end is_unresolved_string_mismatch()
  5921. -
  5922. -
  5923. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5924. - // For consistency allocate memory using os::malloc wrapper.
  5925. - _scratch_classes = (instanceKlassHandle *)
  5926. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5927. - if (_scratch_classes == NULL) {
  5928. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5929. - }
  5930. -
  5931. - ResourceMark rm(THREAD);
  5932. -
  5933. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5934. - // state can only be NULL if the current thread is exiting which
  5935. - // should not happen since we're trying to do a RedefineClasses
  5936. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5937. - for (int i = 0; i < _class_count; i++) {
  5938. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5939. - // classes for primitives cannot be redefined
  5940. - if (!is_modifiable_class(mirror)) {
  5941. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5942. - }
  5943. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5944. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5945. - Symbol* the_class_sym = the_class->name();
  5946. -
  5947. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5948. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5949. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5950. - the_class->external_name(), _class_load_kind,
  5951. - os::available_memory() >> 10));
  5952. -
  5953. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5954. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5955. -
  5956. - // Parse the stream.
  5957. - Handle the_class_loader(THREAD, the_class->class_loader());
  5958. - Handle protection_domain(THREAD, the_class->protection_domain());
  5959. - // Set redefined class handle in JvmtiThreadState class.
  5960. - // This redefined class is sent to agent event handler for class file
  5961. - // load hook event.
  5962. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5963. -
  5964. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5965. - the_class_loader,
  5966. - protection_domain,
  5967. - &st,
  5968. - THREAD);
  5969. - // Clear class_being_redefined just to be sure.
  5970. - state->clear_class_being_redefined();
  5971. -
  5972. - // TODO: if this is retransform, and nothing changed we can skip it
  5973. -
  5974. - instanceKlassHandle scratch_class (THREAD, k);
  5975. -
  5976. - if (HAS_PENDING_EXCEPTION) {
  5977. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5978. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5979. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5980. - ex_name->as_C_string()));
  5981. - CLEAR_PENDING_EXCEPTION;
  5982. -
  5983. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5984. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5985. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5986. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5987. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5988. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5989. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5990. - // The message will be "XXX (wrong name: YYY)"
  5991. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5992. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5993. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5994. - } else { // Just in case more exceptions can be thrown..
  5995. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5996. - }
  5997. - }
  5998. -
  5999. - // Ensure class is linked before redefine
  6000. - if (!the_class->is_linked()) {
  6001. - the_class->link_class(THREAD);
  6002. - if (HAS_PENDING_EXCEPTION) {
  6003. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6004. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6005. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  6006. - ex_name->as_C_string()));
  6007. - CLEAR_PENDING_EXCEPTION;
  6008. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6009. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6010. - } else {
  6011. - return JVMTI_ERROR_INTERNAL;
  6012. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  6013. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  6014. + cur_klass->klass_part()->name()->as_C_string()));
  6015. + cur_klass->klass_part()->set_subtype_changed(true);
  6016. }
  6017. }
  6018. +
  6019. + cur_klass = cur_klass->klass_part()->super();
  6020. }
  6021. - // Do the validity checks in compare_and_normalize_class_versions()
  6022. - // before verifying the byte codes. By doing these checks first, we
  6023. - // limit the number of functions that require redirection from
  6024. - // the_class to scratch_class. In particular, we don't have to
  6025. - // modify JNI GetSuperclass() and thus won't change its performance.
  6026. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6027. - scratch_class);
  6028. - if (res != JVMTI_ERROR_NONE) {
  6029. - return res;
  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. + cur_klass = new_class->super();
  6057. + while (cur_klass != NULL) {
  6058. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  6059. + RC_TRACE(0x00000002, ("Added super class %s",
  6060. + cur_klass->klass_part()->name()->as_C_string()));
  6061. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  6062. }
  6063. - }
  6064. -
  6065. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6066. - if (res != JVMTI_ERROR_NONE) {
  6067. - return res;
  6068. - }
  6069. -
  6070. - if (VerifyMergedCPBytecodes) {
  6071. - // verify what we have done during constant pool merging
  6072. - {
  6073. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6074. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6075. - }
  6076. -
  6077. - if (HAS_PENDING_EXCEPTION) {
  6078. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6079. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6080. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6081. - ("verify_byte_codes post merge-CP exception: '%s'",
  6082. - ex_name->as_C_string()));
  6083. - CLEAR_PENDING_EXCEPTION;
  6084. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6085. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6086. - } else {
  6087. - // tell the caller that constant pool merging screwed up
  6088. - return JVMTI_ERROR_INTERNAL;
  6089. - }
  6090. - }
  6091. - }
  6092. -
  6093. - Rewriter::rewrite(scratch_class, THREAD);
  6094. - if (!HAS_PENDING_EXCEPTION) {
  6095. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6096. - }
  6097. - if (HAS_PENDING_EXCEPTION) {
  6098. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6099. - CLEAR_PENDING_EXCEPTION;
  6100. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6101. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6102. - } else {
  6103. - return JVMTI_ERROR_INTERNAL;
  6104. - }
  6105. - }
  6106. -
  6107. - _scratch_classes[i] = scratch_class;
  6108. -
  6109. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6110. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6111. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6112. - the_class->external_name(), os::available_memory() >> 10));
  6113. - }
  6114. -
  6115. - return JVMTI_ERROR_NONE;
  6116. -}
  6117. -
  6118. -
  6119. -// Map old_index to new_index as needed. scratch_cp is only needed
  6120. -// for RC_TRACE() calls.
  6121. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6122. - int old_index, int new_index) {
  6123. - if (find_new_index(old_index) != 0) {
  6124. - // old_index is already mapped
  6125. - return;
  6126. - }
  6127. -
  6128. - if (old_index == new_index) {
  6129. - // no mapping is needed
  6130. - return;
  6131. - }
  6132. -
  6133. - _index_map_p->at_put(old_index, new_index);
  6134. - _index_map_count++;
  6135. -
  6136. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6137. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6138. -} // end map_index()
  6139. -
  6140. -
  6141. -// Map old_index to new_index as needed.
  6142. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  6143. - if (find_new_operand_index(old_index) != -1) {
  6144. - // old_index is already mapped
  6145. - return;
  6146. - }
  6147. -
  6148. - if (old_index == new_index) {
  6149. - // no mapping is needed
  6150. - return;
  6151. - }
  6152. -
  6153. - _operands_index_map_p->at_put(old_index, new_index);
  6154. - _operands_index_map_count++;
  6155. -
  6156. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  6157. -} // end map_index()
  6158. -
  6159. -
  6160. -// Merge old_cp and scratch_cp and return the results of the merge via
  6161. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6162. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6163. -// in *merge_cp_p. Also creates a map of indices from entries in
  6164. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6165. -// entries are only created for entries in scratch_cp that occupy a
  6166. -// different location in *merged_cp_p.
  6167. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6168. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6169. - int *merge_cp_length_p, TRAPS) {
  6170. -
  6171. - if (merge_cp_p == NULL) {
  6172. - assert(false, "caller must provide scatch constantPool");
  6173. - return false; // robustness
  6174. - }
  6175. - if (merge_cp_length_p == NULL) {
  6176. - assert(false, "caller must provide scatch CP length");
  6177. - return false; // robustness
  6178. - }
  6179. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6180. - // but the caller might be smart so make sure we have at least
  6181. - // the minimum.
  6182. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6183. - assert(false, "merge area too small");
  6184. - return false; // robustness
  6185. - }
  6186. -
  6187. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6188. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6189. - scratch_cp->length()));
  6190. -
  6191. - {
  6192. - // Pass 0:
  6193. - // The old_cp is copied to *merge_cp_p; this means that any code
  6194. - // using old_cp does not have to change. This work looks like a
  6195. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6196. - // handle one special case:
  6197. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6198. - // This will make verification happy.
  6199. -
  6200. - int old_i; // index into old_cp
  6201. -
  6202. - // index zero (0) is not used in constantPools
  6203. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6204. - // leave debugging crumb
  6205. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6206. - switch (old_tag) {
  6207. - case JVM_CONSTANT_Class:
  6208. - case JVM_CONSTANT_UnresolvedClass:
  6209. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6210. - // May be resolving while calling this so do the same for
  6211. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6212. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6213. - old_cp->klass_name_at(old_i));
  6214. - break;
  6215. -
  6216. - case JVM_CONSTANT_Double:
  6217. - case JVM_CONSTANT_Long:
  6218. - // just copy the entry to *merge_cp_p, but double and long take
  6219. - // two constant pool entries
  6220. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6221. - old_i++;
  6222. - break;
  6223. -
  6224. - default:
  6225. - // just copy the entry to *merge_cp_p
  6226. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6227. - break;
  6228. - }
  6229. - } // end for each old_cp entry
  6230. -
  6231. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  6232. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  6233. -
  6234. - // We don't need to sanity check that *merge_cp_length_p is within
  6235. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6236. - (*merge_cp_length_p) = old_i;
  6237. - }
  6238. -
  6239. - // merge_cp_len should be the same as old_cp->length() at this point
  6240. - // so this trace message is really a "warm-and-breathing" message.
  6241. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6242. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6243. -
  6244. - int scratch_i; // index into scratch_cp
  6245. - {
  6246. - // Pass 1a:
  6247. - // Compare scratch_cp entries to the old_cp entries that we have
  6248. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6249. - // exact duplicates (matching entry at same index) so we only
  6250. - // compare entries in the common indice range.
  6251. - int increment = 1;
  6252. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6253. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6254. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6255. - case JVM_CONSTANT_Double:
  6256. - case JVM_CONSTANT_Long:
  6257. - // double and long take two constant pool entries
  6258. - increment = 2;
  6259. - break;
  6260. -
  6261. - default:
  6262. - increment = 1;
  6263. - break;
  6264. - }
  6265. -
  6266. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6267. - scratch_i, CHECK_0);
  6268. - if (match) {
  6269. - // found a match at the same index so nothing more to do
  6270. - continue;
  6271. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6272. - *merge_cp_p, scratch_i)) {
  6273. - // The mismatch in compare_entry_to() above is because of a
  6274. - // resolved versus unresolved class entry at the same index
  6275. - // with the same string value. Since Pass 0 reverted any
  6276. - // class entries to unresolved class entries in *merge_cp_p,
  6277. - // we go with the unresolved class entry.
  6278. - continue;
  6279. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6280. - *merge_cp_p, scratch_i)) {
  6281. - // The mismatch in compare_entry_to() above is because of a
  6282. - // resolved versus unresolved string entry at the same index
  6283. - // with the same string value. We can live with whichever
  6284. - // happens to be at scratch_i in *merge_cp_p.
  6285. - continue;
  6286. - }
  6287. -
  6288. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6289. - CHECK_0);
  6290. - if (found_i != 0) {
  6291. - guarantee(found_i != scratch_i,
  6292. - "compare_entry_to() and find_matching_entry() do not agree");
  6293. -
  6294. - // Found a matching entry somewhere else in *merge_cp_p so
  6295. - // just need a mapping entry.
  6296. - map_index(scratch_cp, scratch_i, found_i);
  6297. - continue;
  6298. - }
  6299. -
  6300. - // The find_matching_entry() call above could fail to find a match
  6301. - // due to a resolved versus unresolved class or string entry situation
  6302. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6303. - // However, we would have to call is_unresolved_*_mismatch() over
  6304. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6305. - // worth the time.
  6306. -
  6307. - // No match found so we have to append this entry and any unique
  6308. - // referenced entries to *merge_cp_p.
  6309. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6310. - CHECK_0);
  6311. + cur_klass = cur_klass->klass_part()->super();
  6312. }
  6313. }
  6314. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6315. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6316. - *merge_cp_length_p, scratch_i, _index_map_count));
  6317. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  6318. + // Check interfaces
  6319. - if (scratch_i < scratch_cp->length()) {
  6320. - // Pass 1b:
  6321. - // old_cp is smaller than scratch_cp so there are entries in
  6322. - // scratch_cp that we have not yet processed. We take care of
  6323. - // those now.
  6324. - int increment = 1;
  6325. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6326. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6327. - case JVM_CONSTANT_Double:
  6328. - case JVM_CONSTANT_Long:
  6329. - // double and long take two constant pool entries
  6330. - increment = 2;
  6331. - break;
  6332. -
  6333. - default:
  6334. - increment = 1;
  6335. - break;
  6336. + // Interfaces removed?
  6337. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  6338. + for (i = 0; i<old_interfaces->length(); i++) {
  6339. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  6340. + if (!new_class->implements_interface_any_version(old_interface())) {
  6341. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  6342. + RC_TRACE(0x00000002, ("Removed interface %s",
  6343. + old_interface->name()->as_C_string()));
  6344. +
  6345. + if (!old_interface->has_subtype_changed()) {
  6346. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  6347. + old_interface->name()->as_C_string()));
  6348. + old_interface->set_subtype_changed(true);
  6349. }
  6350. -
  6351. - int found_i =
  6352. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6353. - if (found_i != 0) {
  6354. - // Found a matching entry somewhere else in *merge_cp_p so
  6355. - // just need a mapping entry.
  6356. - map_index(scratch_cp, scratch_i, found_i);
  6357. - continue;
  6358. - }
  6359. -
  6360. - // No match found so we have to append this entry and any unique
  6361. - // referenced entries to *merge_cp_p.
  6362. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6363. - CHECK_0);
  6364. }
  6365. -
  6366. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6367. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6368. - *merge_cp_length_p, scratch_i, _index_map_count));
  6369. - }
  6370. - finalize_operands_merge(*merge_cp_p, THREAD);
  6371. -
  6372. - return true;
  6373. -} // end merge_constant_pools()
  6374. -
  6375. -
  6376. -// Merge constant pools between the_class and scratch_class and
  6377. -// potentially rewrite bytecodes in scratch_class to use the merged
  6378. -// constant pool.
  6379. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6380. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6381. - TRAPS) {
  6382. - // worst case merged constant pool length is old and new combined
  6383. - int merge_cp_length = the_class->constants()->length()
  6384. - + scratch_class->constants()->length();
  6385. -
  6386. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6387. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6388. -
  6389. - // Constant pools are not easily reused so we allocate a new one
  6390. - // each time.
  6391. - // merge_cp is created unsafe for concurrent GC processing. It
  6392. - // should be marked safe before discarding it. Even though
  6393. - // garbage, if it crosses a card boundary, it may be scanned
  6394. - // in order to find the start of the first complete object on the card.
  6395. - constantPoolHandle merge_cp(THREAD,
  6396. - oopFactory::new_constantPool(merge_cp_length,
  6397. - oopDesc::IsUnsafeConc,
  6398. - THREAD));
  6399. - int orig_length = old_cp->orig_length();
  6400. - if (orig_length == 0) {
  6401. - // This old_cp is an actual original constant pool. We save
  6402. - // the original length in the merged constant pool so that
  6403. - // merge_constant_pools() can be more efficient. If a constant
  6404. - // pool has a non-zero orig_length() value, then that constant
  6405. - // pool was created by a merge operation in RedefineClasses.
  6406. - merge_cp->set_orig_length(old_cp->length());
  6407. - } else {
  6408. - // This old_cp is a merged constant pool from a previous
  6409. - // RedefineClasses() calls so just copy the orig_length()
  6410. - // value.
  6411. - merge_cp->set_orig_length(old_cp->orig_length());
  6412. }
  6413. - ResourceMark rm(THREAD);
  6414. - _index_map_count = 0;
  6415. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6416. -
  6417. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6418. - _operands_index_map_count = 0;
  6419. - _operands_index_map_p = new intArray(
  6420. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6421. -
  6422. - // reference to the cp holder is needed for copy_operands()
  6423. - merge_cp->set_pool_holder(scratch_class());
  6424. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6425. - &merge_cp_length, THREAD);
  6426. - merge_cp->set_pool_holder(NULL);
  6427. -
  6428. - if (!result) {
  6429. - // The merge can fail due to memory allocation failure or due
  6430. - // to robustness checks.
  6431. - return JVMTI_ERROR_INTERNAL;
  6432. + // Interfaces added?
  6433. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  6434. + for (i = 0; i<new_interfaces->length(); i++) {
  6435. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  6436. + result = result | Klass::ModifyClass;
  6437. + RC_TRACE(0x00000002, ("Added interface %s",
  6438. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  6439. + }
  6440. }
  6441. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6442. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6443. - if (_index_map_count == 0) {
  6444. - // there is nothing to map between the new and merged constant pools
  6445. + // Check whether class modifiers are the same.
  6446. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  6447. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  6448. + if (old_flags != new_flags) {
  6449. + // TODO (tw): Can this have any effects?
  6450. + }
  6451. - if (old_cp->length() == scratch_cp->length()) {
  6452. - // The old and new constant pools are the same length and the
  6453. - // index map is empty. This means that the three constant pools
  6454. - // are equivalent (but not the same). Unfortunately, the new
  6455. - // constant pool has not gone through link resolution nor have
  6456. - // the new class bytecodes gone through constant pool cache
  6457. - // rewriting so we can't use the old constant pool with the new
  6458. - // class.
  6459. + // Check if the number, names, types and order of fields declared in these classes
  6460. + // are the same.
  6461. + JavaFieldStream old_fs(the_class);
  6462. + JavaFieldStream new_fs(new_class);
  6463. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  6464. + // access
  6465. + old_flags = old_fs.access_flags().as_short();
  6466. + new_flags = new_fs.access_flags().as_short();
  6467. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  6468. + // (tw) Can this have any effects?
  6469. + }
  6470. + // offset
  6471. + if (old_fs.offset() != new_fs.offset()) {
  6472. + result = result | Klass::ModifyInstances;
  6473. + }
  6474. + // name and signature
  6475. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  6476. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  6477. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  6478. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  6479. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  6480. + result = result | Klass::ModifyInstances;
  6481. + }
  6482. + }
  6483. - merge_cp()->set_is_conc_safe(true);
  6484. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6485. - } else if (old_cp->length() < scratch_cp->length()) {
  6486. - // The old constant pool has fewer entries than the new constant
  6487. - // pool and the index map is empty. This means the new constant
  6488. - // pool is a superset of the old constant pool. However, the old
  6489. - // class bytecodes have already gone through constant pool cache
  6490. - // rewriting so we can't use the new constant pool with the old
  6491. - // class.
  6492. + if (!old_fs.done() || !new_fs.done()) {
  6493. + result = result | Klass::ModifyInstances;
  6494. + }
  6495. - merge_cp()->set_is_conc_safe(true);
  6496. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6497. + // Do a parallel walk through the old and new methods. Detect
  6498. + // cases where they match (exist in both), have been added in
  6499. + // the new methods, or have been deleted (exist only in the
  6500. + // old methods). The class file parser places methods in order
  6501. + // by method name, but does not order overloaded methods by
  6502. + // signature. In order to determine what fate befell the methods,
  6503. + // this code places the overloaded new methods that have matching
  6504. + // old methods in the same order as the old methods and places
  6505. + // new overloaded methods at the end of overloaded methods of
  6506. + // that name. The code for this order normalization is adapted
  6507. + // from the algorithm used in instanceKlass::find_method().
  6508. + // Since we are swapping out of order entries as we find them,
  6509. + // we only have to search forward through the overloaded methods.
  6510. + // Methods which are added and have the same name as an existing
  6511. + // method (but different signature) will be put at the end of
  6512. + // the methods with that name, and the name mismatch code will
  6513. + // handle them.
  6514. + objArrayHandle k_old_methods(the_class->methods());
  6515. + objArrayHandle k_new_methods(new_class->methods());
  6516. + int n_old_methods = k_old_methods->length();
  6517. + int n_new_methods = k_new_methods->length();
  6518. +
  6519. + int ni = 0;
  6520. + int oi = 0;
  6521. + while (true) {
  6522. + methodOop k_old_method;
  6523. + methodOop k_new_method;
  6524. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6525. +
  6526. + if (oi >= n_old_methods) {
  6527. + if (ni >= n_new_methods) {
  6528. + break; // we've looked at everything, done
  6529. + }
  6530. + // New method at the end
  6531. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6532. + method_was = added;
  6533. + } else if (ni >= n_new_methods) {
  6534. + // Old method, at the end, is deleted
  6535. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6536. + method_was = deleted;
  6537. } else {
  6538. - // The old constant pool has more entries than the new constant
  6539. - // pool and the index map is empty. This means that both the old
  6540. - // and merged constant pools are supersets of the new constant
  6541. - // pool.
  6542. + // There are more methods in both the old and new lists
  6543. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6544. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6545. + if (k_old_method->name() != k_new_method->name()) {
  6546. + // Methods are sorted by method name, so a mismatch means added
  6547. + // or deleted
  6548. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6549. + method_was = added;
  6550. + } else {
  6551. + method_was = deleted;
  6552. + }
  6553. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6554. + // Both the name and signature match
  6555. + method_was = matched;
  6556. + } else {
  6557. + // The name matches, but the signature doesn't, which means we have to
  6558. + // search forward through the new overloaded methods.
  6559. + int nj; // outside the loop for post-loop check
  6560. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6561. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6562. + if (k_old_method->name() != m->name()) {
  6563. + // reached another method name so no more overloaded methods
  6564. + method_was = deleted;
  6565. + break;
  6566. + }
  6567. + if (k_old_method->signature() == m->signature()) {
  6568. + // found a match so swap the methods
  6569. + k_new_methods->obj_at_put(ni, m);
  6570. + k_new_methods->obj_at_put(nj, k_new_method);
  6571. + k_new_method = m;
  6572. + method_was = matched;
  6573. + break;
  6574. + }
  6575. + }
  6576. - // Replace the new constant pool with a shrunken copy of the
  6577. - // merged constant pool; the previous new constant pool will
  6578. - // get GCed.
  6579. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6580. - THREAD);
  6581. - // drop local ref to the merged constant pool
  6582. - merge_cp()->set_is_conc_safe(true);
  6583. - merge_cp = constantPoolHandle();
  6584. - }
  6585. - } else {
  6586. - if (RC_TRACE_ENABLED(0x00040000)) {
  6587. - // don't want to loop unless we are tracing
  6588. - int count = 0;
  6589. - for (int i = 1; i < _index_map_p->length(); i++) {
  6590. - int value = _index_map_p->at(i);
  6591. -
  6592. - if (value != -1) {
  6593. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6594. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6595. - count++;
  6596. + if (nj >= n_new_methods) {
  6597. + // reached the end without a match; so method was deleted
  6598. + method_was = deleted;
  6599. }
  6600. }
  6601. }
  6602. - // We have entries mapped between the new and merged constant pools
  6603. - // so we have to rewrite some constant pool references.
  6604. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6605. - return JVMTI_ERROR_INTERNAL;
  6606. + switch (method_was) {
  6607. + case matched:
  6608. + // methods match, be sure modifiers do too
  6609. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6610. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6611. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6612. + // (tw) Can this have any effects? Probably yes on vtables?
  6613. + result = result | Klass::ModifyClass;
  6614. }
  6615. -
  6616. - // Replace the new constant pool with a shrunken copy of the
  6617. - // merged constant pool so now the rewritten bytecodes have
  6618. - // valid references; the previous new constant pool will get
  6619. - // GCed.
  6620. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6621. - THREAD);
  6622. - merge_cp()->set_is_conc_safe(true);
  6623. - }
  6624. - assert(old_cp()->is_conc_safe(), "Just checking");
  6625. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6626. -
  6627. - return JVMTI_ERROR_NONE;
  6628. -} // end merge_cp_and_rewrite()
  6629. -
  6630. -
  6631. -// Rewrite constant pool references in klass scratch_class.
  6632. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6633. - TRAPS) {
  6634. -
  6635. - // rewrite constant pool references in the methods:
  6636. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6637. - // propagate failure back to caller
  6638. - return false;
  6639. - }
  6640. -
  6641. - // rewrite constant pool references in the class_annotations:
  6642. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6643. - // propagate failure back to caller
  6644. - return false;
  6645. - }
  6646. -
  6647. - // rewrite constant pool references in the fields_annotations:
  6648. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6649. - // propagate failure back to caller
  6650. - return false;
  6651. - }
  6652. -
  6653. - // rewrite constant pool references in the methods_annotations:
  6654. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6655. - // propagate failure back to caller
  6656. - return false;
  6657. - }
  6658. -
  6659. - // rewrite constant pool references in the methods_parameter_annotations:
  6660. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6661. - THREAD)) {
  6662. - // propagate failure back to caller
  6663. - return false;
  6664. - }
  6665. -
  6666. - // rewrite constant pool references in the methods_default_annotations:
  6667. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6668. - THREAD)) {
  6669. - // propagate failure back to caller
  6670. - return false;
  6671. - }
  6672. -
  6673. - return true;
  6674. -} // end rewrite_cp_refs()
  6675. -
  6676. -
  6677. -// Rewrite constant pool references in the methods.
  6678. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6679. - instanceKlassHandle scratch_class, TRAPS) {
  6680. -
  6681. - objArrayHandle methods(THREAD, scratch_class->methods());
  6682. -
  6683. - if (methods.is_null() || methods->length() == 0) {
  6684. - // no methods so nothing to do
  6685. - return true;
  6686. - }
  6687. -
  6688. - // rewrite constant pool references in the methods:
  6689. - for (int i = methods->length() - 1; i >= 0; i--) {
  6690. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  6691. - methodHandle new_method;
  6692. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  6693. - if (!new_method.is_null()) {
  6694. - // the method has been replaced so save the new method version
  6695. - methods->obj_at_put(i, new_method());
  6696. + {
  6697. + u2 new_num = k_new_method->method_idnum();
  6698. + u2 old_num = k_old_method->method_idnum();
  6699. + if (new_num != old_num) {
  6700. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6701. + if (idnum_owner != NULL) {
  6702. + // There is already a method assigned this idnum -- switch them
  6703. + idnum_owner->set_method_idnum(new_num);
  6704. + }
  6705. + k_new_method->set_method_idnum(old_num);
  6706. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6707. + new_num,
  6708. + old_num));
  6709. + // swap_all_method_annotations(old_num, new_num, new_class);
  6710. + }
  6711. + }
  6712. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6713. + k_new_method->name_and_sig_as_C_string(), ni,
  6714. + k_old_method->name_and_sig_as_C_string(), oi));
  6715. + // advance to next pair of methods
  6716. + ++oi;
  6717. + ++ni;
  6718. + break;
  6719. + case added:
  6720. + // method added, see if it is OK
  6721. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6722. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6723. + // hack: private should be treated as final, but alas
  6724. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6725. + ) {
  6726. + // new methods must be private
  6727. + result = result | Klass::ModifyClass;
  6728. + }
  6729. + {
  6730. + u2 num = the_class->next_method_idnum();
  6731. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6732. + // cannot add any more methods
  6733. + result = result | Klass::ModifyClass;
  6734. + }
  6735. + u2 new_num = k_new_method->method_idnum();
  6736. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6737. + if (idnum_owner != NULL) {
  6738. + // There is already a method assigned this idnum -- switch them
  6739. + idnum_owner->set_method_idnum(new_num);
  6740. + }
  6741. + k_new_method->set_method_idnum(num);
  6742. + //swap_all_method_annotations(new_num, num, new_class);
  6743. + }
  6744. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6745. + k_new_method->name_and_sig_as_C_string(), ni));
  6746. + ++ni; // advance to next new method
  6747. + break;
  6748. + case deleted:
  6749. + // method deleted, see if it is OK
  6750. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6751. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6752. + // hack: private should be treated as final, but alas
  6753. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6754. + ) {
  6755. + // deleted methods must be private
  6756. + result = result | Klass::ModifyClass;
  6757. + }
  6758. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6759. + k_old_method->name_and_sig_as_C_string(), oi));
  6760. + ++oi; // advance to next old method
  6761. + break;
  6762. + default:
  6763. + ShouldNotReachHere();
  6764. }
  6765. }
  6766. - return true;
  6767. + if (new_class()->size() != new_class->old_version()->size()) {
  6768. + result |= Klass::ModifyClassSize;
  6769. + }
  6770. +
  6771. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6772. + result |= Klass::ModifyInstanceSize;
  6773. + }
  6774. +
  6775. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6776. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6777. + result |= Klass::HasInstanceTransformer;
  6778. + }
  6779. +
  6780. + // (tw) Check method bodies to be able to return NoChange?
  6781. + return result;
  6782. }
  6783. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6784. -// Rewrite constant pool references in the specific method. This code
  6785. -// was adapted from Rewriter::rewrite_method().
  6786. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  6787. - methodHandle *new_method_p, TRAPS) {
  6788. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6789. - *new_method_p = methodHandle(); // default is no new method
  6790. + private:
  6791. - // We cache a pointer to the bytecodes here in code_base. If GC
  6792. - // moves the methodOop, then the bytecodes will also move which
  6793. - // will likely cause a crash. We create a No_Safepoint_Verifier
  6794. - // object to detect whether we pass a possible safepoint in this
  6795. - // code block.
  6796. - No_Safepoint_Verifier nsv;
  6797. + GrowableArray<int> info;
  6798. + int curPosition;
  6799. + bool copy_backwards;
  6800. - // Bytecodes and their length
  6801. - address code_base = method->code_base();
  6802. - int code_length = method->code_size();
  6803. + public:
  6804. - int bc_length;
  6805. - for (int bci = 0; bci < code_length; bci += bc_length) {
  6806. - address bcp = code_base + bci;
  6807. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  6808. -
  6809. - bc_length = Bytecodes::length_for(c);
  6810. - if (bc_length == 0) {
  6811. - // More complicated bytecodes report a length of zero so
  6812. - // we have to try again a slightly different way.
  6813. - bc_length = Bytecodes::length_at(method(), bcp);
  6814. + bool does_copy_backwards() {
  6815. + return copy_backwards;
  6816. }
  6817. - assert(bc_length != 0, "impossible bytecode length");
  6818. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6819. - switch (c) {
  6820. - case Bytecodes::_ldc:
  6821. - {
  6822. - int cp_index = *(bcp + 1);
  6823. - int new_index = find_new_index(cp_index);
  6824. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6825. - if (StressLdcRewrite && new_index == 0) {
  6826. - // If we are stressing ldc -> ldc_w rewriting, then we
  6827. - // always need a new_index value.
  6828. - new_index = cp_index;
  6829. - }
  6830. - if (new_index != 0) {
  6831. - // the original index is mapped so we have more work to do
  6832. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  6833. - // The new value can still use ldc instead of ldc_w
  6834. - // unless we are trying to stress ldc -> ldc_w rewriting
  6835. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6836. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6837. - bcp, cp_index, new_index));
  6838. - *(bcp + 1) = new_index;
  6839. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6840. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6841. + }
  6842. +
  6843. + info.append(base_offset);
  6844. + info.append(0);
  6845. + curPosition = base_offset;
  6846. + copy_backwards = false;
  6847. + }
  6848. +
  6849. + GrowableArray<int> &finish() {
  6850. + info.append(0);
  6851. + return info;
  6852. + }
  6853. +
  6854. + virtual void do_new_field(fieldDescriptor* fd){
  6855. + int alignment = fd->offset() - curPosition;
  6856. + if (alignment > 0) {
  6857. + // This field was aligned, so we need to make sure that we fill the gap
  6858. + fill(alignment);
  6859. + }
  6860. +
  6861. + int size = size_of_type(fd->field_type());
  6862. + fill(size);
  6863. + }
  6864. +
  6865. + private:
  6866. +
  6867. + void fill(int size) {
  6868. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6869. + (*info.adr_at(info.length() - 1)) -= size;
  6870. + } else {
  6871. + info.append(-size);
  6872. + }
  6873. +
  6874. + curPosition += size;
  6875. + }
  6876. +
  6877. + int size_of_type(BasicType type) {
  6878. + int size = 0;
  6879. + switch(type) {
  6880. + case T_BOOLEAN:
  6881. + size = sizeof(jboolean);
  6882. + break;
  6883. +
  6884. + case T_CHAR:
  6885. + size = (sizeof(jchar));
  6886. + break;
  6887. +
  6888. + case T_FLOAT:
  6889. + size = (sizeof(jfloat));
  6890. + break;
  6891. +
  6892. + case T_DOUBLE:
  6893. + size = (sizeof(jdouble));
  6894. + break;
  6895. +
  6896. + case T_BYTE:
  6897. + size = (sizeof(jbyte));
  6898. + break;
  6899. +
  6900. + case T_SHORT:
  6901. + size = (sizeof(jshort));
  6902. + break;
  6903. +
  6904. + case T_INT:
  6905. + size = (sizeof(jint));
  6906. + break;
  6907. +
  6908. + case T_LONG:
  6909. + size = (sizeof(jlong));
  6910. + break;
  6911. +
  6912. + case T_OBJECT:
  6913. + case T_ARRAY:
  6914. + if (UseCompressedOops) {
  6915. + size = sizeof(narrowOop);
  6916. } else {
  6917. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6918. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  6919. - Bytecodes::name(c), bcp, cp_index, new_index));
  6920. - // the new value needs ldc_w instead of ldc
  6921. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  6922. - bcp = (address)inst_buffer;
  6923. - // construct new instruction sequence
  6924. - *bcp = Bytecodes::_ldc_w;
  6925. - bcp++;
  6926. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  6927. - // See comment below for difference between put_Java_u2()
  6928. - // and put_native_u2().
  6929. - Bytes::put_Java_u2(bcp, new_index);
  6930. + size = (sizeof(oop));
  6931. + }
  6932. + break;
  6933. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  6934. - methodHandle m;
  6935. - {
  6936. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  6937. + default:
  6938. + ShouldNotReachHere();
  6939. + }
  6940. - // ldc is 2 bytes and ldc_w is 3 bytes
  6941. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  6942. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  6943. - guarantee(false, "insert_space_at() failed");
  6944. + assert(size > 0, "");
  6945. + return size;
  6946. +
  6947. + }
  6948. +
  6949. + public:
  6950. +
  6951. + virtual void do_old_field(fieldDescriptor* fd){}
  6952. +
  6953. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6954. +
  6955. + int alignment = new_fd->offset() - curPosition;
  6956. + if (alignment > 0) {
  6957. + // This field was aligned, so we need to make sure that we fill the gap
  6958. + fill(alignment);
  6959. + }
  6960. +
  6961. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6962. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6963. +
  6964. + int offset = old_fd->offset();
  6965. + int size = size_of_type(old_fd->field_type());
  6966. +
  6967. + int prevEnd = -1;
  6968. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6969. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6970. + }
  6971. +
  6972. + if (prevEnd == offset) {
  6973. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6974. + } else {
  6975. + info.append(size);
  6976. + info.append(offset);
  6977. + }
  6978. +
  6979. + if (old_fd->offset() < new_fd->offset()) {
  6980. + copy_backwards = true;
  6981. + }
  6982. +
  6983. + transfer_special_access_flags(old_fd, new_fd);
  6984. +
  6985. + curPosition += size;
  6986. + }
  6987. + };
  6988. +
  6989. + UpdateFieldsEvolutionClosure cl(new_version);
  6990. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6991. +
  6992. + GrowableArray<int> result = cl.finish();
  6993. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6994. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6995. +
  6996. + if (RC_TRACE_ENABLED(0x00000002)) {
  6997. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6998. + new_version->klass_part()->name()->as_C_string()));
  6999. + if (cl.does_copy_backwards()) {
  7000. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  7001. + }
  7002. + for (int i=0; i<result.length(); i++) {
  7003. + int curNum = result.at(i);
  7004. + if (curNum < 0) {
  7005. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  7006. + } else if (curNum > 0) {
  7007. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  7008. + i++;
  7009. + } else {
  7010. + RC_TRACE(0x00000002, ("\tEND"));
  7011. + }
  7012. + }
  7013. + }
  7014. +}
  7015. +
  7016. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  7017. + assert(FieldType::is_obj(signature), "");
  7018. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  7019. +}
  7020. +
  7021. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  7022. + if (klass->klass_part()->is_redefining()) {
  7023. + klass = klass->klass_part()->old_version();
  7024. + }
  7025. +
  7026. + // We found an instance klass!
  7027. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  7028. + GrowableArray< Pair<int, klassOop> > type_check_information;
  7029. +
  7030. + class MyFieldClosure : public FieldClosure {
  7031. +
  7032. + public:
  7033. +
  7034. + GrowableArray< Pair<int, klassOop> > *_arr;
  7035. +
  7036. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  7037. + _arr = arr;
  7038. + }
  7039. +
  7040. + virtual void do_field(fieldDescriptor* fd) {
  7041. + if (fd->field_type() == T_OBJECT) {
  7042. + Symbol* signature = fd->signature();
  7043. + if (FieldType::is_obj(signature)) {
  7044. + Symbol* name = signature_to_class_name(signature);
  7045. + klassOop field_klass;
  7046. + if (is_field_dangerous(name, fd, field_klass)) {
  7047. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  7048. + fd->name()->as_C_string(),
  7049. + fd->field_holder()->klass_part()->name()->as_C_string(),
  7050. + name->as_C_string()));
  7051. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  7052. + }
  7053. + }
  7054. +
  7055. + // Array fields can never be a problem!
  7056. + }
  7057. + }
  7058. +
  7059. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  7060. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  7061. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  7062. + if(field_klass != NULL) {
  7063. + if (field_klass->klass_part()->is_redefining()) {
  7064. + field_klass = field_klass->klass_part()->old_version();
  7065. + }
  7066. + if (field_klass->klass_part()->has_subtype_changed()) {
  7067. + return true;
  7068. + }
  7069. + }
  7070. + return false;
  7071. + }
  7072. + };
  7073. +
  7074. + MyFieldClosure fieldClosure(&type_check_information);
  7075. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  7076. +
  7077. + if (type_check_information.length() > 0) {
  7078. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  7079. + cur_instance_klass->store_type_check_information(type_check_information);
  7080. + }
  7081. +}
  7082. +
  7083. +bool VM_RedefineClasses::check_field_value_types() {
  7084. +
  7085. + Thread *THREAD = Thread::current();
  7086. + class CheckFieldTypesClosure : public ObjectClosure {
  7087. +
  7088. + private:
  7089. +
  7090. + bool _result;
  7091. +
  7092. + public:
  7093. +
  7094. + CheckFieldTypesClosure() {
  7095. + _result = true;
  7096. + }
  7097. +
  7098. + bool result() { return _result; }
  7099. +
  7100. + virtual void do_object(oop obj) {
  7101. +
  7102. + if (!_result) {
  7103. + return;
  7104. + }
  7105. +
  7106. + if (obj->is_objArray()) {
  7107. +
  7108. + objArrayOop array = objArrayOop(obj);
  7109. +
  7110. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  7111. +
  7112. + if (element_klass->klass_part()->has_subtype_changed()) {
  7113. + int length = array->length();
  7114. + for (int i=0; i<length; i++) {
  7115. + oop element = array->obj_at(i);
  7116. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  7117. + // Check subtype relationship to static type of array
  7118. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  7119. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  7120. + element_klass->klass_part()->name()->as_C_string(),
  7121. + i,
  7122. + element->blueprint()->name()->as_C_string()));
  7123. + _result = false;
  7124. + break;
  7125. }
  7126. }
  7127. -
  7128. - // return the new method so that the caller can update
  7129. - // the containing class
  7130. - *new_method_p = method = m;
  7131. - // switch our bytecode processing loop from the old method
  7132. - // to the new method
  7133. - code_base = method->code_base();
  7134. - code_length = method->code_size();
  7135. - bcp = code_base + bci;
  7136. - c = (Bytecodes::Code)(*bcp);
  7137. - bc_length = Bytecodes::length_for(c);
  7138. - assert(bc_length != 0, "sanity check");
  7139. - } // end we need ldc_w instead of ldc
  7140. - } // end if there is a mapped index
  7141. - } break;
  7142. -
  7143. - // these bytecodes have a two-byte constant pool index
  7144. - case Bytecodes::_anewarray : // fall through
  7145. - case Bytecodes::_checkcast : // fall through
  7146. - case Bytecodes::_getfield : // fall through
  7147. - case Bytecodes::_getstatic : // fall through
  7148. - case Bytecodes::_instanceof : // fall through
  7149. - case Bytecodes::_invokedynamic : // fall through
  7150. - case Bytecodes::_invokeinterface: // fall through
  7151. - case Bytecodes::_invokespecial : // fall through
  7152. - case Bytecodes::_invokestatic : // fall through
  7153. - case Bytecodes::_invokevirtual : // fall through
  7154. - case Bytecodes::_ldc_w : // fall through
  7155. - case Bytecodes::_ldc2_w : // fall through
  7156. - case Bytecodes::_multianewarray : // fall through
  7157. - case Bytecodes::_new : // fall through
  7158. - case Bytecodes::_putfield : // fall through
  7159. - case Bytecodes::_putstatic :
  7160. - {
  7161. - address p = bcp + 1;
  7162. - int cp_index = Bytes::get_Java_u2(p);
  7163. - int new_index = find_new_index(cp_index);
  7164. - if (new_index != 0) {
  7165. - // the original index is mapped so update w/ new value
  7166. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7167. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7168. - bcp, cp_index, new_index));
  7169. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7170. - // situation because it is reusing the constant pool index
  7171. - // location for a native index into the constantPoolCache.
  7172. - // Since we are updating the constant pool index prior to
  7173. - // verification and constantPoolCache initialization, we
  7174. - // need to keep the new index in Java byte order.
  7175. - Bytes::put_Java_u2(p, new_index);
  7176. + }
  7177. }
  7178. - } break;
  7179. +
  7180. + } else {
  7181. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  7182. + if (cur != NULL) {
  7183. + // Type check information exists for this oop
  7184. + while ((*cur).left() != -1) {
  7185. + check_field(obj, (*cur).left(), (*cur).right());
  7186. + cur++;
  7187. + }
  7188. + }
  7189. + }
  7190. }
  7191. - } // end for each bytecode
  7192. -} // end rewrite_cp_refs_in_method()
  7193. + void check_field(oop obj, int offset, klassOop static_type) {
  7194. + oop field_value = obj->obj_field(offset);
  7195. + if (field_value != NULL) {
  7196. + // Field is not null
  7197. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  7198. + // We are OK
  7199. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7200. + obj->klass()->klass_part()->name()->as_C_string(),
  7201. + static_type->klass_part()->name()->as_C_string(),
  7202. + offset,
  7203. + field_value->klass()->klass_part()->name()->as_C_string()));
  7204. + } else {
  7205. + // Failure!
  7206. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7207. + obj->klass()->klass_part()->name()->as_C_string(),
  7208. + static_type->klass_part()->name()->as_C_string(),
  7209. + offset,
  7210. + field_value->klass()->klass_part()->name()->as_C_string()));
  7211. + _result = false;
  7212. + }
  7213. + }
  7214. + }
  7215. + };
  7216. -// Rewrite constant pool references in the class_annotations field.
  7217. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7218. - instanceKlassHandle scratch_class, TRAPS) {
  7219. + CheckFieldTypesClosure myObjectClosure;
  7220. - typeArrayHandle class_annotations(THREAD,
  7221. - scratch_class->class_annotations());
  7222. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7223. - // no class_annotations so nothing to do
  7224. - return true;
  7225. + // make sure that heap is parsable (fills TLABs with filler objects)
  7226. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  7227. +
  7228. + // do the iteration
  7229. + // If this operation encounters a bad object when using CMS,
  7230. + // consider using safe_object_iterate() which avoids perm gen
  7231. + // objects that may contain bad references.
  7232. + Universe::heap()->object_iterate(&myObjectClosure);
  7233. +
  7234. + // when sharing is enabled we must iterate over the shared spaces
  7235. + if (UseSharedSpaces) {
  7236. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  7237. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  7238. + gen->ro_space()->object_iterate(&myObjectClosure);
  7239. + gen->rw_space()->object_iterate(&myObjectClosure);
  7240. }
  7241. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7242. - ("class_annotations length=%d", class_annotations->length()));
  7243. -
  7244. - int byte_i = 0; // byte index into class_annotations
  7245. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7246. - THREAD);
  7247. + return myObjectClosure.result();
  7248. }
  7249. -
  7250. -// Rewrite constant pool references in an annotations typeArray. This
  7251. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7252. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7253. -//
  7254. -// annotations_typeArray {
  7255. -// u2 num_annotations;
  7256. -// annotation annotations[num_annotations];
  7257. -// }
  7258. -//
  7259. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7260. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7261. -
  7262. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7263. - // not enough room for num_annotations field
  7264. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7265. - ("length() is too small for num_annotations field"));
  7266. - return false;
  7267. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  7268. + if (k->klass_part()->is_redefining()) {
  7269. + k = k->klass_part()->old_version();
  7270. }
  7271. - u2 num_annotations = Bytes::get_Java_u2((address)
  7272. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7273. - byte_i_ref += 2;
  7274. -
  7275. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7276. - ("num_annotations=%d", num_annotations));
  7277. -
  7278. - int calc_num_annotations = 0;
  7279. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7280. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7281. - byte_i_ref, THREAD)) {
  7282. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7283. - ("bad annotation_struct at %d", calc_num_annotations));
  7284. - // propagate failure back to caller
  7285. - return false;
  7286. - }
  7287. - }
  7288. - assert(num_annotations == calc_num_annotations, "sanity check");
  7289. -
  7290. - return true;
  7291. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7292. -
  7293. -
  7294. -// Rewrite constant pool references in the annotation struct portion of
  7295. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7296. -// the 2nd-edition of the VM spec:
  7297. -//
  7298. -// struct annotation {
  7299. -// u2 type_index;
  7300. -// u2 num_element_value_pairs;
  7301. -// {
  7302. -// u2 element_name_index;
  7303. -// element_value value;
  7304. -// } element_value_pairs[num_element_value_pairs];
  7305. -// }
  7306. -//
  7307. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7308. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7309. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7310. - // not enough room for smallest annotation_struct
  7311. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7312. - ("length() is too small for annotation_struct"));
  7313. - return false;
  7314. - }
  7315. -
  7316. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7317. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7318. -
  7319. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7320. - annotations_typeArray->byte_at_addr(
  7321. - byte_i_ref));
  7322. - byte_i_ref += 2;
  7323. -
  7324. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7325. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7326. - num_element_value_pairs));
  7327. -
  7328. - int calc_num_element_value_pairs = 0;
  7329. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7330. - calc_num_element_value_pairs++) {
  7331. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7332. - // not enough room for another element_name_index, let alone
  7333. - // the rest of another component
  7334. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7335. - ("length() is too small for element_name_index"));
  7336. - return false;
  7337. - }
  7338. -
  7339. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7340. - annotations_typeArray, byte_i_ref,
  7341. - "mapped old element_name_index=%d", THREAD);
  7342. -
  7343. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7344. - ("element_name_index=%d", element_name_index));
  7345. -
  7346. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7347. - byte_i_ref, THREAD)) {
  7348. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7349. - ("bad element_value at %d", calc_num_element_value_pairs));
  7350. - // propagate failure back to caller
  7351. - return false;
  7352. - }
  7353. - } // end for each component
  7354. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7355. - "sanity check");
  7356. -
  7357. - return true;
  7358. -} // end rewrite_cp_refs_in_annotation_struct()
  7359. -
  7360. -
  7361. -// Rewrite a constant pool reference at the current position in
  7362. -// annotations_typeArray if needed. Returns the original constant
  7363. -// pool reference if a rewrite was not needed or the new constant
  7364. -// pool reference if a rewrite was needed.
  7365. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7366. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7367. - const char * trace_mesg, TRAPS) {
  7368. -
  7369. - address cp_index_addr = (address)
  7370. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7371. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7372. - u2 new_cp_index = find_new_index(old_cp_index);
  7373. - if (new_cp_index != 0) {
  7374. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7375. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7376. - old_cp_index = new_cp_index;
  7377. - }
  7378. - byte_i_ref += 2;
  7379. - return old_cp_index;
  7380. + // We found an instance klass!
  7381. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  7382. + cur_instance_klass->clear_type_check_information();
  7383. }
  7384. +void VM_RedefineClasses::update_active_methods() {
  7385. -// Rewrite constant pool references in the element_value portion of an
  7386. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7387. -// the 2nd-edition of the VM spec:
  7388. -//
  7389. -// struct element_value {
  7390. -// u1 tag;
  7391. -// union {
  7392. -// u2 const_value_index;
  7393. -// {
  7394. -// u2 type_name_index;
  7395. -// u2 const_name_index;
  7396. -// } enum_const_value;
  7397. -// u2 class_info_index;
  7398. -// annotation annotation_value;
  7399. -// struct {
  7400. -// u2 num_values;
  7401. -// element_value values[num_values];
  7402. -// } array_value;
  7403. -// } value;
  7404. -// }
  7405. -//
  7406. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7407. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7408. + RC_TRACE(0x00000002, ("Updating active methods"));
  7409. + JavaThread *java_thread = Threads::first();
  7410. + while (java_thread != NULL) {
  7411. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7412. - // not enough room for a tag let alone the rest of an element_value
  7413. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7414. - ("length() is too small for a tag"));
  7415. + int stack_depth = 0;
  7416. + if (java_thread->has_last_Java_frame()) {
  7417. +
  7418. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  7419. +
  7420. + // vframes are resource allocated
  7421. + Thread* current_thread = Thread::current();
  7422. + ResourceMark rm(current_thread);
  7423. + HandleMark hm(current_thread);
  7424. +
  7425. + RegisterMap reg_map(java_thread);
  7426. + frame f = java_thread->last_frame();
  7427. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7428. + frame* last_entry_frame = NULL;
  7429. +
  7430. + while (vf != NULL) {
  7431. + if (vf->is_java_frame()) {
  7432. + // java frame (interpreted, compiled, ...)
  7433. + javaVFrame *jvf = javaVFrame::cast(vf);
  7434. +
  7435. + if (!(jvf->method()->is_native())) {
  7436. + int bci = jvf->bci();
  7437. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  7438. + ResourceMark rm(Thread::current());
  7439. + HandleMark hm;
  7440. + instanceKlassHandle klass(jvf->method()->method_holder());
  7441. +
  7442. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  7443. +
  7444. +
  7445. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  7446. + jvf->method()->name_and_sig_as_C_string()));
  7447. +
  7448. + if (RC_TRACE_ENABLED(0x01000000)) {
  7449. + int code_size = jvf->method()->code_size();
  7450. + char *code_base_old = (char*)jvf->method()->code_base();
  7451. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  7452. + for (int i=0; i<code_size; i++) {
  7453. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  7454. + }
  7455. + jvf->method()->print_codes_on(tty);
  7456. + jvf->method()->new_version()->print_codes_on(tty);
  7457. + }
  7458. +
  7459. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  7460. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  7461. +
  7462. +
  7463. + if (RC_TRACE_ENABLED(0x01000000)) {
  7464. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  7465. + tty->print_cr("old cp");
  7466. + for (int i=0; i<cp_old->length(); i++) {
  7467. + cp_old->entry_at(i)->print(tty, i);
  7468. + }
  7469. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  7470. + tty->print_cr("new cp");
  7471. + for (int i=0; i<cp_new->length(); i++) {
  7472. + cp_new->entry_at(i)->print(tty, i);
  7473. + }
  7474. + }
  7475. +
  7476. + iframe->set_method(jvf->method()->new_version(), bci);
  7477. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  7478. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  7479. +
  7480. + }
  7481. + }
  7482. + }
  7483. + vf = vf->sender();
  7484. + }
  7485. + }
  7486. +
  7487. + // Advance to next thread
  7488. + java_thread = java_thread->next();
  7489. + }
  7490. +}
  7491. +
  7492. +void VM_RedefineClasses::method_forwarding() {
  7493. +
  7494. + int forwarding_count = 0;
  7495. + JavaThread *java_thread = Threads::first();
  7496. + while (java_thread != NULL) {
  7497. +
  7498. + int stack_depth = 0;
  7499. + if (java_thread->has_last_Java_frame()) {
  7500. +
  7501. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7502. +
  7503. + // vframes are resource allocated
  7504. + Thread* current_thread = Thread::current();
  7505. + ResourceMark rm(current_thread);
  7506. + HandleMark hm(current_thread);
  7507. +
  7508. + RegisterMap reg_map(java_thread);
  7509. + frame f = java_thread->last_frame();
  7510. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7511. + frame* last_entry_frame = NULL;
  7512. +
  7513. + while (vf != NULL) {
  7514. + if (vf->is_java_frame()) {
  7515. + // java frame (interpreted, compiled, ...)
  7516. + javaVFrame *jvf = javaVFrame::cast(vf);
  7517. +
  7518. + if (!(jvf->method()->is_native())) {
  7519. + RC_TRACE(0x00008000, ("found method: %s",
  7520. + jvf->method()->name()->as_C_string()));
  7521. + ResourceMark rm(Thread::current());
  7522. + HandleMark hm;
  7523. + instanceKlassHandle klass(jvf->method()->method_holder());
  7524. + methodOop m = jvf->method();
  7525. + int bci = jvf->bci();
  7526. + RC_TRACE(0x00008000, ("klass redef %d",
  7527. + klass->is_redefining()));
  7528. +
  7529. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7530. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7531. + m->name()->as_C_string()));
  7532. +
  7533. + klassOop new_klass = klass->newest_version();
  7534. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7535. + RC_TRACE(0x00000002, ("%d %d",
  7536. + new_method,
  7537. + new_method->constMethod()->has_code_section_table()));
  7538. +
  7539. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7540. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7541. + new_method->name()->as_C_string()));
  7542. + m->set_forward_method(new_method);
  7543. + if (new_method->max_locals() != m->max_locals()) {
  7544. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7545. + }
  7546. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7547. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7548. + if (jvf->is_interpreted_frame()) {
  7549. + if (m->is_in_code_section(bci)) {
  7550. + // We must transfer now and cannot delay until next NOP.
  7551. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7552. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7553. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7554. + new_method->name()->as_C_string(),
  7555. + bci,
  7556. + new_bci));
  7557. + iframe->set_method(new_method, new_bci);
  7558. + } else {
  7559. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7560. + new_method->name()->as_C_string(),
  7561. + bci));
  7562. + }
  7563. + } else {
  7564. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7565. + new_method->name()->as_C_string()));
  7566. + }
  7567. + }
  7568. + }
  7569. + }
  7570. + }
  7571. + vf = vf->sender();
  7572. + }
  7573. + }
  7574. +
  7575. + // Advance to next thread
  7576. + java_thread = java_thread->next();
  7577. + }
  7578. +
  7579. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7580. + forwarding_count));
  7581. +}
  7582. +
  7583. +bool VM_RedefineClasses::check_method_stacks() {
  7584. +
  7585. + JavaThread *java_thread = Threads::first();
  7586. + while (java_thread != NULL) {
  7587. +
  7588. + int stack_depth = 0;
  7589. + if (java_thread->has_last_Java_frame()) {
  7590. +
  7591. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7592. +
  7593. + // vframes are resource allocated
  7594. + Thread* current_thread = Thread::current();
  7595. + ResourceMark rm(current_thread);
  7596. + HandleMark hm(current_thread);
  7597. +
  7598. + RegisterMap reg_map(java_thread);
  7599. + frame f = java_thread->last_frame();
  7600. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7601. + frame* last_entry_frame = NULL;
  7602. +
  7603. + while (vf != NULL) {
  7604. + if (vf->is_java_frame()) {
  7605. + // java frame (interpreted, compiled, ...)
  7606. + javaVFrame *jvf = javaVFrame::cast(vf);
  7607. +
  7608. + if (!(jvf->method()->is_native())) {
  7609. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7610. + ResourceMark rm(Thread::current());
  7611. + HandleMark hm;
  7612. + instanceKlassHandle klass(jvf->method()->method_holder());
  7613. +
  7614. + StackValueCollection *locals = jvf->locals();
  7615. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7616. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7617. +
  7618. + for (int i=0; i<locals->size(); i++) {
  7619. + StackValue *stack_value = locals->at(i);
  7620. + if (stack_value->type() == T_OBJECT) {
  7621. + Handle obj = stack_value->get_obj();
  7622. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7623. +
  7624. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7625. + bool result = false;
  7626. + methodOop method = jvf->method();
  7627. + if (method->has_localvariable_table()) {
  7628. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7629. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7630. +
  7631. + if (elem->slot == i) {
  7632. +
  7633. + // Matching index found
  7634. +
  7635. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7636. +
  7637. + // Also in range!!
  7638. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7639. + Symbol* klass_name = signature_to_class_name(signature);
  7640. +
  7641. + 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();
  7642. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7643. +
  7644. + // Field is not null
  7645. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7646. + // We are OK
  7647. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7648. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7649. + result = true;
  7650. + } else {
  7651. + // Failure!
  7652. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7653. + local_klass->klass_part()->name()->as_C_string(),
  7654. + cur->klass_part()->name()->as_C_string()));
  7655. + return false;
  7656. + }
  7657. + }
  7658. + }
  7659. +
  7660. + elem++;
  7661. + }
  7662. + } else {
  7663. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7664. + method->name_and_sig_as_C_string()));
  7665. + }
  7666. +
  7667. + if (!result) {
  7668. + return false;
  7669. + }
  7670. +
  7671. + RC_TRACE(0x00008000, ("Verifying class %s",
  7672. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7673. +
  7674. + Symbol* exception_name;
  7675. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7676. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7677. +
  7678. + Thread::current()->set_pretend_new_universe(true);
  7679. + ClassVerifier split_verifier(klass, Thread::current());
  7680. + split_verifier.verify_method(jvf->method(), Thread::current());
  7681. + exception_name = split_verifier.result();
  7682. + Thread::current()->set_pretend_new_universe(false);
  7683. +
  7684. + if (exception_name != NULL) {
  7685. +
  7686. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7687. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7688. + RC_TRACE(0x00000001, ("Exception: %s",
  7689. + exception_name->as_C_string()));
  7690. + RC_TRACE(0x00000001, ("Message: %s",
  7691. + message_buffer));
  7692. + Thread::current()->clear_pending_exception();
  7693. + return false;
  7694. + }
  7695. +
  7696. + }
  7697. + }
  7698. + }
  7699. + }
  7700. + }
  7701. + vf = vf->sender();
  7702. + }
  7703. + }
  7704. +
  7705. + // Advance to next thread
  7706. + java_thread = java_thread->next();
  7707. + }
  7708. +
  7709. + return true;
  7710. +}
  7711. +
  7712. +bool VM_RedefineClasses::check_method(methodOop method) {
  7713. +
  7714. +
  7715. + return true;
  7716. +}
  7717. +
  7718. +// Warning: destroys redefinition level values of klasses.
  7719. +bool VM_RedefineClasses::check_loaded_methods() {
  7720. +
  7721. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7722. +
  7723. + private:
  7724. +
  7725. + bool _result;
  7726. + GrowableArray<klassOop> *_dangerous_klasses;
  7727. +
  7728. + public:
  7729. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7730. + _result = true;
  7731. + _dangerous_klasses = dangerous_klasses;
  7732. + }
  7733. +
  7734. + bool result() {
  7735. + return _result;
  7736. + }
  7737. +
  7738. + bool is_class_dangerous(klassOop k) {
  7739. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7740. + }
  7741. +
  7742. + bool can_be_affected(instanceKlass *klass) {
  7743. +
  7744. + constantPoolOop cp = klass->constants();
  7745. +
  7746. + Thread *THREAD = Thread::current();
  7747. + klassOop k;
  7748. + Symbol* symbol;
  7749. +
  7750. + for (int i=1; i<cp->length(); i++) {
  7751. + jbyte tag = cp->tag_at(i).value();
  7752. + switch(tag) {
  7753. + case JVM_CONSTANT_Long:
  7754. + case JVM_CONSTANT_Double:
  7755. + i++;
  7756. + break;
  7757. +
  7758. + case JVM_CONSTANT_Utf8:
  7759. + case JVM_CONSTANT_Unicode:
  7760. + case JVM_CONSTANT_Integer:
  7761. + case JVM_CONSTANT_Float:
  7762. + case JVM_CONSTANT_String:
  7763. + case JVM_CONSTANT_Fieldref:
  7764. + case JVM_CONSTANT_Methodref:
  7765. + case JVM_CONSTANT_InterfaceMethodref:
  7766. + case JVM_CONSTANT_ClassIndex:
  7767. + case JVM_CONSTANT_UnresolvedString:
  7768. + case JVM_CONSTANT_StringIndex:
  7769. + case JVM_CONSTANT_UnresolvedClassInError:
  7770. + case JVM_CONSTANT_Object:
  7771. + // do nothing
  7772. + break;
  7773. +
  7774. + case JVM_CONSTANT_Class:
  7775. + k = cp->klass_at(i, CHECK_(true));
  7776. + if (is_class_dangerous(k)) {
  7777. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7778. + klass->name()->as_C_string(),
  7779. + i,
  7780. + k->klass_part()->name()->as_C_string()));
  7781. + return true;
  7782. + }
  7783. + break;
  7784. +
  7785. + case JVM_CONSTANT_NameAndType:
  7786. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7787. + if (symbol->byte_at(0) == '(') {
  7788. + // This must be a method
  7789. + SignatureStream signatureStream(symbol);
  7790. + while (true) {
  7791. +
  7792. + if (signatureStream.is_array()) {
  7793. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7794. + if (is_type_signature_dangerous(cur_signature)) {
  7795. + return true;
  7796. + }
  7797. + } else if (signatureStream.is_object()) {
  7798. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7799. + return true;
  7800. + }
  7801. + }
  7802. +
  7803. + if (signatureStream.at_return_type()) {
  7804. + break;
  7805. + }
  7806. +
  7807. + signatureStream.next();
  7808. + }
  7809. +
  7810. + } else if (is_type_signature_dangerous(symbol)) {
  7811. + return true;
  7812. + }
  7813. + break;
  7814. +
  7815. + case JVM_CONSTANT_UnresolvedClass:
  7816. + symbol = cp->unresolved_klass_at(i);
  7817. + if (is_symbol_dangerous(symbol)) {
  7818. + return true;
  7819. + }
  7820. + break;
  7821. +
  7822. + default:
  7823. + ShouldNotReachHere();
  7824. + }
  7825. + }
  7826. +
  7827. + return false;
  7828. + }
  7829. +
  7830. + bool is_type_signature_dangerous(Symbol* signature) {
  7831. + // This must be a field type
  7832. + if (FieldType::is_obj(signature)) {
  7833. + Symbol* name = signature_to_class_name(signature);
  7834. + if (is_symbol_dangerous(name)) {
  7835. + return true;
  7836. + }
  7837. + } else if (FieldType::is_array(signature)) {
  7838. + //jint dimension;
  7839. + //Symbol* object_key;
  7840. + FieldArrayInfo fd;
  7841. + FieldType::get_array_info(signature, fd, Thread::current());
  7842. + if (is_symbol_dangerous(fd.object_key())) {
  7843. + return true;
  7844. + }
  7845. + }
  7846. + return false;
  7847. + }
  7848. +
  7849. + bool is_symbol_dangerous(Symbol* symbol) {
  7850. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7851. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7852. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7853. + i,
  7854. + symbol->as_C_string()));
  7855. + return true;
  7856. + }
  7857. + }
  7858. + return false;
  7859. + }
  7860. +
  7861. + virtual void do_object(oop obj) {
  7862. +
  7863. + if (!_result) return;
  7864. +
  7865. + klassOop klassObj = (klassOop)obj;
  7866. + Thread *THREAD = Thread::current();
  7867. +
  7868. + // We found an instance klass!
  7869. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7870. + instanceKlassHandle handle(klassObj);
  7871. +
  7872. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7873. +
  7874. + if (!can_be_affected(klass)) {
  7875. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7876. + return;
  7877. + }
  7878. +
  7879. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7880. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7881. + _result = false;
  7882. + return;
  7883. + }
  7884. +
  7885. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7886. +
  7887. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7888. +
  7889. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7890. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7891. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7892. + //PENDING_EXCEPTION->print();
  7893. + CLEAR_PENDING_EXCEPTION;
  7894. + _result = false;
  7895. + }
  7896. +
  7897. + /*int method_count = klass->methods()->length();
  7898. + for (int i=0; i<method_count; i++) {
  7899. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7900. + if (!check_method(cur_method)) {
  7901. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7902. + }
  7903. + }*/
  7904. + }
  7905. + };
  7906. +
  7907. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7908. +
  7909. + GrowableArray<klassOop> dangerous_klasses;
  7910. + for (int i=0; i<_new_classes->length(); i++) {
  7911. + instanceKlassHandle handle = _new_classes->at(i);
  7912. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7913. + dangerous_klasses.append(handle());
  7914. + }
  7915. + }
  7916. +
  7917. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7918. + Thread::current()->set_pretend_new_universe(true);
  7919. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7920. + Thread::current()->set_pretend_new_universe(false);
  7921. +
  7922. +
  7923. + return checkLoadedMethodsClosure.result();
  7924. +}
  7925. +
  7926. +bool VM_RedefineClasses::check_type_consistency() {
  7927. +
  7928. + Universe::set_verify_in_progress(true);
  7929. +
  7930. + SystemDictionary::classes_do(calculate_type_check_information);
  7931. + bool result = check_field_value_types();
  7932. + SystemDictionary::classes_do(clear_type_check_information);
  7933. + if (!result) {
  7934. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7935. + Universe::set_verify_in_progress(false);
  7936. return false;
  7937. }
  7938. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7939. - byte_i_ref++;
  7940. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7941. + result = check_method_stacks();
  7942. + if (!result) {
  7943. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7944. + Universe::set_verify_in_progress(false);
  7945. + return false;
  7946. + }
  7947. - switch (tag) {
  7948. - // These BaseType tag values are from Table 4.2 in VM spec:
  7949. - case 'B': // byte
  7950. - case 'C': // char
  7951. - case 'D': // double
  7952. - case 'F': // float
  7953. - case 'I': // int
  7954. - case 'J': // long
  7955. - case 'S': // short
  7956. - case 'Z': // boolean
  7957. + result = check_loaded_methods();
  7958. + if (!result) {
  7959. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7960. + Universe::set_verify_in_progress(false);
  7961. + return false;
  7962. + }
  7963. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7964. - // the VM spec:
  7965. - case 's':
  7966. - {
  7967. - // For the above tag values (including the BaseType values),
  7968. - // value.const_value_index is right union field.
  7969. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7970. + Universe::set_verify_in_progress(false);
  7971. + return true;
  7972. +}
  7973. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7974. - // not enough room for a const_value_index
  7975. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7976. - ("length() is too small for a const_value_index"));
  7977. - return false;
  7978. +void VM_RedefineClasses::rollback() {
  7979. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7980. + SystemDictionary::rollback_redefinition();
  7981. +
  7982. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7983. + for (int i=0; i<_new_classes->length(); i++) {
  7984. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7985. + }
  7986. +
  7987. + for (int i=0; i<_new_classes->length(); i++) {
  7988. + instanceKlassHandle new_class = _new_classes->at(i);
  7989. + new_class->set_redefining(false);
  7990. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7991. + new_class->set_old_version(NULL);
  7992. + }
  7993. +
  7994. +}
  7995. +
  7996. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7997. + T heap_oop = oopDesc::load_heap_oop(p);
  7998. + if (!oopDesc::is_null(heap_oop)) {
  7999. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  8000. + if (obj->is_instanceKlass()) {
  8001. + klassOop klass = (klassOop)obj;
  8002. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  8003. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  8004. + obj = klass->klass_part()->new_version();
  8005. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  8006. }
  8007. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  8008. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  8009. + // java.lang.Class instances.
  8010. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  8011. + if (klass_oop != NULL) {
  8012. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  8013. + obj = klass_oop->new_version()->java_mirror();
  8014. + } else if (klass_oop->klass_part()->is_redefining()) {
  8015. + obj = klass_oop->java_mirror();
  8016. + }
  8017. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  8018. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8019. - annotations_typeArray, byte_i_ref,
  8020. - "mapped old const_value_index=%d", THREAD);
  8021. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8022. - ("const_value_index=%d", const_value_index));
  8023. - } break;
  8024. -
  8025. - case 'e':
  8026. - {
  8027. - // for the above tag value, value.enum_const_value is right union field
  8028. -
  8029. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8030. - // not enough room for a enum_const_value
  8031. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8032. - ("length() is too small for a enum_const_value"));
  8033. - return false;
  8034. - }
  8035. -
  8036. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8037. - annotations_typeArray, byte_i_ref,
  8038. - "mapped old type_name_index=%d", THREAD);
  8039. -
  8040. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8041. - annotations_typeArray, byte_i_ref,
  8042. - "mapped old const_name_index=%d", THREAD);
  8043. -
  8044. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8045. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8046. - const_name_index));
  8047. - } break;
  8048. -
  8049. - case 'c':
  8050. - {
  8051. - // for the above tag value, value.class_info_index is right union field
  8052. -
  8053. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8054. - // not enough room for a class_info_index
  8055. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8056. - ("length() is too small for a class_info_index"));
  8057. - return false;
  8058. - }
  8059. -
  8060. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8061. - annotations_typeArray, byte_i_ref,
  8062. - "mapped old class_info_index=%d", THREAD);
  8063. -
  8064. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8065. - ("class_info_index=%d", class_info_index));
  8066. - } break;
  8067. -
  8068. - case '@':
  8069. - // For the above tag value, value.attr_value is the right union
  8070. - // field. This is a nested annotation.
  8071. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8072. - byte_i_ref, THREAD)) {
  8073. - // propagate failure back to caller
  8074. - return false;
  8075. - }
  8076. - break;
  8077. -
  8078. - case '[':
  8079. - {
  8080. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8081. - // not enough room for a num_values field
  8082. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8083. - ("length() is too small for a num_values field"));
  8084. - return false;
  8085. - }
  8086. -
  8087. - // For the above tag value, value.array_value is the right union
  8088. - // field. This is an array of nested element_value.
  8089. - u2 num_values = Bytes::get_Java_u2((address)
  8090. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8091. - byte_i_ref += 2;
  8092. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8093. -
  8094. - int calc_num_values = 0;
  8095. - for (; calc_num_values < num_values; calc_num_values++) {
  8096. - if (!rewrite_cp_refs_in_element_value(
  8097. - annotations_typeArray, byte_i_ref, THREAD)) {
  8098. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8099. - ("bad nested element_value at %d", calc_num_values));
  8100. - // propagate failure back to caller
  8101. - return false;
  8102. + // FIXME: DCEVM: better implementation?
  8103. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  8104. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  8105. + // case we need to run write barrier to make sure card table is properly updated. This will
  8106. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  8107. + if (Universe::heap()->is_in_reserved(p)) {
  8108. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  8109. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  8110. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  8111. + CardTableRS* _rs = (CardTableRS*)rs;
  8112. + _rs->inline_write_ref_field_gc(p, obj);
  8113. + }
  8114. }
  8115. }
  8116. - assert(num_values == calc_num_values, "sanity check");
  8117. - } break;
  8118. -
  8119. - default:
  8120. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8121. - return false;
  8122. - } // end decode tag field
  8123. -
  8124. - return true;
  8125. -} // end rewrite_cp_refs_in_element_value()
  8126. -
  8127. -
  8128. -// Rewrite constant pool references in a fields_annotations field.
  8129. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8130. - instanceKlassHandle scratch_class, TRAPS) {
  8131. -
  8132. - objArrayHandle fields_annotations(THREAD,
  8133. - scratch_class->fields_annotations());
  8134. -
  8135. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8136. - // no fields_annotations so nothing to do
  8137. - return true;
  8138. - }
  8139. -
  8140. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8141. - ("fields_annotations length=%d", fields_annotations->length()));
  8142. -
  8143. - for (int i = 0; i < fields_annotations->length(); i++) {
  8144. - typeArrayHandle field_annotations(THREAD,
  8145. - (typeArrayOop)fields_annotations->obj_at(i));
  8146. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8147. - // this field does not have any annotations so skip it
  8148. - continue;
  8149. - }
  8150. -
  8151. - int byte_i = 0; // byte index into field_annotations
  8152. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8153. - THREAD)) {
  8154. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8155. - ("bad field_annotations at %d", i));
  8156. - // propagate failure back to caller
  8157. - return false;
  8158. }
  8159. }
  8160. +}
  8161. - return true;
  8162. -} // end rewrite_cp_refs_in_fields_annotations()
  8163. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  8164. + markOop first_mark = first->mark();
  8165. + markOop second_mark = second->mark();
  8166. + first->set_mark(second_mark);
  8167. + second->set_mark(first_mark);
  8168. +}
  8169. +void VM_RedefineClasses::doit() {
  8170. + Thread *thread = Thread::current();
  8171. -// Rewrite constant pool references in a methods_annotations field.
  8172. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8173. - instanceKlassHandle scratch_class, TRAPS) {
  8174. + RC_TRACE(0x00000001, ("Entering doit!"));
  8175. - objArrayHandle methods_annotations(THREAD,
  8176. - scratch_class->methods_annotations());
  8177. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8178. - // no methods_annotations so nothing to do
  8179. - return true;
  8180. - }
  8181. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  8182. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8183. - ("methods_annotations length=%d", methods_annotations->length()));
  8184. + RC_TIMER_START(_timer_check_type);
  8185. - for (int i = 0; i < methods_annotations->length(); i++) {
  8186. - typeArrayHandle method_annotations(THREAD,
  8187. - (typeArrayOop)methods_annotations->obj_at(i));
  8188. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8189. - // this method does not have any annotations so skip it
  8190. - continue;
  8191. - }
  8192. -
  8193. - int byte_i = 0; // byte index into method_annotations
  8194. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8195. - THREAD)) {
  8196. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8197. - ("bad method_annotations at %d", i));
  8198. - // propagate failure back to caller
  8199. - return false;
  8200. - }
  8201. - }
  8202. -
  8203. - return true;
  8204. -} // end rewrite_cp_refs_in_methods_annotations()
  8205. -
  8206. -
  8207. -// Rewrite constant pool references in a methods_parameter_annotations
  8208. -// field. This "structure" is adapted from the
  8209. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8210. -// 4.8.17 of the 2nd-edition of the VM spec:
  8211. -//
  8212. -// methods_parameter_annotations_typeArray {
  8213. -// u1 num_parameters;
  8214. -// {
  8215. -// u2 num_annotations;
  8216. -// annotation annotations[num_annotations];
  8217. -// } parameter_annotations[num_parameters];
  8218. -// }
  8219. -//
  8220. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8221. - instanceKlassHandle scratch_class, TRAPS) {
  8222. -
  8223. - objArrayHandle methods_parameter_annotations(THREAD,
  8224. - scratch_class->methods_parameter_annotations());
  8225. -
  8226. - if (methods_parameter_annotations.is_null()
  8227. - || methods_parameter_annotations->length() == 0) {
  8228. - // no methods_parameter_annotations so nothing to do
  8229. - return true;
  8230. - }
  8231. -
  8232. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8233. - ("methods_parameter_annotations length=%d",
  8234. - methods_parameter_annotations->length()));
  8235. -
  8236. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8237. - typeArrayHandle method_parameter_annotations(THREAD,
  8238. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8239. - if (method_parameter_annotations.is_null()
  8240. - || method_parameter_annotations->length() == 0) {
  8241. - // this method does not have any parameter annotations so skip it
  8242. - continue;
  8243. - }
  8244. -
  8245. - if (method_parameter_annotations->length() < 1) {
  8246. - // not enough room for a num_parameters field
  8247. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8248. - ("length() is too small for a num_parameters field at %d", i));
  8249. - return false;
  8250. - }
  8251. -
  8252. - int byte_i = 0; // byte index into method_parameter_annotations
  8253. -
  8254. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8255. - byte_i++;
  8256. -
  8257. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8258. - ("num_parameters=%d", num_parameters));
  8259. -
  8260. - int calc_num_parameters = 0;
  8261. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8262. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8263. - method_parameter_annotations, byte_i, THREAD)) {
  8264. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8265. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8266. - // propagate failure back to caller
  8267. - return false;
  8268. - }
  8269. - }
  8270. - assert(num_parameters == calc_num_parameters, "sanity check");
  8271. - }
  8272. -
  8273. - return true;
  8274. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8275. -
  8276. -
  8277. -// Rewrite constant pool references in a methods_default_annotations
  8278. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8279. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8280. -//
  8281. -// methods_default_annotations_typeArray {
  8282. -// element_value default_value;
  8283. -// }
  8284. -//
  8285. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8286. - instanceKlassHandle scratch_class, TRAPS) {
  8287. -
  8288. - objArrayHandle methods_default_annotations(THREAD,
  8289. - scratch_class->methods_default_annotations());
  8290. -
  8291. - if (methods_default_annotations.is_null()
  8292. - || methods_default_annotations->length() == 0) {
  8293. - // no methods_default_annotations so nothing to do
  8294. - return true;
  8295. - }
  8296. -
  8297. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8298. - ("methods_default_annotations length=%d",
  8299. - methods_default_annotations->length()));
  8300. -
  8301. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8302. - typeArrayHandle method_default_annotations(THREAD,
  8303. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8304. - if (method_default_annotations.is_null()
  8305. - || method_default_annotations->length() == 0) {
  8306. - // this method does not have any default annotations so skip it
  8307. - continue;
  8308. - }
  8309. -
  8310. - int byte_i = 0; // byte index into method_default_annotations
  8311. -
  8312. - if (!rewrite_cp_refs_in_element_value(
  8313. - method_default_annotations, byte_i, THREAD)) {
  8314. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8315. - ("bad default element_value at %d", i));
  8316. - // propagate failure back to caller
  8317. - return false;
  8318. - }
  8319. - }
  8320. -
  8321. - return true;
  8322. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8323. -
  8324. -
  8325. -// Rewrite constant pool references in the method's stackmap table.
  8326. -// These "structures" are adapted from the StackMapTable_attribute that
  8327. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8328. -// (dated 2005.10.26):
  8329. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8330. -//
  8331. -// stack_map {
  8332. -// u2 number_of_entries;
  8333. -// stack_map_frame entries[number_of_entries];
  8334. -// }
  8335. -//
  8336. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8337. - methodHandle method, TRAPS) {
  8338. -
  8339. - if (!method->has_stackmap_table()) {
  8340. - return;
  8341. - }
  8342. -
  8343. - typeArrayOop stackmap_data = method->stackmap_data();
  8344. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8345. - address stackmap_end = stackmap_p + stackmap_data->length();
  8346. -
  8347. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8348. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8349. - stackmap_p += 2;
  8350. -
  8351. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8352. - ("number_of_entries=%u", number_of_entries));
  8353. -
  8354. - // walk through each stack_map_frame
  8355. - u2 calc_number_of_entries = 0;
  8356. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8357. - // The stack_map_frame structure is a u1 frame_type followed by
  8358. - // 0 or more bytes of data:
  8359. - //
  8360. - // union stack_map_frame {
  8361. - // same_frame;
  8362. - // same_locals_1_stack_item_frame;
  8363. - // same_locals_1_stack_item_frame_extended;
  8364. - // chop_frame;
  8365. - // same_frame_extended;
  8366. - // append_frame;
  8367. - // full_frame;
  8368. - // }
  8369. -
  8370. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8371. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8372. - // issues the following warning for the first if-statement below:
  8373. - //
  8374. - // "warning: comparison is always true due to limited range of data type"
  8375. - //
  8376. - u4 frame_type = *stackmap_p;
  8377. - stackmap_p++;
  8378. -
  8379. - // same_frame {
  8380. - // u1 frame_type = SAME; /* 0-63 */
  8381. - // }
  8382. - if (frame_type >= 0 && frame_type <= 63) {
  8383. - // nothing more to do for same_frame
  8384. - }
  8385. -
  8386. - // same_locals_1_stack_item_frame {
  8387. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8388. - // verification_type_info stack[1];
  8389. - // }
  8390. - else if (frame_type >= 64 && frame_type <= 127) {
  8391. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8392. - calc_number_of_entries, frame_type, THREAD);
  8393. - }
  8394. -
  8395. - // reserved for future use
  8396. - else if (frame_type >= 128 && frame_type <= 246) {
  8397. - // nothing more to do for reserved frame_types
  8398. - }
  8399. -
  8400. - // same_locals_1_stack_item_frame_extended {
  8401. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8402. - // u2 offset_delta;
  8403. - // verification_type_info stack[1];
  8404. - // }
  8405. - else if (frame_type == 247) {
  8406. - stackmap_p += 2;
  8407. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8408. - calc_number_of_entries, frame_type, THREAD);
  8409. - }
  8410. -
  8411. - // chop_frame {
  8412. - // u1 frame_type = CHOP; /* 248-250 */
  8413. - // u2 offset_delta;
  8414. - // }
  8415. - else if (frame_type >= 248 && frame_type <= 250) {
  8416. - stackmap_p += 2;
  8417. - }
  8418. -
  8419. - // same_frame_extended {
  8420. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8421. - // u2 offset_delta;
  8422. - // }
  8423. - else if (frame_type == 251) {
  8424. - stackmap_p += 2;
  8425. - }
  8426. -
  8427. - // append_frame {
  8428. - // u1 frame_type = APPEND; /* 252-254 */
  8429. - // u2 offset_delta;
  8430. - // verification_type_info locals[frame_type - 251];
  8431. - // }
  8432. - else if (frame_type >= 252 && frame_type <= 254) {
  8433. - assert(stackmap_p + 2 <= stackmap_end,
  8434. - "no room for offset_delta");
  8435. - stackmap_p += 2;
  8436. - u1 len = frame_type - 251;
  8437. - for (u1 i = 0; i < len; i++) {
  8438. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8439. - calc_number_of_entries, frame_type, THREAD);
  8440. - }
  8441. - }
  8442. -
  8443. - // full_frame {
  8444. - // u1 frame_type = FULL_FRAME; /* 255 */
  8445. - // u2 offset_delta;
  8446. - // u2 number_of_locals;
  8447. - // verification_type_info locals[number_of_locals];
  8448. - // u2 number_of_stack_items;
  8449. - // verification_type_info stack[number_of_stack_items];
  8450. - // }
  8451. - else if (frame_type == 255) {
  8452. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8453. - "no room for smallest full_frame");
  8454. - stackmap_p += 2;
  8455. -
  8456. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8457. - stackmap_p += 2;
  8458. -
  8459. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8460. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8461. - calc_number_of_entries, frame_type, THREAD);
  8462. - }
  8463. -
  8464. - // Use the largest size for the number_of_stack_items, but only get
  8465. - // the right number of bytes.
  8466. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8467. - stackmap_p += 2;
  8468. -
  8469. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8470. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8471. - calc_number_of_entries, frame_type, THREAD);
  8472. - }
  8473. - }
  8474. - } // end while there is a stack_map_frame
  8475. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8476. -} // end rewrite_cp_refs_in_stack_map_table()
  8477. -
  8478. -
  8479. -// Rewrite constant pool references in the verification type info
  8480. -// portion of the method's stackmap table. These "structures" are
  8481. -// adapted from the StackMapTable_attribute that is described in
  8482. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8483. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8484. -//
  8485. -// The verification_type_info structure is a u1 tag followed by 0 or
  8486. -// more bytes of data:
  8487. -//
  8488. -// union verification_type_info {
  8489. -// Top_variable_info;
  8490. -// Integer_variable_info;
  8491. -// Float_variable_info;
  8492. -// Long_variable_info;
  8493. -// Double_variable_info;
  8494. -// Null_variable_info;
  8495. -// UninitializedThis_variable_info;
  8496. -// Object_variable_info;
  8497. -// Uninitialized_variable_info;
  8498. -// }
  8499. -//
  8500. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8501. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8502. - u1 frame_type, TRAPS) {
  8503. -
  8504. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8505. - u1 tag = *stackmap_p_ref;
  8506. - stackmap_p_ref++;
  8507. -
  8508. - switch (tag) {
  8509. - // Top_variable_info {
  8510. - // u1 tag = ITEM_Top; /* 0 */
  8511. - // }
  8512. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8513. - case 0: // fall through
  8514. -
  8515. - // Integer_variable_info {
  8516. - // u1 tag = ITEM_Integer; /* 1 */
  8517. - // }
  8518. - case ITEM_Integer: // fall through
  8519. -
  8520. - // Float_variable_info {
  8521. - // u1 tag = ITEM_Float; /* 2 */
  8522. - // }
  8523. - case ITEM_Float: // fall through
  8524. -
  8525. - // Double_variable_info {
  8526. - // u1 tag = ITEM_Double; /* 3 */
  8527. - // }
  8528. - case ITEM_Double: // fall through
  8529. -
  8530. - // Long_variable_info {
  8531. - // u1 tag = ITEM_Long; /* 4 */
  8532. - // }
  8533. - case ITEM_Long: // fall through
  8534. -
  8535. - // Null_variable_info {
  8536. - // u1 tag = ITEM_Null; /* 5 */
  8537. - // }
  8538. - case ITEM_Null: // fall through
  8539. -
  8540. - // UninitializedThis_variable_info {
  8541. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8542. - // }
  8543. - case ITEM_UninitializedThis:
  8544. - // nothing more to do for the above tag types
  8545. - break;
  8546. -
  8547. - // Object_variable_info {
  8548. - // u1 tag = ITEM_Object; /* 7 */
  8549. - // u2 cpool_index;
  8550. - // }
  8551. - case ITEM_Object:
  8552. - {
  8553. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8554. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8555. - u2 new_cp_index = find_new_index(cpool_index);
  8556. - if (new_cp_index != 0) {
  8557. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8558. - ("mapped old cpool_index=%d", cpool_index));
  8559. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8560. - cpool_index = new_cp_index;
  8561. - }
  8562. - stackmap_p_ref += 2;
  8563. -
  8564. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8565. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8566. - frame_type, cpool_index));
  8567. - } break;
  8568. -
  8569. - // Uninitialized_variable_info {
  8570. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8571. - // u2 offset;
  8572. - // }
  8573. - case ITEM_Uninitialized:
  8574. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8575. - stackmap_p_ref += 2;
  8576. - break;
  8577. -
  8578. - default:
  8579. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8580. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8581. - ShouldNotReachHere();
  8582. - break;
  8583. - } // end switch (tag)
  8584. -} // end rewrite_cp_refs_in_verification_type_info()
  8585. -
  8586. -
  8587. -// Change the constant pool associated with klass scratch_class to
  8588. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8589. -// are copied from scratch_cp to a smaller constant pool and the
  8590. -// smaller constant pool is associated with scratch_class.
  8591. -void VM_RedefineClasses::set_new_constant_pool(
  8592. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8593. - int scratch_cp_length, TRAPS) {
  8594. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  8595. -
  8596. - // scratch_cp is a merged constant pool and has enough space for a
  8597. - // worst case merge situation. We want to associate the minimum
  8598. - // sized constant pool with the klass to save space.
  8599. - constantPoolHandle smaller_cp(THREAD,
  8600. - oopFactory::new_constantPool(scratch_cp_length,
  8601. - oopDesc::IsUnsafeConc,
  8602. - THREAD));
  8603. - // preserve orig_length() value in the smaller copy
  8604. - int orig_length = scratch_cp->orig_length();
  8605. - assert(orig_length != 0, "sanity check");
  8606. - smaller_cp->set_orig_length(orig_length);
  8607. -
  8608. - // attach klass to new constant pool
  8609. - // reference to the cp holder is needed for copy_operands()
  8610. - smaller_cp->set_pool_holder(scratch_class());
  8611. -
  8612. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8613. - scratch_cp = smaller_cp;
  8614. - smaller_cp()->set_is_conc_safe(true);
  8615. -
  8616. - // attach new constant pool to klass
  8617. - scratch_class->set_constants(scratch_cp());
  8618. -
  8619. - int i; // for portability
  8620. -
  8621. - // update each field in klass to use new constant pool indices as needed
  8622. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8623. - jshort cur_index = fs.name_index();
  8624. - jshort new_index = find_new_index(cur_index);
  8625. - if (new_index != 0) {
  8626. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8627. - ("field-name_index change: %d to %d", cur_index, new_index));
  8628. - fs.set_name_index(new_index);
  8629. - }
  8630. - cur_index = fs.signature_index();
  8631. - new_index = find_new_index(cur_index);
  8632. - if (new_index != 0) {
  8633. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8634. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8635. - fs.set_signature_index(new_index);
  8636. - }
  8637. - cur_index = fs.initval_index();
  8638. - new_index = find_new_index(cur_index);
  8639. - if (new_index != 0) {
  8640. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8641. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8642. - fs.set_initval_index(new_index);
  8643. - }
  8644. - cur_index = fs.generic_signature_index();
  8645. - new_index = find_new_index(cur_index);
  8646. - if (new_index != 0) {
  8647. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8648. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8649. - fs.set_generic_signature_index(new_index);
  8650. - }
  8651. - } // end for each field
  8652. -
  8653. - // Update constant pool indices in the inner classes info to use
  8654. - // new constant indices as needed. The inner classes info is a
  8655. - // quadruple:
  8656. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8657. - InnerClassesIterator iter(scratch_class);
  8658. - for (; !iter.done(); iter.next()) {
  8659. - int cur_index = iter.inner_class_info_index();
  8660. - if (cur_index == 0) {
  8661. - continue; // JVM spec. allows null inner class refs so skip it
  8662. - }
  8663. - int new_index = find_new_index(cur_index);
  8664. - if (new_index != 0) {
  8665. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8666. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8667. - iter.set_inner_class_info_index(new_index);
  8668. - }
  8669. - cur_index = iter.outer_class_info_index();
  8670. - new_index = find_new_index(cur_index);
  8671. - if (new_index != 0) {
  8672. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8673. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8674. - iter.set_outer_class_info_index(new_index);
  8675. - }
  8676. - cur_index = iter.inner_name_index();
  8677. - new_index = find_new_index(cur_index);
  8678. - if (new_index != 0) {
  8679. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8680. - ("inner_name change: %d to %d", cur_index, new_index));
  8681. - iter.set_inner_name_index(new_index);
  8682. - }
  8683. - } // end for each inner class
  8684. -
  8685. - // Attach each method in klass to the new constant pool and update
  8686. - // to use new constant pool indices as needed:
  8687. - objArrayHandle methods(THREAD, scratch_class->methods());
  8688. - for (i = methods->length() - 1; i >= 0; i--) {
  8689. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8690. - method->set_constants(scratch_cp());
  8691. -
  8692. - int new_index = find_new_index(method->name_index());
  8693. - if (new_index != 0) {
  8694. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8695. - ("method-name_index change: %d to %d", method->name_index(),
  8696. - new_index));
  8697. - method->set_name_index(new_index);
  8698. - }
  8699. - new_index = find_new_index(method->signature_index());
  8700. - if (new_index != 0) {
  8701. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8702. - ("method-signature_index change: %d to %d",
  8703. - method->signature_index(), new_index));
  8704. - method->set_signature_index(new_index);
  8705. - }
  8706. - new_index = find_new_index(method->generic_signature_index());
  8707. - if (new_index != 0) {
  8708. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8709. - ("method-generic_signature_index change: %d to %d",
  8710. - method->generic_signature_index(), new_index));
  8711. - method->set_generic_signature_index(new_index);
  8712. - }
  8713. -
  8714. - // Update constant pool indices in the method's checked exception
  8715. - // table to use new constant indices as needed.
  8716. - int cext_length = method->checked_exceptions_length();
  8717. - if (cext_length > 0) {
  8718. - CheckedExceptionElement * cext_table =
  8719. - method->checked_exceptions_start();
  8720. - for (int j = 0; j < cext_length; j++) {
  8721. - int cur_index = cext_table[j].class_cp_index;
  8722. - int new_index = find_new_index(cur_index);
  8723. - if (new_index != 0) {
  8724. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8725. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8726. - cext_table[j].class_cp_index = (u2)new_index;
  8727. - }
  8728. - } // end for each checked exception table entry
  8729. - } // end if there are checked exception table entries
  8730. -
  8731. - // Update each catch type index in the method's exception table
  8732. - // to use new constant pool indices as needed. The exception table
  8733. - // holds quadruple entries of the form:
  8734. - // (beg_bci, end_bci, handler_bci, klass_index)
  8735. -
  8736. - ExceptionTable ex_table(method());
  8737. - int ext_length = ex_table.length();
  8738. -
  8739. - for (int j = 0; j < ext_length; j ++) {
  8740. - int cur_index = ex_table.catch_type_index(j);
  8741. - int new_index = find_new_index(cur_index);
  8742. - if (new_index != 0) {
  8743. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8744. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8745. - ex_table.set_catch_type_index(j, new_index);
  8746. - }
  8747. - } // end for each exception table entry
  8748. -
  8749. - // Update constant pool indices in the method's local variable
  8750. - // table to use new constant indices as needed. The local variable
  8751. - // table hold sextuple entries of the form:
  8752. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8753. - int lvt_length = method->localvariable_table_length();
  8754. - if (lvt_length > 0) {
  8755. - LocalVariableTableElement * lv_table =
  8756. - method->localvariable_table_start();
  8757. - for (int j = 0; j < lvt_length; j++) {
  8758. - int cur_index = lv_table[j].name_cp_index;
  8759. - int new_index = find_new_index(cur_index);
  8760. - if (new_index != 0) {
  8761. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8762. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8763. - lv_table[j].name_cp_index = (u2)new_index;
  8764. - }
  8765. - cur_index = lv_table[j].descriptor_cp_index;
  8766. - new_index = find_new_index(cur_index);
  8767. - if (new_index != 0) {
  8768. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8769. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8770. - new_index));
  8771. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8772. - }
  8773. - cur_index = lv_table[j].signature_cp_index;
  8774. - new_index = find_new_index(cur_index);
  8775. - if (new_index != 0) {
  8776. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8777. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8778. - lv_table[j].signature_cp_index = (u2)new_index;
  8779. - }
  8780. - } // end for each local variable table entry
  8781. - } // end if there are local variable table entries
  8782. -
  8783. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8784. - } // end for each method
  8785. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8786. -} // end set_new_constant_pool()
  8787. -
  8788. -
  8789. -// Unevolving classes may point to methods of the_class directly
  8790. -// from their constant pool caches, itables, and/or vtables. We
  8791. -// use the SystemDictionary::classes_do() facility and this helper
  8792. -// to fix up these pointers.
  8793. -//
  8794. -// Note: We currently don't support updating the vtable in
  8795. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8796. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8797. - oop initiating_loader, TRAPS) {
  8798. - Klass *k = k_oop->klass_part();
  8799. - if (k->oop_is_instance()) {
  8800. - HandleMark hm(THREAD);
  8801. - instanceKlass *ik = (instanceKlass *) k;
  8802. -
  8803. - // HotSpot specific optimization! HotSpot does not currently
  8804. - // support delegation from the bootstrap class loader to a
  8805. - // user-defined class loader. This means that if the bootstrap
  8806. - // class loader is the initiating class loader, then it will also
  8807. - // be the defining class loader. This also means that classes
  8808. - // loaded by the bootstrap class loader cannot refer to classes
  8809. - // loaded by a user-defined class loader. Note: a user-defined
  8810. - // class loader can delegate to the bootstrap class loader.
  8811. - //
  8812. - // If the current class being redefined has a user-defined class
  8813. - // loader as its defining class loader, then we can skip all
  8814. - // classes loaded by the bootstrap class loader.
  8815. - bool is_user_defined =
  8816. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8817. - if (is_user_defined && ik->class_loader() == NULL) {
  8818. + if (!check_type_consistency()) {
  8819. + // (tw) TODO: Rollback the class redefinition
  8820. + rollback();
  8821. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  8822. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  8823. + RC_TIMER_STOP(_timer_check_type);
  8824. return;
  8825. }
  8826. - // This is a very busy routine. We don't want too much tracing
  8827. - // printed out.
  8828. - bool trace_name_printed = false;
  8829. + RC_TIMER_STOP(_timer_check_type);
  8830. - // Very noisy: only enable this call if you are trying to determine
  8831. - // that a specific class gets found by this routine.
  8832. - // RC_TRACE macro has an embedded ResourceMark
  8833. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8834. - // ("adjust check: name=%s", ik->external_name()));
  8835. - // trace_name_printed = true;
  8836. + } else {
  8837. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  8838. + }
  8839. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8840. - // if one exists. We discard scratch_class and we don't keep an
  8841. - // instanceKlass around to hold obsolete methods so we don't have
  8842. - // any other instanceKlass embedded vtables to update. The vtable
  8843. - // holds the methodOops for virtual (but not final) methods.
  8844. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8845. - // ik->vtable() creates a wrapper object; rm cleans it up
  8846. - ResourceMark rm(THREAD);
  8847. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8848. - _matching_new_methods,
  8849. - _matching_methods_length,
  8850. - &trace_name_printed);
  8851. + if (UseMethodForwardPoints) {
  8852. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  8853. + method_forwarding();
  8854. + }
  8855. +
  8856. + if (UseSharedSpaces) {
  8857. + // Sharing is enabled so we remap the shared readonly space to
  8858. + // shared readwrite, private just in case we need to redefine
  8859. + // a shared class. We do the remap during the doit() phase of
  8860. + // the safepoint to be safer.
  8861. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  8862. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  8863. + _result = JVMTI_ERROR_INTERNAL;
  8864. + return;
  8865. + }
  8866. + }
  8867. +
  8868. + RC_TIMER_START(_timer_prepare_redefinition);
  8869. + for (int i = 0; i < _new_classes->length(); i++) {
  8870. + redefine_single_class(_new_classes->at(i), thread);
  8871. + }
  8872. +
  8873. + // Deoptimize all compiled code that depends on this class
  8874. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  8875. +
  8876. + // Adjust constantpool caches and vtables for all classes
  8877. + // that reference methods of the evolved class.
  8878. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  8879. +
  8880. + RC_TIMER_STOP(_timer_prepare_redefinition);
  8881. + RC_TIMER_START(_timer_redefinition);
  8882. +
  8883. + class ChangePointersOopClosure : public OopClosure {
  8884. + virtual void do_oop(oop* o) {
  8885. + do_oop_work(o);
  8886. + }
  8887. +
  8888. + virtual void do_oop(narrowOop* o) {
  8889. + do_oop_work(o);
  8890. + }
  8891. + };
  8892. +
  8893. + class ChangePointersObjectClosure : public ObjectClosure {
  8894. +
  8895. + private:
  8896. +
  8897. + OopClosure *_closure;
  8898. + bool _needs_instance_update;
  8899. + GrowableArray<oop> *_updated_oops;
  8900. +
  8901. + public:
  8902. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  8903. +
  8904. + bool needs_instance_update() {
  8905. + return _needs_instance_update;
  8906. + }
  8907. +
  8908. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  8909. +
  8910. + virtual void do_object(oop obj) {
  8911. + if (!obj->is_instanceKlass()) {
  8912. + obj->oop_iterate(_closure);
  8913. +
  8914. + if (obj->blueprint()->is_redefining()) {
  8915. +
  8916. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8917. + if (_updated_oops == NULL) {
  8918. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  8919. + }
  8920. + _updated_oops->append(obj);
  8921. + }
  8922. +
  8923. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  8924. +
  8925. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  8926. + obj->set_klass_no_check(obj->blueprint()->old_version());
  8927. +
  8928. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  8929. + // We need an instance update => set back to old klass
  8930. + _needs_instance_update = true;
  8931. +
  8932. + } else {
  8933. + MarkSweep::update_fields(obj, obj);
  8934. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  8935. + }
  8936. + }
  8937. + }
  8938. +
  8939. + } else {
  8940. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  8941. + if (klass->is_redefining()) {
  8942. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  8943. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  8944. + old_klass->constants()->set_pool_holder(klass->old_version());
  8945. +
  8946. + // Initialize the new class! Special static initialization that does not execute the
  8947. + // static constructor but copies static field values from the old class if name
  8948. + // and signature of a static field match.
  8949. + klass->initialize_redefined_class();
  8950. + }
  8951. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  8952. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  8953. + // idubrov: will get new version of that class
  8954. + //klass->iterate_static_fields(_closure);
  8955. + }
  8956. + }
  8957. + };
  8958. +
  8959. + ChangePointersOopClosure oopClosure;
  8960. + ChangePointersObjectClosure objectClosure(&oopClosure);
  8961. +
  8962. + {
  8963. + SharedHeap::heap()->gc_prologue(true);
  8964. + Universe::root_oops_do(&oopClosure);
  8965. + Universe::heap()->object_iterate(&objectClosure);
  8966. + SharedHeap::heap()->gc_epilogue(false);
  8967. }
  8968. - // If the current class has an itable and we are either redefining an
  8969. - // interface or if the current class is a subclass of the_class, then
  8970. - // we potentially have to fix the itable. If we are redefining an
  8971. - // interface, then we have to call adjust_method_entries() for
  8972. - // every instanceKlass that has an itable since there isn't a
  8973. - // subclass relationship between an interface and an instanceKlass.
  8974. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8975. - || ik->is_subclass_of(_the_class_oop))) {
  8976. - // ik->itable() creates a wrapper object; rm cleans it up
  8977. - ResourceMark rm(THREAD);
  8978. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8979. - _matching_new_methods,
  8980. - _matching_methods_length,
  8981. - &trace_name_printed);
  8982. + // Swap marks to have same hashcodes
  8983. + for (int i=0; i<_new_classes->length(); i++) {
  8984. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  8985. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  8986. }
  8987. - // The constant pools in other classes (other_cp) can refer to
  8988. - // methods in the_class. We have to update method information in
  8989. - // other_cp's cache. If other_cp has a previous version, then we
  8990. - // have to repeat the process for each previous version. The
  8991. - // constant pool cache holds the methodOops for non-virtual
  8992. - // methods and for virtual, final methods.
  8993. - //
  8994. - // Special case: if the current class is the_class, then new_cp
  8995. - // has already been attached to the_class and old_cp has already
  8996. - // been added as a previous version. The new_cp doesn't have any
  8997. - // cached references to old methods so it doesn't need to be
  8998. - // updated. We can simply start with the previous version(s) in
  8999. - // that case.
  9000. - constantPoolHandle other_cp;
  9001. - constantPoolCacheOop cp_cache;
  9002. + _updated_oops = objectClosure.updated_oops();
  9003. - if (k_oop != _the_class_oop) {
  9004. - // this klass' constant pool cache may need adjustment
  9005. - other_cp = constantPoolHandle(ik->constants());
  9006. - cp_cache = other_cp->cache();
  9007. - if (cp_cache != NULL) {
  9008. - cp_cache->adjust_method_entries(_matching_old_methods,
  9009. - _matching_new_methods,
  9010. - _matching_methods_length,
  9011. - &trace_name_printed);
  9012. + if (objectClosure.needs_instance_update()){
  9013. +
  9014. + // Do a full garbage collection to update the instance sizes accordingly
  9015. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  9016. + Universe::set_redefining_gc_run(true);
  9017. + JvmtiGCMarker jgcm;
  9018. + notify_gc_begin(true);
  9019. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  9020. + notify_gc_end();
  9021. + Universe::set_redefining_gc_run(false);
  9022. + RC_TRACE(0x00000001, ("GC done!"));
  9023. + }
  9024. +
  9025. +
  9026. + if (RC_TRACE_ENABLED(0x00000001)) {
  9027. + if (_updated_oops != NULL) {
  9028. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  9029. + } else {
  9030. + RC_TRACE(0x00000001, ("No objects updated!"));
  9031. + }
  9032. + }
  9033. +
  9034. + // Unmark klassOops as "redefining"
  9035. + for (int i=0; i<_new_classes->length(); i++) {
  9036. + klassOop cur = _new_classes->at(i)();
  9037. + _new_classes->at(i)->set_redefining(false);
  9038. + _new_classes->at(i)->clear_update_information();
  9039. + _new_classes->at(i)->update_supers_to_newest_version();
  9040. +
  9041. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  9042. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9043. +
  9044. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  9045. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9046. +
  9047. + oop new_mirror = _new_classes->at(i)->java_mirror();
  9048. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  9049. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  9050. + }
  9051. + }
  9052. +
  9053. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  9054. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  9055. + }
  9056. +
  9057. + // Disable any dependent concurrent compilations
  9058. + SystemDictionary::notice_modification();
  9059. +
  9060. + // Set flag indicating that some invariants are no longer true.
  9061. + // See jvmtiExport.hpp for detailed explanation.
  9062. + JvmtiExport::set_has_redefined_a_class();
  9063. +
  9064. + // Clean up caches in the compiler interface and compiler threads
  9065. + CompileBroker::cleanup_after_redefinition();
  9066. +
  9067. +#ifdef ASSERT
  9068. +
  9069. + // Universe::verify();
  9070. + // JNIHandles::verify();
  9071. +
  9072. + SystemDictionary::classes_do(check_class, thread);
  9073. +#endif
  9074. +
  9075. + update_active_methods();
  9076. + RC_TIMER_STOP(_timer_redefinition);
  9077. +
  9078. +}
  9079. +
  9080. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  9081. +
  9082. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  9083. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  9084. +
  9085. +
  9086. + while (curArrayKlass != NULL) {
  9087. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  9088. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  9089. + curArrayKlass->update_supers_to_newest_version();
  9090. +
  9091. + curArrayKlass = NULL;
  9092. + if (higher_dimension != NULL) {
  9093. + curArrayKlass = arrayKlass::cast(higher_dimension);
  9094. + }
  9095. + }
  9096. +
  9097. +}
  9098. +
  9099. +void VM_RedefineClasses::doit_epilogue() {
  9100. +
  9101. + RC_TIMER_START(_timer_vm_op_epilogue);
  9102. +
  9103. + unlock_threads();
  9104. +
  9105. + ResourceMark mark;
  9106. +
  9107. + VM_GC_Operation::doit_epilogue();
  9108. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  9109. +
  9110. + GrowableArray<methodHandle> instanceTransformerMethods;
  9111. +
  9112. + // Call static transformers
  9113. + for (int i=0; i<_new_classes->length(); i++) {
  9114. +
  9115. + instanceKlassHandle klass = _new_classes->at(i);
  9116. +
  9117. + // Transfer init state
  9118. + if (klass->old_version() != NULL) {
  9119. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  9120. + if (state > instanceKlass::linked) {
  9121. + klass->initialize(Thread::current());
  9122. }
  9123. }
  9124. - {
  9125. - ResourceMark rm(THREAD);
  9126. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9127. - // contain a GrowableArray of handles. We have to clean up the
  9128. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9129. - // has destroyed the handles.
  9130. - {
  9131. - // the previous versions' constant pool caches may need adjustment
  9132. - PreviousVersionWalker pvw(ik);
  9133. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9134. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9135. - other_cp = pv_info->prev_constant_pool_handle();
  9136. - cp_cache = other_cp->cache();
  9137. - if (cp_cache != NULL) {
  9138. - cp_cache->adjust_method_entries(_matching_old_methods,
  9139. - _matching_new_methods,
  9140. - _matching_methods_length,
  9141. - &trace_name_printed);
  9142. - }
  9143. +
  9144. + // Find instance transformer method
  9145. +
  9146. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9147. +
  9148. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  9149. + klassOop cur_klass = klass();
  9150. + while (cur_klass != NULL) {
  9151. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  9152. + if (method != NULL) {
  9153. + methodHandle instanceTransformerMethod(method);
  9154. + instanceTransformerMethods.append(instanceTransformerMethod);
  9155. + break;
  9156. + } else {
  9157. + cur_klass = cur_klass->klass_part()->super();
  9158. }
  9159. - } // pvw is cleaned up
  9160. - } // rm is cleaned up
  9161. + }
  9162. + assert(cur_klass != NULL, "must have instance transformer method");
  9163. + } else {
  9164. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  9165. + }
  9166. + }
  9167. +
  9168. +
  9169. + // Call instance transformers
  9170. + if (_updated_oops != NULL) {
  9171. +
  9172. + for (int i=0; i<_updated_oops->length(); i++) {
  9173. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  9174. + Handle cur(_updated_oops->at(i));
  9175. + instanceKlassHandle klass(cur->klass());
  9176. +
  9177. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9178. +
  9179. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  9180. +
  9181. + RC_TRACE(0x00008000, ("executing transformer method"));
  9182. +
  9183. + Thread *__the_thread__ = Thread::current();
  9184. + JavaValue result(T_VOID);
  9185. + JavaCallArguments args(cur);
  9186. + JavaCalls::call(&result,
  9187. + method,
  9188. + &args,
  9189. + THREAD);
  9190. +
  9191. + // TODO: What to do with an exception here?
  9192. + if (HAS_PENDING_EXCEPTION) {
  9193. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  9194. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  9195. + ex_name->as_C_string()));
  9196. + CLEAR_PENDING_EXCEPTION;
  9197. + }
  9198. + }
  9199. + }
  9200. +
  9201. + delete _updated_oops;
  9202. + _updated_oops = NULL;
  9203. + }
  9204. +
  9205. + // Free the array of scratch classes
  9206. + delete _new_classes;
  9207. + _new_classes = NULL;
  9208. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  9209. +
  9210. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  9211. +}
  9212. +
  9213. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  9214. + // classes for primitives cannot be redefined
  9215. + if (java_lang_Class::is_primitive(klass_mirror)) {
  9216. + return false;
  9217. + }
  9218. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  9219. + // classes for arrays cannot be redefined
  9220. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  9221. + return false;
  9222. + }
  9223. + return true;
  9224. +}
  9225. +
  9226. +#ifdef ASSERT
  9227. +
  9228. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9229. + klassOop k_oop = k_oop_latest;
  9230. + while (k_oop != NULL) {
  9231. +
  9232. + instanceKlassHandle k_handle(THREAD, k_oop);
  9233. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  9234. + k_oop = k_oop->klass_part()->old_version();
  9235. + }
  9236. +}
  9237. +
  9238. +#endif
  9239. +
  9240. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  9241. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  9242. +// do that, they assume that cache entry is resolved already.
  9243. +static void unpatch_bytecode(methodOop method) {
  9244. + RawBytecodeStream bcs(method);
  9245. + Bytecodes::Code code;
  9246. + Bytecodes::Code java_code;
  9247. + while (!bcs.is_last_bytecode()) {
  9248. + code = bcs.raw_next();
  9249. + address bcp = bcs.bcp();
  9250. +
  9251. + if (code == Bytecodes::_breakpoint) {
  9252. + int bci = method->bci_from(bcp);
  9253. + code = method->orig_bytecode_at(bci);
  9254. + java_code = Bytecodes::java_code(code);
  9255. + if (code != java_code &&
  9256. + (java_code == Bytecodes::_getfield ||
  9257. + java_code == Bytecodes::_putfield ||
  9258. + java_code == Bytecodes::_aload_0)) {
  9259. + // Let breakpoint table handling unpatch bytecode
  9260. + method->set_orig_bytecode_at(bci, java_code);
  9261. + }
  9262. + } else {
  9263. + java_code = Bytecodes::java_code(code);
  9264. + if (code != java_code &&
  9265. + (java_code == Bytecodes::_getfield ||
  9266. + java_code == Bytecodes::_putfield ||
  9267. + java_code == Bytecodes::_aload_0)) {
  9268. + *bcp = java_code;
  9269. + }
  9270. + }
  9271. +
  9272. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  9273. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  9274. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  9275. + assert(code2 == Bytecodes::_fast_igetfield ||
  9276. + code2 == Bytecodes::_fast_agetfield ||
  9277. + code2 == Bytecodes::_fast_fgetfield, "");
  9278. + *(bcp + 1) = Bytecodes::java_code(code2);
  9279. + }
  9280. + }
  9281. +}
  9282. +
  9283. +// Unevolving classes may point to old methods directly
  9284. +// from their constant pool caches, itables, and/or vtables. We
  9285. +// use the SystemDictionary::classes_do() facility and this helper
  9286. +// to fix up these pointers. Additional field offsets and vtable indices
  9287. +// in the constant pool cache entries are fixed.
  9288. +//
  9289. +// Note: We currently don't support updating the vtable in
  9290. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9291. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9292. + klassOop k_oop = k_oop_latest;
  9293. + while (k_oop != NULL) {
  9294. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9295. +/*
  9296. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9297. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9298. +
  9299. + for (int i=0; i<_matching_methods_length; i++) {
  9300. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9301. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9302. + }*/
  9303. +
  9304. + Klass *k = k_oop->klass_part();
  9305. + if (k->oop_is_instance()) {
  9306. + HandleMark hm(THREAD);
  9307. + instanceKlass *ik = (instanceKlass *) k;
  9308. +
  9309. + constantPoolHandle other_cp;
  9310. + constantPoolCacheOop cp_cache;
  9311. +
  9312. + other_cp = constantPoolHandle(ik->constants());
  9313. +
  9314. + for (int i=0; i<other_cp->length(); i++) {
  9315. + if (other_cp->tag_at(i).is_klass()) {
  9316. + klassOop klass = other_cp->klass_at(i, THREAD);
  9317. + if (klass->klass_part()->new_version() != NULL) {
  9318. +
  9319. + // (tw) TODO: check why/if this is necessary
  9320. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9321. + }
  9322. + klass = other_cp->klass_at(i, THREAD);
  9323. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9324. + }
  9325. + }
  9326. +
  9327. + cp_cache = other_cp->cache();
  9328. +
  9329. + if (cp_cache != NULL) {
  9330. + cp_cache->adjust_entries(NULL,
  9331. + NULL,
  9332. + 0);
  9333. + }
  9334. +
  9335. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9336. + if (RewriteBytecodes) {
  9337. + ik->methods_do(unpatch_bytecode);
  9338. + }
  9339. + }
  9340. + k_oop = k_oop->klass_part()->old_version();
  9341. }
  9342. }
  9343. void VM_RedefineClasses::update_jmethod_ids() {
  9344. for (int j = 0; j < _matching_methods_length; ++j) {
  9345. - methodOop old_method = _matching_old_methods[j];
  9346. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9347. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9348. +
  9349. jmethodID jmid = old_method->find_jmethod_id_or_null();
  9350. + if (old_method->new_version() != NULL && jmid == NULL) {
  9351. + // (tw) Have to create jmethodID in this case
  9352. + jmid = old_method->jmethod_id();
  9353. + }
  9354. +
  9355. if (jmid != NULL) {
  9356. // There is a jmethodID, change it to point to the new method
  9357. - methodHandle new_method_h(_matching_new_methods[j]);
  9358. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9359. + if (old_method->new_version() == NULL) {
  9360. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9361. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9362. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9363. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9364. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9365. + } else {
  9366. + jmethodID mid = new_method_h->jmethod_id();
  9367. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9368. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9369. +
  9370. + }
  9371. JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9372. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9373. - "should be replaced");
  9374. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9375. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9376. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9377. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9378. +
  9379. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9380. }
  9381. }
  9382. }
  9383. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9384. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9385. - *emcp_method_count_p = 0;
  9386. - int obsolete_count = 0;
  9387. - int old_index = 0;
  9388. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9389. - methodOop old_method = _matching_old_methods[j];
  9390. - methodOop new_method = _matching_new_methods[j];
  9391. - methodOop old_array_method;
  9392. - // Maintain an old_index into the _old_methods array by skipping
  9393. - // deleted methods
  9394. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9395. - != old_method) {
  9396. - ++old_index;
  9397. - }
  9398. +// Deoptimize all compiled code that depends on this class.
  9399. +//
  9400. +// If the can_redefine_classes capability is obtained in the onload
  9401. +// phase then the compiler has recorded all dependencies from startup.
  9402. +// In that case we need only deoptimize and throw away all compiled code
  9403. +// that depends on the class.
  9404. +//
  9405. +// If can_redefine_classes is obtained sometime after the onload
  9406. +// phase then the dependency information may be incomplete. In that case
  9407. +// the first call to RedefineClasses causes all compiled code to be
  9408. +// thrown away. As can_redefine_classes has been obtained then
  9409. +// all future compilations will record dependencies so second and
  9410. +// subsequent calls to RedefineClasses need only throw away code
  9411. +// that depends on the class.
  9412. +//
  9413. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9414. + assert_locked_or_safepoint(Compile_lock);
  9415. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9416. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9417. - // the same with the exception of constant pool indices which may
  9418. - // differ. However, the constants referred to by those indices
  9419. - // must be the same.
  9420. - //
  9421. - // We use methods_EMCP() for comparison since constant pool
  9422. - // merging can remove duplicate constant pool entries that were
  9423. - // present in the old method and removed from the rewritten new
  9424. - // method. A faster binary comparison function would consider the
  9425. - // old and new methods to be different when they are actually
  9426. - // EMCP.
  9427. - //
  9428. - // The old and new methods are EMCP and you would think that we
  9429. - // could get rid of one of them here and now and save some space.
  9430. - // However, the concept of EMCP only considers the bytecodes and
  9431. - // the constant pool entries in the comparison. Other things,
  9432. - // e.g., the line number table (LNT) or the local variable table
  9433. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9434. - // method can have a new LNT that we need so we can't just
  9435. - // overwrite the new method with the old method.
  9436. - //
  9437. - // When this routine is called, we have already attached the new
  9438. - // methods to the_class so the old methods are effectively
  9439. - // overwritten. However, if an old method is still executing,
  9440. - // then the old method cannot be collected until sometime after
  9441. - // the old method call has returned. So the overwriting of old
  9442. - // methods by new methods will save us space except for those
  9443. - // (hopefully few) old methods that are still executing.
  9444. - //
  9445. - // A method refers to a constMethodOop and this presents another
  9446. - // possible avenue to space savings. The constMethodOop in the
  9447. - // new method contains possibly new attributes (LNT, LVT, etc).
  9448. - // At first glance, it seems possible to save space by replacing
  9449. - // the constMethodOop in the old method with the constMethodOop
  9450. - // from the new method. The old and new methods would share the
  9451. - // same constMethodOop and we would save the space occupied by
  9452. - // the old constMethodOop. However, the constMethodOop contains
  9453. - // a back reference to the containing method. Sharing the
  9454. - // constMethodOop between two methods could lead to confusion in
  9455. - // the code that uses the back reference. This would lead to
  9456. - // brittle code that could be broken in non-obvious ways now or
  9457. - // in the future.
  9458. - //
  9459. - // Another possibility is to copy the constMethodOop from the new
  9460. - // method to the old method and then overwrite the new method with
  9461. - // the old method. Since the constMethodOop contains the bytecodes
  9462. - // for the method embedded in the oop, this option would change
  9463. - // the bytecodes out from under any threads executing the old
  9464. - // method and make the thread's bcp invalid. Since EMCP requires
  9465. - // that the bytecodes be the same modulo constant pool indices, it
  9466. - // is straight forward to compute the correct new bcp in the new
  9467. - // constMethodOop from the old bcp in the old constMethodOop. The
  9468. - // time consuming part would be searching all the frames in all
  9469. - // of the threads to find all of the calls to the old method.
  9470. - //
  9471. - // It looks like we will have to live with the limited savings
  9472. - // that we get from effectively overwriting the old methods
  9473. - // when the new methods are attached to the_class.
  9474. + // All dependencies have been recorded from startup or this is a second or
  9475. + // subsequent use of RedefineClasses
  9476. - // track which methods are EMCP for add_previous_version() call
  9477. - emcp_methods->set_bit(old_index);
  9478. - (*emcp_method_count_p)++;
  9479. + // For now deopt all
  9480. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9481. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9482. + Universe::flush_evol_dependents_on(k_h);
  9483. + } else {
  9484. + CodeCache::mark_all_nmethods_for_deoptimization();
  9485. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9486. - // different jmethodID than the current method. An EMCP method
  9487. - // has the same jmethodID as the current method. Having the
  9488. - // same jmethodID for all EMCP versions of a method allows for
  9489. - // a consistent view of the EMCP methods regardless of which
  9490. - // EMCP method you happen to have in hand. For example, a
  9491. - // breakpoint set in one EMCP method will work for all EMCP
  9492. - // versions of the method including the current one.
  9493. - } else {
  9494. - // mark obsolete methods as such
  9495. - old_method->set_is_obsolete();
  9496. - obsolete_count++;
  9497. + ResourceMark rm(THREAD);
  9498. + DeoptimizationMarker dm;
  9499. - // obsolete methods need a unique idnum
  9500. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9501. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9502. -// u2 old_num = old_method->method_idnum();
  9503. - old_method->set_method_idnum(num);
  9504. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9505. + // Deoptimize all activations depending on marked nmethods
  9506. + Deoptimization::deoptimize_dependents();
  9507. +
  9508. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9509. + CodeCache::make_marked_nmethods_not_entrant();
  9510. +
  9511. + // From now on we know that the dependency information is complete
  9512. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9513. + }
  9514. +}
  9515. +
  9516. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9517. + methodOop old_method;
  9518. + methodOop new_method;
  9519. +
  9520. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9521. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9522. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9523. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9524. +
  9525. + _matching_methods_length = 0;
  9526. + _deleted_methods_length = 0;
  9527. + _added_methods_length = 0;
  9528. +
  9529. + int nj = 0;
  9530. + int oj = 0;
  9531. + while (true) {
  9532. + if (oj >= _old_methods->length()) {
  9533. + if (nj >= _new_methods->length()) {
  9534. + break; // we've looked at everything, done
  9535. }
  9536. + // New method at the end
  9537. + new_method = (methodOop) _new_methods->obj_at(nj);
  9538. + _added_methods[_added_methods_length++] = nj;
  9539. + ++nj;
  9540. + } else if (nj >= _new_methods->length()) {
  9541. + // Old method, at the end, is deleted
  9542. + old_method = (methodOop) _old_methods->obj_at(oj);
  9543. + _deleted_methods[_deleted_methods_length++] = oj;
  9544. + ++oj;
  9545. + } else {
  9546. + old_method = (methodOop) _old_methods->obj_at(oj);
  9547. + new_method = (methodOop) _new_methods->obj_at(nj);
  9548. + if (old_method->name() == new_method->name()) {
  9549. + if (old_method->signature() == new_method->signature()) {
  9550. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9551. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9552. + ++nj;
  9553. + ++oj;
  9554. + } else {
  9555. + // added overloaded have already been moved to the end,
  9556. + // so this is a deleted overloaded method
  9557. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9558. + ++oj;
  9559. + }
  9560. + } else { // names don't match
  9561. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9562. + // new method
  9563. + _added_methods[_added_methods_length++] = nj;//new_method;
  9564. + ++nj;
  9565. + } else {
  9566. + // deleted method
  9567. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9568. + ++oj;
  9569. + }
  9570. + }
  9571. + }
  9572. + }
  9573. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9574. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9575. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9576. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9577. +}
  9578. +
  9579. +
  9580. +
  9581. +// Install the redefinition of a class:
  9582. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9583. +// dependent compiled code)
  9584. +// - adjusting constant pool caches and vtables in other classes
  9585. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9586. +
  9587. + ResourceMark rm(THREAD);
  9588. +
  9589. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9590. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9591. +
  9592. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9593. +
  9594. +#ifndef JVMTI_KERNEL
  9595. + // Remove all breakpoints in methods of this class
  9596. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9597. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9598. +#endif // !JVMTI_KERNEL
  9599. +
  9600. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9601. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9602. + // cached and users of the cache care about each active version of
  9603. + // the method so we have to track this previous version.
  9604. + // Do this before methods get switched
  9605. + Universe::reflect_invoke_cache()->add_previous_version(
  9606. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9607. + }
  9608. +
  9609. + _old_methods = the_old_class->methods();
  9610. + _new_methods = the_new_class->methods();
  9611. + _the_class_oop = the_old_class();
  9612. + compute_added_deleted_matching_methods();
  9613. +
  9614. + // track which methods are EMCP for add_previous_version() call below
  9615. +
  9616. + // (tw) TODO: Check if we need the concept of EMCP?
  9617. + BitMap emcp_methods(_old_methods->length());
  9618. + int emcp_method_count = 0;
  9619. + emcp_methods.clear(); // clears 0..(length() - 1)
  9620. +
  9621. + // We need to mark methods as old!!
  9622. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9623. + update_jmethod_ids();
  9624. +
  9625. + // keep track of previous versions of this class
  9626. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9627. + emcp_method_count);
  9628. +
  9629. + // TODO:
  9630. + transfer_old_native_function_registrations(the_old_class);
  9631. +
  9632. +
  9633. +#ifdef ASSERT
  9634. +
  9635. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9636. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9637. +
  9638. + //JNIHandles::verify();
  9639. +
  9640. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9641. +
  9642. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9643. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9644. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9645. +
  9646. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9647. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9648. + }
  9649. +
  9650. + _old_methods->verify();
  9651. + _new_methods->verify();
  9652. +
  9653. + the_new_class->vtable()->verify(tty);
  9654. + the_old_class->vtable()->verify(tty);
  9655. +
  9656. +#endif
  9657. +
  9658. + // increment the classRedefinedCount field in the_class and in any
  9659. + // direct and indirect subclasses of the_class
  9660. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9661. +
  9662. +}
  9663. +
  9664. +
  9665. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9666. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9667. + *emcp_method_count_p = 0;
  9668. + int obsolete_count = 0;
  9669. + int old_index = 0;
  9670. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9671. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9672. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9673. + methodOop old_array_method;
  9674. +
  9675. + // Maintain an old_index into the _old_methods array by skipping
  9676. + // deleted methods
  9677. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9678. + != old_method) {
  9679. + ++old_index;
  9680. + }
  9681. +
  9682. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9683. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9684. + // the same with the exception of constant pool indices which may
  9685. + // differ. However, the constants referred to by those indices
  9686. + // must be the same.
  9687. + //
  9688. + // We use methods_EMCP() for comparison since constant pool
  9689. + // merging can remove duplicate constant pool entries that were
  9690. + // present in the old method and removed from the rewritten new
  9691. + // method. A faster binary comparison function would consider the
  9692. + // old and new methods to be different when they are actually
  9693. + // EMCP.
  9694. +
  9695. + // track which methods are EMCP for add_previous_version() call
  9696. + emcp_methods->set_bit(old_index);
  9697. + (*emcp_method_count_p)++;
  9698. +
  9699. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9700. + // different jmethodID than the current method. An EMCP method
  9701. + // has the same jmethodID as the current method. Having the
  9702. + // same jmethodID for all EMCP versions of a method allows for
  9703. + // a consistent view of the EMCP methods regardless of which
  9704. + // EMCP method you happen to have in hand. For example, a
  9705. + // breakpoint set in one EMCP method will work for all EMCP
  9706. + // versions of the method including the current one.
  9707. +
  9708. + old_method->set_new_version(new_method);
  9709. + new_method->set_old_version(old_method);
  9710. +
  9711. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9712. +
  9713. + // Transfer breakpoints
  9714. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9715. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9716. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9717. + RC_TRACE(0x00000002, ("%d / %d",
  9718. + bp->match(old_method), bp->match(new_method)));
  9719. + if (bp->match(old_method)) {
  9720. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9721. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9722. + new_method->set_breakpoint(bp->bci());
  9723. + }
  9724. + }
  9725. +
  9726. +
  9727. +
  9728. + } else {
  9729. + // mark obsolete methods as such
  9730. + old_method->set_is_obsolete();
  9731. + obsolete_count++;
  9732. +
  9733. + // With tracing we try not to "yack" too much. The position of
  9734. + // this trace assumes there are fewer obsolete methods than
  9735. + // EMCP methods.
  9736. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9737. + old_method->name()->as_C_string(),
  9738. + old_method->signature()->as_C_string()));
  9739. + }
  9740. + old_method->set_is_old();
  9741. + }
  9742. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9743. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9744. +
  9745. + //assert(old_method->vtable_index() < 0,
  9746. + // "cannot delete methods with vtable entries");;
  9747. +
  9748. + // Mark all deleted methods as old and obsolete
  9749. + old_method->set_is_old();
  9750. + old_method->set_is_obsolete();
  9751. + ++obsolete_count;
  9752. // With tracing we try not to "yack" too much. The position of
  9753. // this trace assumes there are fewer obsolete methods than
  9754. // EMCP methods.
  9755. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9756. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9757. old_method->name()->as_C_string(),
  9758. old_method->signature()->as_C_string()));
  9759. }
  9760. - old_method->set_is_old();
  9761. - }
  9762. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9763. - methodOop old_method = _deleted_methods[i];
  9764. -
  9765. - assert(old_method->vtable_index() < 0,
  9766. - "cannot delete methods with vtable entries");;
  9767. -
  9768. - // Mark all deleted methods as old and obsolete
  9769. - old_method->set_is_old();
  9770. - old_method->set_is_obsolete();
  9771. - ++obsolete_count;
  9772. - // With tracing we try not to "yack" too much. The position of
  9773. - // this trace assumes there are fewer obsolete methods than
  9774. - // EMCP methods.
  9775. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9776. - old_method->name()->as_C_string(),
  9777. - old_method->signature()->as_C_string()));
  9778. - }
  9779. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9780. - "sanity check");
  9781. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9782. - obsolete_count));
  9783. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9784. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9785. }
  9786. +
  9787. +// Increment the classRedefinedCount field in the specific instanceKlass
  9788. +// and in all direct and indirect subclasses.
  9789. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9790. + oop class_mirror = ik->java_mirror();
  9791. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9792. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9793. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9794. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9795. +}
  9796. +
  9797. +#ifndef PRODUCT
  9798. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9799. + Klass *k = k_oop->klass_part();
  9800. + if (k->oop_is_instance()) {
  9801. + HandleMark hm(THREAD);
  9802. + instanceKlass *ik = (instanceKlass *) k;
  9803. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9804. +
  9805. + if (ik->vtable_length() > 0) {
  9806. + ResourceMark rm(THREAD);
  9807. + if (!ik->vtable()->check_no_old_entries()) {
  9808. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9809. + k_oop->size()));
  9810. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9811. + ik->signature_name()));
  9812. + assert(false, "OLD method found");
  9813. + }
  9814. +
  9815. + ik->vtable()->verify(tty, true);
  9816. + }
  9817. + }
  9818. +}
  9819. +
  9820. +#endif
  9821. +
  9822. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9823. +{
  9824. + assert(original_klasses != NULL && result != NULL, "");
  9825. + this->_original_klasses = original_klasses;
  9826. + this->_result = result;
  9827. + SystemDictionary::classes_do(this);
  9828. +}
  9829. +
  9830. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9831. +{
  9832. + klassOop klass = (klassOop)obj;
  9833. + assert(!_result->contains(klass), "must not occur more than once!");
  9834. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9835. +
  9836. + for(int i=0; i<_original_klasses->length(); i++) {
  9837. + instanceKlassHandle cur = _original_klasses->at(i);
  9838. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9839. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9840. + _result->append(klass);
  9841. + break;
  9842. + }
  9843. + }
  9844. +}
  9845. +
  9846. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9847. +{
  9848. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9849. +
  9850. + for (int i=0; i<class_count; i++) {
  9851. +
  9852. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9853. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9854. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9855. + Handle the_class_loader(THREAD, the_class->class_loader());
  9856. + Handle protection_domain(THREAD, the_class->protection_domain());
  9857. +
  9858. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9859. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9860. + ClassFileParser cfp(&st);
  9861. +
  9862. + GrowableArray<Symbol*> symbolArr;
  9863. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9864. + the_class->name()->as_C_string()));
  9865. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9866. +
  9867. + for (int j=0; j<symbolArr.length(); j++) {
  9868. + Symbol* sym = symbolArr.at(j);
  9869. +
  9870. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9871. +
  9872. + for (int k=0; k<arr->length(); k++) {
  9873. + klassOop curOop = arr->at(k)();
  9874. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9875. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9876. + RC_TRACE(0x00000002, ("Found class to link"));
  9877. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9878. + break;
  9879. + }
  9880. + }
  9881. + }
  9882. + }
  9883. +
  9884. +
  9885. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9886. +
  9887. + for (int i=0; i<affected->length(); i++) {
  9888. +
  9889. + instanceKlassHandle klass = affected->at(i);
  9890. +
  9891. + klassOop superKlass = klass->super();
  9892. + if (affected->contains(superKlass)) {
  9893. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9894. + }
  9895. +
  9896. + objArrayOop superInterfaces = klass->local_interfaces();
  9897. + for (int j=0; j<superInterfaces->length(); j++) {
  9898. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9899. + if (arr->contains(interfaceKlass)) {
  9900. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9901. + }
  9902. + }
  9903. + }
  9904. +
  9905. + if (RC_TRACE_ENABLED(0x00000002)) {
  9906. + RC_TRACE(0x00000002, ("Identified links: "));
  9907. + for (int i=0; i<links->length(); i++) {
  9908. + RC_TRACE(0x00000002, ("%s to %s",
  9909. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9910. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9911. + }
  9912. + }
  9913. +
  9914. + for (int i=0; i<arr->length(); i++) {
  9915. +
  9916. + int j;
  9917. + for (j=i; j<arr->length(); j++) {
  9918. +
  9919. + int k;
  9920. + for (k=0; k<links->length(); k++) {
  9921. +
  9922. + klassOop k1 = links->adr_at(k)->right();
  9923. + klassOop k2 = arr->at(j)();
  9924. + if (k1 == k2) {
  9925. + break;
  9926. + }
  9927. + }
  9928. +
  9929. + if (k == links->length()) {
  9930. + break;
  9931. + }
  9932. + }
  9933. +
  9934. + if (j == arr->length()) {
  9935. + // circle detected
  9936. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9937. + }
  9938. +
  9939. + for (int k=0; k<links->length(); k++) {
  9940. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9941. + links->at_put(k, links->at(links->length() - 1));
  9942. + links->remove_at(links->length() - 1);
  9943. + k--;
  9944. + }
  9945. + }
  9946. +
  9947. + instanceKlassHandle tmp = arr->at(j);
  9948. + arr->at_put(j, arr->at(i));
  9949. + arr->at_put(i, tmp);
  9950. + }
  9951. +
  9952. + return JVMTI_ERROR_NONE;
  9953. +}
  9954. +
  9955. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9956. +
  9957. + if (_updated_oops != NULL) {
  9958. + for (int i=0; i<_updated_oops->length(); i++) {
  9959. + closure->do_oop(_updated_oops->adr_at(i));
  9960. + }
  9961. + }
  9962. +}
  9963. +
  9964. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9965. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9966. + to->set_is_field_access_watched(from->is_field_access_watched());
  9967. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9968. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  9969. + from->name()->as_C_string()));
  9970. + }
  9971. + update_klass_field_access_flag(to);
  9972. +}
  9973. +
  9974. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9975. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9976. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9977. + fi->set_access_flags(fd->access_flags().as_short());
  9978. +}
  9979. +
  9980. // This internal class transfers the native function registration from old methods
  9981. // to new methods. It is designed to handle both the simple case of unchanged
  9982. @@ -2969,7 +3161,7 @@
  9983. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9984. //
  9985. class TransferNativeFunctionRegistration {
  9986. - private:
  9987. +private:
  9988. instanceKlassHandle the_class;
  9989. int prefix_count;
  9990. char** prefixes;
  9991. @@ -2982,42 +3174,42 @@
  9992. // (2) with the prefix.
  9993. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9994. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9995. - Symbol* signature) {
  9996. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9997. - if (name_symbol != NULL) {
  9998. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9999. - if (method != NULL) {
  10000. - // Even if prefixed, intermediate methods must exist.
  10001. - if (method->is_native()) {
  10002. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10003. - return method;
  10004. - }
  10005. - if (depth < prefix_count) {
  10006. - // Try applying further prefixes (other than this one).
  10007. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10008. - if (method != NULL) {
  10009. - return method; // found
  10010. + Symbol* signature) {
  10011. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10012. + if (name_symbol != NULL) {
  10013. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10014. + if (method != NULL) {
  10015. + // Even if prefixed, intermediate methods must exist.
  10016. + if (method->is_native()) {
  10017. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10018. + return method;
  10019. }
  10020. + if (depth < prefix_count) {
  10021. + // Try applying further prefixes (other than this one).
  10022. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10023. + if (method != NULL) {
  10024. + return method; // found
  10025. + }
  10026. - // Try adding this prefix to the method name and see if it matches
  10027. - // another method name.
  10028. - char* prefix = prefixes[depth];
  10029. - size_t prefix_len = strlen(prefix);
  10030. - size_t trial_len = name_len + prefix_len;
  10031. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10032. - strcpy(trial_name_str, prefix);
  10033. - strcat(trial_name_str, name_str);
  10034. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10035. - signature);
  10036. - if (method != NULL) {
  10037. - // If found along this branch, it was prefixed, mark as such
  10038. - method->set_is_prefixed_native();
  10039. - return method; // found
  10040. + // Try adding this prefix to the method name and see if it matches
  10041. + // another method name.
  10042. + char* prefix = prefixes[depth];
  10043. + size_t prefix_len = strlen(prefix);
  10044. + size_t trial_len = name_len + prefix_len;
  10045. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10046. + strcpy(trial_name_str, prefix);
  10047. + strcat(trial_name_str, name_str);
  10048. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10049. + signature);
  10050. + if (method != NULL) {
  10051. + // If found along this branch, it was prefixed, mark as such
  10052. + method->set_is_prefixed_native();
  10053. + return method; // found
  10054. + }
  10055. }
  10056. }
  10057. }
  10058. - }
  10059. - return NULL; // This whole branch bore nothing
  10060. + return NULL; // This whole branch bore nothing
  10061. }
  10062. // Return the method name with old prefixes stripped away.
  10063. @@ -3042,10 +3234,10 @@
  10064. ResourceMark rm;
  10065. char* name_str = method_name_without_prefixes(method);
  10066. return search_prefix_name_space(0, name_str, strlen(name_str),
  10067. - method->signature());
  10068. + method->signature());
  10069. }
  10070. - public:
  10071. +public:
  10072. // Construct a native method transfer processor for this class.
  10073. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10074. @@ -3056,9 +3248,9 @@
  10075. }
  10076. // Attempt to transfer any of the old or deleted methods that are native
  10077. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  10078. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10079. for (int j = 0; j < methods_length; j++) {
  10080. - methodOop old_method = old_methods[j];
  10081. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10082. if (old_method->is_native() && old_method->has_native_function()) {
  10083. methodOop new_method = strip_and_search_for_new_native(old_method);
  10084. @@ -3067,7 +3259,9 @@
  10085. // Redefine does not send events (except CFLH), certainly not this
  10086. // behind the scenes re-registration.
  10087. new_method->set_native_function(old_method->native_function(),
  10088. - !methodOopDesc::native_bind_event_is_interesting);
  10089. + !methodOopDesc::native_bind_event_is_interesting);
  10090. +
  10091. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10092. }
  10093. }
  10094. }
  10095. @@ -3075,544 +3269,8 @@
  10096. };
  10097. // Don't lose the association between a native method and its JNI function.
  10098. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  10099. - TransferNativeFunctionRegistration transfer(the_class);
  10100. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  10101. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  10102. -}
  10103. -
  10104. -// Deoptimize all compiled code that depends on this class.
  10105. -//
  10106. -// If the can_redefine_classes capability is obtained in the onload
  10107. -// phase then the compiler has recorded all dependencies from startup.
  10108. -// In that case we need only deoptimize and throw away all compiled code
  10109. -// that depends on the class.
  10110. -//
  10111. -// If can_redefine_classes is obtained sometime after the onload
  10112. -// phase then the dependency information may be incomplete. In that case
  10113. -// the first call to RedefineClasses causes all compiled code to be
  10114. -// thrown away. As can_redefine_classes has been obtained then
  10115. -// all future compilations will record dependencies so second and
  10116. -// subsequent calls to RedefineClasses need only throw away code
  10117. -// that depends on the class.
  10118. -//
  10119. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  10120. - assert_locked_or_safepoint(Compile_lock);
  10121. -
  10122. - // All dependencies have been recorded from startup or this is a second or
  10123. - // subsequent use of RedefineClasses
  10124. - if (JvmtiExport::all_dependencies_are_recorded()) {
  10125. - Universe::flush_evol_dependents_on(k_h);
  10126. - } else {
  10127. - CodeCache::mark_all_nmethods_for_deoptimization();
  10128. -
  10129. - ResourceMark rm(THREAD);
  10130. - DeoptimizationMarker dm;
  10131. -
  10132. - // Deoptimize all activations depending on marked nmethods
  10133. - Deoptimization::deoptimize_dependents();
  10134. -
  10135. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  10136. - CodeCache::make_marked_nmethods_not_entrant();
  10137. -
  10138. - // From now on we know that the dependency information is complete
  10139. - JvmtiExport::set_all_dependencies_are_recorded(true);
  10140. - }
  10141. -}
  10142. -
  10143. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  10144. - methodOop old_method;
  10145. - methodOop new_method;
  10146. -
  10147. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10148. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10149. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  10150. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10151. -
  10152. - _matching_methods_length = 0;
  10153. - _deleted_methods_length = 0;
  10154. - _added_methods_length = 0;
  10155. -
  10156. - int nj = 0;
  10157. - int oj = 0;
  10158. - while (true) {
  10159. - if (oj >= _old_methods->length()) {
  10160. - if (nj >= _new_methods->length()) {
  10161. - break; // we've looked at everything, done
  10162. - }
  10163. - // New method at the end
  10164. - new_method = (methodOop) _new_methods->obj_at(nj);
  10165. - _added_methods[_added_methods_length++] = new_method;
  10166. - ++nj;
  10167. - } else if (nj >= _new_methods->length()) {
  10168. - // Old method, at the end, is deleted
  10169. - old_method = (methodOop) _old_methods->obj_at(oj);
  10170. - _deleted_methods[_deleted_methods_length++] = old_method;
  10171. - ++oj;
  10172. - } else {
  10173. - old_method = (methodOop) _old_methods->obj_at(oj);
  10174. - new_method = (methodOop) _new_methods->obj_at(nj);
  10175. - if (old_method->name() == new_method->name()) {
  10176. - if (old_method->signature() == new_method->signature()) {
  10177. - _matching_old_methods[_matching_methods_length ] = old_method;
  10178. - _matching_new_methods[_matching_methods_length++] = new_method;
  10179. - ++nj;
  10180. - ++oj;
  10181. - } else {
  10182. - // added overloaded have already been moved to the end,
  10183. - // so this is a deleted overloaded method
  10184. - _deleted_methods[_deleted_methods_length++] = old_method;
  10185. - ++oj;
  10186. - }
  10187. - } else { // names don't match
  10188. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10189. - // new method
  10190. - _added_methods[_added_methods_length++] = new_method;
  10191. - ++nj;
  10192. - } else {
  10193. - // deleted method
  10194. - _deleted_methods[_deleted_methods_length++] = old_method;
  10195. - ++oj;
  10196. - }
  10197. - }
  10198. - }
  10199. - }
  10200. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10201. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10202. -}
  10203. -
  10204. -
  10205. -
  10206. -// Install the redefinition of a class:
  10207. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10208. -// dependent compiled code)
  10209. -// - replacing parts in the_class with parts from scratch_class
  10210. -// - adding a weak reference to track the obsolete but interesting
  10211. -// parts of the_class
  10212. -// - adjusting constant pool caches and vtables in other classes
  10213. -// that refer to methods in the_class. These adjustments use the
  10214. -// SystemDictionary::classes_do() facility which only allows
  10215. -// a helper method to be specified. The interesting parameters
  10216. -// that we would like to pass to the helper method are saved in
  10217. -// static global fields in the VM operation.
  10218. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10219. - instanceKlassHandle scratch_class, TRAPS) {
  10220. -
  10221. - RC_TIMER_START(_timer_rsc_phase1);
  10222. -
  10223. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10224. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10225. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10226. -
  10227. - // Remove all breakpoints in methods of this class
  10228. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10229. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10230. -
  10231. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10232. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10233. - // cached and users of the cache care about each active version of
  10234. - // the method so we have to track this previous version.
  10235. - // Do this before methods get switched
  10236. - Universe::reflect_invoke_cache()->add_previous_version(
  10237. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10238. - }
  10239. -
  10240. - // Deoptimize all compiled code that depends on this class
  10241. - flush_dependent_code(the_class, THREAD);
  10242. -
  10243. - _old_methods = the_class->methods();
  10244. - _new_methods = scratch_class->methods();
  10245. - _the_class_oop = the_class_oop;
  10246. - compute_added_deleted_matching_methods();
  10247. - update_jmethod_ids();
  10248. -
  10249. - // Attach new constant pool to the original klass. The original
  10250. - // klass still refers to the old constant pool (for now).
  10251. - scratch_class->constants()->set_pool_holder(the_class());
  10252. -
  10253. -#if 0
  10254. - // In theory, with constant pool merging in place we should be able
  10255. - // to save space by using the new, merged constant pool in place of
  10256. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10257. - // the klass version we are replacing now and any constant pool(s) in
  10258. - // previous versions of klass. Nice theory, doesn't work in practice.
  10259. - // When this code is enabled, even simple programs throw NullPointer
  10260. - // exceptions. I'm guessing that this is caused by some constant pool
  10261. - // cache difference between the new, merged constant pool and the
  10262. - // constant pool that was just being used by the klass. I'm keeping
  10263. - // this code around to archive the idea, but the code has to remain
  10264. - // disabled for now.
  10265. -
  10266. - // Attach each old method to the new constant pool. This can be
  10267. - // done here since we are past the bytecode verification and
  10268. - // constant pool optimization phases.
  10269. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10270. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10271. - method->set_constants(scratch_class->constants());
  10272. - }
  10273. -
  10274. - {
  10275. - // walk all previous versions of the klass
  10276. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10277. - PreviousVersionWalker pvw(ik);
  10278. - instanceKlassHandle ikh;
  10279. - do {
  10280. - ikh = pvw.next_previous_version();
  10281. - if (!ikh.is_null()) {
  10282. - ik = ikh();
  10283. -
  10284. - // attach previous version of klass to the new constant pool
  10285. - ik->set_constants(scratch_class->constants());
  10286. -
  10287. - // Attach each method in the previous version of klass to the
  10288. - // new constant pool
  10289. - objArrayOop prev_methods = ik->methods();
  10290. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10291. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10292. - method->set_constants(scratch_class->constants());
  10293. - }
  10294. - }
  10295. - } while (!ikh.is_null());
  10296. - }
  10297. -#endif
  10298. -
  10299. - // Replace methods and constantpool
  10300. - the_class->set_methods(_new_methods);
  10301. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10302. - // and to be able to undo operation easily.
  10303. -
  10304. - constantPoolOop old_constants = the_class->constants();
  10305. - the_class->set_constants(scratch_class->constants());
  10306. - scratch_class->set_constants(old_constants); // See the previous comment.
  10307. -#if 0
  10308. - // We are swapping the guts of "the new class" with the guts of "the
  10309. - // class". Since the old constant pool has just been attached to "the
  10310. - // new class", it seems logical to set the pool holder in the old
  10311. - // constant pool also. However, doing this will change the observable
  10312. - // class hierarchy for any old methods that are still executing. A
  10313. - // method can query the identity of its "holder" and this query uses
  10314. - // the method's constant pool link to find the holder. The change in
  10315. - // holding class from "the class" to "the new class" can confuse
  10316. - // things.
  10317. - //
  10318. - // Setting the old constant pool's holder will also cause
  10319. - // verification done during vtable initialization below to fail.
  10320. - // During vtable initialization, the vtable's class is verified to be
  10321. - // a subtype of the method's holder. The vtable's class is "the
  10322. - // class" and the method's holder is gotten from the constant pool
  10323. - // link in the method itself. For "the class"'s directly implemented
  10324. - // methods, the method holder is "the class" itself (as gotten from
  10325. - // the new constant pool). The check works fine in this case. The
  10326. - // check also works fine for methods inherited from super classes.
  10327. - //
  10328. - // Miranda methods are a little more complicated. A miranda method is
  10329. - // provided by an interface when the class implementing the interface
  10330. - // does not provide its own method. These interfaces are implemented
  10331. - // internally as an instanceKlass. These special instanceKlasses
  10332. - // share the constant pool of the class that "implements" the
  10333. - // interface. By sharing the constant pool, the method holder of a
  10334. - // miranda method is the class that "implements" the interface. In a
  10335. - // non-redefine situation, the subtype check works fine. However, if
  10336. - // the old constant pool's pool holder is modified, then the check
  10337. - // fails because there is no class hierarchy relationship between the
  10338. - // vtable's class and "the new class".
  10339. -
  10340. - old_constants->set_pool_holder(scratch_class());
  10341. -#endif
  10342. -
  10343. - // track which methods are EMCP for add_previous_version() call below
  10344. - BitMap emcp_methods(_old_methods->length());
  10345. - int emcp_method_count = 0;
  10346. - emcp_methods.clear(); // clears 0..(length() - 1)
  10347. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10348. - transfer_old_native_function_registrations(the_class);
  10349. -
  10350. - // The class file bytes from before any retransformable agents mucked
  10351. - // with them was cached on the scratch class, move to the_class.
  10352. - // Note: we still want to do this if nothing needed caching since it
  10353. - // should get cleared in the_class too.
  10354. - if (the_class->get_cached_class_file_bytes() == 0) {
  10355. - // the_class doesn't have a cache yet so copy it
  10356. - the_class->set_cached_class_file(
  10357. - scratch_class->get_cached_class_file_bytes(),
  10358. - scratch_class->get_cached_class_file_len());
  10359. - }
  10360. -#ifndef PRODUCT
  10361. - else {
  10362. - assert(the_class->get_cached_class_file_bytes() ==
  10363. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10364. - assert(the_class->get_cached_class_file_len() ==
  10365. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10366. - }
  10367. -#endif
  10368. -
  10369. - // Replace inner_classes
  10370. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10371. - the_class->set_inner_classes(scratch_class->inner_classes());
  10372. - scratch_class->set_inner_classes(old_inner_classes);
  10373. -
  10374. - // Initialize the vtable and interface table after
  10375. - // methods have been rewritten
  10376. - {
  10377. - ResourceMark rm(THREAD);
  10378. - // no exception should happen here since we explicitly
  10379. - // do not check loader constraints.
  10380. - // compare_and_normalize_class_versions has already checked:
  10381. - // - classloaders unchanged, signatures unchanged
  10382. - // - all instanceKlasses for redefined classes reused & contents updated
  10383. - the_class->vtable()->initialize_vtable(false, THREAD);
  10384. - the_class->itable()->initialize_itable(false, THREAD);
  10385. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10386. - }
  10387. -
  10388. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10389. -
  10390. - // Copy the "source file name" attribute from new class version
  10391. - the_class->set_source_file_name(scratch_class->source_file_name());
  10392. -
  10393. - // Copy the "source debug extension" attribute from new class version
  10394. - the_class->set_source_debug_extension(
  10395. - scratch_class->source_debug_extension(),
  10396. - scratch_class->source_debug_extension() == NULL ? 0 :
  10397. - (int)strlen(scratch_class->source_debug_extension()));
  10398. -
  10399. - // Use of javac -g could be different in the old and the new
  10400. - if (scratch_class->access_flags().has_localvariable_table() !=
  10401. - the_class->access_flags().has_localvariable_table()) {
  10402. -
  10403. - AccessFlags flags = the_class->access_flags();
  10404. - if (scratch_class->access_flags().has_localvariable_table()) {
  10405. - flags.set_has_localvariable_table();
  10406. - } else {
  10407. - flags.clear_has_localvariable_table();
  10408. - }
  10409. - the_class->set_access_flags(flags);
  10410. - }
  10411. -
  10412. - // Replace class annotation fields values
  10413. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10414. - the_class->set_class_annotations(scratch_class->class_annotations());
  10415. - scratch_class->set_class_annotations(old_class_annotations);
  10416. -
  10417. - // Replace fields annotation fields values
  10418. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10419. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10420. - scratch_class->set_fields_annotations(old_fields_annotations);
  10421. -
  10422. - // Replace methods annotation fields values
  10423. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10424. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10425. - scratch_class->set_methods_annotations(old_methods_annotations);
  10426. -
  10427. - // Replace methods parameter annotation fields values
  10428. - objArrayOop old_methods_parameter_annotations =
  10429. - the_class->methods_parameter_annotations();
  10430. - the_class->set_methods_parameter_annotations(
  10431. - scratch_class->methods_parameter_annotations());
  10432. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10433. -
  10434. - // Replace methods default annotation fields values
  10435. - objArrayOop old_methods_default_annotations =
  10436. - the_class->methods_default_annotations();
  10437. - the_class->set_methods_default_annotations(
  10438. - scratch_class->methods_default_annotations());
  10439. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10440. -
  10441. - // Replace minor version number of class file
  10442. - u2 old_minor_version = the_class->minor_version();
  10443. - the_class->set_minor_version(scratch_class->minor_version());
  10444. - scratch_class->set_minor_version(old_minor_version);
  10445. -
  10446. - // Replace major version number of class file
  10447. - u2 old_major_version = the_class->major_version();
  10448. - the_class->set_major_version(scratch_class->major_version());
  10449. - scratch_class->set_major_version(old_major_version);
  10450. -
  10451. - // Replace CP indexes for class and name+type of enclosing method
  10452. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10453. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10454. - the_class->set_enclosing_method_indices(
  10455. - scratch_class->enclosing_method_class_index(),
  10456. - scratch_class->enclosing_method_method_index());
  10457. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10458. -
  10459. - // keep track of previous versions of this class
  10460. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10461. - emcp_method_count);
  10462. -
  10463. - RC_TIMER_STOP(_timer_rsc_phase1);
  10464. - RC_TIMER_START(_timer_rsc_phase2);
  10465. -
  10466. - // Adjust constantpool caches and vtables for all classes
  10467. - // that reference methods of the evolved class.
  10468. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10469. -
  10470. - // JSR-292 support
  10471. - MemberNameTable* mnt = the_class->member_names();
  10472. - if (mnt != NULL) {
  10473. - bool trace_name_printed = false;
  10474. - mnt->adjust_method_entries(_matching_old_methods,
  10475. - _matching_new_methods,
  10476. - _matching_methods_length,
  10477. - &trace_name_printed);
  10478. - }
  10479. -
  10480. - if (the_class->oop_map_cache() != NULL) {
  10481. - // Flush references to any obsolete methods from the oop map cache
  10482. - // so that obsolete methods are not pinned.
  10483. - the_class->oop_map_cache()->flush_obsolete_entries();
  10484. - }
  10485. -
  10486. - // increment the classRedefinedCount field in the_class and in any
  10487. - // direct and indirect subclasses of the_class
  10488. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10489. -
  10490. - // RC_TRACE macro has an embedded ResourceMark
  10491. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10492. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10493. - the_class->external_name(),
  10494. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10495. - os::available_memory() >> 10));
  10496. -
  10497. - RC_TIMER_STOP(_timer_rsc_phase2);
  10498. -} // end redefine_single_class()
  10499. -
  10500. -
  10501. -// Increment the classRedefinedCount field in the specific instanceKlass
  10502. -// and in all direct and indirect subclasses.
  10503. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10504. - oop class_mirror = ik->java_mirror();
  10505. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10506. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10507. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10508. -
  10509. - if (class_oop != _the_class_oop) {
  10510. - // _the_class_oop count is printed at end of redefine_single_class()
  10511. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10512. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10513. - }
  10514. -
  10515. - for (Klass *subk = ik->subklass(); subk != NULL;
  10516. - subk = subk->next_sibling()) {
  10517. - if (subk->oop_is_instance()) {
  10518. - // Only update instanceKlasses
  10519. - instanceKlass *subik = (instanceKlass*)subk;
  10520. - // recursively do subclasses of the current subclass
  10521. - increment_class_counter(subik, THREAD);
  10522. - }
  10523. - }
  10524. -}
  10525. -
  10526. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10527. - oop initiating_loader, TRAPS) {
  10528. - Klass *k = k_oop->klass_part();
  10529. - if (k->oop_is_instance()) {
  10530. - HandleMark hm(THREAD);
  10531. - instanceKlass *ik = (instanceKlass *) k;
  10532. - bool no_old_methods = true; // be optimistic
  10533. - ResourceMark rm(THREAD);
  10534. -
  10535. - // a vtable should never contain old or obsolete methods
  10536. - if (ik->vtable_length() > 0 &&
  10537. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  10538. - if (RC_TRACE_ENABLED(0x00004000)) {
  10539. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10540. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  10541. - " -- OLD or OBSOLETE method found -- class: %s",
  10542. - ik->signature_name()));
  10543. - ik->vtable()->dump_vtable();
  10544. - }
  10545. - no_old_methods = false;
  10546. - }
  10547. -
  10548. - // an itable should never contain old or obsolete methods
  10549. - if (ik->itable_length() > 0 &&
  10550. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  10551. - if (RC_TRACE_ENABLED(0x00004000)) {
  10552. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10553. - ("klassItable::check_no_old_or_obsolete_entries failure"
  10554. - " -- OLD or OBSOLETE method found -- class: %s",
  10555. - ik->signature_name()));
  10556. - ik->itable()->dump_itable();
  10557. - }
  10558. - no_old_methods = false;
  10559. - }
  10560. -
  10561. - // the constant pool cache should never contain old or obsolete methods
  10562. - if (ik->constants() != NULL &&
  10563. - ik->constants()->cache() != NULL &&
  10564. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  10565. - if (RC_TRACE_ENABLED(0x00004000)) {
  10566. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10567. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  10568. - " -- OLD or OBSOLETE method found -- class: %s",
  10569. - ik->signature_name()));
  10570. - ik->constants()->cache()->dump_cache();
  10571. - }
  10572. - no_old_methods = false;
  10573. - }
  10574. -
  10575. - if (!no_old_methods) {
  10576. - if (RC_TRACE_ENABLED(0x00004000)) {
  10577. - dump_methods();
  10578. - } else {
  10579. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  10580. - "to see more info about the following guarantee() failure.");
  10581. - }
  10582. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10583. - }
  10584. - }
  10585. -}
  10586. -
  10587. -void VM_RedefineClasses::dump_methods() {
  10588. - int j;
  10589. - RC_TRACE(0x00004000, ("_old_methods --"));
  10590. - for (j = 0; j < _old_methods->length(); ++j) {
  10591. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10592. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10593. - m->access_flags().print_on(tty);
  10594. - tty->print(" -- ");
  10595. - m->print_name(tty);
  10596. - tty->cr();
  10597. - }
  10598. - RC_TRACE(0x00004000, ("_new_methods --"));
  10599. - for (j = 0; j < _new_methods->length(); ++j) {
  10600. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10601. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10602. - m->access_flags().print_on(tty);
  10603. - tty->print(" -- ");
  10604. - m->print_name(tty);
  10605. - tty->cr();
  10606. - }
  10607. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10608. - for (j = 0; j < _matching_methods_length; ++j) {
  10609. - methodOop m = _matching_old_methods[j];
  10610. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10611. - m->access_flags().print_on(tty);
  10612. - tty->print(" -- ");
  10613. - m->print_name(tty);
  10614. - tty->cr();
  10615. - m = _matching_new_methods[j];
  10616. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10617. - m->access_flags().print_on(tty);
  10618. - tty->cr();
  10619. - }
  10620. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10621. - for (j = 0; j < _deleted_methods_length; ++j) {
  10622. - methodOop m = _deleted_methods[j];
  10623. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10624. - m->access_flags().print_on(tty);
  10625. - tty->print(" -- ");
  10626. - m->print_name(tty);
  10627. - tty->cr();
  10628. - }
  10629. - RC_TRACE(0x00004000, ("_added_methods --"));
  10630. - for (j = 0; j < _added_methods_length; ++j) {
  10631. - methodOop m = _added_methods[j];
  10632. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10633. - m->access_flags().print_on(tty);
  10634. - tty->print(" -- ");
  10635. - m->print_name(tty);
  10636. - tty->cr();
  10637. - }
  10638. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10639. + TransferNativeFunctionRegistration transfer(old_klass);
  10640. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10641. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10642. }
  10643. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10644. index bfac62c..7908cf6 100644
  10645. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10646. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10647. @@ -1,26 +1,29 @@
  10648. /*
  10649. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10650. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10651. - *
  10652. - * This code is free software; you can redistribute it and/or modify it
  10653. - * under the terms of the GNU General Public License version 2 only, as
  10654. - * published by the Free Software Foundation.
  10655. - *
  10656. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10657. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10658. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10659. - * version 2 for more details (a copy is included in the LICENSE file that
  10660. - * accompanied this code).
  10661. - *
  10662. - * You should have received a copy of the GNU General Public License version
  10663. - * 2 along with this work; if not, write to the Free Software Foundation,
  10664. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10665. - *
  10666. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10667. - * or visit www.oracle.com if you need additional information or have any
  10668. - * questions.
  10669. - *
  10670. - */
  10671. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10672. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10673. +*
  10674. +* This code is free software; you can redistribute it and/or modify it
  10675. +* under the terms of the GNU General Public License version 2 only, as
  10676. +* published by the Free Software Foundation.
  10677. +*
  10678. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10679. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10680. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10681. +* version 2 for more details (a copy is included in the LICENSE file that
  10682. +* accompanied this code).
  10683. +*
  10684. +* You should have received a copy of the GNU General Public License version
  10685. +* 2 along with this work; if not, write to the Free Software Foundation,
  10686. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10687. +*
  10688. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10689. +* or visit www.oracle.com if you need additional information or have any
  10690. +* questions.
  10691. +*
  10692. +*/
  10693. +
  10694. +// New version that allows arbitrary changes to already loaded classes.
  10695. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10696. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10697. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10698. @@ -32,330 +35,27 @@
  10699. #include "oops/objArrayOop.hpp"
  10700. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10701. #include "runtime/vm_operations.hpp"
  10702. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10703. -// Introduction:
  10704. -//
  10705. -// The RedefineClasses() API is used to change the definition of one or
  10706. -// more classes. While the API supports redefining more than one class
  10707. -// in a single call, in general, the API is discussed in the context of
  10708. -// changing the definition of a single current class to a single new
  10709. -// class. For clarity, the current class is will always be called
  10710. -// "the_class" and the new class will always be called "scratch_class".
  10711. -//
  10712. -// The name "the_class" is used because there is only one structure
  10713. -// that represents a specific class; redefinition does not replace the
  10714. -// structure, but instead replaces parts of the structure. The name
  10715. -// "scratch_class" is used because the structure that represents the
  10716. -// new definition of a specific class is simply used to carry around
  10717. -// the parts of the new definition until they are used to replace the
  10718. -// appropriate parts in the_class. Once redefinition of a class is
  10719. -// complete, scratch_class is thrown away.
  10720. -//
  10721. -//
  10722. -// Implementation Overview:
  10723. -//
  10724. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10725. -// does the real work. The work is split in varying degrees between
  10726. -// doit_prologue(), doit() and doit_epilogue().
  10727. -//
  10728. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10729. -// safepoint. It does parameter verification and loads scratch_class
  10730. -// which involves:
  10731. -// - parsing the incoming class definition using the_class' class
  10732. -// loader and security context
  10733. -// - linking scratch_class
  10734. -// - merging constant pools and rewriting bytecodes as needed
  10735. -// for the merged constant pool
  10736. -// - verifying the bytecodes in scratch_class
  10737. -// - setting up the constant pool cache and rewriting bytecodes
  10738. -// as needed to use the cache
  10739. -// - finally, scratch_class is compared to the_class to verify
  10740. -// that it is a valid replacement class
  10741. -// - if everything is good, then scratch_class is saved in an
  10742. -// instance field in the VM operation for the doit() call
  10743. -//
  10744. -// Note: A JavaThread must do the above work.
  10745. -//
  10746. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10747. -// the new class definition(s) which involves:
  10748. -// - retrieving the scratch_class from the instance field in the
  10749. -// VM operation
  10750. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10751. -// dependent compiled code)
  10752. -// - replacing parts in the_class with parts from scratch_class
  10753. -// - adding weak reference(s) to track the obsolete but interesting
  10754. -// parts of the_class
  10755. -// - adjusting constant pool caches and vtables in other classes
  10756. -// that refer to methods in the_class. These adjustments use the
  10757. -// SystemDictionary::classes_do() facility which only allows
  10758. -// a helper method to be specified. The interesting parameters
  10759. -// that we would like to pass to the helper method are saved in
  10760. -// static global fields in the VM operation.
  10761. -// - telling the SystemDictionary to notice our changes
  10762. -//
  10763. -// Note: the above work must be done by the VMThread to be safe.
  10764. -//
  10765. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10766. -// is finished and the safepoint is done. It simply cleans up
  10767. -// memory allocated in doit_prologue() and used in doit().
  10768. -//
  10769. -//
  10770. -// Constant Pool Details:
  10771. -//
  10772. -// When the_class is redefined, we cannot just replace the constant
  10773. -// pool in the_class with the constant pool from scratch_class because
  10774. -// that could confuse obsolete methods that may still be running.
  10775. -// Instead, the constant pool from the_class, old_cp, is merged with
  10776. -// the constant pool from scratch_class, scratch_cp. The resulting
  10777. -// constant pool, merge_cp, replaces old_cp in the_class.
  10778. -//
  10779. -// The key part of any merging algorithm is the entry comparison
  10780. -// function so we have to know the types of entries in a constant pool
  10781. -// in order to merge two of them together. Constant pools can contain
  10782. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10783. -// is not presently used so we only have to worry about the other 11
  10784. -// entry types. For the purposes of constant pool merging, it is
  10785. -// helpful to know that the 11 entry types fall into 3 different
  10786. -// subtypes: "direct", "indirect" and "double-indirect".
  10787. -//
  10788. -// Direct CP entries contain data and do not contain references to
  10789. -// other CP entries. The following are direct CP entries:
  10790. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10791. -//
  10792. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10793. -// and no other data. The following are indirect CP entries:
  10794. -// JVM_CONSTANT_{Class,NameAndType,String}
  10795. -//
  10796. -// Double-indirect CP entries contain two references to indirect CP
  10797. -// entries and no other data. The following are double-indirect CP
  10798. -// entries:
  10799. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10800. -//
  10801. -// When comparing entries between two constant pools, the entry types
  10802. -// are compared first and if they match, then further comparisons are
  10803. -// made depending on the entry subtype. Comparing direct CP entries is
  10804. -// simply a matter of comparing the data associated with each entry.
  10805. -// Comparing both indirect and double-indirect CP entries requires
  10806. -// recursion.
  10807. -//
  10808. -// Fortunately, the recursive combinations are limited because indirect
  10809. -// CP entries can only refer to direct CP entries and double-indirect
  10810. -// CP entries can only refer to indirect CP entries. The following is
  10811. -// an example illustration of the deepest set of indirections needed to
  10812. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10813. -//
  10814. -// JVM_CONSTANT_Fieldref {
  10815. -// class_index => JVM_CONSTANT_Class {
  10816. -// name_index => JVM_CONSTANT_Utf8 {
  10817. -// <data-1>
  10818. -// }
  10819. -// }
  10820. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10821. -// name_index => JVM_CONSTANT_Utf8 {
  10822. -// <data-2>
  10823. -// }
  10824. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10825. -// <data-3>
  10826. -// }
  10827. -// }
  10828. -// }
  10829. -//
  10830. -// The above illustration is not a data structure definition for any
  10831. -// computer language. The curly braces ('{' and '}') are meant to
  10832. -// delimit the context of the "fields" in the CP entry types shown.
  10833. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10834. -// "=>", e.g., the class_index is used to indirectly reference a
  10835. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10836. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10837. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10838. -// have to do a total of 5 indirections just to get to the CP entries
  10839. -// that contain the interesting pieces of data and then we have to
  10840. -// fetch the three pieces of data. This means we have to do a total of
  10841. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10842. -// entries.
  10843. -//
  10844. -// Here is the indirection, data and dereference count for each entry
  10845. -// type:
  10846. -//
  10847. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10848. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10849. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10850. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10851. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10852. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10853. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10854. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10855. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10856. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10857. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10858. -//
  10859. -// So different subtypes of CP entries require different amounts of
  10860. -// work for a proper comparison.
  10861. -//
  10862. -// Now that we've talked about the different entry types and how to
  10863. -// compare them we need to get back to merging. This is not a merge in
  10864. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10865. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10866. -// preserving entry order. Next we append all the unique entries from
  10867. -// scratch_cp to merge_cp and we track the index changes from the
  10868. -// location in scratch_cp to the possibly new location in merge_cp.
  10869. -// When we are done, any obsolete code that is still running that
  10870. -// uses old_cp should not be able to observe any difference if it
  10871. -// were to use merge_cp. As for the new code in scratch_class, it is
  10872. -// modified to use the appropriate index values in merge_cp before it
  10873. -// is used to replace the code in the_class.
  10874. -//
  10875. -// There is one small complication in copying the entries from old_cp
  10876. -// to merge_cp. Two of the CP entry types are special in that they are
  10877. -// lazily resolved. Before explaining the copying complication, we need
  10878. -// to digress into CP entry resolution.
  10879. -//
  10880. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10881. -// the class file, but are not stored in memory as such until they are
  10882. -// resolved. The entries are not resolved unless they are used because
  10883. -// resolution is expensive. During class file parsing the entries are
  10884. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10885. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10886. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10887. -// have been parsed, but the index values in the entries have not been
  10888. -// validated. After the entire constant pool has been parsed, the index
  10889. -// values can be validated and then the entries are converted into
  10890. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10891. -// entries. During this conversion process, the UTF8 values that are
  10892. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10893. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10894. -// entries are modified to refer to the Symbol*s. This optimization
  10895. -// eliminates one level of indirection for those two CP entry types and
  10896. -// gets the entries ready for verification. During class file parsing
  10897. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10898. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10899. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10900. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10901. -// entries.
  10902. -//
  10903. -// Now we can get back to the copying complication. When we copy
  10904. -// entries from old_cp to merge_cp, we have to revert any
  10905. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10906. -// or verification will fail.
  10907. -//
  10908. -// It is important to explicitly state that the merging algorithm
  10909. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10910. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10911. -// entries in the merge_cp. This is done both to make verification
  10912. -// happy and to avoid adding more brittleness between RedefineClasses
  10913. -// and the constant pool cache. By allowing the constant pool cache
  10914. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10915. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10916. -// about those algorithms in RedefineClasses.
  10917. -//
  10918. -// Appending unique entries from scratch_cp to merge_cp is straight
  10919. -// forward for direct CP entries and most indirect CP entries. For the
  10920. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10921. -// indirect CP entry types, the presence of more than one piece of
  10922. -// interesting data makes appending the entries more complicated.
  10923. -//
  10924. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10925. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10926. -// If the index in scratch_cp is different than the destination index
  10927. -// in merge_cp, then the change in index value is tracked.
  10928. -//
  10929. -// Note: the above discussion for the direct CP entries also applies
  10930. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10931. -//
  10932. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10933. -// one data element at the end of the recursion, we know that we have
  10934. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10935. -// unique then it is appended to merge_cp before the current entry.
  10936. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10937. -// is updated to refer to the duplicate entry in merge_cp before it is
  10938. -// appended to merge_cp. Again, any changes in index values are tracked
  10939. -// as needed.
  10940. -//
  10941. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10942. -// types is theoretical. Since those entry types have already been
  10943. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10944. -// they are handled as direct CP entries.
  10945. -//
  10946. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10947. -// data elements at the end of the recursions, we know that we have
  10948. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10949. -// entries are appended to merge_cp before the current entry. For any
  10950. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10951. -// updated to refer to the duplicate entry in merge_cp before it is
  10952. -// appended to merge_cp. Again, any changes in index values are tracked
  10953. -// as needed.
  10954. -//
  10955. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10956. -// types, since there are two indirect CP entries and three data
  10957. -// elements at the end of the recursions, we know that we have between
  10958. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10959. -// above for an example of all six entries. The uniqueness algorithm
  10960. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10961. -// covered above. Any unique entries are appended to merge_cp before
  10962. -// the current entry. For any entries that are not unique, the current
  10963. -// entry is updated to refer to the duplicate entry in merge_cp before
  10964. -// it is appended to merge_cp. Again, any changes in index values are
  10965. -// tracked as needed.
  10966. -//
  10967. -//
  10968. -// Other Details:
  10969. -//
  10970. -// Details for other parts of RedefineClasses need to be written.
  10971. -// This is a placeholder section.
  10972. -//
  10973. -//
  10974. -// Open Issues (in no particular order):
  10975. -//
  10976. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10977. -//
  10978. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10979. -// domain since the initial version. This has been changed to pass
  10980. -// the_class->protection_domain(). This change has been tested with
  10981. -// all NSK tests and nothing broke, but what will adding it now break
  10982. -// in ways that we don't test?
  10983. -//
  10984. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10985. -// (indirect) use of the Relocator class that the max instruction
  10986. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10987. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10988. -// what it does to the bytecodes. More investigation is needed.
  10989. -//
  10990. -// - java.lang.Object methods can be called on arrays. This is
  10991. -// implemented via the arrayKlassOop vtable which we don't
  10992. -// update. For example, if we redefine java.lang.Object.toString(),
  10993. -// then the new version of the method will not be called for array
  10994. -// objects.
  10995. -//
  10996. -// - How do we know if redefine_single_class() and the guts of
  10997. -// instanceKlass are out of sync? I don't think this can be
  10998. -// automated, but we should probably order the work in
  10999. -// redefine_single_class() to match the order of field
  11000. -// definitions in instanceKlass. We also need to add some
  11001. -// comments about keeping things in sync.
  11002. -//
  11003. -// - set_new_constant_pool() is huge and we should consider refactoring
  11004. -// it into smaller chunks of work.
  11005. -//
  11006. -// - The exception table update code in set_new_constant_pool() defines
  11007. -// const values that are also defined in a local context elsewhere.
  11008. -// The same literal values are also used in elsewhere. We need to
  11009. -// coordinate a cleanup of these constants with Runtime.
  11010. -//
  11011. +#define RC_ABORT(error) { _result = error; return false; }
  11012. -class VM_RedefineClasses: public VM_Operation {
  11013. +class VM_RedefineClasses: public VM_GC_Operation {
  11014. private:
  11015. +
  11016. // These static fields are needed by SystemDictionary::classes_do()
  11017. // facility and the adjust_cpool_cache_and_vtable() helper:
  11018. static objArrayOop _old_methods;
  11019. static objArrayOop _new_methods;
  11020. - static methodOop* _matching_old_methods;
  11021. - static methodOop* _matching_new_methods;
  11022. - static methodOop* _deleted_methods;
  11023. - static methodOop* _added_methods;
  11024. + static int* _matching_old_methods;
  11025. + static int* _matching_new_methods;
  11026. + static int* _deleted_methods;
  11027. + static int* _added_methods;
  11028. static int _matching_methods_length;
  11029. static int _deleted_methods_length;
  11030. static int _added_methods_length;
  11031. static klassOop _the_class_oop;
  11032. +
  11033. + static int _revision_number;
  11034. // The instance fields are used to pass information from
  11035. // doit_prologue() to doit() and doit_epilogue().
  11036. @@ -370,42 +70,28 @@
  11037. // _index_map_p contains any entries.
  11038. int _index_map_count;
  11039. intArray * _index_map_p;
  11040. -
  11041. - // _operands_index_map_count is just an optimization for knowing if
  11042. - // _operands_index_map_p contains any entries.
  11043. - int _operands_cur_length;
  11044. - int _operands_index_map_count;
  11045. - intArray * _operands_index_map_p;
  11046. -
  11047. - // ptr to _class_count scratch_classes
  11048. - instanceKlassHandle * _scratch_classes;
  11049. - jvmtiError _res;
  11050. + GrowableArray<instanceKlassHandle>* _new_classes;
  11051. + GrowableArray<oop>* _updated_oops;
  11052. + jvmtiError _result;
  11053. + int _max_redefinition_flags;
  11054. // Performance measurement support. These timers do not cover all
  11055. // the work done for JVM/TI RedefineClasses() but they do cover
  11056. // the heavy lifting.
  11057. - elapsedTimer _timer_rsc_phase1;
  11058. - elapsedTimer _timer_rsc_phase2;
  11059. - elapsedTimer _timer_vm_op_prologue;
  11060. + elapsedTimer _timer_total;
  11061. + elapsedTimer _timer_prologue;
  11062. + elapsedTimer _timer_class_linking;
  11063. + elapsedTimer _timer_class_loading;
  11064. + elapsedTimer _timer_check_type;
  11065. + elapsedTimer _timer_prepare_redefinition;
  11066. + elapsedTimer _timer_wait_for_locks;
  11067. + elapsedTimer _timer_redefinition;
  11068. + elapsedTimer _timer_vm_op_epilogue;
  11069. - // These routines are roughly in call order unless otherwise noted.
  11070. -
  11071. - // Load the caller's new class definition(s) into _scratch_classes.
  11072. - // Constant pool merging work is done here as needed. Also calls
  11073. - // compare_and_normalize_class_versions() to verify the class
  11074. - // definition(s).
  11075. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  11076. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  11077. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  11078. jvmtiError load_new_class_versions(TRAPS);
  11079. -
  11080. - // Verify that the caller provided class definition(s) that meet
  11081. - // the restrictions of RedefineClasses. Normalize the order of
  11082. - // overloaded methods as needed.
  11083. - jvmtiError compare_and_normalize_class_versions(
  11084. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  11085. -
  11086. - // Swap annotations[i] with annotations[j]
  11087. - // Used by compare_and_normalize_class_versions() when normalizing
  11088. - // overloaded methods or changing idnum as when adding or deleting methods.
  11089. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  11090. // Figure out which new methods match old methods in name and signature,
  11091. // which methods have been added, and which are no longer present
  11092. @@ -414,103 +100,100 @@
  11093. // Change jmethodIDs to point to the new methods
  11094. void update_jmethod_ids();
  11095. - // In addition to marking methods as obsolete, this routine
  11096. - // records which methods are EMCP (Equivalent Module Constant
  11097. - // Pool) in the emcp_methods BitMap and returns the number of
  11098. - // EMCP methods via emcp_method_count_p. This information is
  11099. - // used when information about the previous version of the_class
  11100. - // is squirreled away.
  11101. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  11102. - int * emcp_method_count_p);
  11103. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11104. + class FindAffectedKlassesClosure : public ObjectClosure {
  11105. - // Unevolving classes may point to methods of the_class directly
  11106. - // from their constant pool caches, itables, and/or vtables. We
  11107. - // use the SystemDictionary::classes_do() facility and this helper
  11108. - // to fix up these pointers.
  11109. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  11110. + private:
  11111. + GrowableArray<instanceKlassHandle> *_original_klasses;
  11112. + GrowableArray<instanceKlassHandle> *_result;
  11113. +
  11114. + public:
  11115. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  11116. +
  11117. + virtual void do_object(oop obj);
  11118. + };
  11119. +
  11120. +
  11121. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  11122. // Install the redefinition of a class
  11123. - void redefine_single_class(jclass the_jclass,
  11124. - instanceKlassHandle scratch_class, TRAPS);
  11125. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  11126. // Increment the classRedefinedCount field in the specific instanceKlass
  11127. // and in all direct and indirect subclasses.
  11128. void increment_class_counter(instanceKlass *ik, TRAPS);
  11129. - // Support for constant pool merging (these routines are in alpha order):
  11130. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  11131. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11132. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11133. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11134. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  11135. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  11136. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11137. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11138. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11139. - int find_new_index(int old_index);
  11140. - int find_new_operand_index(int old_bootstrap_spec_index);
  11141. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  11142. - constantPoolHandle cp2, int index2);
  11143. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  11144. - constantPoolHandle cp2, int index2);
  11145. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  11146. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  11147. - bool merge_constant_pools(constantPoolHandle old_cp,
  11148. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  11149. - int *merge_cp_length_p, TRAPS);
  11150. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  11151. - instanceKlassHandle scratch_class, TRAPS);
  11152. - u2 rewrite_cp_ref_in_annotation_data(
  11153. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  11154. - const char * trace_mesg, TRAPS);
  11155. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  11156. - bool rewrite_cp_refs_in_annotation_struct(
  11157. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11158. - bool rewrite_cp_refs_in_annotations_typeArray(
  11159. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  11160. - bool rewrite_cp_refs_in_class_annotations(
  11161. - instanceKlassHandle scratch_class, TRAPS);
  11162. - bool rewrite_cp_refs_in_element_value(
  11163. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11164. - bool rewrite_cp_refs_in_fields_annotations(
  11165. - instanceKlassHandle scratch_class, TRAPS);
  11166. - void rewrite_cp_refs_in_method(methodHandle method,
  11167. - methodHandle * new_method_p, TRAPS);
  11168. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  11169. - bool rewrite_cp_refs_in_methods_annotations(
  11170. - instanceKlassHandle scratch_class, TRAPS);
  11171. - bool rewrite_cp_refs_in_methods_default_annotations(
  11172. - instanceKlassHandle scratch_class, TRAPS);
  11173. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  11174. - instanceKlassHandle scratch_class, TRAPS);
  11175. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  11176. - void rewrite_cp_refs_in_verification_type_info(
  11177. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  11178. - u1 frame_size, TRAPS);
  11179. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  11180. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  11181. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  11182. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  11183. - static void dump_methods();
  11184. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  11185. +
  11186. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  11187. +
  11188. +#ifdef ASSERT
  11189. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  11190. +#endif
  11191. +
  11192. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  11193. + void calculate_instance_update_information(klassOop new_version);
  11194. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  11195. +
  11196. + static void calculate_type_check_information(klassOop k);
  11197. + static void clear_type_check_information(klassOop k);
  11198. public:
  11199. - VM_RedefineClasses(jint class_count,
  11200. - const jvmtiClassDefinition *class_defs,
  11201. - JvmtiClassLoadKind class_load_kind);
  11202. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  11203. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  11204. + virtual ~VM_RedefineClasses();
  11205. +
  11206. + bool check_arguments();
  11207. bool doit_prologue();
  11208. void doit();
  11209. void doit_epilogue();
  11210. + void rollback();
  11211. - bool allow_nested_vm_operations() const { return true; }
  11212. - jvmtiError check_error() { return _res; }
  11213. + jvmtiError check_exception() const;
  11214. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  11215. + bool skip_operation() const { return false; }
  11216. + bool allow_nested_vm_operations() const { return true; }
  11217. + jvmtiError check_error() { return _result; }
  11218. +
  11219. + void update_active_methods();
  11220. +
  11221. + // Checks for type consistency after hierarchy change
  11222. + bool check_type_consistency();
  11223. + void calculate_type_check_information();
  11224. + bool check_field_value_types();
  11225. + void clear_type_check_information();
  11226. + bool check_method_stacks();
  11227. + bool check_loaded_methods();
  11228. + bool check_method(methodOop method);
  11229. + static Symbol* signature_to_class_name(Symbol* signature);
  11230. +
  11231. + void method_forwarding();
  11232. +
  11233. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11234. // Modifiable test must be shared between IsModifiableClass query
  11235. // and redefine implementation
  11236. static bool is_modifiable_class(oop klass_mirror);
  11237. +
  11238. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11239. + void oops_do(OopClosure* f);
  11240. +
  11241. + // Utility methods for transferring field access flags
  11242. +
  11243. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11244. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11245. +
  11246. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11247. +
  11248. + void lock_threads();
  11249. + void unlock_threads();
  11250. +
  11251. + template <class T> static void do_oop_work(T* p);
  11252. +
  11253. + static void swap_marks(oop first, oop second);
  11254. +
  11255. };
  11256. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11257. +
  11258. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  11259. index 60eaf97..07bb6e3 100644
  11260. --- a/src/share/vm/prims/methodComparator.cpp
  11261. +++ b/src/share/vm/prims/methodComparator.cpp
  11262. @@ -65,6 +65,7 @@
  11263. if (! args_same(c_old, c_new))
  11264. return false;
  11265. }
  11266. +
  11267. return true;
  11268. }
  11269. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  11270. index 41fc42d..53b3e0c 100644
  11271. --- a/src/share/vm/prims/nativeLookup.cpp
  11272. +++ b/src/share/vm/prims/nativeLookup.cpp
  11273. @@ -35,6 +35,7 @@
  11274. #include "oops/symbol.hpp"
  11275. #include "prims/jvm_misc.hpp"
  11276. #include "prims/nativeLookup.hpp"
  11277. +#include "prims/jvmtiRedefineClasses.hpp"
  11278. #include "runtime/arguments.hpp"
  11279. #include "runtime/handles.inline.hpp"
  11280. #include "runtime/javaCalls.hpp"
  11281. @@ -52,7 +53,6 @@
  11282. #ifdef TARGET_OS_FAMILY_bsd
  11283. # include "os_bsd.inline.hpp"
  11284. #endif
  11285. -
  11286. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11287. char* bytes = (char*)name->bytes() + begin;
  11288. @@ -138,6 +138,40 @@
  11289. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  11290. };
  11291. +// Helper function to call redefineClasses from Java Code
  11292. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11293. + ResourceMark rm(THREAD);
  11294. +
  11295. + JavaThread* current_thread = JavaThread::current();
  11296. + jbyte* bytecodes = NULL;
  11297. + const int class_count = 1;
  11298. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11299. +
  11300. + {
  11301. + ThreadToNativeFromVM ttnfv(thread);
  11302. + jboolean is_copy = JNI_FALSE;
  11303. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11304. + class_definitions[0].klass = target;
  11305. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11306. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11307. + }
  11308. +
  11309. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11310. + VMThread::execute(&op);
  11311. + int result = op.check_error();
  11312. +
  11313. + {
  11314. + ThreadToNativeFromVM ttnfv(thread);
  11315. + if (env->ExceptionOccurred()) {
  11316. + return -1;
  11317. + }
  11318. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11319. + }
  11320. +
  11321. + return result;
  11322. +JVM_END
  11323. +
  11324. +
  11325. static address lookup_special_native(char* jni_name) {
  11326. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11327. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11328. @@ -177,6 +211,9 @@
  11329. return entry;
  11330. }
  11331. }
  11332. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11333. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11334. + }
  11335. // Otherwise call static method findNative in ClassLoader
  11336. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11337. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  11338. index 02971ac..8e55430 100644
  11339. --- a/src/share/vm/runtime/arguments.cpp
  11340. +++ b/src/share/vm/runtime/arguments.cpp
  11341. @@ -1831,6 +1831,15 @@
  11342. status = false;
  11343. }
  11344. + // (tw) Must use serial GC
  11345. + if (!UseSerialGC && i >= 1) {
  11346. + jio_fprintf(defaultStream::error_stream(),
  11347. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11348. + status = false;
  11349. + } else {
  11350. + UseSerialGC = true;
  11351. + }
  11352. +
  11353. return status;
  11354. }
  11355. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  11356. index 2b767d4..e9b6f47 100644
  11357. --- a/src/share/vm/runtime/deoptimization.cpp
  11358. +++ b/src/share/vm/runtime/deoptimization.cpp
  11359. @@ -599,6 +599,38 @@
  11360. // Cleanup thread deopt data
  11361. cleanup_deopt_info(thread, array);
  11362. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11363. + {
  11364. + ResourceMark res_mark;
  11365. +
  11366. + // Verify that the just-unpacked frames match the interpreter's
  11367. + // notions of expression stack and locals
  11368. + vframeArray* cur_array = thread->vframe_array_last();
  11369. + RegisterMap rm(thread, false);
  11370. + rm.set_include_argument_oops(false);
  11371. + for (int i = 0; i < cur_array->frames(); i++) {
  11372. + vframeArrayElement* el = cur_array->element(i);
  11373. + frame* frame = el->iframe();
  11374. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11375. + RegisterMap reg_map(thread);
  11376. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11377. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11378. + methodOop method = iframe->method();
  11379. + int bci = iframe->bci();
  11380. + method = method->newest_version();
  11381. + iframe->set_method(method, bci);
  11382. +
  11383. + methodOop forward_method = method->forward_method();
  11384. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11385. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11386. + if (TraceRedefineClasses >= 2) {
  11387. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  11388. + }
  11389. + iframe->set_method(forward_method, new_bci);
  11390. + }
  11391. + }
  11392. + }
  11393. +
  11394. #ifndef PRODUCT
  11395. if (VerifyStack) {
  11396. ResourceMark res_mark;
  11397. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  11398. index aacd835..3772b3f 100644
  11399. --- a/src/share/vm/runtime/frame.cpp
  11400. +++ b/src/share/vm/runtime/frame.cpp
  11401. @@ -408,6 +408,12 @@
  11402. *interpreter_frame_method_addr() = method;
  11403. }
  11404. +// (tw) Sets constant pool cache oop
  11405. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11406. + assert(is_interpreted_frame(), "interpreted frame expected");
  11407. + *interpreter_frame_cache_addr() = cp;
  11408. +}
  11409. +
  11410. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11411. assert(is_interpreted_frame(), "Not an interpreted frame");
  11412. if (ProfileInterpreter) {
  11413. @@ -423,19 +429,27 @@
  11414. // The bcx was just converted from bci to bcp.
  11415. // Convert the mdx in parallel.
  11416. methodDataOop mdo = interpreter_frame_method()->method_data();
  11417. - assert(mdo != NULL, "");
  11418. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11419. - address mdp = mdo->di_to_dp(mdi);
  11420. - interpreter_frame_set_mdx((intptr_t)mdp);
  11421. + if (mdo == NULL) {
  11422. + interpreter_frame_set_mdx(0);
  11423. + } else {
  11424. + assert(mdo != NULL, "");
  11425. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11426. + address mdp = mdo->di_to_dp(mdi);
  11427. + interpreter_frame_set_mdx((intptr_t)mdp);
  11428. + }
  11429. }
  11430. } else {
  11431. if (is_now_bci) {
  11432. // The bcx was just converted from bcp to bci.
  11433. // Convert the mdx in parallel.
  11434. methodDataOop mdo = interpreter_frame_method()->method_data();
  11435. - assert(mdo != NULL, "");
  11436. - int mdi = mdo->dp_to_di((address)mdx);
  11437. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11438. + if (mdo == NULL) {
  11439. + interpreter_frame_set_mdx(0);
  11440. + } else {
  11441. + assert(mdo != NULL, "");
  11442. + int mdi = mdo->dp_to_di((address)mdx);
  11443. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11444. + }
  11445. }
  11446. }
  11447. }
  11448. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  11449. index 9c7bb72..04a6595 100644
  11450. --- a/src/share/vm/runtime/frame.hpp
  11451. +++ b/src/share/vm/runtime/frame.hpp
  11452. @@ -346,6 +346,7 @@
  11453. // Method & constant pool cache
  11454. methodOop interpreter_frame_method() const;
  11455. void interpreter_frame_set_method(methodOop method);
  11456. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11457. methodOop* interpreter_frame_method_addr() const;
  11458. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11459. #ifdef PPC
  11460. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  11461. index bf8b9d0..4775f3d 100644
  11462. --- a/src/share/vm/runtime/globals.hpp
  11463. +++ b/src/share/vm/runtime/globals.hpp
  11464. @@ -1227,9 +1227,23 @@
  11465. product(bool, StressLdcRewrite, false, \
  11466. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11467. \
  11468. + product(bool, UseMethodForwardPoints, false, \
  11469. + "Use method forward points") \
  11470. + \
  11471. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11472. + "Maximum number of locals in forwarding method") \
  11473. + \
  11474. + product(intx, MethodForwardPointsMaxStack, 300, \
  11475. + "Maximum number of stack slots in forwarding method") \
  11476. + \
  11477. product(intx, TraceRedefineClasses, 0, \
  11478. "Trace level for JVMTI RedefineClasses") \
  11479. \
  11480. + product(bool, TimeRedefineClasses, false, \
  11481. + "Measure timing for JVMTI RedefineClasses") \
  11482. + \
  11483. + product(bool, AllowAdvancedClassRedefinition, true, \
  11484. + "Allow advanced class redefinition beyond swapping method bodies")\
  11485. develop(bool, StressMethodComparator, false, \
  11486. "run the MethodComparator on all loaded methods") \
  11487. \
  11488. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  11489. index 2875ee0..61fd8fe 100644
  11490. --- a/src/share/vm/runtime/interfaceSupport.hpp
  11491. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  11492. @@ -296,7 +296,7 @@
  11493. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11494. // We are leaving the VM at this point and going directly to native code.
  11495. // Block, if we are in the middle of a safepoint synchronization.
  11496. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11497. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11498. thread->frame_anchor()->make_walkable(thread);
  11499. trans_and_fence(_thread_in_vm, _thread_in_native);
  11500. // Check for pending. async. exceptions or suspends.
  11501. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11502. index edbba98..4a27925 100644
  11503. --- a/src/share/vm/runtime/javaCalls.cpp
  11504. +++ b/src/share/vm/runtime/javaCalls.cpp
  11505. @@ -60,7 +60,7 @@
  11506. bool clear_pending_exception = true;
  11507. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11508. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11509. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11510. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11511. _result = result;
  11512. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11513. index 3cbcaca..30839d7 100644
  11514. --- a/src/share/vm/runtime/jniHandles.cpp
  11515. +++ b/src/share/vm/runtime/jniHandles.cpp
  11516. @@ -112,6 +112,10 @@
  11517. }
  11518. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11519. + if (mh->newest_version() != mh()) {
  11520. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11521. + return (jmethodID) make_weak_global(mh_new);
  11522. + }
  11523. return (jmethodID) make_weak_global(mh);
  11524. }
  11525. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11526. index 2095237..c541434 100644
  11527. --- a/src/share/vm/runtime/mutex.cpp
  11528. +++ b/src/share/vm/runtime/mutex.cpp
  11529. @@ -1227,7 +1227,7 @@
  11530. // in increasing rank order (modulo any native ranks)
  11531. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11532. if (tmp->next() != NULL) {
  11533. - assert(tmp->rank() == Mutex::native ||
  11534. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11535. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11536. }
  11537. }
  11538. @@ -1247,7 +1247,7 @@
  11539. // in increasing rank order (modulo any native ranks)
  11540. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11541. if (tmp->next() != NULL) {
  11542. - assert(tmp->rank() == Mutex::native ||
  11543. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11544. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11545. }
  11546. }
  11547. @@ -1310,6 +1310,7 @@
  11548. // already hold Terminator_lock - may happen because of periodic safepoints
  11549. if (this->rank() != Mutex::native &&
  11550. this->rank() != Mutex::suspend_resume &&
  11551. + this->rank() != Mutex::redefine_classes &&
  11552. locks != NULL && locks->rank() <= this->rank() &&
  11553. !SafepointSynchronize::is_at_safepoint() &&
  11554. this != Interrupt_lock &&
  11555. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11556. index 7d2cd82..11eb32e 100644
  11557. --- a/src/share/vm/runtime/mutex.hpp
  11558. +++ b/src/share/vm/runtime/mutex.hpp
  11559. @@ -109,7 +109,8 @@
  11560. barrier = safepoint + 1,
  11561. nonleaf = barrier + 1,
  11562. max_nonleaf = nonleaf + 900,
  11563. - native = max_nonleaf + 1
  11564. + native = max_nonleaf + 1,
  11565. + redefine_classes = native + 1
  11566. };
  11567. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11568. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11569. index 77fddef..9d453d4 100644
  11570. --- a/src/share/vm/runtime/mutexLocker.cpp
  11571. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11572. @@ -49,6 +49,7 @@
  11573. // Consider using GCC's __read_mostly.
  11574. Mutex* Patching_lock = NULL;
  11575. +Mutex* RedefineClasses_lock = NULL;
  11576. Monitor* SystemDictionary_lock = NULL;
  11577. Mutex* PackageTable_lock = NULL;
  11578. Mutex* CompiledIC_lock = NULL;
  11579. @@ -91,6 +92,7 @@
  11580. Mutex* DirtyCardQ_FL_lock = NULL;
  11581. Monitor* DirtyCardQ_CBL_mon = NULL;
  11582. Mutex* Shared_DirtyCardQ_lock = NULL;
  11583. +Monitor* RedefinitionSync_lock = NULL;
  11584. Mutex* ParGCRareEvent_lock = NULL;
  11585. Mutex* EvacFailureStack_lock = NULL;
  11586. Mutex* DerivedPointerTableGC_lock = NULL;
  11587. @@ -208,6 +210,7 @@
  11588. def(HotCardCache_lock , Mutex , special , true );
  11589. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11590. }
  11591. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11592. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11593. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11594. def(CodeCache_lock , Mutex , special, true );
  11595. @@ -283,6 +286,7 @@
  11596. def(Debug3_lock , Mutex , nonleaf+4, true );
  11597. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11598. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11599. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11600. #ifdef INCLUDE_TRACE
  11601. def(JfrMsg_lock , Monitor, leaf, true);
  11602. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11603. index a6549b1..089ed11 100644
  11604. --- a/src/share/vm/runtime/mutexLocker.hpp
  11605. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11606. @@ -43,6 +43,8 @@
  11607. // Mutexes used in the VM.
  11608. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11609. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11610. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11611. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11612. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11613. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11614. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11615. index 1665d93..6baabba 100644
  11616. --- a/src/share/vm/runtime/reflection.cpp
  11617. +++ b/src/share/vm/runtime/reflection.cpp
  11618. @@ -468,7 +468,8 @@
  11619. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11620. if ( JDK_Version::is_gte_jdk14x_version()
  11621. && UseNewReflection
  11622. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11623. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11624. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11625. return true;
  11626. }
  11627. @@ -519,6 +520,12 @@
  11628. AccessFlags access,
  11629. bool classloader_only,
  11630. bool protected_restriction) {
  11631. +
  11632. + // (tw) Decide accessibility based on active version
  11633. + if (current_class != NULL) {
  11634. + current_class = current_class->klass_part()->active_version();
  11635. + }
  11636. +
  11637. // Verify that current_class can access a field of field_class, where that
  11638. // field's access bits are "access". We assume that we've already verified
  11639. // that current_class can access field_class.
  11640. @@ -560,7 +567,8 @@
  11641. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11642. if ( JDK_Version::is_gte_jdk14x_version()
  11643. && UseNewReflection
  11644. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11645. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11646. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11647. return true;
  11648. }
  11649. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11650. index 709d783..e0e19b1 100644
  11651. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11652. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11653. @@ -1137,7 +1137,20 @@
  11654. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11655. int retry_count = 0;
  11656. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11657. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11658. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11659. +
  11660. + // DCEVM: If we are executing an old method, this is OK!
  11661. + {
  11662. + ResourceMark rm(thread);
  11663. + RegisterMap cbl_map(thread, false);
  11664. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11665. +
  11666. + CodeBlob* caller_cb = caller_frame.cb();
  11667. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11668. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11669. + if (caller_nm->method()->is_old()) break;
  11670. + }
  11671. +
  11672. // If has a pending exception then there is no need to re-try to
  11673. // resolve this method.
  11674. // If the method has been redefined, we need to try again.
  11675. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11676. index f3acf4d..ea61cae 100644
  11677. --- a/src/share/vm/runtime/thread.cpp
  11678. +++ b/src/share/vm/runtime/thread.cpp
  11679. @@ -216,6 +216,8 @@
  11680. set_self_raw_id(0);
  11681. set_lgrp_id(-1);
  11682. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11683. +
  11684. // allocated data structures
  11685. set_osthread(NULL);
  11686. set_resource_area(new (mtThread)ResourceArea());
  11687. @@ -249,6 +251,7 @@
  11688. omFreeProvision = 32 ;
  11689. omInUseList = NULL ;
  11690. omInUseCount = 0 ;
  11691. + _pretend_new_universe = false;
  11692. #ifdef ASSERT
  11693. _visited_for_critical_count = false;
  11694. @@ -880,6 +883,15 @@
  11695. bool Thread::owns_locks_but_compiled_lock() const {
  11696. for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11697. if (cur != Compile_lock) return true;
  11698. + }
  11699. + return false;
  11700. +}
  11701. +
  11702. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11703. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11704. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11705. + return true;
  11706. + }
  11707. }
  11708. return false;
  11709. }
  11710. @@ -1637,7 +1649,7 @@
  11711. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11712. assert(JavaThread::current() == this, "sanity check");
  11713. - assert(!Thread::current()->owns_locks(), "sanity check");
  11714. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11715. DTRACE_THREAD_PROBE(start, this);
  11716. @@ -3193,7 +3205,7 @@
  11717. // Create a CompilerThread
  11718. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11719. -: JavaThread(&compiler_thread_entry) {
  11720. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11721. _env = NULL;
  11722. _log = NULL;
  11723. _task = NULL;
  11724. @@ -3201,6 +3213,7 @@
  11725. _counters = counters;
  11726. _buffer_blob = NULL;
  11727. _scanned_nmethod = NULL;
  11728. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11729. #ifndef PRODUCT
  11730. _ideal_graph_printer = NULL;
  11731. @@ -3230,6 +3243,7 @@
  11732. int Threads::_number_of_non_daemon_threads = 0;
  11733. int Threads::_return_code = 0;
  11734. size_t JavaThread::_stack_size_at_create = 0;
  11735. +bool Threads::_wait_at_instrumentation_entry = false;
  11736. // All JavaThreads
  11737. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11738. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11739. index 774bd27..4ca4502 100644
  11740. --- a/src/share/vm/runtime/thread.hpp
  11741. +++ b/src/share/vm/runtime/thread.hpp
  11742. @@ -203,10 +203,13 @@
  11743. void enter_signal_handler() { _num_nested_signal++; }
  11744. void leave_signal_handler() { _num_nested_signal--; }
  11745. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11746. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11747. private:
  11748. // Debug tracing
  11749. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11750. +
  11751. + Mutex* _redefine_classes_mutex;
  11752. // Active_handles points to a block of handles
  11753. JNIHandleBlock* _active_handles;
  11754. @@ -530,10 +533,15 @@
  11755. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11756. int _lgrp_id;
  11757. +
  11758. + bool _pretend_new_universe;
  11759. +
  11760. public:
  11761. // Stack overflow support
  11762. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11763. + 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; } }
  11764. + bool pretend_new_universe() { return _pretend_new_universe; }
  11765. void set_stack_base(address base) { _stack_base = base; }
  11766. size_t stack_size() const { return _stack_size; }
  11767. void set_stack_size(size_t size) { _stack_size = size; }
  11768. @@ -570,6 +578,7 @@
  11769. void print_owned_locks() const { print_owned_locks_on(tty); }
  11770. Monitor* owned_locks() const { return _owned_locks; }
  11771. bool owns_locks() const { return owned_locks() != NULL; }
  11772. + bool owns_locks_but_redefine_classes_lock() const;
  11773. bool owns_locks_but_compiled_lock() const;
  11774. // Deadlock detection
  11775. @@ -1793,6 +1802,8 @@
  11776. CompileTask* _task;
  11777. CompileQueue* _queue;
  11778. BufferBlob* _buffer_blob;
  11779. + bool _should_bailout;
  11780. + Mutex* _compilation_mutex;
  11781. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11782. @@ -1802,12 +1813,16 @@
  11783. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11784. + bool should_bailout() const { return _should_bailout; }
  11785. + void set_should_bailout(bool b) { _should_bailout = false; }
  11786. +
  11787. bool is_Compiler_thread() const { return true; }
  11788. // Hide this compiler thread from external view.
  11789. bool is_hidden_from_external_view() const { return true; }
  11790. CompileQueue* queue() { return _queue; }
  11791. CompilerCounters* counters() { return _counters; }
  11792. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11793. // Get/set the thread's compilation environment.
  11794. ciEnv* env() { return _env; }
  11795. @@ -1862,6 +1877,7 @@
  11796. static int _number_of_threads;
  11797. static int _number_of_non_daemon_threads;
  11798. static int _return_code;
  11799. + static bool _wait_at_instrumentation_entry;
  11800. public:
  11801. // Thread management
  11802. @@ -1873,6 +1889,9 @@
  11803. static JavaThread* first() { return _thread_list; }
  11804. static void threads_do(ThreadClosure* tc);
  11805. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11806. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11807. +
  11808. // Initializes the vm and creates the vm thread
  11809. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11810. static void convert_vm_init_libraries_to_agents();
  11811. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11812. index 09e324f..d47ffef 100644
  11813. --- a/src/share/vm/runtime/vframe.cpp
  11814. +++ b/src/share/vm/runtime/vframe.cpp
  11815. @@ -253,6 +253,46 @@
  11816. return fr().interpreter_frame_method();
  11817. }
  11818. +// (tw) Sets interpreter frame method.
  11819. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11820. + methodOop old_method = fr().interpreter_frame_method();
  11821. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11822. + if (old_method == new_method) return;
  11823. + u_char *old_bcp = bcp();
  11824. + int old_bci = bci();
  11825. + fr().interpreter_frame_set_method(new_method);
  11826. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11827. + u_char *new_bcp = new_method->code_base() + new_bci;
  11828. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11829. +
  11830. + set_bcp(new_bcp);
  11831. +
  11832. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11833. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11834. +
  11835. + switch (code) {
  11836. + case Bytecodes::_invokevirtual :
  11837. + case Bytecodes::_invokespecial :
  11838. + case Bytecodes::_invokestatic :
  11839. + case Bytecodes::_invokeinterface: {
  11840. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11841. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11842. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11843. + break;
  11844. + }
  11845. +
  11846. + case Bytecodes::_invokedynamic: {
  11847. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11848. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11849. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11850. + break;
  11851. + }
  11852. + }
  11853. +
  11854. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11855. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11856. +}
  11857. +
  11858. StackValueCollection* interpretedVFrame::locals() const {
  11859. int length = method()->max_locals();
  11860. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11861. index badfea5..edbc5c7 100644
  11862. --- a/src/share/vm/runtime/vframe.hpp
  11863. +++ b/src/share/vm/runtime/vframe.hpp
  11864. @@ -163,6 +163,7 @@
  11865. StackValueCollection* locals() const;
  11866. StackValueCollection* expressions() const;
  11867. GrowableArray<MonitorInfo*>* monitors() const;
  11868. + void set_method(methodOop method, int new_bci);
  11869. void set_locals(StackValueCollection* values) const;
  11870. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11871. index 5ddcf26..213e678 100644
  11872. --- a/src/share/vm/runtime/vmThread.cpp
  11873. +++ b/src/share/vm/runtime/vmThread.cpp
  11874. @@ -691,6 +691,10 @@
  11875. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11876. Thread::oops_do(f, cf);
  11877. _vm_queue->oops_do(f);
  11878. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11879. + if (_cur_vm_operation != NULL) {
  11880. + _cur_vm_operation->oops_do(f);
  11881. + }
  11882. }
  11883. //------------------------------------------------------------------------------------------------------------------
  11884. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11885. index 03f254d..c9e0efc 100644
  11886. --- a/src/share/vm/utilities/exceptions.cpp
  11887. +++ b/src/share/vm/utilities/exceptions.cpp
  11888. @@ -254,6 +254,8 @@
  11889. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11890. assert(!thread->has_pending_exception(), "already has exception");
  11891. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11892. + Thread::current()->set_pretend_new_universe(false);
  11893. Handle h_exception;
  11894. // Resolve exception klass
  11895. @@ -285,6 +287,7 @@
  11896. h_exception = Handle(thread, thread->pending_exception());
  11897. thread->clear_pending_exception();
  11898. }
  11899. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11900. return h_exception;
  11901. }
  11902. @@ -295,6 +298,8 @@
  11903. Symbol* signature, JavaCallArguments *args,
  11904. Handle h_cause,
  11905. Handle h_loader, Handle h_protection_domain) {
  11906. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11907. + Thread::current()->set_pretend_new_universe(false);
  11908. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11909. // Future: object initializer should take a cause argument
  11910. @@ -317,6 +322,8 @@
  11911. h_exception = Handle(thread, thread->pending_exception());
  11912. thread->clear_pending_exception();
  11913. }
  11914. +
  11915. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11916. return h_exception;
  11917. }
  11918. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11919. index ea92a80..05e940e 100644
  11920. --- a/src/share/vm/utilities/growableArray.hpp
  11921. +++ b/src/share/vm/utilities/growableArray.hpp
  11922. @@ -145,6 +145,33 @@
  11923. assert(on_stack(), "fast ResourceObj path only");
  11924. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11925. }
  11926. +
  11927. +};
  11928. +
  11929. +template<class E, class F> class Pair : public StackObj
  11930. +{
  11931. +private:
  11932. + E _left;
  11933. + F _right;
  11934. +
  11935. +public:
  11936. +
  11937. + Pair() {
  11938. +
  11939. + }
  11940. +
  11941. + Pair(E left, F right) {
  11942. + this->_left = left;
  11943. + this->_right = right;
  11944. + }
  11945. +
  11946. + E left() {
  11947. + return _left;
  11948. + }
  11949. +
  11950. + F right() {
  11951. + return _right;
  11952. + }
  11953. };
  11954. template<class E> class GrowableArray : public GenericGrowableArray {