您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

full-jdk7u11-b21.patch 508KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875
  1. diff --git a/make/openjdk_distro b/make/openjdk_distro
  2. index 520b33d..ea7eff0 100644
  3. --- a/make/openjdk_distro
  4. +++ b/make/openjdk_distro
  5. @@ -27,6 +27,6 @@
  6. #
  7. # Don't put quotes (fail windows build).
  8. -HOTSPOT_VM_DISTRO=OpenJDK
  9. +HOTSPOT_VM_DISTRO=Dynamic Code Evolution
  10. COMPANY_NAME=
  11. PRODUCT_NAME=OpenJDK
  12. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  13. index 1cbc67e..2b22724 100644
  14. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  15. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  16. @@ -2109,6 +2109,22 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  17. // resolve first time through
  18. address entry;
  19. switch (bytecode()) {
  20. + case Bytecodes::_fast_agetfield : // fall through
  21. + case Bytecodes::_fast_bgetfield : // fall through
  22. + case Bytecodes::_fast_cgetfield : // fall through
  23. + case Bytecodes::_fast_dgetfield : // fall through
  24. + case Bytecodes::_fast_fgetfield : // fall through
  25. + case Bytecodes::_fast_igetfield : // fall through
  26. + case Bytecodes::_fast_lgetfield : // fall through
  27. + case Bytecodes::_fast_sgetfield : // fall through
  28. + case Bytecodes::_fast_aputfield : // fall through
  29. + case Bytecodes::_fast_bputfield : // fall through
  30. + case Bytecodes::_fast_cputfield : // fall through
  31. + case Bytecodes::_fast_dputfield : // fall through
  32. + case Bytecodes::_fast_fputfield : // fall through
  33. + case Bytecodes::_fast_iputfield : // fall through
  34. + case Bytecodes::_fast_lputfield : // fall through
  35. + case Bytecodes::_fast_sputfield : // fall through
  36. case Bytecodes::_getstatic : // fall through
  37. case Bytecodes::_putstatic : // fall through
  38. case Bytecodes::_getfield : // fall through
  39. @@ -2203,6 +2219,7 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  40. // Correct values of the cache and index registers are preserved.
  41. void TemplateTable::jvmti_post_field_access(Register cache,
  42. Register index,
  43. + int byte_no,
  44. bool is_static,
  45. bool has_tos) {
  46. if (JvmtiExport::can_post_field_access()) {
  47. @@ -2229,7 +2246,11 @@ void TemplateTable::jvmti_post_field_access(Register cache,
  48. // cache: cache entry pointer
  49. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  50. rax, cache);
  51. - __ get_cache_and_index_at_bcp(cache, index, 1);
  52. +
  53. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  54. + __ restore_bcp();
  55. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  56. +
  57. __ bind(L1);
  58. }
  59. }
  60. @@ -2250,7 +2271,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  61. const Register flags = rax;
  62. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  63. - jvmti_post_field_access(cache, index, is_static, false);
  64. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  65. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  66. if (!is_static) pop_and_check_object(obj);
  67. @@ -2385,7 +2406,7 @@ void TemplateTable::getstatic(int byte_no) {
  68. // The registers cache and index expected to be set before call.
  69. // The function may destroy various registers, just not the cache and index registers.
  70. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  71. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  72. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  73. @@ -2443,7 +2464,11 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  74. // rcx: jvalue object on the stack
  75. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  76. rbx, rax, rcx);
  77. - __ get_cache_and_index_at_bcp(cache, index, 1);
  78. +
  79. + // (tw) Redefinition might have occured => reresolve the cp entry.
  80. + __ restore_bcp();
  81. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  82. +
  83. __ bind(L1);
  84. }
  85. }
  86. @@ -2459,7 +2484,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  87. const Register flags = rax;
  88. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  89. - jvmti_post_field_mod(cache, index, is_static);
  90. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  91. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  92. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  93. @@ -2697,6 +2722,11 @@ void TemplateTable::jvmti_post_fast_field_mod() {
  94. // rax,: cache entry pointer
  95. // rcx: jvalue object on the stack
  96. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  97. +
  98. + // (tw) Redefinition might have occured => reresolve the cp entry.
  99. + __ restore_bcp();
  100. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  101. +
  102. if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); // restore high value
  103. __ pop(rax); // restore lower value
  104. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  105. @@ -2817,6 +2847,11 @@ void TemplateTable::fast_accessfield(TosState state) {
  106. // rcx: cache entry pointer
  107. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  108. __ pop_ptr(rax); // restore object pointer
  109. +
  110. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  111. + __ restore_bcp();
  112. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  113. +
  114. __ bind(L1);
  115. }
  116. @@ -2987,6 +3022,26 @@ void TemplateTable::invokevirtual_helper(Register index, Register recv,
  117. __ bind(notFinal);
  118. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  119. + Label notOld;
  120. + __ movl(rax, flags);
  121. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  122. + __ jcc(Assembler::zero, notOld);
  123. +
  124. + // Need a null check here!
  125. + __ null_check(recv);
  126. +
  127. + // 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)
  128. + // DCEVM: TODO: Check if we can improve performance by inlining.
  129. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  130. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  131. +
  132. + // profile this call
  133. + __ profile_final_call(rax);
  134. + __ jump_from_interpreted(method, rdx);
  135. +
  136. + __ bind(notOld);
  137. +
  138. // get receiver klass
  139. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  140. // Keep recv in rcx for callee expects it there
  141. @@ -3068,6 +3123,31 @@ void TemplateTable::invokeinterface(int byte_no) {
  142. invokevirtual_helper(rbx, rcx, rdx);
  143. __ bind(notMethod);
  144. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  145. + //__ movl(rax, rdx);
  146. + Label notOld;
  147. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  148. + __ jcc(Assembler::zero, notOld);
  149. +
  150. + // Get receiver klass into rdx - also a null check
  151. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  152. + __ verify_oop(rdx);
  153. +
  154. + // 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)
  155. + // DCEVM: TODO: Check if we can improve performance by inlining.
  156. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  157. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  158. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  159. +
  160. + // DCEVM: TODO: Check if resolved method could be null.
  161. +
  162. + // profile this call
  163. + __ profile_virtual_call(rdx, rsi, rdi);
  164. +
  165. + __ jump_from_interpreted(rbx, rdx);
  166. +
  167. + __ bind(notOld);
  168. +
  169. // Get receiver klass into rdx - also a null check
  170. __ restore_locals(); // restore rdi
  171. __ load_klass(rdx, rcx);
  172. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  173. index 0e5ac27..c77a358 100644
  174. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  175. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  176. @@ -2145,6 +2145,22 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  177. // resolve first time through
  178. address entry;
  179. switch (bytecode()) {
  180. + case Bytecodes::_fast_agetfield : // fall through
  181. + case Bytecodes::_fast_bgetfield : // fall through
  182. + case Bytecodes::_fast_cgetfield : // fall through
  183. + case Bytecodes::_fast_dgetfield : // fall through
  184. + case Bytecodes::_fast_fgetfield : // fall through
  185. + case Bytecodes::_fast_igetfield : // fall through
  186. + case Bytecodes::_fast_lgetfield : // fall through
  187. + case Bytecodes::_fast_sgetfield : // fall through
  188. + case Bytecodes::_fast_aputfield : // fall through
  189. + case Bytecodes::_fast_bputfield : // fall through
  190. + case Bytecodes::_fast_cputfield : // fall through
  191. + case Bytecodes::_fast_dputfield : // fall through
  192. + case Bytecodes::_fast_fputfield : // fall through
  193. + case Bytecodes::_fast_iputfield : // fall through
  194. + case Bytecodes::_fast_lputfield : // fall through
  195. + case Bytecodes::_fast_sputfield : // fall through
  196. case Bytecodes::_getstatic:
  197. case Bytecodes::_putstatic:
  198. case Bytecodes::_getfield:
  199. @@ -2251,7 +2267,7 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  200. // The registers cache and index expected to be set before call.
  201. // Correct values of the cache and index registers are preserved.
  202. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  203. - bool is_static, bool has_tos) {
  204. + int byte_no, bool is_static, bool has_tos) {
  205. // do the JVMTI work here to avoid disturbing the register state below
  206. // We use c_rarg registers here because we want to use the register used in
  207. // the call to the VM
  208. @@ -2282,7 +2298,11 @@ void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  209. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  210. InterpreterRuntime::post_field_access),
  211. c_rarg1, c_rarg2, c_rarg3);
  212. - __ get_cache_and_index_at_bcp(cache, index, 1);
  213. +
  214. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  215. + __ restore_bcp();
  216. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  217. +
  218. __ bind(L1);
  219. }
  220. }
  221. @@ -2304,7 +2324,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  222. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  223. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  224. - jvmti_post_field_access(cache, index, is_static, false);
  225. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  226. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  227. if (!is_static) {
  228. @@ -2438,7 +2458,7 @@ void TemplateTable::getstatic(int byte_no) {
  229. // The registers cache and index expected to be set before call.
  230. // The function may destroy various registers, just not the cache and index registers.
  231. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  232. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  233. transition(vtos, vtos);
  234. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  235. @@ -2491,7 +2511,11 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  236. CAST_FROM_FN_PTR(address,
  237. InterpreterRuntime::post_field_modification),
  238. c_rarg1, c_rarg2, c_rarg3);
  239. - __ get_cache_and_index_at_bcp(cache, index, 1);
  240. +
  241. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  242. + __ restore_bcp();
  243. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  244. +
  245. __ bind(L1);
  246. }
  247. }
  248. @@ -2507,7 +2531,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  249. const Register bc = c_rarg3;
  250. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  251. - jvmti_post_field_mod(cache, index, is_static);
  252. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  253. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  254. // [jk] not needed currently
  255. @@ -2715,6 +2739,11 @@ void TemplateTable::jvmti_post_fast_field_mod() {
  256. CAST_FROM_FN_PTR(address,
  257. InterpreterRuntime::post_field_modification),
  258. rbx, c_rarg2, c_rarg3);
  259. +
  260. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  261. + __ restore_bcp();
  262. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  263. +
  264. __ pop(rax); // restore lower value
  265. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  266. __ bind(L2);
  267. @@ -2815,6 +2844,11 @@ void TemplateTable::fast_accessfield(TosState state) {
  268. InterpreterRuntime::post_field_access),
  269. c_rarg1, c_rarg2);
  270. __ pop_ptr(rax); // restore object pointer
  271. +
  272. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  273. + __ restore_bcp();
  274. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  275. +
  276. __ bind(L1);
  277. }
  278. @@ -3030,6 +3064,26 @@ void TemplateTable::invokevirtual_helper(Register index,
  279. __ bind(notFinal);
  280. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  281. + Label notOld;
  282. + __ movl(rax, flags);
  283. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  284. + __ jcc(Assembler::zero, notOld);
  285. +
  286. + // Need a null check here!
  287. + __ null_check(recv);
  288. +
  289. + // 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)
  290. + // DCEVM: TODO: Check if we can improve performance by inlining.
  291. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  292. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  293. +
  294. + // profile this call
  295. + __ profile_final_call(rax);
  296. + __ jump_from_interpreted(method, rdx);
  297. +
  298. + __ bind(notOld);
  299. +
  300. // get receiver klass
  301. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  302. __ load_klass(rax, recv);
  303. @@ -3113,6 +3167,35 @@ void TemplateTable::invokeinterface(int byte_no) {
  304. invokevirtual_helper(rbx, rcx, rdx);
  305. __ bind(notMethod);
  306. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  307. + Label notOld;
  308. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  309. + __ jcc(Assembler::zero, notOld);
  310. +
  311. + // 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)
  312. + // DCEVM: TODO: Check if we can improve performance by inlining.
  313. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  314. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  315. + // DCEVM: FIXME: What exactly should we store here?
  316. + __ push(rcx); // destroyed by Linux arguments passing conventions
  317. + __ movptr(r14, rcx);
  318. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  319. + __ pop(rcx);
  320. +
  321. + // Get receiver klass into rdx - also a null check
  322. + __ restore_locals(); // restore r14
  323. + __ load_klass(rdx, rcx);
  324. + __ verify_oop(rdx);
  325. +
  326. + // DCEVM: TODO: Check if resolved method could be null.
  327. +
  328. + // profile this call
  329. + __ profile_virtual_call(rdx, r13, r14);
  330. +
  331. + __ jump_from_interpreted(rbx, rdx);
  332. +
  333. + __ bind(notOld);
  334. +
  335. // Get receiver klass into rdx - also a null check
  336. __ restore_locals(); // restore r14
  337. __ load_klass(rdx, rcx);
  338. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  339. index 376b6f3..e01d3c7 100644
  340. --- a/src/share/vm/c1/c1_Compilation.hpp
  341. +++ b/src/share/vm/c1/c1_Compilation.hpp
  342. @@ -239,8 +239,8 @@ class Compilation: public StackObj {
  343. #define BAILOUT(msg) { bailout(msg); return; }
  344. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  345. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  346. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  347. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  348. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  349. class InstructionMark: public StackObj {
  350. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  351. index 1366177..b01c003 100644
  352. --- a/src/share/vm/ci/ciEnv.cpp
  353. +++ b/src/share/vm/ci/ciEnv.cpp
  354. @@ -1181,3 +1181,11 @@ void ciEnv::record_out_of_memory_failure() {
  355. // If memory is low, we stop compiling methods.
  356. record_method_not_compilable("out of memory");
  357. }
  358. +
  359. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  360. +void ciEnv::cleanup_after_redefinition() {
  361. +
  362. + if (_factory != NULL) {
  363. + _factory->cleanup_after_redefinition();
  364. + }
  365. +}
  366. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  367. index d00c9f7..ca6dace 100644
  368. --- a/src/share/vm/ci/ciEnv.hpp
  369. +++ b/src/share/vm/ci/ciEnv.hpp
  370. @@ -419,6 +419,8 @@ public:
  371. void record_failure(const char* reason);
  372. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  373. void record_out_of_memory_failure();
  374. +
  375. + void cleanup_after_redefinition();
  376. };
  377. #endif // SHARE_VM_CI_CIENV_HPP
  378. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  379. index 9aa6b26..fbbd0be 100644
  380. --- a/src/share/vm/ci/ciObjectFactory.cpp
  381. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  382. @@ -294,6 +294,11 @@ ciObject* ciObjectFactory::get(oop key) {
  383. // into the table. We need to recompute our index.
  384. index = find(keyHandle(), _ci_objects);
  385. }
  386. +
  387. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  388. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  389. + return _ci_objects->at(index);
  390. + }
  391. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  392. insert(index, new_object, _ci_objects);
  393. return new_object;
  394. @@ -758,3 +763,50 @@ void ciObjectFactory::print() {
  395. _unloaded_instances->length(),
  396. _unloaded_klasses->length());
  397. }
  398. +
  399. +// DCEVM: Resoring the ciObject arrays after class redefinition
  400. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  401. +
  402. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  403. + oop last = NULL;
  404. + for (int j = 0; j< objects->length(); j++) {
  405. + oop o = objects->at(j)->get_oop();
  406. + if (last >= o) {
  407. + int cur_last_index = j - 1;
  408. + oop cur_last = last;
  409. + while (cur_last >= o) {
  410. +
  411. + // Swap the two objects to guarantee ordering
  412. + ciObject *tmp = objects->at(cur_last_index);
  413. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  414. + objects->at_put(cur_last_index + 1, tmp);
  415. +
  416. + // Decrement index to move one step to the left
  417. + cur_last_index--;
  418. + if (cur_last_index < 0) {
  419. + break;
  420. + }
  421. + cur_last = objects->at(cur_last_index)->get_oop();
  422. + }
  423. + } else {
  424. + assert(last < o, "out of order");
  425. + last = o;
  426. + }
  427. + }
  428. +
  429. +#ifdef ASSERT
  430. + if (CIObjectFactoryVerify) {
  431. + oop last = NULL;
  432. + for (int j = 0; j< objects->length(); j++) {
  433. + oop o = objects->at(j)->get_oop();
  434. + assert(last < o, "out of order");
  435. + last = o;
  436. + }
  437. + }
  438. +#endif // ASSERT
  439. +}
  440. +
  441. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  442. +void ciObjectFactory::cleanup_after_redefinition() {
  443. + sort_ci_objects(_ci_objects);
  444. +}
  445. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  446. index 26cc2c3..855a4ac 100644
  447. --- a/src/share/vm/ci/ciObjectFactory.hpp
  448. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  449. @@ -38,6 +38,7 @@
  450. class ciObjectFactory : public ResourceObj {
  451. friend class VMStructs;
  452. friend class ciEnv;
  453. + friend class CompileBroker;
  454. private:
  455. static volatile bool _initialized;
  456. @@ -137,6 +138,11 @@ public:
  457. void print_contents();
  458. void print();
  459. +
  460. +private:
  461. +
  462. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  463. + void cleanup_after_redefinition();
  464. };
  465. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  466. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  467. index 83bd038..fc64571 100644
  468. --- a/src/share/vm/classfile/classFileParser.cpp
  469. +++ b/src/share/vm/classfile/classFileParser.cpp
  470. @@ -787,6 +787,7 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  471. Handle class_loader,
  472. Handle protection_domain,
  473. Symbol* class_name,
  474. + KlassHandle old_klass,
  475. TRAPS) {
  476. ClassFileStream* cfs = stream();
  477. assert(length > 0, "only called for length>0");
  478. @@ -805,6 +806,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  479. interface_index, CHECK_(nullHandle));
  480. if (cp->tag_at(interface_index).is_klass()) {
  481. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  482. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  483. + interf = KlassHandle(THREAD, interf->newest_version());
  484. + }
  485. } else {
  486. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  487. @@ -817,6 +821,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  488. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  489. unresolved_klass, class_loader, protection_domain,
  490. false, CHECK_(nullHandle));
  491. + if (!old_klass.is_null()) {
  492. + k = k->klass_part()->newest_version();
  493. + }
  494. interf = KlassHandle(THREAD, k);
  495. if (LinkWellKnownClasses) // my super type is well known to me
  496. @@ -1705,6 +1712,8 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  497. int runtime_invisible_parameter_annotations_length = 0;
  498. u1* annotation_default = NULL;
  499. int annotation_default_length = 0;
  500. + u2 code_section_table_length;
  501. + typeArrayHandle code_section_table;
  502. // Parse code and exceptions attribute
  503. u2 method_attributes_count = cfs->get_u2_fast();
  504. @@ -1874,6 +1883,24 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  505. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  506. stackmap_data = typeArrayHandle(THREAD, sm);
  507. parsed_stackmap_attribute = true;
  508. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  509. + int length = code_attribute_length;
  510. + int value_count = length / sizeof(u2);
  511. + int line_count = length / 3;
  512. + if (TraceRedefineClasses >= 3) {
  513. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  514. + }
  515. + code_section_table_length = value_count;
  516. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  517. + code_section_table->set_length(value_count);
  518. +
  519. + for (int i = 0; i < value_count; ++i) {
  520. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  521. + code_section_table->short_at_put(i, value);
  522. + if (TraceRedefineClasses >= 4) {
  523. + tty->print_cr("Code section table at %d: %d", i, value);
  524. + }
  525. + }
  526. } else {
  527. // Skip unknown attributes
  528. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  529. @@ -1994,6 +2021,18 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  530. }
  531. #endif
  532. + // DCEVM: TODO: Get a different solution for the problem of method forward
  533. + // points and variable sized interpreter frames.
  534. + if (UseMethodForwardPoints) {
  535. + if (max_stack > MethodForwardPointsMaxStack) {
  536. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  537. + }
  538. + if (max_locals > MethodForwardPointsMaxLocals) {
  539. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  540. + }
  541. + max_stack = MethodForwardPointsMaxStack;
  542. + max_locals = MethodForwardPointsMaxLocals;
  543. + }
  544. // Fill in code attribute information
  545. m->set_max_stack(max_stack);
  546. m->set_max_locals(max_locals);
  547. @@ -2008,6 +2047,8 @@ methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interf
  548. */
  549. m->set_exception_table(exception_handlers());
  550. + m->constMethod()->set_code_section_table(code_section_table());
  551. +
  552. // Copy byte codes
  553. m->set_code(code_start);
  554. @@ -2543,6 +2584,24 @@ void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instance
  555. "Invalid Deprecated classfile attribute length %u in class file %s",
  556. attribute_length, CHECK);
  557. }
  558. + // DCEVM: Check for deleted field attribute
  559. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  560. +
  561. + char field_redefinition_policy = cfs->get_u1_fast();
  562. + k->set_field_redefinition_policy(field_redefinition_policy);
  563. +
  564. + // DCEVM: Check for deleted static field attribute
  565. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  566. +
  567. + char static_field_redefinition_policy = cfs->get_u1_fast();
  568. + k->set_static_field_redefinition_policy(static_field_redefinition_policy);
  569. +
  570. + // DCEVM: Check for deleted method attribute
  571. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  572. +
  573. + char method_redefinition_policy = cfs->get_u1_fast();
  574. + k->set_method_redefinition_policy(method_redefinition_policy);
  575. +
  576. } else if (_major_version >= JAVA_1_5_VERSION) {
  577. if (tag == vmSymbols::tag_signature()) {
  578. if (attribute_length != 2) {
  579. @@ -2634,9 +2693,126 @@ typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annota
  580. }
  581. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  582. +// them in a growable array.
  583. +void ClassFileParser::findSuperSymbols(Symbol* name,
  584. + Handle class_loader,
  585. + Handle protection_domain,
  586. + KlassHandle old_klass,
  587. + GrowableArray<Symbol*> &handles,
  588. + TRAPS) {
  589. +
  590. + _cp_patches = NULL;
  591. + // So that JVMTI can cache class file in the state before retransformable agents
  592. + // have modified it
  593. + unsigned char *cached_class_file_bytes = NULL;
  594. +
  595. + ClassFileStream* cfs = stream();
  596. +
  597. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  598. +
  599. + instanceKlassHandle nullHandle;
  600. +
  601. + // Save the class file name for easier error message printing.
  602. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  603. +
  604. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  605. + // Magic value
  606. + u4 magic = cfs->get_u4_fast();
  607. + if (magic != JAVA_CLASSFILE_MAGIC) {
  608. + // Invalid class file!
  609. + return;
  610. + }
  611. +
  612. + // Version numbers
  613. + u2 minor_version = cfs->get_u2_fast();
  614. + u2 major_version = cfs->get_u2_fast();
  615. +
  616. + // Check version numbers - we check this even with verifier off
  617. + if (!is_supported_version(major_version, minor_version)) {
  618. +
  619. + // Unsupported version!
  620. + return;
  621. + }
  622. +
  623. + _major_version = major_version;
  624. + _minor_version = minor_version;
  625. +
  626. +
  627. + // Check if verification needs to be relaxed for this class file
  628. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  629. + _relax_verify = Verifier::relax_verify_for(class_loader());
  630. + _need_verify = false;
  631. +
  632. + // Constant pool
  633. + constantPoolHandle cp = parse_constant_pool(CHECK);
  634. + int cp_size = cp->length();
  635. +
  636. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  637. +
  638. + // Access flags
  639. + AccessFlags access_flags;
  640. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  641. +
  642. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  643. + // Set abstract bit for old class files for backward compatibility
  644. + flags |= JVM_ACC_ABSTRACT;
  645. + }
  646. + access_flags.set_flags(flags);
  647. +
  648. + // This class and superclass
  649. + instanceKlassHandle super_klass;
  650. + u2 this_class_index = cfs->get_u2_fast();
  651. + check_property(
  652. + valid_cp_range(this_class_index, cp_size) &&
  653. + cp->tag_at(this_class_index).is_unresolved_klass(),
  654. + "Invalid this class index %u in constant pool in class file %s",
  655. + this_class_index, CHECK);
  656. +
  657. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  658. + assert(class_name != NULL, "class_name can't be null");
  659. +
  660. + // Update _class_name which could be null previously to be class_name
  661. + _class_name = class_name;
  662. +
  663. + // DCEVM: DO NOT release all handles when parsing is done
  664. + {// HandleMark hm(THREAD);
  665. +
  666. + // Checks if name in class file matches requested name
  667. + if (name != NULL && class_name != name) {
  668. + return;
  669. + }
  670. +
  671. + u2 super_class_index = cfs->get_u2_fast();
  672. +
  673. + if (super_class_index != 0) {
  674. + Symbol* super_class = cp->klass_name_at(super_class_index);
  675. + handles.append(super_class);
  676. + } else {
  677. + // DCEVM: This redefinition must be for the Object class.
  678. + }
  679. +
  680. + // Interfaces
  681. + u2 itfs_len = cfs->get_u2_fast();
  682. + objArrayHandle local_interfaces;
  683. + if (itfs_len == 0) {
  684. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  685. + } else {
  686. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  687. + }
  688. +
  689. + for (int i=0; i<local_interfaces->length(); i++) {
  690. + oop o = local_interfaces->obj_at(i);
  691. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  692. + handles.append(interface_handle);
  693. + }
  694. + }
  695. +}
  696. +
  697. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  698. Handle class_loader,
  699. Handle protection_domain,
  700. + KlassHandle old_klass,
  701. KlassHandle host_klass,
  702. GrowableArray<Handle>* cp_patches,
  703. TempNewSymbol& parsed_name,
  704. @@ -2688,10 +2864,13 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  705. unsigned char* ptr = cfs->buffer();
  706. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  707. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  708. + Thread::current()->set_pretend_new_universe(false);
  709. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  710. &ptr, &end_ptr,
  711. &cached_class_file_bytes,
  712. &cached_class_file_length);
  713. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  714. if (ptr != cfs->buffer()) {
  715. // JVMTI agent has modified class file data.
  716. @@ -2847,7 +3026,11 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  717. // However, make sure it is not an array type.
  718. bool is_array = false;
  719. if (cp->tag_at(super_class_index).is_klass()) {
  720. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  721. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  722. + if (!old_klass.is_null()) {
  723. + resolved_klass = resolved_klass->klass_part()->newest_version();
  724. + }
  725. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  726. if (_need_verify)
  727. is_array = super_klass->oop_is_array();
  728. } else if (_need_verify) {
  729. @@ -2865,7 +3048,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  730. if (itfs_len == 0) {
  731. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  732. } else {
  733. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  734. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  735. }
  736. u2 java_fields_count = 0;
  737. @@ -2912,7 +3095,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  738. protection_domain,
  739. true,
  740. CHECK_(nullHandle));
  741. -
  742. + if (!old_klass.is_null()) {
  743. + k = k->klass_part()->newest_version();
  744. + }
  745. KlassHandle kh (THREAD, k);
  746. super_klass = instanceKlassHandle(THREAD, kh());
  747. if (LinkWellKnownClasses) // my super class is well known to me
  748. @@ -3303,6 +3488,19 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  749. rt = REF_NONE;
  750. } else {
  751. rt = super_klass->reference_type();
  752. +
  753. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  754. + if (name == vmSymbols::java_lang_ref_Reference()) {
  755. + rt = REF_OTHER;
  756. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  757. + rt = REF_SOFT;
  758. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  759. + rt = REF_WEAK;
  760. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  761. + rt = REF_FINAL;
  762. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  763. + rt = REF_PHANTOM;
  764. + }
  765. }
  766. // We can now create the basic klassOop for this klass
  767. @@ -3402,7 +3600,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  768. // Do final class setup
  769. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  770. - set_precomputed_flags(this_klass);
  771. + set_precomputed_flags(this_klass, old_klass);
  772. // reinitialize modifiers, using the InnerClasses attribute
  773. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  774. @@ -3425,6 +3623,10 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  775. // Allocate mirror and initialize static fields
  776. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  777. + if (rt == REF_OTHER) {
  778. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  779. + }
  780. +
  781. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  782. false /* not shared class */);
  783. @@ -3567,7 +3769,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  784. }
  785. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  786. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  787. klassOop super = k->super();
  788. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  789. @@ -3575,7 +3777,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  790. if (!_has_empty_finalizer) {
  791. if (_has_finalizer ||
  792. (super != NULL && super->klass_part()->has_finalizer())) {
  793. - k->set_has_finalizer();
  794. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  795. + k->set_has_finalizer();
  796. + }
  797. }
  798. }
  799. @@ -3591,7 +3795,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  800. // Check if this klass supports the java.lang.Cloneable interface
  801. if (SystemDictionary::Cloneable_klass_loaded()) {
  802. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  803. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  804. k->set_is_cloneable();
  805. }
  806. }
  807. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  808. index fef48eb..65453dd 100644
  809. --- a/src/share/vm/classfile/classFileParser.hpp
  810. +++ b/src/share/vm/classfile/classFileParser.hpp
  811. @@ -78,6 +78,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  812. Handle class_loader,
  813. Handle protection_domain,
  814. Symbol* class_name,
  815. + KlassHandle old_klass,
  816. TRAPS);
  817. // Field parsing
  818. @@ -151,7 +152,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  819. unsigned int nonstatic_oop_map_count,
  820. int* nonstatic_oop_offsets,
  821. unsigned int* nonstatic_oop_counts);
  822. - void set_precomputed_flags(instanceKlassHandle k);
  823. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  824. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  825. objArrayHandle local_ifs, TRAPS);
  826. @@ -263,21 +264,33 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  827. instanceKlassHandle parseClassFile(Symbol* name,
  828. Handle class_loader,
  829. Handle protection_domain,
  830. + KlassHandle old_klass,
  831. TempNewSymbol& parsed_name,
  832. bool verify,
  833. TRAPS) {
  834. KlassHandle no_host_klass;
  835. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  836. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  837. }
  838. instanceKlassHandle parseClassFile(Symbol* name,
  839. Handle class_loader,
  840. Handle protection_domain,
  841. + KlassHandle old_klass,
  842. KlassHandle host_klass,
  843. GrowableArray<Handle>* cp_patches,
  844. TempNewSymbol& parsed_name,
  845. bool verify,
  846. TRAPS);
  847. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  848. +
  849. + // DCEVM: Creates symbol handles for the super class and the interfaces
  850. + void findSuperSymbols(Symbol* name,
  851. + Handle class_loader,
  852. + Handle protection_domain,
  853. + KlassHandle old_klass,
  854. + GrowableArray<Symbol*> &handles,
  855. + TRAPS);
  856. +
  857. // Verifier checks
  858. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  859. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  860. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  861. index df42dc7..6c22530 100644
  862. --- a/src/share/vm/classfile/classLoader.cpp
  863. +++ b/src/share/vm/classfile/classLoader.cpp
  864. @@ -915,6 +915,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
  865. instanceKlassHandle result = parser.parseClassFile(h_name,
  866. class_loader,
  867. protection_domain,
  868. + KlassHandle(),
  869. parsed_name,
  870. false,
  871. CHECK_(h));
  872. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  873. index 4458f46..7b193db 100644
  874. --- a/src/share/vm/classfile/dictionary.cpp
  875. +++ b/src/share/vm/classfile/dictionary.cpp
  876. @@ -326,6 +326,21 @@ void Dictionary::classes_do(void f(klassOop)) {
  877. }
  878. }
  879. +
  880. +// DCEVM: Just the classes from defining class loaders
  881. +void Dictionary::classes_do(ObjectClosure *closure) {
  882. + for (int index = 0; index < table_size(); index++) {
  883. + for (DictionaryEntry* probe = bucket(index);
  884. + probe != NULL;
  885. + probe = probe->next()) {
  886. + klassOop k = probe->klass();
  887. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  888. + closure->do_object(k);
  889. + }
  890. + }
  891. + }
  892. +}
  893. +
  894. // Added for initialize_itable_for_klass to handle exceptions
  895. // Just the classes from defining class loaders
  896. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  897. @@ -433,6 +448,33 @@ void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
  898. add_entry(index, entry);
  899. }
  900. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  901. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  902. +
  903. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  904. + bool found = false;
  905. + for (int index = 0; index < table_size(); index++) {
  906. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  907. + if (entry->klass() == old_class()) {
  908. + entry->set_literal(k());
  909. + found = true;
  910. + }
  911. + }
  912. + }
  913. +
  914. + return found;
  915. +}
  916. +
  917. +// DCEVM: Undo previous updates to the system dictionary
  918. +void Dictionary::rollback_redefinition() {
  919. + for (int index = 0; index < table_size(); index++) {
  920. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  921. + if (entry->klass()->klass_part()->is_redefining()) {
  922. + entry->set_literal(entry->klass()->klass_part()->old_version());
  923. + }
  924. + }
  925. + }
  926. +}
  927. // This routine does not lock the system dictionary.
  928. //
  929. @@ -459,12 +501,22 @@ DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
  930. return NULL;
  931. }
  932. +// DCEVM: return old version if we are not in the new universe?
  933. +klassOop Dictionary::intercept_for_version(klassOop k) {
  934. + if (k == NULL) return k;
  935. +
  936. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  937. + return k->klass_part()->old_version();
  938. + }
  939. +
  940. + return k;
  941. +}
  942. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  943. Handle loader, Handle protection_domain, TRAPS) {
  944. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  945. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  946. - return entry->klass();
  947. + return intercept_for_version(entry->klass());
  948. } else {
  949. return NULL;
  950. }
  951. @@ -477,7 +529,7 @@ klassOop Dictionary::find_class(int index, unsigned int hash,
  952. assert (index == index_for(name, loader), "incorrect index?");
  953. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  954. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  955. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  956. }
  957. @@ -489,7 +541,7 @@ klassOop Dictionary::find_shared_class(int index, unsigned int hash,
  958. assert (index == index_for(name, Handle()), "incorrect index?");
  959. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  960. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  961. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  962. }
  963. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  964. index 98e0169..305e039 100644
  965. --- a/src/share/vm/classfile/dictionary.hpp
  966. +++ b/src/share/vm/classfile/dictionary.hpp
  967. @@ -73,6 +73,10 @@ public:
  968. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  969. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  970. +
  971. + void rollback_redefinition();
  972. +
  973. klassOop find_class(int index, unsigned int hash,
  974. Symbol* name, Handle loader);
  975. @@ -89,6 +93,7 @@ public:
  976. void classes_do(void f(klassOop, TRAPS), TRAPS);
  977. void classes_do(void f(klassOop, oop));
  978. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  979. + void classes_do(ObjectClosure *closure);
  980. void methods_do(void f(methodOop));
  981. @@ -105,6 +110,7 @@ public:
  982. bool do_unloading(BoolObjectClosure* is_alive);
  983. // Protection domains
  984. + static klassOop intercept_for_version(klassOop k);
  985. klassOop find(int index, unsigned int hash, Symbol* name,
  986. Handle loader, Handle protection_domain, TRAPS);
  987. bool is_valid_protection_domain(int index, unsigned int hash,
  988. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  989. index 0c452cf..94f3d3e 100644
  990. --- a/src/share/vm/classfile/javaClasses.cpp
  991. +++ b/src/share/vm/classfile/javaClasses.cpp
  992. @@ -1783,7 +1783,7 @@ Handle java_lang_reflect_Method::create(TRAPS) {
  993. klassOop klass = SystemDictionary::reflect_Method_klass();
  994. // This class is eagerly initialized during VM initialization, since we keep a refence
  995. // to one of the methods
  996. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  997. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  998. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  999. }
  1000. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1001. index 9ada298..ba5a60e 100644
  1002. --- a/src/share/vm/classfile/javaClasses.hpp
  1003. +++ b/src/share/vm/classfile/javaClasses.hpp
  1004. @@ -213,7 +213,6 @@ class java_lang_String : AllStatic {
  1005. class java_lang_Class : AllStatic {
  1006. friend class VMStructs;
  1007. -
  1008. private:
  1009. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1010. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1011. index 5e25e4c..c887547 100644
  1012. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1013. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1014. @@ -449,7 +449,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
  1015. if (k != NULL) {
  1016. // We found the class in the system dictionary, so we should
  1017. // make sure that the klassOop matches what we already have.
  1018. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1019. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1020. } else {
  1021. // If we don't find the class in the system dictionary, it
  1022. // has to be in the placeholders table.
  1023. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1024. index 60612f5..77f955f 100644
  1025. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1026. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1027. @@ -106,7 +106,7 @@ public:
  1028. klassOop klass() { return literal(); }
  1029. klassOop* klass_addr() { return literal_addr(); }
  1030. - void set_klass(klassOop k) { set_literal(k); }
  1031. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1032. LoaderConstraintEntry* next() {
  1033. return (LoaderConstraintEntry*)HashtableEntry<klassOop>::next();
  1034. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1035. index 0bdc16d..0f5ede5 100644
  1036. --- a/src/share/vm/classfile/systemDictionary.cpp
  1037. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1038. @@ -151,6 +151,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_load
  1039. // can return a null klass
  1040. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1041. }
  1042. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1043. return klass;
  1044. }
  1045. @@ -193,7 +194,8 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
  1046. // Forwards to resolve_instance_class_or_null
  1047. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1048. - assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
  1049. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1050. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL, "Can not load classes with the Compiler thread");
  1051. if (FieldType::is_array(class_name)) {
  1052. return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
  1053. } else if (FieldType::is_obj(class_name)) {
  1054. @@ -997,6 +999,7 @@ klassOop SystemDictionary::parse_stream(Symbol* class_name,
  1055. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1056. class_loader,
  1057. protection_domain,
  1058. + KlassHandle(),
  1059. host_klass,
  1060. cp_patches,
  1061. parsed_name,
  1062. @@ -1056,8 +1059,15 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1063. Handle protection_domain,
  1064. ClassFileStream* st,
  1065. bool verify,
  1066. + KlassHandle old_class,
  1067. TRAPS) {
  1068. + bool redefine_classes_locked = false;
  1069. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1070. + Thread::current()->redefine_classes_mutex()->lock();
  1071. + redefine_classes_locked = true;
  1072. + }
  1073. +
  1074. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1075. // or all classloaders with UnsyncloadClass do not acquire lock here
  1076. bool DoObjectLock = true;
  1077. @@ -1085,9 +1095,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1078. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1079. class_loader,
  1080. protection_domain,
  1081. + old_class,
  1082. parsed_name,
  1083. verify,
  1084. THREAD);
  1085. + if (!old_class.is_null() && !k.is_null()) {
  1086. + k->set_redefining(true);
  1087. + k->set_old_version(old_class());
  1088. + }
  1089. const char* pkg = "java/";
  1090. if (!HAS_PENDING_EXCEPTION &&
  1091. @@ -1122,13 +1137,18 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1092. // Add class just loaded
  1093. // If a class loader supports parallel classloading handle parallel define requests
  1094. // find_or_define_instance_class may return a different instanceKlass
  1095. - if (is_parallelCapable(class_loader)) {
  1096. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1097. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1098. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1099. } else {
  1100. - define_instance_class(k, THREAD);
  1101. + define_instance_class(k, old_class, THREAD);
  1102. }
  1103. }
  1104. + if (redefine_classes_locked) {
  1105. + Thread::current()->redefine_classes_mutex()->unlock();
  1106. + }
  1107. +
  1108. // If parsing the class file or define_instance_class failed, we
  1109. // need to remove the placeholder added on our behalf. But we
  1110. // must make sure parsed_name is valid first (it won't be if we had
  1111. @@ -1157,7 +1177,7 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1112. MutexLocker mu(SystemDictionary_lock, THREAD);
  1113. klassOop check = find_class(parsed_name, class_loader);
  1114. - assert(check == k(), "should be present in the dictionary");
  1115. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1116. klassOop check2 = find_class(h_name, h_loader);
  1117. assert(check == check2, "name inconsistancy in SystemDictionary");
  1118. @@ -1453,7 +1473,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
  1119. }
  1120. }
  1121. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1122. +void SystemDictionary::rollback_redefinition() {
  1123. + dictionary()->rollback_redefinition();
  1124. +}
  1125. +
  1126. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1127. Handle class_loader_h(THREAD, k->class_loader());
  1128. @@ -1480,13 +1504,23 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1129. Symbol* name_h = k->name();
  1130. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1131. int d_index = dictionary()->hash_to_index(d_hash);
  1132. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1133. +
  1134. + // DCEVM: Update version of the klassOop in the system dictionary
  1135. + // TODO: Check for thread safety!
  1136. + if (!old_class.is_null()) {
  1137. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1138. + assert (ok, "must have found old class and updated!");
  1139. + }
  1140. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1141. +
  1142. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1143. // Register class just loaded with class loader (placed in Vector)
  1144. // Note we do this before updating the dictionary, as this can
  1145. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1146. // class in the dictionary and will not update the class hierarchy).
  1147. - if (k->class_loader() != NULL) {
  1148. + // (tw) Only register if not redefining a class.
  1149. + if (k->class_loader() != NULL && old_class.is_null()) {
  1150. methodHandle m(THREAD, Universe::loader_addClass_method());
  1151. JavaValue result(T_VOID);
  1152. JavaCallArguments args(class_loader_h);
  1153. @@ -1512,8 +1546,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1154. }
  1155. k->eager_initialize(THREAD);
  1156. + // (tw) Only notify jvmti if not redefining a class.
  1157. // notify jvmti
  1158. - if (JvmtiExport::should_post_class_load()) {
  1159. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1160. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1161. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1162. @@ -1586,7 +1621,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
  1163. }
  1164. }
  1165. - define_instance_class(k, THREAD);
  1166. + define_instance_class(k, KlassHandle(), THREAD);
  1167. Handle linkage_exception = Handle(); // null handle
  1168. @@ -1716,6 +1751,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
  1169. Universe::flush_dependents_on(k);
  1170. }
  1171. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1172. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1173. + assert(k.not_null(), "just checking");
  1174. +
  1175. + k->remove_from_sibling_list();
  1176. +
  1177. + // TODO: Remove from interfaces.
  1178. +}
  1179. // ----------------------------------------------------------------------------
  1180. // GC support
  1181. @@ -1804,6 +1847,24 @@ void SystemDictionary::oops_do(OopClosure* f) {
  1182. }
  1183. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1184. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1185. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1186. + f->do_oop((oop*) &_well_known_klasses[k]);
  1187. + }
  1188. +
  1189. + {
  1190. + for (int i = 0; i < T_VOID+1; i++) {
  1191. + if (_box_klasses[i] != NULL) {
  1192. + assert(i >= T_BOOLEAN, "checking");
  1193. + f->do_oop((oop*) &_box_klasses[i]);
  1194. + }
  1195. + }
  1196. + }
  1197. +
  1198. + // TODO: Check if we need to call FilterFieldsMap
  1199. +}
  1200. +
  1201. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1202. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1203. f->do_oop((oop*) &_well_known_klasses[k]);
  1204. @@ -1836,6 +1897,11 @@ void SystemDictionary::classes_do(void f(klassOop)) {
  1205. dictionary()->classes_do(f);
  1206. }
  1207. +// (tw) Iterate over all classes in the dictionary.
  1208. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1209. + dictionary()->classes_do(closure);
  1210. +}
  1211. +
  1212. // Added for initialize_itable_for_klass
  1213. // Just the classes from defining class loaders
  1214. // Don't iterate over placeholders
  1215. @@ -1989,7 +2055,9 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) {
  1216. // Preload ref klasses and set reference types
  1217. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1218. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1219. +
  1220. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1221. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1222. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1223. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1224. @@ -2081,7 +2149,11 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
  1225. // also holds array classes
  1226. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1227. - if ((defining == true) || (k() != check)) {
  1228. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1229. + ResourceMark rm(Thread::current());
  1230. + 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());
  1231. + k()->print();
  1232. + check->print();
  1233. linkage_error = "loader (instance of %s): attempted duplicate class "
  1234. "definition for name: \"%s\"";
  1235. } else {
  1236. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1237. index 3abc505..db32aad 100644
  1238. --- a/src/share/vm/classfile/systemDictionary.hpp
  1239. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1240. @@ -276,7 +276,7 @@ public:
  1241. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1242. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1243. Handle protection_domain,
  1244. - ClassFileStream* st, bool verify, TRAPS);
  1245. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1246. // Lookup an already loaded class. If not found NULL is returned.
  1247. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1248. @@ -320,6 +320,8 @@ public:
  1249. // Iterate over all klasses in dictionary
  1250. // Just the classes from defining class loaders
  1251. static void classes_do(void f(klassOop));
  1252. + static void classes_do(ObjectClosure *closure);
  1253. + static void preloaded_classes_do(OopClosure *closure);
  1254. // Added for initialize_itable_for_klass to handle exceptions
  1255. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1256. // All classes, and their class loaders
  1257. @@ -427,6 +429,8 @@ public:
  1258. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1259. }
  1260. + static void rollback_redefinition();
  1261. +
  1262. public:
  1263. #define WK_KLASS_DECLARE(name, symbol, option) \
  1264. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1265. @@ -608,7 +612,7 @@ private:
  1266. // after waiting, but before reentering SystemDictionary_lock
  1267. // to preserve lock order semantics.
  1268. static void double_lock_wait(Handle lockObject, TRAPS);
  1269. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1270. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1271. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1272. Handle class_loader,
  1273. instanceKlassHandle k, TRAPS);
  1274. @@ -627,6 +631,11 @@ private:
  1275. // Setup link to hierarchy
  1276. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1277. +public:
  1278. +
  1279. + // Remove link to hierarchy
  1280. + static void remove_from_hierarchy(instanceKlassHandle k);
  1281. +
  1282. private:
  1283. // We pass in the hashtable index so we can calculate it outside of
  1284. // the SystemDictionary_lock.
  1285. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1286. index 905456a..fe6b80d 100644
  1287. --- a/src/share/vm/classfile/verifier.cpp
  1288. +++ b/src/share/vm/classfile/verifier.cpp
  1289. @@ -103,7 +103,7 @@ bool Verifier::relax_verify_for(oop loader) {
  1290. return !need_verify;
  1291. }
  1292. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1293. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1294. HandleMark hm;
  1295. ResourceMark rm(THREAD);
  1296. @@ -127,17 +127,19 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1297. split_verifier.verify_class(THREAD);
  1298. exception_name = split_verifier.result();
  1299. if (klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1300. - FailOverToOldVerifier && !HAS_PENDING_EXCEPTION &&
  1301. + FailOverToOldVerifier && may_use_old_verifier && !HAS_PENDING_EXCEPTION &&
  1302. (exception_name == vmSymbols::java_lang_VerifyError() ||
  1303. exception_name == vmSymbols::java_lang_ClassFormatError())) {
  1304. if (TraceClassInitialization) {
  1305. tty->print_cr(
  1306. "Fail over class verification to old verifier for: %s", klassName);
  1307. }
  1308. + assert(may_use_old_verifier, "");
  1309. exception_name = inference_verify(
  1310. klass, message_buffer, message_buffer_len, THREAD);
  1311. }
  1312. } else {
  1313. + assert(may_use_old_verifier, "");
  1314. exception_name = inference_verify(
  1315. klass, message_buffer, message_buffer_len, THREAD);
  1316. }
  1317. @@ -152,6 +154,9 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1318. }
  1319. tty->print_cr("End class verification for: %s", klassName);
  1320. }
  1321. + } else if (TraceClassInitialization) {
  1322. + // (tw) Output not verified classes
  1323. + tty->print_cr("Class %s was not verified", klassName);
  1324. }
  1325. if (HAS_PENDING_EXCEPTION) {
  1326. @@ -203,7 +208,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
  1327. // NOTE: this is called too early in the bootstrapping process to be
  1328. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1329. (refl_magic_klass == NULL ||
  1330. - !klass->is_subtype_of(refl_magic_klass) ||
  1331. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1332. VerifyReflectionBytecodes)
  1333. );
  1334. }
  1335. @@ -272,7 +277,7 @@ bool ClassVerifier::_verify_verbose = false;
  1336. ClassVerifier::ClassVerifier(
  1337. instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS)
  1338. : _thread(THREAD), _exception_type(NULL), _message(msg),
  1339. - _message_buffer_len(msg_len), _klass(klass) {
  1340. + _message_buffer_len(msg_len), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1341. _this_type = VerificationType::reference_type(klass->name());
  1342. // Create list to hold symbols in reference area.
  1343. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1344. @@ -296,7 +301,7 @@ void ClassVerifier::verify_class(TRAPS) {
  1345. _klass->external_name());
  1346. }
  1347. - objArrayHandle methods(THREAD, _klass->methods());
  1348. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1349. int num_methods = methods->length();
  1350. for (int index = 0; index < num_methods; index++) {
  1351. @@ -2081,7 +2086,10 @@ void ClassVerifier::verify_invoke_instructions(
  1352. VerificationType stack_object_type =
  1353. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1354. if (current_type() != stack_object_type) {
  1355. - assert(cp->cache() == NULL, "not rewritten yet");
  1356. +
  1357. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1358. + //assert(cp->cache() == NULL, "not rewritten yet");
  1359. +
  1360. Symbol* ref_class_name =
  1361. cp->klass_name_at(cp->klass_ref_index_at(index));
  1362. // See the comments in verify_field_instructions() for
  1363. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1364. index 6686858..d16ae52 100644
  1365. --- a/src/share/vm/classfile/verifier.hpp
  1366. +++ b/src/share/vm/classfile/verifier.hpp
  1367. @@ -47,7 +47,7 @@ class Verifier : AllStatic {
  1368. * Otherwise, no exception is thrown and the return indicates the
  1369. * error.
  1370. */
  1371. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1372. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1373. // Return false if the class is loaded by the bootstrap loader,
  1374. // or if defineClass was called requesting skipping verification
  1375. @@ -97,7 +97,10 @@ class ClassVerifier : public StackObj {
  1376. size_t _message_buffer_len;
  1377. GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
  1378. +public:
  1379. void verify_method(methodHandle method, TRAPS);
  1380. +
  1381. +private:
  1382. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1383. void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
  1384. void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
  1385. @@ -168,6 +171,7 @@ class ClassVerifier : public StackObj {
  1386. VerificationType object_type() const;
  1387. + instanceKlassHandle _klass_to_verify;
  1388. instanceKlassHandle _klass; // the class being verified
  1389. methodHandle _method; // current method being verified
  1390. VerificationType _this_type; // the verification type of the current class
  1391. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1392. index d6beb93..53dab58 100644
  1393. --- a/src/share/vm/classfile/vmSymbols.hpp
  1394. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1395. @@ -131,6 +131,10 @@
  1396. template(tag_annotation_default, "AnnotationDefault") \
  1397. template(tag_enclosing_method, "EnclosingMethod") \
  1398. template(tag_bootstrap_methods, "BootstrapMethods") \
  1399. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1400. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1401. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1402. + template(tag_code_sections, "CodeSections") \
  1403. \
  1404. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1405. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1406. @@ -376,6 +380,10 @@
  1407. template(oop_size_name, "oop_size") \
  1408. template(static_oop_field_count_name, "static_oop_field_count") \
  1409. \
  1410. + /* mutator in case of class redefinition */ \
  1411. + template(static_transformer_name, "$staticTransformer") \
  1412. + template(transformer_name, "$transformer") \
  1413. + \
  1414. /* non-intrinsic name/signature pairs: */ \
  1415. template(register_method_name, "register") \
  1416. do_alias(register_method_signature, object_void_signature) \
  1417. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1418. index 8729e05..162a44e 100644
  1419. --- a/src/share/vm/compiler/compileBroker.cpp
  1420. +++ b/src/share/vm/compiler/compileBroker.cpp
  1421. @@ -1166,6 +1166,14 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1422. int comp_level,
  1423. methodHandle hot_method, int hot_count,
  1424. const char* comment, Thread* THREAD) {
  1425. + JavaThread* thread = JavaThread::current();
  1426. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1427. + return NULL; // FIXME: DCEVM: should we do something else?
  1428. + }
  1429. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1430. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1431. + }
  1432. +
  1433. // make sure arguments make sense
  1434. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1435. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1436. @@ -1245,6 +1253,7 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1437. }
  1438. // RedefineClasses() has replaced this method; just return
  1439. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1440. if (method->is_old()) {
  1441. return NULL;
  1442. }
  1443. @@ -1576,6 +1585,8 @@ void CompileBroker::compiler_thread_loop() {
  1444. // Never compile a method if breakpoints are present in it
  1445. if (method()->number_of_breakpoints() == 0) {
  1446. + thread->compilation_mutex()->lock();
  1447. + thread->set_should_bailout(false);
  1448. // Compile the method.
  1449. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1450. #ifdef COMPILER1
  1451. @@ -1599,6 +1610,7 @@ void CompileBroker::compiler_thread_loop() {
  1452. // After compilation is disabled, remove remaining methods from queue
  1453. method->clear_queued_for_compilation();
  1454. }
  1455. + thread->compilation_mutex()->unlock();
  1456. }
  1457. }
  1458. }
  1459. @@ -2127,3 +2139,15 @@ void CompileBroker::print_compiler_threads_on(outputStream* st) {
  1460. st->cr();
  1461. #endif
  1462. }
  1463. +
  1464. +// (tw) Clean up compiler interface after a class redefinition step
  1465. +void CompileBroker::cleanup_after_redefinition() {
  1466. + int num_threads = _method_threads->length();
  1467. +
  1468. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1469. + for (int i=0; i<num_threads; i++) {
  1470. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1471. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1472. + }
  1473. + }
  1474. +}
  1475. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1476. index 1ee2c54..2a20852 100644
  1477. --- a/src/share/vm/compiler/compileBroker.hpp
  1478. +++ b/src/share/vm/compiler/compileBroker.hpp
  1479. @@ -407,6 +407,8 @@ class CompileBroker: AllStatic {
  1480. static void print_last_compile();
  1481. static void print_compiler_threads_on(outputStream* st);
  1482. +
  1483. + static void cleanup_after_redefinition();
  1484. };
  1485. #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP
  1486. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1487. index 2cb5e2f..74af5d1 100644
  1488. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1489. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1490. @@ -157,6 +157,13 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
  1491. }
  1492. }
  1493. +
  1494. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1495. + CompactPoint* cp, HeapWord* compact_top) {
  1496. + ShouldNotReachHere();
  1497. + return NULL;
  1498. +}
  1499. +
  1500. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1501. // update the block offset table. Removed initialize_threshold call because
  1502. // CFLS does not use a block offset array for contiguous spaces.
  1503. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1504. index 90d2f5f..14daefa 100644
  1505. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1506. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1507. @@ -149,6 +149,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
  1508. // Support for compacting cms
  1509. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1510. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1511. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1512. // Initialization helpers.
  1513. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1514. index 584c24c..121d9f1 100644
  1515. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1516. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1517. @@ -30,6 +30,8 @@
  1518. #include "oops/objArrayKlass.inline.hpp"
  1519. #include "oops/oop.inline.hpp"
  1520. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1521. +
  1522. Stack<oop> MarkSweep::_marking_stack;
  1523. Stack<DataLayout*> MarkSweep::_revisit_mdo_stack;
  1524. Stack<Klass*> MarkSweep::_revisit_klass_stack;
  1525. @@ -350,3 +352,86 @@ void MarkSweep::trace(const char* msg) {
  1526. }
  1527. #endif
  1528. +
  1529. +// (tw) Copy the rescued objects to their destination address after compaction.
  1530. +void MarkSweep::copy_rescued_objects_back() {
  1531. +
  1532. + if (_rescued_oops != NULL) {
  1533. +
  1534. + for (int i=0; i<_rescued_oops->length(); i++) {
  1535. + oop rescued_obj = _rescued_oops->at(i);
  1536. +
  1537. + int size = rescued_obj->size();
  1538. + oop new_obj = rescued_obj->forwardee();
  1539. +
  1540. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1541. + MarkSweep::update_fields(rescued_obj, new_obj);
  1542. + } else {
  1543. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1544. + }
  1545. +
  1546. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1547. +
  1548. + new_obj->init_mark();
  1549. + assert(new_obj->is_oop(), "must be a valid oop");
  1550. + }
  1551. + _rescued_oops->clear();
  1552. + _rescued_oops = NULL;
  1553. + }
  1554. +}
  1555. +
  1556. +// (tw) Update instances of a class whose fields changed.
  1557. +void MarkSweep::update_fields(oop q, oop new_location) {
  1558. +
  1559. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1560. +
  1561. + klassOop old_klass_oop = q->klass();
  1562. + klassOop new_klass_oop = q->blueprint()->new_version();
  1563. +
  1564. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1565. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1566. +
  1567. + int size = q->size_given_klass(old_klass);
  1568. + int new_size = q->size_given_klass(new_klass);
  1569. +
  1570. + oop tmp_obj = q;
  1571. +
  1572. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1573. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1574. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1575. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1576. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1577. + }
  1578. + }
  1579. +
  1580. + int *cur = new_klass_oop->klass_part()->update_information();
  1581. +
  1582. + tmp_obj->set_klass_no_check(new_klass_oop);
  1583. +
  1584. + if (cur == NULL) {
  1585. + assert(size == new_size, "just checking");
  1586. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1587. + } else {
  1588. + int destOffset = 0;
  1589. + while (*cur != 0) {
  1590. + if (*cur > 0) {
  1591. + int size = *cur;
  1592. + cur++;
  1593. + int offset = *cur;
  1594. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1595. + destOffset += size;
  1596. + cur++;
  1597. + } else {
  1598. + assert(*cur < 0, "");
  1599. + int skip = -*cur;
  1600. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1601. + destOffset += skip;
  1602. + cur++;
  1603. + }
  1604. + }
  1605. + }
  1606. +
  1607. + if (tmp_obj != q) {
  1608. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1609. + }
  1610. +}
  1611. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1612. index 19bee0e..850dd42 100644
  1613. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1614. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1615. @@ -115,8 +115,12 @@ class MarkSweep : AllStatic {
  1616. friend class AdjustPointerClosure;
  1617. friend class KeepAliveClosure;
  1618. friend class VM_MarkSweep;
  1619. + friend class GenMarkSweep;
  1620. friend void marksweep_init();
  1621. +public:
  1622. + static GrowableArray<oop>* _rescued_oops;
  1623. +
  1624. //
  1625. // Vars
  1626. //
  1627. @@ -200,6 +204,8 @@ class MarkSweep : AllStatic {
  1628. template <class T> static inline void mark_and_push(T* p);
  1629. static inline void push_objarray(oop obj, size_t index);
  1630. + static void copy_rescued_objects_back();
  1631. + static void update_fields(oop q, oop new_location);
  1632. static void follow_stack(); // Empty marking stack.
  1633. static void preserve_mark(oop p, markOop mark);
  1634. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1635. index 6f5511f..e01eafd 100644
  1636. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1637. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1638. @@ -403,7 +403,7 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
  1639. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1640. assert(h_exception->is_oop(), "just checking");
  1641. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1642. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1643. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1644. if (ExitVMOnVerifyError) vm_exit(-1);
  1645. ShouldNotReachHere();
  1646. }
  1647. @@ -674,6 +674,82 @@ IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDes
  1648. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1649. IRT_END
  1650. +// (tw) Correctly resolve method when running old code.
  1651. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1652. + {
  1653. + MonitorLockerEx ml(RedefinitionSync_lock);
  1654. + while (Threads::wait_at_instrumentation_entry()) {
  1655. + ml.wait();
  1656. + }
  1657. + }
  1658. + frame f = last_frame(thread);
  1659. + methodOop m = f.interpreter_frame_method();
  1660. + methodOop forward_method = m->forward_method();
  1661. + if (forward_method != NULL) {
  1662. + int bci = f.interpreter_frame_bci();
  1663. +
  1664. + if (TraceRedefineClasses >= 3) {
  1665. + 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));
  1666. + }
  1667. +
  1668. + int next_bci = bci - 1;
  1669. + // First try bci before NOP.
  1670. + if (!m->is_in_code_section(next_bci)) {
  1671. + // Try bci after NOP.
  1672. + next_bci = bci + 1;
  1673. + if (!m->is_in_code_section(next_bci)) return;
  1674. + }
  1675. +
  1676. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1677. + if (TraceRedefineClasses >= 2) {
  1678. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1679. + }
  1680. + RegisterMap reg_map(thread);
  1681. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1682. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1683. + iframe->set_method(forward_method, new_bci - 1);
  1684. + }
  1685. +IRT_END
  1686. +
  1687. +// (tw) Correctly resolve method when running old code.
  1688. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1689. + // extract receiver from the outgoing argument list if necessary
  1690. + Handle receiver(thread, receiverOop);
  1691. +
  1692. + // TODO: Check for invokeinterface!
  1693. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1694. +
  1695. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1696. + klassOop klass = receiverOop->klass();
  1697. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1698. + klass = klass->klass_part()->old_version();
  1699. + }
  1700. +
  1701. + // TODO: Check for correctness if different vtable indices in different versions?
  1702. +
  1703. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1704. + thread->set_vm_result(method);
  1705. +IRT_END
  1706. +
  1707. +// Correctly resolve interface method when running old code.
  1708. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1709. +
  1710. + // extract receiver from the outgoing argument list if necessary
  1711. + Handle receiver(thread, receiverOop);
  1712. +
  1713. + // TODO: Check for invokeinterface!
  1714. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1715. +
  1716. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1717. + klassOop klass = receiverOop->klass();
  1718. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1719. + klass = klass->klass_part()->old_version();
  1720. + }
  1721. +
  1722. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1723. + thread->set_vm_result(method);
  1724. +IRT_END
  1725. +
  1726. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
  1727. // extract receiver from the outgoing argument list if necessary
  1728. Handle receiver(thread, NULL);
  1729. @@ -702,6 +778,10 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes
  1730. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1731. int retry_count = 0;
  1732. while (info.resolved_method()->is_old()) {
  1733. + // (tw) If we are executing an old method, this is OK!
  1734. + if (method(thread)->is_old()) {
  1735. + break;
  1736. + }
  1737. // It is very unlikely that method is redefined more than 100 times
  1738. // in the middle of resolve. If it is looping here more than 100 times
  1739. // means then there could be a bug here.
  1740. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1741. index 93c1a9e..daf4813 100644
  1742. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1743. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1744. @@ -137,6 +137,9 @@ class InterpreterRuntime: AllStatic {
  1745. static void post_method_entry(JavaThread *thread);
  1746. static void post_method_exit (JavaThread *thread);
  1747. static int interpreter_contains(address pc);
  1748. + static void forward_method(JavaThread *thread);
  1749. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1750. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1751. // Native signature handlers
  1752. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1753. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1754. index b7defd7..ea6843f 100644
  1755. --- a/src/share/vm/interpreter/linkResolver.cpp
  1756. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1757. @@ -145,8 +145,8 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass
  1758. // Klass resolution
  1759. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1760. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1761. - sel_klass->as_klassOop(),
  1762. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1763. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1764. true)) {
  1765. ResourceMark rm(THREAD);
  1766. Exceptions::fthrow(
  1767. @@ -258,7 +258,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
  1768. // We'll check for the method name first, as that's most likely
  1769. // to be false (so we'll short-circuit out of these tests).
  1770. if (sel_method->name() == vmSymbols::clone_name() &&
  1771. - sel_klass() == SystemDictionary::Object_klass() &&
  1772. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1773. resolved_klass->oop_is_array()) {
  1774. // We need to change "protected" to "public".
  1775. assert(flags.is_protected(), "clone not protected?");
  1776. @@ -334,6 +334,149 @@ void LinkResolver::resolve_interface_method(methodHandle& resolved_method, Klass
  1777. }
  1778. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1779. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1780. +
  1781. + // Interface method lookup?
  1782. + if (is_interface) {
  1783. +
  1784. + // lookup method in this interface or its super, java.lang.Object
  1785. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1786. +
  1787. + if (resolved_method.is_null()) {
  1788. + // lookup method in all the super-interfaces
  1789. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1790. + }
  1791. +
  1792. + // Other methods
  1793. + } else {
  1794. +
  1795. + // 2. lookup method in resolved klass and its super klasses
  1796. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1797. +
  1798. + if (resolved_method.is_null()) { // not found in the class hierarchy
  1799. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1800. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1801. +
  1802. + if (resolved_method.is_null()) {
  1803. + // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  1804. + lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  1805. + }
  1806. + }
  1807. + }
  1808. +}
  1809. +
  1810. +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) {
  1811. +
  1812. + // First attempt unversioned
  1813. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1814. +
  1815. +
  1816. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1817. +
  1818. + // 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).
  1819. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1820. + if (is_static) {
  1821. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1822. + }
  1823. +
  1824. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1825. +
  1826. + if (redefinition_policy != Klass::DynamicCheck) {
  1827. +
  1828. + if (redefinition_policy == Klass::AccessOldMembers) {
  1829. + // Forget looked up fields
  1830. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1831. + }
  1832. +
  1833. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1834. +
  1835. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1836. +
  1837. + // Select correct version for resolved klass.
  1838. + find_correct_resolved_klass(resolved_klass, current_klass);
  1839. +
  1840. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1841. +
  1842. + // FIXME: idubrov
  1843. + //if (sel_klass.is_null()) {
  1844. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1845. + //} else {
  1846. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1847. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1848. + //}
  1849. + }
  1850. + }
  1851. + }
  1852. +}
  1853. +
  1854. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1855. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1856. +
  1857. + // First attempt unversioned
  1858. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1859. +
  1860. + // (tw) Are we in an old method that wants to see a different view on the world?
  1861. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1862. +
  1863. + // 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).
  1864. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1865. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1866. +
  1867. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1868. +
  1869. + // We do not throw the exception
  1870. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1871. + // Forget any new member lookup
  1872. + resolved_method = methodHandle(THREAD, NULL);
  1873. + }
  1874. +
  1875. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1876. +
  1877. + if (resolved_method.is_null()) {
  1878. +
  1879. + // Select correct version for resolved klass.
  1880. + find_correct_resolved_klass(resolved_klass, current_klass);
  1881. +
  1882. + // Now do the lookup in a second attempt with a different resolved klass.
  1883. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1884. +
  1885. + // FIXME: idubrov
  1886. + //IF_TRACE_RC2 {
  1887. + // ResourceMark rm(THREAD);
  1888. + // if (resolved_method.is_null()) {
  1889. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1890. + // } else {
  1891. + // assert(resolved_method->is_old(), "must be old method!");
  1892. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1893. + // }
  1894. + //}
  1895. + }
  1896. + }
  1897. + }
  1898. +
  1899. + if (resolved_method.is_null()) {
  1900. + // no method found
  1901. + ResourceMark rm(THREAD);
  1902. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1903. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1904. + method_name,
  1905. + method_signature));
  1906. + }
  1907. +}
  1908. +
  1909. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1910. + int current_klass_revision = current_klass->revision_number();
  1911. + int resolved_klass_revision = resolved_klass->revision_number();
  1912. + // FIXME: idubrov
  1913. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1914. +
  1915. + while (resolved_klass->revision_number() > current_klass_revision) {
  1916. + assert(resolved_klass->old_version(), "must have old version");
  1917. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1918. + }
  1919. +}
  1920. +
  1921. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1922. Symbol* method_name, Symbol* method_signature,
  1923. KlassHandle current_klass, bool check_access, TRAPS) {
  1924. @@ -346,27 +489,8 @@ void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle res
  1925. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1926. }
  1927. - // 2. lookup method in resolved klass and its super klasses
  1928. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1929. -
  1930. - if (resolved_method.is_null()) { // not found in the class hierarchy
  1931. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1932. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1933. -
  1934. - if (resolved_method.is_null()) {
  1935. - // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  1936. - lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  1937. - }
  1938. -
  1939. - if (resolved_method.is_null()) {
  1940. - // 4. method lookup failed
  1941. - ResourceMark rm(THREAD);
  1942. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1943. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1944. - method_name,
  1945. - method_signature));
  1946. - }
  1947. - }
  1948. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1949. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1950. // 5. check if method is concrete
  1951. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1952. @@ -434,20 +558,7 @@ void LinkResolver::resolve_interface_method(methodHandle& resolved_method,
  1953. }
  1954. // lookup method in this interface or its super, java.lang.Object
  1955. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1956. -
  1957. - if (resolved_method.is_null()) {
  1958. - // lookup method in all the super-interfaces
  1959. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1960. - if (resolved_method.is_null()) {
  1961. - // no method found
  1962. - ResourceMark rm(THREAD);
  1963. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1964. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1965. - method_name,
  1966. - method_signature));
  1967. - }
  1968. - }
  1969. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1970. if (check_access) {
  1971. HandleMark hm(THREAD);
  1972. @@ -534,9 +645,14 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  1973. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1974. }
  1975. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  1976. +
  1977. // Resolve instance field
  1978. fieldDescriptor fd; // find_field initializes fd if found
  1979. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  1980. +
  1981. + KlassHandle sel_klass;
  1982. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  1983. +
  1984. // check if field exists; i.e., if a klass containing the field def has been selected
  1985. if (sel_klass.is_null()){
  1986. ResourceMark rm(THREAD);
  1987. @@ -544,7 +660,6 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  1988. }
  1989. // check access
  1990. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  1991. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  1992. // check for errors
  1993. @@ -556,7 +671,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  1994. }
  1995. // Final fields can only be accessed from its own class.
  1996. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1997. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1998. THROW(vmSymbols::java_lang_IllegalAccessError());
  1999. }
  2000. @@ -761,7 +876,7 @@ void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHand
  2001. bool check_access, bool check_null_and_abstract, TRAPS) {
  2002. methodHandle resolved_method;
  2003. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2004. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2005. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2006. }
  2007. // throws linktime exceptions
  2008. @@ -791,6 +906,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  2009. KlassHandle resolved_klass,
  2010. Handle recv,
  2011. KlassHandle recv_klass,
  2012. + KlassHandle current_klass,
  2013. bool check_null_and_abstract,
  2014. TRAPS) {
  2015. @@ -839,7 +955,40 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  2016. // recv_klass might be an arrayKlassOop but all vtables start at
  2017. // the same place. The cast is to avoid virtual call and assertion.
  2018. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2019. +
  2020. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2021. + // have anything in common, as the receiver type could've been hotswapped.
  2022. + // Does not always work (method could be resolved with correct dynamic type and later
  2023. + // be called at the same place with a wrong dynamic type).
  2024. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2025. +
  2026. + // The vTable must be based on the view of the world of the resolved method
  2027. + klassOop method_holder = resolved_method->method_holder();
  2028. +
  2029. + if (method_holder->klass_part()->new_version() != NULL) {
  2030. + // We are executing in old code
  2031. + // FIXME: idubrov
  2032. + //TRACE_RC2("Calling a method in old code");
  2033. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2034. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2035. + }
  2036. + }
  2037. +
  2038. + if (inst->is_subtype_of(method_holder)) {
  2039. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2040. + } else {
  2041. +
  2042. + tty->print_cr("Failure:");
  2043. + inst->as_klassOop()->print();
  2044. + inst->super()->print();
  2045. + juint off = inst->super_check_offset();
  2046. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2047. + sup->print();
  2048. + method_holder->print();
  2049. +
  2050. + bool b = inst->is_subtype_of(method_holder);
  2051. + 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!");
  2052. + }
  2053. }
  2054. }
  2055. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2056. index 3d4c6f4..501f1e4 100644
  2057. --- a/src/share/vm/interpreter/linkResolver.hpp
  2058. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2059. @@ -106,7 +106,11 @@ class CallInfo: public LinkInfo {
  2060. // It does all necessary link-time checks & throws exceptions if necessary.
  2061. class LinkResolver: AllStatic {
  2062. - private:
  2063. +private:
  2064. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2065. + 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);
  2066. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2067. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2068. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2069. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2070. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2071. @@ -129,7 +133,7 @@ class LinkResolver: AllStatic {
  2072. 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);
  2073. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2074. - 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);
  2075. + 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);
  2076. 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);
  2077. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2078. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2079. index 3b006ad..b27ec97 100644
  2080. --- a/src/share/vm/interpreter/templateTable.hpp
  2081. +++ b/src/share/vm/interpreter/templateTable.hpp
  2082. @@ -328,8 +328,8 @@ class TemplateTable: AllStatic {
  2083. static void shouldnotreachhere();
  2084. // jvmti support
  2085. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2086. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2087. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2088. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2089. static void jvmti_post_fast_field_mod();
  2090. // debugging of TemplateGenerator
  2091. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2092. index d5cf4dc..ec88a6c 100644
  2093. --- a/src/share/vm/memory/genMarkSweep.cpp
  2094. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2095. @@ -409,6 +409,7 @@ void GenMarkSweep::mark_sweep_phase4() {
  2096. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2097. // here (perm_gen first rather than last), so we tell the validate code
  2098. // to use a higher index (saved from phase2) when verifying perm_gen.
  2099. + assert(_rescued_oops == NULL, "must be empty before processing");
  2100. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2101. Generation* pg = gch->perm_gen();
  2102. @@ -421,10 +422,14 @@ void GenMarkSweep::mark_sweep_phase4() {
  2103. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2104. + MarkSweep::copy_rescued_objects_back();
  2105. +
  2106. GenCompactClosure blk;
  2107. gch->generation_iterate(&blk, true);
  2108. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2109. + MarkSweep::copy_rescued_objects_back();
  2110. +
  2111. pg->post_compact(); // Shared spaces verification.
  2112. }
  2113. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2114. index 350f583..59faad1 100644
  2115. --- a/src/share/vm/memory/permGen.cpp
  2116. +++ b/src/share/vm/memory/permGen.cpp
  2117. @@ -57,7 +57,12 @@ HeapWord* PermGen::mem_allocate_in_gen(size_t size, Generation* gen) {
  2118. for (;;) {
  2119. {
  2120. - MutexLocker ml(Heap_lock);
  2121. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2122. + Monitor *lock = Heap_lock;
  2123. + if (SafepointSynchronize::is_at_safepoint()) {
  2124. + lock = NULL;
  2125. + }
  2126. + MutexLockerEx ml(lock);
  2127. if ((obj = gen->allocate(size, false)) != NULL) {
  2128. return obj;
  2129. }
  2130. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2131. index 7f3aceb..bb84a5a 100644
  2132. --- a/src/share/vm/memory/space.cpp
  2133. +++ b/src/share/vm/memory/space.cpp
  2134. @@ -378,6 +378,31 @@ void CompactibleSpace::clear(bool mangle_space) {
  2135. _compaction_top = bottom();
  2136. }
  2137. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2138. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2139. +CompactPoint* cp, HeapWord* compact_top) {
  2140. + // First check if we should switch compaction space
  2141. + assert(this == cp->space, "'this' should be current compaction space.");
  2142. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2143. + while (size > compaction_max_size) {
  2144. + // switch to next compaction space
  2145. + cp->space->set_compaction_top(compact_top);
  2146. + cp->space = cp->space->next_compaction_space();
  2147. + if (cp->space == NULL) {
  2148. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2149. + assert(cp->gen != NULL, "compaction must succeed");
  2150. + cp->space = cp->gen->first_compaction_space();
  2151. + assert(cp->space != NULL, "generation must have a first compaction space");
  2152. + }
  2153. + compact_top = cp->space->bottom();
  2154. + cp->space->set_compaction_top(compact_top);
  2155. + cp->threshold = cp->space->initialize_threshold();
  2156. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2157. + }
  2158. +
  2159. + return compact_top;
  2160. +}
  2161. +
  2162. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2163. CompactPoint* cp, HeapWord* compact_top) {
  2164. // q is alive
  2165. @@ -401,7 +426,7 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2166. }
  2167. // store the forwarding pointer into the mark word
  2168. - if ((HeapWord*)q != compact_top) {
  2169. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2170. q->forward_to(oop(compact_top));
  2171. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2172. } else {
  2173. @@ -449,7 +474,208 @@ void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  2174. // Faster object search.
  2175. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2176. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2177. + if (!Universe::is_redefining_gc_run()) {
  2178. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2179. + return;
  2180. + }
  2181. +
  2182. + /* Compute the new addresses for the live objects and store it in the mark
  2183. + * Used by universe::mark_sweep_phase2()
  2184. + */
  2185. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2186. +
  2187. + /* We're sure to be here before any objects are compacted into this
  2188. + * space, so this is a good time to initialize this:
  2189. + */
  2190. + set_compaction_top(bottom());
  2191. +
  2192. + if (cp->space == NULL) {
  2193. + assert(cp->gen != NULL, "need a generation");
  2194. + assert(cp->threshold == NULL, "just checking");
  2195. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2196. + cp->space = cp->gen->first_compaction_space();
  2197. + compact_top = cp->space->bottom();
  2198. + cp->space->set_compaction_top(compact_top);
  2199. + cp->threshold = cp->space->initialize_threshold();
  2200. + } else {
  2201. + compact_top = cp->space->compaction_top();
  2202. + }
  2203. +
  2204. + /* We allow some amount of garbage towards the bottom of the space, so
  2205. + * we don't start compacting before there is a significant gain to be made.
  2206. + * Occasionally, we want to ensure a full compaction, which is determined
  2207. + * by the MarkSweepAlwaysCompactCount parameter.
  2208. + */
  2209. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2210. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2211. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2212. +
  2213. + size_t allowed_deadspace = 0;
  2214. + if (skip_dead) {
  2215. + int ratio = (int)allowed_dead_ratio();
  2216. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2217. + }
  2218. +
  2219. + HeapWord* q = bottom();
  2220. + HeapWord* t = end();
  2221. +
  2222. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2223. + live object. */
  2224. + HeapWord* first_dead = end();/* The first dead object. */
  2225. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2226. + first header of preceding free area. */
  2227. + _first_dead = first_dead;
  2228. +
  2229. + const intx interval = PrefetchScanIntervalInBytes;
  2230. +
  2231. + while (q < t) {
  2232. + assert(!block_is_obj(q) ||
  2233. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2234. + oop(q)->mark()->has_bias_pattern(),
  2235. + "these are the only valid states during a mark sweep");
  2236. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2237. + /* prefetch beyond q */
  2238. + Prefetch::write(q, interval);
  2239. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2240. + size_t size = block_size(q);
  2241. +
  2242. + // DCEVM: begin
  2243. + //////////////////////////////////////////////////////////////////////////
  2244. + size_t forward_size = size;
  2245. +
  2246. + // Compute the forward sizes and leave out objects whose position could
  2247. + // possibly overlap other objects.
  2248. +
  2249. + // DCEVM: There is a new version of the class of q => different size
  2250. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2251. +
  2252. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2253. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2254. + forward_size = new_size;
  2255. + }
  2256. +
  2257. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2258. +
  2259. + bool rescueing = false;
  2260. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2261. + if (MarkSweep::_rescued_oops == NULL) {
  2262. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2263. + }
  2264. + // FIXME: idubrov
  2265. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2266. + MarkSweep::_rescued_oops->append(oop(q));
  2267. + } else {
  2268. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2269. + }
  2270. +
  2271. + if ((size != forward_size || rescueing) && q < first_dead) {
  2272. + // (tw) This object moves => first_dead must be set to here!
  2273. + first_dead = q;
  2274. + }
  2275. + //////////////////////////////////////////////////////////////////////////
  2276. + q += size;
  2277. + end_of_live = q;
  2278. + } else {
  2279. + /* run over all the contiguous dead objects */
  2280. + HeapWord* end = q;
  2281. + do {
  2282. + /* prefetch beyond end */
  2283. + Prefetch::write(end, interval);
  2284. + end += block_size(end);
  2285. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2286. +
  2287. + /* see if we might want to pretend this object is alive so that
  2288. + * we don't have to compact quite as often.
  2289. + */
  2290. + if (allowed_deadspace > 0 && q == compact_top) {
  2291. + size_t sz = pointer_delta(end, q);
  2292. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2293. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2294. + q = end;
  2295. + end_of_live = end;
  2296. + continue;
  2297. + }
  2298. + }
  2299. +
  2300. + /* otherwise, it really is a free region. */
  2301. +
  2302. + /* for the previous LiveRange, record the end of the live objects. */
  2303. + if (liveRange) {
  2304. + liveRange->set_end(q);
  2305. + }
  2306. +
  2307. + /* record the current LiveRange object.
  2308. + * liveRange->start() is overlaid on the mark word.
  2309. + */
  2310. + liveRange = (LiveRange*)q;
  2311. + liveRange->set_start(end);
  2312. + liveRange->set_end(end);
  2313. +
  2314. + /* see if this is the first dead region. */
  2315. + if (q < first_dead) {
  2316. + first_dead = q;
  2317. + }
  2318. +
  2319. + /* move on to the next object */
  2320. + q = end;
  2321. + }
  2322. + }
  2323. +
  2324. + //////////////////////////////////////////////////////////////////////////
  2325. + // Compute the forwarding addresses for the objects that need to be
  2326. + // rescued.
  2327. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2328. + if (MarkSweep::_rescued_oops != NULL) {
  2329. + // FIXME: idubrov
  2330. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2331. +
  2332. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2333. + oop q = MarkSweep::_rescued_oops->at(i);
  2334. +
  2335. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2336. + size_t size = block_size((HeapWord*)q);
  2337. +
  2338. + size_t forward_size = size;
  2339. +
  2340. + // (tw) There is a new version of the class of q => different size
  2341. + if (oop(q)->blueprint()->new_version() != NULL) {
  2342. +
  2343. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2344. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2345. + forward_size = new_size;
  2346. + }
  2347. +
  2348. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2349. + assert(compact_top <= t, "must not write over end of space!");
  2350. + }
  2351. + MarkSweep::_rescued_oops->clear();
  2352. + MarkSweep::_rescued_oops = NULL;
  2353. + }
  2354. + //////////////////////////////////////////////////////////////////////////
  2355. +
  2356. + assert(q == t, "just checking");
  2357. + if (liveRange != NULL) {
  2358. + liveRange->set_end(q);
  2359. + }
  2360. + _end_of_live = end_of_live;
  2361. + if (end_of_live < first_dead) {
  2362. + first_dead = end_of_live;
  2363. + }
  2364. + _first_dead = first_dead;
  2365. +
  2366. +// FIXME: idubrov
  2367. +// if (_first_dead > top()) {
  2368. +// _first_dead = top();
  2369. +// }
  2370. +//
  2371. +// if (_end_of_live > top()) {
  2372. +// _end_of_live = top();
  2373. +// }
  2374. + assert(_first_dead <= top(), "Must be smaller equal");
  2375. + assert(_end_of_live <= top(), "Must be smaller equal");
  2376. +
  2377. + /* save the compaction_top of the compaction space. */
  2378. + cp->space->set_compaction_top(compact_top);
  2379. }
  2380. void Space::adjust_pointers() {
  2381. @@ -490,17 +716,313 @@ void Space::adjust_pointers() {
  2382. assert(q == t, "just checking");
  2383. }
  2384. +
  2385. +#ifdef ASSERT
  2386. +
  2387. +int CompactibleSpace::space_index(oop obj) {
  2388. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2389. +
  2390. + if (heap->is_in_permanent(obj)) {
  2391. + return -1;
  2392. + }
  2393. +
  2394. + int index = 0;
  2395. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2396. + Generation* gen = heap->get_gen(i);
  2397. + CompactibleSpace* space = gen->first_compaction_space();
  2398. + while (space != NULL) {
  2399. + if (space->is_in_reserved(obj)) {
  2400. + return index;
  2401. + }
  2402. + space = space->next_compaction_space();
  2403. + index++;
  2404. + }
  2405. + }
  2406. +
  2407. + tty->print_cr("could not compute space_index for %08xh", obj);
  2408. + index = 0;
  2409. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2410. + Generation* gen = heap->get_gen(i);
  2411. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2412. +
  2413. + CompactibleSpace* space = gen->first_compaction_space();
  2414. + while (space != NULL) {
  2415. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2416. + space = space->next_compaction_space();
  2417. + index++;
  2418. + }
  2419. + }
  2420. +
  2421. + ShouldNotReachHere();
  2422. + return 0;
  2423. +}
  2424. +#endif
  2425. +
  2426. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2427. +
  2428. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2429. +
  2430. + if (old_obj->is_perm()) {
  2431. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2432. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2433. + return true;
  2434. + }
  2435. + }
  2436. +
  2437. + int size = old_obj->size();
  2438. + int original_size = size;
  2439. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2440. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2441. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2442. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2443. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2444. + }
  2445. +
  2446. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2447. +
  2448. + if (is_in_reserved(new_obj)) {
  2449. + // Old and new address are in same space, so just compare the address.
  2450. + // Must rescue if object moves towards the top of the space.
  2451. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2452. + return normalComparison;
  2453. +
  2454. + } else {
  2455. +
  2456. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2457. +
  2458. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2459. + if (tenured_gen->is_in_reserved(new_obj)) {
  2460. + // Must never rescue when moving from the new into the old generation.
  2461. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2462. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2463. + return false;
  2464. +
  2465. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2466. + // Must always rescue when moving from the old into the new generation.
  2467. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2468. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2469. + return true;
  2470. +
  2471. + } else {
  2472. + // In the new generation, eden is located before the from space, so a
  2473. + // simple pointer comparison is sufficient.
  2474. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2475. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2476. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2477. + return normalComparison;
  2478. + }
  2479. + }
  2480. +}
  2481. +
  2482. +oop CompactibleSpace::rescue(oop old_obj) {
  2483. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2484. +
  2485. + int size = old_obj->size();
  2486. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2487. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2488. +
  2489. + if (MarkSweep::_rescued_oops == NULL) {
  2490. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2491. + }
  2492. +
  2493. + MarkSweep::_rescued_oops->append(rescued_obj);
  2494. + return rescued_obj;
  2495. +}
  2496. +
  2497. void CompactibleSpace::adjust_pointers() {
  2498. // Check first is there is any work to do.
  2499. if (used() == 0) {
  2500. return; // Nothing to do.
  2501. }
  2502. -
  2503. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2504. + /* adjust all the interior pointers to point at the new locations of objects
  2505. + * Used by MarkSweep::mark_sweep_phase3() */
  2506. +
  2507. + HeapWord* q = bottom();
  2508. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2509. +
  2510. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2511. +
  2512. + debug_only(HeapWord* prev_q = NULL);
  2513. + debug_only(HeapWord* prev_prev_q = NULL);
  2514. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2515. + if (q < t && _first_dead > q &&
  2516. + !oop(q)->is_gc_marked()) {
  2517. + /* we have a chunk of the space which hasn't moved and we've
  2518. + * reinitialized the mark word during the previous pass, so we can't
  2519. + * use is_gc_marked for the traversal. */
  2520. + HeapWord* end = _first_dead;
  2521. +
  2522. + while (q < end) {
  2523. + /* I originally tried to conjoin "block_start(q) == q" to the
  2524. + * assertion below, but that doesn't work, because you can't
  2525. + * accurately traverse previous objects to get to the current one
  2526. + * after their pointers (including pointers into permGen) have been
  2527. + * updated, until the actual compaction is done. dld, 4/00 */
  2528. + assert(block_is_obj(q),
  2529. + "should be at block boundaries, and should be looking at objs");
  2530. +
  2531. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2532. +
  2533. + /* point all the oops to the new location */
  2534. + size_t size = oop(q)->adjust_pointers();
  2535. + size = adjust_obj_size(size);
  2536. +
  2537. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2538. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2539. +
  2540. + debug_only(prev_prev_prev_q = prev_prev_q);
  2541. + debug_only(prev_prev_q = prev_q);
  2542. + debug_only(prev_q = q);
  2543. + q += size;
  2544. + }
  2545. +
  2546. + // (tw) first_dead can be live object!
  2547. + q = _first_dead;
  2548. +
  2549. +// if (_first_dead == t) {
  2550. +// q = t;
  2551. +// } else {
  2552. +// /* $$$ This is funky. Using this to read the previously written
  2553. +// * LiveRange. See also use below. */
  2554. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2555. +// }
  2556. + }
  2557. +
  2558. + const intx interval = PrefetchScanIntervalInBytes;
  2559. +
  2560. + debug_only(prev_q = NULL);
  2561. + debug_only(prev_prev_q = NULL);
  2562. + debug_only(prev_prev_prev_q = NULL);
  2563. + while (q < t) {
  2564. + /* prefetch beyond q */
  2565. + Prefetch::write(q, interval);
  2566. + if (oop(q)->is_gc_marked()) {
  2567. + /* q is alive */
  2568. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2569. + /* point all the oops to the new location */
  2570. + size_t size = oop(q)->adjust_pointers();
  2571. + size = adjust_obj_size(size);
  2572. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2573. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2574. + debug_only(prev_prev_prev_q = prev_prev_q);
  2575. + debug_only(prev_prev_q = prev_q);
  2576. + debug_only(prev_q = q);
  2577. + q += size;
  2578. + } else {
  2579. + /* q is not a live object, so its mark should point at the next
  2580. + * live object */
  2581. + debug_only(prev_prev_prev_q = prev_prev_q);
  2582. + debug_only(prev_prev_q = prev_q);
  2583. + debug_only(prev_q = q);
  2584. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2585. + assert(q > prev_q, "we should be moving forward through memory");
  2586. + }
  2587. + }
  2588. +
  2589. + assert(q == t, "just checking");
  2590. }
  2591. void CompactibleSpace::compact() {
  2592. - SCAN_AND_COMPACT(obj_size);
  2593. +
  2594. + if(!Universe::is_redefining_gc_run()) {
  2595. + SCAN_AND_COMPACT(obj_size);
  2596. + return;
  2597. + }
  2598. +
  2599. + /* Copy all live objects to their new location
  2600. + * Used by MarkSweep::mark_sweep_phase4() */
  2601. +
  2602. + HeapWord* q = bottom();
  2603. + HeapWord* const t = _end_of_live;
  2604. + debug_only(HeapWord* prev_q = NULL);
  2605. +
  2606. + if (q < t && _first_dead > q &&
  2607. + !oop(q)->is_gc_marked()) {
  2608. + debug_only(
  2609. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2610. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2611. + * the traversal. */
  2612. + HeapWord* const end = _first_dead;
  2613. +
  2614. + while (q < end) {
  2615. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2616. + assert(!oop(q)->is_gc_marked(),
  2617. + "should be unmarked (special dense prefix handling)");
  2618. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2619. + debug_only(prev_q = q);
  2620. + q += size;
  2621. + }
  2622. + ) /* debug_only */
  2623. + // (tw) first_dead can be live object!
  2624. + q = _first_dead;
  2625. +
  2626. + //if (_first_dead == t) {
  2627. + // q = t;
  2628. + //} else {
  2629. + ///* $$$ Funky */
  2630. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2631. + //}
  2632. + }
  2633. +
  2634. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2635. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2636. + while (q < t) {
  2637. + if (!oop(q)->is_gc_marked()) {
  2638. + /* mark is pointer to next marked oop */
  2639. + debug_only(prev_q = q);
  2640. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2641. + assert(q > prev_q, "we should be moving forward through memory");
  2642. + } else {
  2643. + /* prefetch beyond q */
  2644. + Prefetch::read(q, scan_interval);
  2645. +
  2646. + /* size and destination */
  2647. + size_t size = obj_size(q);
  2648. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2649. +
  2650. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2651. + oop dest_obj = rescue(oop(q));
  2652. + debug_only(Copy::fill_to_words(q, size, 0));
  2653. + } else {
  2654. +
  2655. + /* prefetch beyond compaction_top */
  2656. + Prefetch::write(compaction_top, copy_interval);
  2657. +
  2658. + /* copy object and reinit its mark */
  2659. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2660. + compaction_top));
  2661. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2662. +
  2663. + if (oop(q)->blueprint()->new_version() != NULL) {
  2664. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2665. + } else {
  2666. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2667. + }
  2668. + oop(compaction_top)->init_mark();
  2669. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2670. + }
  2671. +
  2672. + debug_only(prev_q = q);
  2673. + q += size;
  2674. + }
  2675. + }
  2676. +
  2677. + /* Let's remember if we were empty before we did the compaction. */
  2678. + bool was_empty = used_region().is_empty();
  2679. + /* Reset space after compaction is complete */
  2680. + reset_after_compaction();
  2681. + /* We do this clear, below, since it has overloaded meanings for some */
  2682. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2683. + /* compacted into will have had their offset table thresholds updated */
  2684. + /* continuously, but those that weren't need to have their thresholds */
  2685. + /* re-initialized. Also mangles unused area for debugging. */
  2686. + if (used_region().is_empty()) {
  2687. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2688. + } else {
  2689. + if (ZapUnusedHeapArea) mangle_unused_area();
  2690. + }
  2691. +
  2692. + //SCAN_AND_COMPACT(obj_size);
  2693. }
  2694. void Space::print_short() const { print_short_on(tty); }
  2695. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2696. index 2d718c2..3f1d74b 100644
  2697. --- a/src/share/vm/memory/space.hpp
  2698. +++ b/src/share/vm/memory/space.hpp
  2699. @@ -445,6 +445,9 @@ public:
  2700. // indicates when the next such action should be taken.
  2701. virtual void prepare_for_compaction(CompactPoint* cp);
  2702. // MarkSweep support phase3
  2703. + DEBUG_ONLY(int space_index(oop obj));
  2704. + bool must_rescue(oop old_obj, oop new_obj);
  2705. + oop rescue(oop old_obj);
  2706. virtual void adjust_pointers();
  2707. // MarkSweep support phase4
  2708. virtual void compact();
  2709. @@ -475,6 +478,10 @@ public:
  2710. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2711. HeapWord* compact_top);
  2712. + // (tw)
  2713. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2714. + HeapWord* compact_top);
  2715. +
  2716. // Return a size with adjusments as required of the space.
  2717. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2718. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2719. index 2651f4d..90d244c 100644
  2720. --- a/src/share/vm/memory/universe.cpp
  2721. +++ b/src/share/vm/memory/universe.cpp
  2722. @@ -100,6 +100,8 @@
  2723. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2724. #endif
  2725. +bool Universe::_is_redefining_gc_run = false;
  2726. +
  2727. // Known objects
  2728. klassOop Universe::_boolArrayKlassObj = NULL;
  2729. klassOop Universe::_byteArrayKlassObj = NULL;
  2730. @@ -203,6 +205,38 @@ void Universe::system_classes_do(void f(klassOop)) {
  2731. f(systemObjArrayKlassObj());
  2732. }
  2733. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2734. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2735. +
  2736. + class AlwaysTrueClosure: public BoolObjectClosure {
  2737. + public:
  2738. + void do_object(oop p) { ShouldNotReachHere(); }
  2739. + bool do_object_b(oop p) { return true; }
  2740. + };
  2741. + AlwaysTrueClosure always_true;
  2742. +
  2743. + // General strong roots
  2744. + Universe::oops_do(oopClosure);
  2745. + JNIHandles::oops_do(oopClosure);
  2746. + Threads::oops_do(oopClosure, NULL);
  2747. + ObjectSynchronizer::oops_do(oopClosure);
  2748. + FlatProfiler::oops_do(oopClosure);
  2749. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2750. + JvmtiExport::oops_do(oopClosure);
  2751. + // SO_AllClasses
  2752. + SystemDictionary::oops_do(oopClosure);
  2753. +
  2754. + // Now adjust pointers in remaining weak roots. (All of which should
  2755. + // have been cleared if they pointed to non-surviving objects.)
  2756. + // Global (weak) JNI handles
  2757. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2758. +
  2759. + CodeCache::oops_do(oopClosure);
  2760. + StringTable::oops_do(oopClosure);
  2761. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2762. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2763. +}
  2764. +
  2765. void Universe::oops_do(OopClosure* f, bool do_all) {
  2766. f->do_oop((oop*) &_int_mirror);
  2767. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2768. index e8ebf8f..535c8ca 100644
  2769. --- a/src/share/vm/memory/universe.hpp
  2770. +++ b/src/share/vm/memory/universe.hpp
  2771. @@ -127,6 +127,8 @@ class Universe: AllStatic {
  2772. friend class SystemDictionary;
  2773. friend class VMStructs;
  2774. friend class CompactingPermGenGen;
  2775. + friend class Space;
  2776. + friend class ContiguousSpace;
  2777. friend class VM_PopulateDumpSharedSpace;
  2778. friend jint universe_init();
  2779. @@ -257,7 +259,18 @@ class Universe: AllStatic {
  2780. static void compute_verify_oop_data();
  2781. + static bool _is_redefining_gc_run;
  2782. +
  2783. public:
  2784. +
  2785. + static bool is_redefining_gc_run() {
  2786. + return _is_redefining_gc_run;
  2787. + }
  2788. +
  2789. + static void set_redefining_gc_run(bool b) {
  2790. + _is_redefining_gc_run = b;
  2791. + }
  2792. +
  2793. // Known classes in the VM
  2794. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2795. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2796. @@ -396,6 +409,8 @@ class Universe: AllStatic {
  2797. // Iteration
  2798. + static void root_oops_do(OopClosure *f);
  2799. +
  2800. // Apply "f" to the addresses of all the direct heap pointers maintained
  2801. // as static fields of "Universe".
  2802. static void oops_do(OopClosure* f, bool do_all = false);
  2803. @@ -412,6 +427,7 @@ class Universe: AllStatic {
  2804. // Debugging
  2805. static bool verify_in_progress() { return _verify_in_progress; }
  2806. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2807. static void verify(bool allow_dirty = true, bool silent = false,
  2808. VerifyOption option = VerifyOption_Default );
  2809. static int verify_count() { return _verify_count; }
  2810. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2811. index 4aa1155..2738ea9 100644
  2812. --- a/src/share/vm/oops/arrayKlass.cpp
  2813. +++ b/src/share/vm/oops/arrayKlass.cpp
  2814. @@ -129,9 +129,9 @@ objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
  2815. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2816. // An array is a subtype of Serializable, Clonable, and Object
  2817. - return k == SystemDictionary::Object_klass()
  2818. - || k == SystemDictionary::Cloneable_klass()
  2819. - || k == SystemDictionary::Serializable_klass();
  2820. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2821. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2822. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2823. }
  2824. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2825. index 509b411..53d1858 100644
  2826. --- a/src/share/vm/oops/constMethodKlass.cpp
  2827. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2828. @@ -101,6 +101,7 @@ void constMethodKlass::oop_follow_contents(oop obj) {
  2829. MarkSweep::mark_and_push(cm->adr_method());
  2830. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2831. MarkSweep::mark_and_push(cm->adr_exception_table());
  2832. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2833. // Performance tweak: We skip iterating over the klass pointer since we
  2834. // know that Universe::constMethodKlassObj never moves.
  2835. }
  2836. @@ -113,6 +114,7 @@ void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
  2837. PSParallelCompact::mark_and_push(cm, cm_oop->adr_method());
  2838. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2839. PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table());
  2840. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2841. // Performance tweak: We skip iterating over the klass pointer since we
  2842. // know that Universe::constMethodKlassObj never moves.
  2843. }
  2844. @@ -124,6 +126,7 @@ int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  2845. blk->do_oop(cm->adr_method());
  2846. blk->do_oop(cm->adr_stackmap_data());
  2847. blk->do_oop(cm->adr_exception_table());
  2848. + blk->do_oop(cm->adr_code_section_table());
  2849. // Get size before changing pointers.
  2850. // Don't call size() or oop_size() since that is a virtual call.
  2851. int size = cm->object_size();
  2852. @@ -141,6 +144,8 @@ int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr)
  2853. if (mr.contains(adr)) blk->do_oop(adr);
  2854. adr = cm->adr_exception_table();
  2855. if (mr.contains(adr)) blk->do_oop(adr);
  2856. + adr = cm->adr_code_section_table();
  2857. + if (mr.contains(adr)) blk->do_oop(adr);
  2858. // Get size before changing pointers.
  2859. // Don't call size() or oop_size() since that is a virtual call.
  2860. int size = cm->object_size();
  2861. @@ -156,6 +161,7 @@ int constMethodKlass::oop_adjust_pointers(oop obj) {
  2862. MarkSweep::adjust_pointer(cm->adr_method());
  2863. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2864. MarkSweep::adjust_pointer(cm->adr_exception_table());
  2865. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2866. // Get size before changing pointers.
  2867. // Don't call size() or oop_size() since that is a virtual call.
  2868. int size = cm->object_size();
  2869. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2870. index 91f9786..6c6acc9 100644
  2871. --- a/src/share/vm/oops/constMethodOop.hpp
  2872. +++ b/src/share/vm/oops/constMethodOop.hpp
  2873. @@ -114,7 +114,7 @@ private:
  2874. public:
  2875. oop* oop_block_beg() const { return adr_method(); }
  2876. - oop* oop_block_end() const { return adr_exception_table() + 1; }
  2877. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2878. private:
  2879. //
  2880. @@ -132,6 +132,10 @@ private:
  2881. // table is pointing to Universe::the_empty_int_array
  2882. typeArrayOop _exception_table;
  2883. +
  2884. + // (tw) Table mapping code sections for method forward points.
  2885. + typeArrayOop _code_section_table;
  2886. +
  2887. //
  2888. // End of the oop block.
  2889. //
  2890. @@ -184,6 +188,28 @@ public:
  2891. void set_exception_table(typeArrayOop e) { oop_store_without_check((oop*) &_exception_table, (oop) e); }
  2892. bool has_exception_handler() const { return exception_table() != NULL && exception_table()->length() > 0; }
  2893. + // code section table
  2894. + typeArrayOop code_section_table() const { return _code_section_table; }
  2895. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2896. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2897. + static const int ValuesPerCodeSectionEntry = 3;
  2898. + int code_section_entries() const {
  2899. + if (!has_code_section_table()) return 0;
  2900. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2901. + }
  2902. +
  2903. + int code_section_new_index_at(int index) const {
  2904. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2905. + }
  2906. +
  2907. + int code_section_original_index_at(int index) const {
  2908. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2909. + }
  2910. +
  2911. + int code_section_length_at(int index) const {
  2912. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2913. + }
  2914. +
  2915. void init_fingerprint() {
  2916. const uint64_t initval = CONST64(0x8000000000000000);
  2917. _fingerprint = initval;
  2918. @@ -285,6 +311,7 @@ public:
  2919. oop* adr_method() const { return (oop*)&_method; }
  2920. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2921. oop* adr_exception_table() const { return (oop*)&_exception_table; }
  2922. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2923. bool is_conc_safe() { return _is_conc_safe; }
  2924. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2925. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2926. index 678bc13..d34f7c3 100644
  2927. --- a/src/share/vm/oops/cpCacheOop.cpp
  2928. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2929. @@ -36,9 +36,15 @@
  2930. // Implememtation of ConstantPoolCacheEntry
  2931. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2932. + _flags = other->_flags; // flags
  2933. +}
  2934. +
  2935. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2936. assert(0 < index && index < 0x10000, "sanity check");
  2937. _indices = index;
  2938. + _f1 = NULL;
  2939. + _f2 = 0;
  2940. assert(constant_pool_index() == index, "");
  2941. }
  2942. @@ -50,7 +56,7 @@ void ConstantPoolCacheEntry::initialize_secondary_entry(int main_index) {
  2943. int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
  2944. bool is_vfinal, bool is_volatile,
  2945. - bool is_method_interface, bool is_method) {
  2946. + bool is_method_interface, bool is_method, bool is_old_method) {
  2947. int f = state;
  2948. assert( state < number_of_states, "Invalid state in as_flags");
  2949. @@ -65,7 +71,9 @@ int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
  2950. if (is_method_interface) f |= 1;
  2951. f <<= 1;
  2952. if (is_method) f |= 1;
  2953. - f <<= ConstantPoolCacheEntry::hotSwapBit;
  2954. + f <<= 1;
  2955. + if (is_old_method) f |= 1;
  2956. + f <<= ConstantPoolCacheEntry::oldMethodBit;
  2957. // Preserve existing flag bit values
  2958. #ifdef ASSERT
  2959. int old_state = ((_flags >> tosBits) & 0x0F);
  2960. @@ -137,7 +145,7 @@ void ConstantPoolCacheEntry::set_field(Bytecodes::Code get_code,
  2961. set_f2(field_offset);
  2962. assert(field_index <= field_index_mask,
  2963. "field index does not fit in low flag bits");
  2964. - set_flags(as_flags(field_type, is_final, false, is_volatile, false, false) |
  2965. + set_flags(as_flags(field_type, is_final, false, is_volatile, false, false, false) |
  2966. (field_index & field_index_mask));
  2967. set_bytecode_1(get_code);
  2968. set_bytecode_2(put_code);
  2969. @@ -153,7 +161,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2970. int vtable_index) {
  2971. assert(!is_secondary_entry(), "");
  2972. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2973. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2974. + // (tw) No longer valid assert
  2975. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2976. bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
  2977. int byte_no = -1;
  2978. @@ -167,6 +176,9 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2979. } else {
  2980. assert(vtable_index >= 0, "valid index");
  2981. set_f2(vtable_index);
  2982. +
  2983. + // (tw) save method holder in f1 for virtual calls
  2984. + set_f1(method());
  2985. }
  2986. byte_no = 2;
  2987. break;
  2988. @@ -212,7 +224,7 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2989. needs_vfinal_flag,
  2990. false,
  2991. change_to_virtual,
  2992. - true)|
  2993. + true, method->is_old())|
  2994. method()->size_of_parameters());
  2995. // Note: byte_no also appears in TemplateTable::resolve.
  2996. @@ -252,7 +264,7 @@ void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index)
  2997. assert(instanceKlass::cast(interf)->is_interface(), "must be an interface");
  2998. set_f1(interf);
  2999. set_f2(index);
  3000. - set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true) | method()->size_of_parameters());
  3001. + set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true, method->is_old()) | method()->size_of_parameters());
  3002. set_bytecode_1(Bytecodes::_invokeinterface);
  3003. }
  3004. @@ -282,7 +294,7 @@ void ConstantPoolCacheEntry::set_dynamic_call(Handle call_site, methodHandle sig
  3005. param_size -= 1; // do not count MH.this; it is not stacked for invokedynamic
  3006. bool is_final = true;
  3007. assert(signature_invoker->is_final_method(), "is_final");
  3008. - int flags = as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true) | param_size;
  3009. + int flags = as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true, false) | param_size;
  3010. assert(_flags == 0 || _flags == flags, "flags should be the same");
  3011. set_flags(flags);
  3012. // do not do set_bytecode on a secondary CP cache entry
  3013. @@ -416,26 +428,13 @@ void ConstantPoolCacheEntry::update_pointers() {
  3014. // If this constantPoolCacheEntry refers to old_method then update it
  3015. // to refer to new_method.
  3016. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3017. - methodOop new_method, bool * trace_name_printed) {
  3018. + methodOop new_method) {
  3019. if (is_vfinal()) {
  3020. - // virtual and final so f2() contains method ptr instead of vtable index
  3021. - if (f2() == (intptr_t)old_method) {
  3022. - // match old_method so need an update
  3023. - _f2 = (intptr_t)new_method;
  3024. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3025. - if (!(*trace_name_printed)) {
  3026. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3027. - RC_TRACE_MESG(("adjust: name=%s",
  3028. - Klass::cast(old_method->method_holder())->external_name()));
  3029. - *trace_name_printed = true;
  3030. - }
  3031. - // RC_TRACE macro has an embedded ResourceMark
  3032. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3033. - new_method->name()->as_C_string(),
  3034. - new_method->signature()->as_C_string()));
  3035. - }
  3036. + // virtual and final so f2() contains method ptr instead of vtable index
  3037. + if((methodOop)f2() != NULL && ((methodOop)f2())->method_holder()->klass_part()->new_version()) {
  3038. + initialize_entry(constant_pool_index());
  3039. return true;
  3040. }
  3041. @@ -443,65 +442,28 @@ bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3042. return false;
  3043. }
  3044. - if ((oop)_f1 == NULL) {
  3045. - // NULL f1() means this is a virtual entry so bail out
  3046. - // We are assuming that the vtable index does not need change.
  3047. + // (tw) check how to update interface methods!
  3048. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3049. +
  3050. + if(((methodOop)f1())->method_holder()->klass_part()->new_version()) {
  3051. + initialize_entry(constant_pool_index());
  3052. + return true;
  3053. + }
  3054. +
  3055. return false;
  3056. }
  3057. if ((oop)_f1 == old_method) {
  3058. _f1 = new_method;
  3059. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3060. - if (!(*trace_name_printed)) {
  3061. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3062. - RC_TRACE_MESG(("adjust: name=%s",
  3063. - Klass::cast(old_method->method_holder())->external_name()));
  3064. - *trace_name_printed = true;
  3065. - }
  3066. - // RC_TRACE macro has an embedded ResourceMark
  3067. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3068. - new_method->name()->as_C_string(),
  3069. - new_method->signature()->as_C_string()));
  3070. - }
  3071. -
  3072. + return true;
  3073. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && ((methodOop)f1())->method_holder()->klass_part()->new_version())) {
  3074. + initialize_entry(constant_pool_index());
  3075. return true;
  3076. }
  3077. return false;
  3078. }
  3079. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3080. - if (!is_method_entry()) {
  3081. - // not a method entry so not interesting by default
  3082. - return false;
  3083. - }
  3084. -
  3085. - methodOop m = NULL;
  3086. - if (is_vfinal()) {
  3087. - // virtual and final so _f2 contains method ptr instead of vtable index
  3088. - m = (methodOop)_f2;
  3089. - } else if ((oop)_f1 == NULL) {
  3090. - // NULL _f1 means this is a virtual entry so also not interesting
  3091. - return false;
  3092. - } else {
  3093. - if (!((oop)_f1)->is_method()) {
  3094. - // _f1 can also contain a klassOop for an interface
  3095. - return false;
  3096. - }
  3097. - m = (methodOop)_f1;
  3098. - }
  3099. -
  3100. - assert(m != NULL && m->is_method(), "sanity check");
  3101. - if (m == NULL || !m->is_method() || m->method_holder() != k) {
  3102. - // robustness for above sanity checks or method is not in
  3103. - // the interesting class
  3104. - return false;
  3105. - }
  3106. -
  3107. - // the method is in the interesting class so the entry is interesting
  3108. - return true;
  3109. -}
  3110. -
  3111. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3112. // print separator
  3113. if (index == 0) tty->print_cr(" -------------");
  3114. @@ -542,38 +504,18 @@ void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
  3115. // RedefineClasses() API support:
  3116. // If any entry of this constantPoolCache points to any of
  3117. // old_methods, replace it with the corresponding new_method.
  3118. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3119. - int methods_length, bool * trace_name_printed) {
  3120. -
  3121. - if (methods_length == 0) {
  3122. - // nothing to do if there are no methods
  3123. - return;
  3124. - }
  3125. -
  3126. - // get shorthand for the interesting class
  3127. - klassOop old_holder = old_methods[0]->method_holder();
  3128. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3129. + int methods_length) {
  3130. for (int i = 0; i < length(); i++) {
  3131. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3132. - // skip uninteresting methods
  3133. - continue;
  3134. - }
  3135. -
  3136. - // The constantPoolCache contains entries for several different
  3137. - // things, but we only care about methods. In fact, we only care
  3138. - // about methods in the same class as the one that contains the
  3139. - // old_methods. At this point, we have an interesting entry.
  3140. -
  3141. - for (int j = 0; j < methods_length; j++) {
  3142. - methodOop old_method = old_methods[j];
  3143. - methodOop new_method = new_methods[j];
  3144. -
  3145. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3146. - trace_name_printed)) {
  3147. - // current old_method matched this entry and we updated it so
  3148. - // break out and get to the next interesting entry if there one
  3149. - break;
  3150. - }
  3151. + if (entry_at(i)->is_field_entry()) {
  3152. +
  3153. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3154. + // point to changed fields
  3155. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3156. +
  3157. + } else if(entry_at(i)->is_method_entry()) {
  3158. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3159. }
  3160. }
  3161. }
  3162. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3163. index c3d1847..ab7a095 100644
  3164. --- a/src/share/vm/oops/cpCacheOop.hpp
  3165. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3166. @@ -135,19 +135,24 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3167. void set_bytecode_2(Bytecodes::Code code);
  3168. void set_f1(oop f1) {
  3169. oop existing_f1 = _f1; // read once
  3170. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3171. + // (tw) need to relax assertion for redefinition
  3172. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3173. oop_store(&_f1, f1);
  3174. }
  3175. void set_f1_if_null_atomic(oop f1);
  3176. - void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; }
  3177. + void set_f2(intx f2) {
  3178. + // (tw) need to relax assertion for redefinition
  3179. + // assert(_f2 == 0 || _f2 == f2, "illegal field change");
  3180. + _f2 = f2; }
  3181. int as_flags(TosState state, bool is_final, bool is_vfinal, bool is_volatile,
  3182. - bool is_method_interface, bool is_method);
  3183. + bool is_method_interface, bool is_method, bool is_old_method);
  3184. void set_flags(intx flags) { _flags = flags; }
  3185. public:
  3186. // specific bit values in flag field
  3187. // Note: the interpreter knows this layout!
  3188. enum FlagBitValues {
  3189. + oldMethodBit = 22,
  3190. hotSwapBit = 23,
  3191. methodInterface = 24,
  3192. volatileField = 25,
  3193. @@ -167,6 +172,8 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3194. void initialize_entry(int original_index); // initialize primary entry
  3195. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3196. + void copy_from(ConstantPoolCacheEntry *other);
  3197. +
  3198. void set_field( // sets entry to resolved field state
  3199. Bytecodes::Code get_code, // the bytecode used for reading the field
  3200. Bytecodes::Code put_code, // the bytecode used for writing the field
  3201. @@ -296,9 +303,7 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3202. // trace_name_printed is set to true if the current call has
  3203. // printed the klass name so that other routines in the adjust_*
  3204. // group don't print the klass name.
  3205. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3206. - bool * trace_name_printed);
  3207. - bool is_interesting_method_entry(klassOop k);
  3208. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3209. bool is_field_entry() const { return (_flags & (1 << hotSwapBit)) == 0; }
  3210. bool is_method_entry() const { return (_flags & (1 << hotSwapBit)) != 0; }
  3211. @@ -397,14 +402,9 @@ class constantPoolCacheOopDesc: public oopDesc {
  3212. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3213. }
  3214. - // RedefineClasses() API support:
  3215. - // If any entry of this constantPoolCache points to any of
  3216. - // old_methods, replace it with the corresponding new_method.
  3217. - // trace_name_printed is set to true if the current call has
  3218. - // printed the klass name so that other routines in the adjust_*
  3219. - // group don't print the klass name.
  3220. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3221. - int methods_length, bool * trace_name_printed);
  3222. + // (tw) Update method and field references
  3223. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3224. + int methods_length);
  3225. };
  3226. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3227. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3228. index eec2e23..cc793e2 100644
  3229. --- a/src/share/vm/oops/instanceKlass.cpp
  3230. +++ b/src/share/vm/oops/instanceKlass.cpp
  3231. @@ -248,12 +248,118 @@ void instanceKlass::initialize(TRAPS) {
  3232. }
  3233. +void instanceKlass::initialize_redefined_class() {
  3234. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3235. + name()->as_C_string()));
  3236. +
  3237. + assert(!is_initialized(), "");
  3238. + assert(this->old_version() != NULL, "");
  3239. + assert(is_linked(), "must be linked before");
  3240. +
  3241. +
  3242. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3243. + class UpdateStaticFieldClosure : public FieldClosure {
  3244. +
  3245. + private:
  3246. + instanceKlassHandle this_oop;
  3247. +
  3248. + public:
  3249. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3250. + this->this_oop = this_oop;
  3251. + }
  3252. +
  3253. + virtual void do_field(fieldDescriptor* fd) {
  3254. + fieldDescriptor result;
  3255. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3256. +
  3257. + if (found && result.is_static()) {
  3258. + int old_offset = result.offset();
  3259. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3260. +
  3261. + oop new_location = this_oop()->java_mirror();
  3262. + oop old_location = this_oop->old_version()->java_mirror();
  3263. + int offset = fd->offset();
  3264. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3265. + fd->name()->as_C_string(), old_offset, offset));
  3266. +
  3267. + oop cur_oop;
  3268. +
  3269. + switch(result.field_type()) {
  3270. +
  3271. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3272. +
  3273. + case T_BOOLEAN:
  3274. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3275. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3276. + break;
  3277. +
  3278. + case T_CHAR:
  3279. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3280. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3281. + break;
  3282. +
  3283. + case T_FLOAT:
  3284. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3285. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3286. + break;
  3287. +
  3288. + case T_DOUBLE:
  3289. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3290. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3291. + break;
  3292. +
  3293. + case T_BYTE:
  3294. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3295. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3296. + break;
  3297. +
  3298. + case T_SHORT:
  3299. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3300. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3301. + break;
  3302. +
  3303. + case T_INT:
  3304. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3305. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3306. + break;
  3307. +
  3308. + case T_LONG:
  3309. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3310. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3311. + break;
  3312. +
  3313. + case T_OBJECT:
  3314. + case T_ARRAY:
  3315. + cur_oop = old_location->obj_field(old_offset);
  3316. + new_location->obj_field_put_raw(offset, cur_oop);
  3317. + old_location->obj_field_put_raw(old_offset, NULL);
  3318. + break;
  3319. +
  3320. + default:
  3321. + ShouldNotReachHere();
  3322. + }
  3323. + } else {
  3324. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3325. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3326. + // field not found
  3327. + // (tw) TODO: Probably this call is not necessary here!
  3328. + // FIXME: idubrov
  3329. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3330. + }
  3331. + }
  3332. + };
  3333. +
  3334. + UpdateStaticFieldClosure cl(this_oop);
  3335. + this->do_local_static_fields(&cl);
  3336. +}
  3337. +
  3338. +
  3339. bool instanceKlass::verify_code(
  3340. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3341. // 1) Verify the bytecodes
  3342. Verifier::Mode mode =
  3343. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3344. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3345. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3346. }
  3347. @@ -360,7 +466,13 @@ bool instanceKlass::link_class_impl(
  3348. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3349. jt->get_thread_stat()->perf_timers_addr(),
  3350. PerfClassTraceTime::CLASS_VERIFY);
  3351. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3352. + if (this_oop->is_redefining()) {
  3353. + Thread::current()->set_pretend_new_universe(true);
  3354. + }
  3355. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3356. + if (this_oop->is_redefining()) {
  3357. + Thread::current()->set_pretend_new_universe(false);
  3358. + }
  3359. if (!verify_ok) {
  3360. return false;
  3361. }
  3362. @@ -398,7 +510,8 @@ bool instanceKlass::link_class_impl(
  3363. }
  3364. #endif
  3365. this_oop->set_init_state(linked);
  3366. - if (JvmtiExport::should_post_class_prepare()) {
  3367. + // (tw) Must check for old version in order to prevent infinite loops.
  3368. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3369. Thread *thread = THREAD;
  3370. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3371. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3372. @@ -665,6 +778,18 @@ bool instanceKlass::implements_interface(klassOop k) const {
  3373. return false;
  3374. }
  3375. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3376. + k = k->klass_part()->newest_version();
  3377. + if (this->newest_version() == k) return true;
  3378. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3379. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3380. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3381. + return true;
  3382. + }
  3383. + }
  3384. + return false;
  3385. +}
  3386. +
  3387. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3388. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3389. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3390. @@ -793,7 +918,25 @@ methodOop instanceKlass::class_initializer() {
  3391. }
  3392. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3393. +
  3394. + ResourceMark rm(THREAD);
  3395. methodHandle h_method(THREAD, this_oop->class_initializer());
  3396. +
  3397. + if (this_oop->revision_number() != -1){
  3398. + methodOop m = NULL;
  3399. + if (AllowAdvancedClassRedefinition) {
  3400. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3401. + }
  3402. + methodHandle method(m);
  3403. + if (method() != NULL && method()->is_static()) {
  3404. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3405. + h_method = method;
  3406. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3407. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3408. + return;
  3409. + }
  3410. + }
  3411. +
  3412. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3413. if (TraceClassInitialization) {
  3414. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3415. @@ -942,6 +1085,137 @@ void instanceKlass::methods_do(void f(methodOop method)) {
  3416. }
  3417. }
  3418. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3419. + int *arr = NEW_C_HEAP_ARRAY(int, values.length());
  3420. + for (int i=0; i<values.length(); i++) {
  3421. + arr[i] = values.at(i);
  3422. + }
  3423. + set_update_information(arr);
  3424. +}
  3425. +
  3426. +void instanceKlass::clear_update_information() {
  3427. + FREE_C_HEAP_ARRAY(int, update_information());
  3428. + set_update_information(NULL);
  3429. +}
  3430. +
  3431. +typedef Pair<int, klassOop> typeInfoPair;
  3432. +
  3433. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3434. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length());
  3435. + for (int i=0; i<values.length(); i++) {
  3436. + arr[i] = values.at(i);
  3437. + }
  3438. + set_type_check_information(arr);
  3439. +}
  3440. +
  3441. +void instanceKlass::clear_type_check_information() {
  3442. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information());
  3443. + set_type_check_information(NULL);
  3444. +}
  3445. +
  3446. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3447. +
  3448. + assert (old_version() != NULL, "must have old version!");
  3449. +
  3450. + klassOop old_klass_oop = old_version();
  3451. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3452. + instanceKlass *new_klass = this;
  3453. +
  3454. + fieldDescriptor fd;
  3455. + fieldDescriptor old_fd;
  3456. +
  3457. + instanceKlass *cur_new_klass = new_klass;
  3458. + klassOop cur_new_klass_oop = this->as_klassOop();
  3459. +
  3460. + if (_fields_not_changed) {
  3461. +
  3462. + class MyFieldClosure : public FieldClosure {
  3463. +
  3464. + FieldEvolutionClosure *_cl;
  3465. + public:
  3466. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3467. + virtual void do_field(fieldDescriptor* fd) {
  3468. + _cl->do_changed_field(fd, fd);
  3469. + }
  3470. + };
  3471. +
  3472. + MyFieldClosure mfc(cl);
  3473. + do_nonstatic_fields(&mfc);
  3474. + } else {
  3475. +
  3476. + _fields_not_changed = true;
  3477. + GrowableArray<fieldDescriptor> fds;
  3478. + while (true) {
  3479. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3480. + fd.initialize(cur_new_klass_oop, fs.index());
  3481. + if (fd.is_static()) {
  3482. + continue;
  3483. + }
  3484. + fds.append(fd);
  3485. + }
  3486. +
  3487. + if (cur_new_klass->super() != NULL) {
  3488. + cur_new_klass_oop = cur_new_klass->super();
  3489. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3490. + } else {
  3491. + break;
  3492. + }
  3493. + }
  3494. +
  3495. + GrowableArray<fieldDescriptor> sortedFds;
  3496. + while (fds.length() > 0) {
  3497. + int minOffset = 0x7fffffff;
  3498. + int minIndex = -1;
  3499. + for (int i=0; i<fds.length(); i++) {
  3500. + int curOffset = fds.adr_at(i)->offset();
  3501. + if (curOffset < minOffset) {
  3502. + minOffset = curOffset;
  3503. + minIndex = i;
  3504. + }
  3505. + }
  3506. +
  3507. + sortedFds.append(fds.at(minIndex));
  3508. + fds.remove_at(minIndex);
  3509. + }
  3510. +
  3511. +
  3512. + for (int i=0; i<sortedFds.length(); i++) {
  3513. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3514. +
  3515. + char found = 0;
  3516. + instanceKlass *cur_old_klass = old_klass;
  3517. + klassOop cur_old_klass_oop = old_klass_oop;
  3518. + while (true) {
  3519. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3520. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3521. + if (old_fd.is_static()) {
  3522. + continue;
  3523. + }
  3524. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3525. + found = 1;
  3526. + break;
  3527. + }
  3528. + }
  3529. + if (!found && cur_old_klass->super()) {
  3530. + cur_old_klass_oop = cur_old_klass->super();
  3531. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3532. + } else {
  3533. + break;
  3534. + }
  3535. + }
  3536. +
  3537. + if (found) {
  3538. + if (old_fd.offset() != fd.offset()) {
  3539. + _fields_not_changed = false;
  3540. + }
  3541. + cl->do_changed_field(&old_fd, &fd);
  3542. + } else {
  3543. + _fields_not_changed = false;
  3544. + cl->do_new_field(&fd);
  3545. + }
  3546. + }
  3547. + }
  3548. +}
  3549. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3550. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3551. @@ -1331,6 +1605,20 @@ jmethodID instanceKlass::jmethod_id_or_null(methodOop method) {
  3552. return id;
  3553. }
  3554. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3555. + size_t idnum = (size_t)method->method_idnum();
  3556. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3557. + size_t length; // length assigned as debugging crumb
  3558. + jmethodID id = NULL;
  3559. + if (jmeths != NULL && // If there is a cache
  3560. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3561. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3562. + return true;
  3563. + }
  3564. +
  3565. + return false;
  3566. +}
  3567. +
  3568. // Cache an itable index
  3569. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3570. @@ -1490,6 +1778,13 @@ void instanceKlass::remove_dependent_nmethod(nmethod* nm) {
  3571. last = b;
  3572. b = b->next();
  3573. }
  3574. +
  3575. + // (tw) Hack as dependencies get wrong version of klassOop
  3576. + if(this->old_version() != NULL) {
  3577. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3578. + return;
  3579. + }
  3580. +
  3581. #ifdef ASSERT
  3582. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3583. nm->print();
  3584. @@ -2337,6 +2632,9 @@ void instanceKlass::oop_print_on(oop obj, outputStream* st) {
  3585. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3586. st->print(BULLET"fake entry for mirror: ");
  3587. mirrored_klass->print_value_on(st);
  3588. + if (mirrored_klass != NULL) {
  3589. + 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());
  3590. + }
  3591. st->cr();
  3592. st->print(BULLET"fake entry resolved_constructor: ");
  3593. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3594. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3595. index e981cde..fb79827 100644
  3596. --- a/src/share/vm/oops/instanceKlass.hpp
  3597. +++ b/src/share/vm/oops/instanceKlass.hpp
  3598. @@ -99,6 +99,22 @@ public:
  3599. virtual void do_field(fieldDescriptor* fd) = 0;
  3600. };
  3601. +// (tw) Iterates over the fields of the old and new class
  3602. +class FieldEvolutionClosure : public StackObj {
  3603. +public:
  3604. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3605. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3606. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3607. +};
  3608. +
  3609. +// (tw) Iterates over the methods of the old and new class
  3610. +class MethodEvolutionClosure : public StackObj {
  3611. +public:
  3612. + virtual void do_new_method(methodOop oop) = 0;
  3613. + virtual void do_old_method(methodOop oop) = 0;
  3614. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3615. +};
  3616. +
  3617. #ifndef PRODUCT
  3618. // Print fields.
  3619. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3620. @@ -264,6 +280,11 @@ class instanceKlass: public Klass {
  3621. // _idnum_allocated_count.
  3622. u1 _init_state; // state of class
  3623. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3624. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3625. + // information is cached.
  3626. + bool _fields_not_changed;
  3627. +
  3628. u1 _reference_type; // reference type
  3629. // embedded Java vtable follows here
  3630. @@ -397,6 +418,7 @@ class instanceKlass: public Klass {
  3631. // initialization (virtuals from Klass)
  3632. bool should_be_initialized() const; // means that initialize should be called
  3633. void initialize(TRAPS);
  3634. + void initialize_redefined_class();
  3635. void link_class(TRAPS);
  3636. bool link_class_or_fail(TRAPS); // returns false on failure
  3637. void unlink_class();
  3638. @@ -549,6 +571,7 @@ class instanceKlass: public Klass {
  3639. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3640. size_t *length_p, jmethodID* id_p);
  3641. jmethodID jmethod_id_or_null(methodOop method);
  3642. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3643. // cached itable index support
  3644. void set_cached_itable_index(size_t idnum, int index);
  3645. @@ -630,6 +653,7 @@ class instanceKlass: public Klass {
  3646. // subclass/subinterface checks
  3647. bool implements_interface(klassOop k) const;
  3648. + bool implements_interface_any_version(klassOop k) const;
  3649. // Access to implementors of an interface. We only store the count
  3650. // of implementors, and in case, there are only a few
  3651. @@ -659,6 +683,12 @@ class instanceKlass: public Klass {
  3652. void do_local_static_fields(FieldClosure* cl);
  3653. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3654. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3655. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3656. + void store_update_information(GrowableArray<int> &values);
  3657. + void clear_update_information();
  3658. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3659. + void clear_type_check_information();
  3660. +
  3661. void methods_do(void f(methodOop method));
  3662. void array_klasses_do(void f(klassOop k));
  3663. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3664. index fa13f17..ef1444b 100644
  3665. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3666. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3667. @@ -451,6 +451,28 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  3668. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3669. klassKlass::oop_print_on(obj, st);
  3670. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3671. +
  3672. + st->print(BULLET"revision: %d", ik->revision_number());
  3673. +
  3674. + if (ik->new_version() != NULL) {
  3675. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3676. + }
  3677. +
  3678. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3679. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3680. + }
  3681. +
  3682. + if (ik->old_version() != NULL) {
  3683. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3684. + }
  3685. +
  3686. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3687. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3688. + }
  3689. +
  3690. + st->cr();
  3691. +
  3692. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3693. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3694. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3695. @@ -636,7 +658,7 @@ void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
  3696. }
  3697. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3698. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3699. - guarantee(sib->super() == super, "siblings should have same superklass");
  3700. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3701. sib = sib->next_sibling();
  3702. }
  3703. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3704. index 71a7a1f..c7644b0 100644
  3705. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3706. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3707. @@ -455,10 +455,13 @@ void instanceRefKlass::update_nonstatic_oop_maps(klassOop k) {
  3708. instanceKlass* ik = instanceKlass::cast(k);
  3709. // Check that we have the right class
  3710. - debug_only(static bool first_time = true);
  3711. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3712. - "Invalid update of maps");
  3713. - debug_only(first_time = false);
  3714. +
  3715. + // (tw) Asserts no longer valid for class redefinition
  3716. + // debug_only(static bool first_time = true);
  3717. +
  3718. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3719. + // "Invalid update of maps");
  3720. + //debug_only(first_time = false);
  3721. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3722. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3723. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3724. index 345d0b2..f49db6c 100644
  3725. --- a/src/share/vm/oops/klass.cpp
  3726. +++ b/src/share/vm/oops/klass.cpp
  3727. @@ -54,6 +54,26 @@ bool Klass::is_subclass_of(klassOop k) const {
  3728. return false;
  3729. }
  3730. +void Klass::update_supers_to_newest_version() {
  3731. +
  3732. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3733. +
  3734. + for (uint i=0; i<primary_super_limit(); i++) {
  3735. + klassOop cur = _primary_supers[i];
  3736. + if (cur != NULL) {
  3737. + _primary_supers[i] = cur->klass_part()->newest_version();
  3738. + }
  3739. + }
  3740. +
  3741. + // Scan the array-of-objects
  3742. + int cnt = secondary_supers()->length();
  3743. + for (int i = 0; i < cnt; i++) {
  3744. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3745. + if (cur != NULL) {
  3746. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3747. + }
  3748. + }
  3749. +}
  3750. bool Klass::search_secondary_supers(klassOop k) const {
  3751. // Put some extra logic here out-of-line, before the search proper.
  3752. // This cuts down the size of the inline method.
  3753. @@ -160,6 +180,16 @@ klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
  3754. kl->set_alloc_size(0);
  3755. TRACE_SET_KLASS_TRACE_ID(kl, 0);
  3756. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3757. + kl->set_redefining(false);
  3758. + kl->set_new_version(NULL);
  3759. + kl->set_old_version(NULL);
  3760. + kl->set_redefinition_index(-1);
  3761. + kl->set_revision_number(-1);
  3762. + kl->set_field_redefinition_policy(DynamicCheck);
  3763. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3764. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3765. +
  3766. kl->set_prototype_header(markOopDesc::prototype());
  3767. kl->set_biased_lock_revocation_count(0);
  3768. kl->set_last_biased_lock_bulk_revocation_time(0);
  3769. @@ -232,7 +262,7 @@ void Klass::initialize_supers(klassOop k, TRAPS) {
  3770. set_super(NULL);
  3771. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3772. assert(super_depth() == 0, "Object must already be initialized properly");
  3773. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3774. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3775. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3776. "initialize this only once to a non-trivial value");
  3777. set_super(k);
  3778. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3779. index 035f44c..3cd26a3 100644
  3780. --- a/src/share/vm/oops/klass.hpp
  3781. +++ b/src/share/vm/oops/klass.hpp
  3782. @@ -170,6 +170,7 @@ class Klass_vtbl {
  3783. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3784. };
  3785. +template<class L, class R> class Pair;
  3786. class Klass : public Klass_vtbl {
  3787. friend class VMStructs;
  3788. @@ -222,6 +223,39 @@ class Klass : public Klass_vtbl {
  3789. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3790. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3791. + // (tw) Different class redefinition flags of code evolution.
  3792. + enum RedefinitionFlags {
  3793. +
  3794. + // This class is not redefined at all!
  3795. + NoRedefinition,
  3796. +
  3797. + // There are changes to the class meta data.
  3798. + ModifyClass = 1,
  3799. +
  3800. + // The size of the class meta data changes.
  3801. + ModifyClassSize = ModifyClass << 1,
  3802. +
  3803. + // There are change to the instance format.
  3804. + ModifyInstances = ModifyClassSize << 1,
  3805. +
  3806. + // The size of instances changes.
  3807. + ModifyInstanceSize = ModifyInstances << 1,
  3808. +
  3809. + // A super type of this class is removed.
  3810. + RemoveSuperType = ModifyInstanceSize << 1,
  3811. +
  3812. + // This class (or one of its super classes) has an instance transformer method.
  3813. + HasInstanceTransformer = RemoveSuperType << 1,
  3814. + };
  3815. +
  3816. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3817. + enum RedefinitionPolicy {
  3818. + StaticCheck,
  3819. + DynamicCheck,
  3820. + AccessDeletedMembers,
  3821. + AccessOldMembers
  3822. + };
  3823. +
  3824. protected:
  3825. //
  3826. // The oop block. All oop fields must be declared here and only oop fields
  3827. @@ -241,6 +275,10 @@ class Klass : public Klass_vtbl {
  3828. oop _java_mirror;
  3829. // Superclass
  3830. klassOop _super;
  3831. + // Old class
  3832. + klassOop _old_version;
  3833. + // New class
  3834. + klassOop _new_version;
  3835. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3836. klassOop _subklass;
  3837. // Sibling link (or NULL); links all subklasses of a klass
  3838. @@ -253,6 +291,19 @@ class Klass : public Klass_vtbl {
  3839. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3840. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3841. + // (tw) Non-oop fields for enhanced class redefinition
  3842. + jint _revision_number; // The revision number for redefined classes
  3843. + jint _redefinition_index; // Index of this class when performing the redefinition
  3844. + bool _subtype_changed;
  3845. + int _redefinition_flags; // Level of class redefinition
  3846. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3847. + int * _update_information; // Update information
  3848. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3849. + char _method_redefinition_policy;
  3850. + char _field_redefinition_policy;
  3851. + char _static_field_redefinition_policy;
  3852. + bool _is_redefining;
  3853. +
  3854. #ifndef PRODUCT
  3855. int _verify_count; // to avoid redundant verifies
  3856. #endif
  3857. @@ -301,6 +352,99 @@ class Klass : public Klass_vtbl {
  3858. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3859. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3860. + // BEGIN class redefinition utilities
  3861. +
  3862. + // double links between new and old version of a class
  3863. + klassOop old_version() const { return _old_version; }
  3864. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3865. + klassOop new_version() const { return _new_version; }
  3866. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3867. +
  3868. + // A subtype of this class is no longer a subtype
  3869. + bool has_subtype_changed() const { return _subtype_changed; }
  3870. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3871. + _subtype_changed = b; }
  3872. + // state of being redefined
  3873. + int redefinition_index() const { return _redefinition_index; }
  3874. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3875. + void set_redefining(bool b) { _is_redefining = b; }
  3876. + bool is_redefining() const { return _is_redefining; }
  3877. + int redefinition_flags() const { return _redefinition_flags; }
  3878. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3879. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3880. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3881. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3882. +
  3883. + // update information
  3884. + int *update_information() const { return _update_information; }
  3885. + void set_update_information(int *info) { _update_information = info; }
  3886. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3887. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3888. +
  3889. + bool is_same_or_older_version(klassOop klass) const {
  3890. + if (Klass::cast(klass) == this) { return true; }
  3891. + else if (_old_version == NULL) { return false; }
  3892. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3893. + }
  3894. +
  3895. + // Revision number for redefined classes, -1 for originally loaded classes
  3896. + jint revision_number() const {
  3897. + return _revision_number;
  3898. + }
  3899. +
  3900. + bool was_redefined() const {
  3901. + return _revision_number != -1;
  3902. + }
  3903. +
  3904. + void set_revision_number(jint number) {
  3905. + _revision_number = number;
  3906. + }
  3907. +
  3908. + char method_redefinition_policy() {
  3909. + return _method_redefinition_policy;
  3910. + }
  3911. +
  3912. + void set_method_redefinition_policy(char v) {
  3913. + _method_redefinition_policy = v;
  3914. + }
  3915. +
  3916. + char field_redefinition_policy() {
  3917. + return _field_redefinition_policy;
  3918. + }
  3919. +
  3920. + void set_field_redefinition_policy(char v) {
  3921. + _field_redefinition_policy = v;
  3922. + }
  3923. +
  3924. + char static_field_redefinition_policy() {
  3925. + return _static_field_redefinition_policy;
  3926. + }
  3927. +
  3928. + void set_static_field_redefinition_policy(char v) {
  3929. + _static_field_redefinition_policy = v;
  3930. + }
  3931. +
  3932. + klassOop oldest_version() const {
  3933. + if (_old_version == NULL) { return this->as_klassOop(); }
  3934. + else { return _old_version->klass_part()->oldest_version(); };
  3935. + }
  3936. +
  3937. + klassOop newest_version() const {
  3938. + if (_new_version == NULL) { return this->as_klassOop(); }
  3939. + else { return _new_version->klass_part()->newest_version(); };
  3940. + }
  3941. +
  3942. + klassOop active_version() const {
  3943. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3944. + else { return _new_version->klass_part()->active_version(); };
  3945. + }
  3946. +
  3947. + bool is_newest_version() const {
  3948. + return _new_version == NULL;
  3949. + }
  3950. +
  3951. + // END class redefinition utilities
  3952. +
  3953. objArrayOop secondary_supers() const { return _secondary_supers; }
  3954. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3955. @@ -361,6 +505,8 @@ class Klass : public Klass_vtbl {
  3956. void set_next_sibling(klassOop s);
  3957. oop* adr_super() const { return (oop*)&_super; }
  3958. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3959. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3960. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3961. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3962. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3963. @@ -490,6 +636,7 @@ class Klass : public Klass_vtbl {
  3964. return search_secondary_supers(k);
  3965. }
  3966. }
  3967. + void update_supers_to_newest_version();
  3968. bool search_secondary_supers(klassOop k) const;
  3969. // Find LCA in class hierarchy
  3970. @@ -818,6 +965,8 @@ class Klass : public Klass_vtbl {
  3971. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  3972. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  3973. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  3974. #endif // SHARE_VM_OOPS_KLASS_HPP
  3975. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  3976. index 06809d5..9c08f32 100644
  3977. --- a/src/share/vm/oops/klassKlass.cpp
  3978. +++ b/src/share/vm/oops/klassKlass.cpp
  3979. @@ -68,6 +68,8 @@ void klassKlass::oop_follow_contents(oop obj) {
  3980. Klass* k = Klass::cast(klassOop(obj));
  3981. // If we are alive it is valid to keep our superclass and subtype caches alive
  3982. MarkSweep::mark_and_push(k->adr_super());
  3983. + MarkSweep::mark_and_push(k->adr_old_version());
  3984. + MarkSweep::mark_and_push(k->adr_new_version());
  3985. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3986. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3987. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3988. @@ -87,6 +89,8 @@ void klassKlass::oop_follow_contents(ParCompactionManager* cm,
  3989. Klass* k = Klass::cast(klassOop(obj));
  3990. // If we are alive it is valid to keep our superclass and subtype caches alive
  3991. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3992. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3993. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3994. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3995. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3996. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3997. @@ -106,6 +110,8 @@ int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  3998. int size = oop_size(obj);
  3999. Klass* k = Klass::cast(klassOop(obj));
  4000. blk->do_oop(k->adr_super());
  4001. + blk->do_oop(k->adr_old_version());
  4002. + blk->do_oop(k->adr_new_version());
  4003. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4004. blk->do_oop(k->adr_primary_supers()+i);
  4005. blk->do_oop(k->adr_secondary_super_cache());
  4006. @@ -134,6 +140,10 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4007. oop* adr;
  4008. adr = k->adr_super();
  4009. if (mr.contains(adr)) blk->do_oop(adr);
  4010. + adr = k->adr_old_version();
  4011. + if (mr.contains(adr)) blk->do_oop(adr);
  4012. + adr = k->adr_new_version();
  4013. + if (mr.contains(adr)) blk->do_oop(adr);
  4014. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4015. adr = k->adr_primary_supers()+i;
  4016. if (mr.contains(adr)) blk->do_oop(adr);
  4017. @@ -147,6 +157,8 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4018. // The following are "weak links" in the perm gen and are
  4019. // treated specially in a later phase of a perm gen collection.
  4020. assert(oop(k)->is_perm(), "should be in perm");
  4021. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4022. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4023. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4024. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4025. if (blk->should_remember_klasses()
  4026. @@ -167,6 +179,8 @@ int klassKlass::oop_adjust_pointers(oop obj) {
  4027. Klass* k = Klass::cast(klassOop(obj));
  4028. MarkSweep::adjust_pointer(k->adr_super());
  4029. + MarkSweep::adjust_pointer(k->adr_new_version());
  4030. + MarkSweep::adjust_pointer(k->adr_old_version());
  4031. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4032. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4033. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4034. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4035. index f212fc5..9731a9c 100644
  4036. --- a/src/share/vm/oops/klassOop.hpp
  4037. +++ b/src/share/vm/oops/klassOop.hpp
  4038. @@ -41,8 +41,10 @@ class klassOopDesc : public oopDesc {
  4039. // returns the Klass part containing dispatching behavior
  4040. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4041. - // Convenience wrapper
  4042. + // Convenience wrappers
  4043. inline oop java_mirror() const;
  4044. + inline klassOop old_version() const;
  4045. + inline klassOop new_version() const;
  4046. private:
  4047. // These have no implementation since klassOop should never be accessed in this fashion
  4048. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4049. index 8b8bc7d..cefe839 100644
  4050. --- a/src/share/vm/oops/klassVtable.cpp
  4051. +++ b/src/share/vm/oops/klassVtable.cpp
  4052. @@ -97,7 +97,8 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4053. vtable_length = Universe::base_vtable_size();
  4054. }
  4055. - if (super == NULL && !Universe::is_bootstrapping() &&
  4056. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4057. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4058. vtable_length != Universe::base_vtable_size()) {
  4059. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4060. // only way this should happen is from
  4061. @@ -107,9 +108,9 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4062. vtable_length = Universe::base_vtable_size();
  4063. }
  4064. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4065. - "bad vtable size for class Object");
  4066. + "bad vtable size for class Object");*/
  4067. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4068. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4069. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4070. }
  4071. int klassVtable::index_of(methodOop m, int len) const {
  4072. @@ -1186,6 +1187,7 @@ void klassVtable::verify(outputStream* st, bool forced) {
  4073. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4074. vtableEntry* vte = &vt->table()[index];
  4075. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4076. if (vte->method()->name() != table()[index].method()->name() ||
  4077. vte->method()->signature() != table()[index].method()->signature()) {
  4078. fatal("mismatched name/signature of vtable entries");
  4079. @@ -1205,6 +1207,8 @@ void klassVtable::print() {
  4080. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4081. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4082. + // (tw) TODO: Check: Does not hold?
  4083. + if (method() != NULL) {
  4084. assert(method() != NULL, "must have set method");
  4085. method()->verify();
  4086. // we sub_type, because it could be a miranda method
  4087. @@ -1212,7 +1216,13 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4088. #ifndef PRODUCT
  4089. print();
  4090. #endif
  4091. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4092. + klassOop first_klass = vt->klass()();
  4093. + klassOop second_klass = method()->method_holder();
  4094. + // (tw) the following fatal does not work for old versions of classes
  4095. + if (first_klass->klass_part()->is_newest_version()) {
  4096. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4097. + }
  4098. + }
  4099. }
  4100. }
  4101. @@ -1220,7 +1230,7 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4102. void vtableEntry::print() {
  4103. ResourceMark rm;
  4104. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4105. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4106. if (Verbose) {
  4107. tty->print("m %#lx ", (address)method());
  4108. }
  4109. @@ -1292,7 +1302,7 @@ bool klassVtable::check_no_old_entries() {
  4110. for (int i = 0; i < length(); i++) {
  4111. methodOop m = unchecked_method_at(i);
  4112. if (m != NULL) {
  4113. - if (m->is_old()) {
  4114. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4115. return false;
  4116. }
  4117. }
  4118. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4119. index b2d6235..1876420 100644
  4120. --- a/src/share/vm/oops/methodKlass.cpp
  4121. +++ b/src/share/vm/oops/methodKlass.cpp
  4122. @@ -93,6 +93,10 @@ methodOop methodKlass::allocate(constMethodHandle xconst,
  4123. m->set_adapter_entry(NULL);
  4124. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4125. + m->set_forward_method(NULL);
  4126. + m->set_new_version(NULL);
  4127. + m->set_old_version(NULL);
  4128. +
  4129. if (access_flags.is_native()) {
  4130. m->clear_native_function();
  4131. m->set_signature_handler(NULL);
  4132. @@ -127,6 +131,9 @@ void methodKlass::oop_follow_contents(oop obj) {
  4133. // Performance tweak: We skip iterating over the klass pointer since we
  4134. // know that Universe::methodKlassObj never moves.
  4135. MarkSweep::mark_and_push(m->adr_constMethod());
  4136. + MarkSweep::mark_and_push(m->adr_forward_method());
  4137. + MarkSweep::mark_and_push(m->adr_new_version());
  4138. + MarkSweep::mark_and_push(m->adr_old_version());
  4139. MarkSweep::mark_and_push(m->adr_constants());
  4140. if (m->method_data() != NULL) {
  4141. MarkSweep::mark_and_push(m->adr_method_data());
  4142. @@ -141,6 +148,9 @@ void methodKlass::oop_follow_contents(ParCompactionManager* cm,
  4143. // Performance tweak: We skip iterating over the klass pointer since we
  4144. // know that Universe::methodKlassObj never moves.
  4145. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4146. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4147. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4148. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4149. PSParallelCompact::mark_and_push(cm, m->adr_constants());
  4150. #ifdef COMPILER2
  4151. if (m->method_data() != NULL) {
  4152. @@ -159,6 +169,9 @@ int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  4153. // Performance tweak: We skip iterating over the klass pointer since we
  4154. // know that Universe::methodKlassObj never moves
  4155. blk->do_oop(m->adr_constMethod());
  4156. + blk->do_oop(m->adr_forward_method());
  4157. + blk->do_oop(m->adr_new_version());
  4158. + blk->do_oop(m->adr_old_version());
  4159. blk->do_oop(m->adr_constants());
  4160. if (m->method_data() != NULL) {
  4161. blk->do_oop(m->adr_method_data());
  4162. @@ -178,6 +191,12 @@ int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4163. oop* adr;
  4164. adr = m->adr_constMethod();
  4165. if (mr.contains(adr)) blk->do_oop(adr);
  4166. + adr = m->adr_new_version();
  4167. + if (mr.contains(adr)) blk->do_oop(adr);
  4168. + adr = m->adr_forward_method();
  4169. + if (mr.contains(adr)) blk->do_oop(adr);
  4170. + adr = m->adr_old_version();
  4171. + if (mr.contains(adr)) blk->do_oop(adr);
  4172. adr = m->adr_constants();
  4173. if (mr.contains(adr)) blk->do_oop(adr);
  4174. if (m->method_data() != NULL) {
  4175. @@ -197,6 +216,9 @@ int methodKlass::oop_adjust_pointers(oop obj) {
  4176. // Performance tweak: We skip iterating over the klass pointer since we
  4177. // know that Universe::methodKlassObj never moves.
  4178. MarkSweep::adjust_pointer(m->adr_constMethod());
  4179. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4180. + MarkSweep::adjust_pointer(m->adr_new_version());
  4181. + MarkSweep::adjust_pointer(m->adr_old_version());
  4182. MarkSweep::adjust_pointer(m->adr_constants());
  4183. if (m->method_data() != NULL) {
  4184. MarkSweep::adjust_pointer(m->adr_method_data());
  4185. @@ -213,6 +235,9 @@ int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
  4186. assert(obj->is_method(), "should be method");
  4187. methodOop m = methodOop(obj);
  4188. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4189. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4190. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4191. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4192. PSParallelCompact::adjust_pointer(m->adr_constants());
  4193. #ifdef COMPILER2
  4194. if (m->method_data() != NULL) {
  4195. @@ -234,7 +259,18 @@ void methodKlass::oop_print_on(oop obj, outputStream* st) {
  4196. methodOop m = methodOop(obj);
  4197. // get the effect of PrintOopAddress, always, for methods:
  4198. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4199. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4200. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4201. +
  4202. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4203. + st->print(" (old)");
  4204. + }
  4205. + st->cr();
  4206. +
  4207. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4208. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4209. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4210. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4211. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4212. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4213. m->constants()->print_value_on(st); st->cr();
  4214. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4215. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4216. index 0a7850f..c62ce28 100644
  4217. --- a/src/share/vm/oops/methodOop.cpp
  4218. +++ b/src/share/vm/oops/methodOop.cpp
  4219. @@ -328,6 +328,70 @@ void methodOopDesc::cleanup_inline_caches() {
  4220. }
  4221. +bool methodOopDesc::is_in_code_section(int bci) {
  4222. + // There is no table => every bci is in the code section table.
  4223. + if (!constMethod()->has_code_section_table()) return true;
  4224. +
  4225. + constMethodOop m = constMethod();
  4226. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4227. + u2 new_index = m->code_section_new_index_at(i);
  4228. + u2 length = m->code_section_length_at(i);
  4229. + if (bci >= new_index && bci < new_index + length) {
  4230. + // We are in a specified code section.
  4231. + return true;
  4232. + }
  4233. + }
  4234. +
  4235. + return false;
  4236. +}
  4237. +
  4238. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4239. + int original_bci = -1;
  4240. + if (constMethod()->has_code_section_table()) {
  4241. + assert(is_in_code_section(bci), "can only forward in section");
  4242. + // First calculate back to original bci.
  4243. + constMethodOop m = constMethod();
  4244. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4245. + u2 new_index = m->code_section_new_index_at(i);
  4246. + u2 original_index = m->code_section_original_index_at(i);
  4247. + u2 length = m->code_section_length_at(i);
  4248. + if (bci >= new_index && bci < new_index + length) {
  4249. + // We are in a specified code section.
  4250. + original_bci = bci - new_index + original_index;
  4251. + break;
  4252. + }
  4253. + }
  4254. + assert (original_bci != -1, "must have been in code section");
  4255. + } else {
  4256. + // No code sections specified => we are in an original method.
  4257. + original_bci = bci;
  4258. + }
  4259. +
  4260. + // We know the original bci => match to new method.
  4261. + int new_bci = -1;
  4262. + if (new_method->constMethod()->has_code_section_table()) {
  4263. + // Map to new bci.
  4264. + constMethodOop m = new_method->constMethod();
  4265. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4266. + u2 new_index = m->code_section_new_index_at(i);
  4267. + u2 original_index = m->code_section_original_index_at(i);
  4268. + u2 length = m->code_section_length_at(i);
  4269. + if (original_bci >= original_index && original_bci < original_index + length) {
  4270. + new_bci = original_bci - original_index + new_index;
  4271. + break;
  4272. + }
  4273. + }
  4274. + assert (new_bci != -1, "must have found new code section");
  4275. +
  4276. + } else {
  4277. + // We are in an original method.
  4278. + new_bci = original_bci;
  4279. + }
  4280. +
  4281. + return new_bci;
  4282. +}
  4283. +
  4284. +
  4285. int methodOopDesc::extra_stack_words() {
  4286. // not an inline function, to avoid a header dependency on Interpreter
  4287. return extra_stack_entries() * Interpreter::stackElementSize;
  4288. @@ -1079,6 +1143,9 @@ methodHandle methodOopDesc:: clone_with_new_data(methodHandle m, u_char* new_cod
  4289. // Reset correct method/const method, method size, and parameter info
  4290. newcm->set_method(newm());
  4291. newm->set_constMethod(newcm);
  4292. + newm->set_forward_method(newm->forward_method());
  4293. + newm->set_new_version(newm->new_version());
  4294. + newm->set_old_version(newm->old_version());
  4295. assert(newcm->method() == newm(), "check");
  4296. newm->constMethod()->set_code_size(new_code_length);
  4297. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4298. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4299. index 03f62f6..7f7b05a 100644
  4300. --- a/src/share/vm/oops/methodOop.hpp
  4301. +++ b/src/share/vm/oops/methodOop.hpp
  4302. @@ -116,6 +116,11 @@ class methodOopDesc : public oopDesc {
  4303. AccessFlags _access_flags; // Access flags
  4304. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4305. // note: can have vtables with >2**16 elements (because of inheritance)
  4306. + // (tw) Newer version of method available?
  4307. + methodOop _forward_method;
  4308. + methodOop _new_version;
  4309. + methodOop _old_version;
  4310. +
  4311. #ifdef CC_INTERP
  4312. int _result_index; // C++ interpreter needs for converting results to/from stack
  4313. #endif
  4314. @@ -174,6 +179,32 @@ class methodOopDesc : public oopDesc {
  4315. int name_index() const { return constMethod()->name_index(); }
  4316. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4317. + methodOop forward_method() const {return _forward_method; }
  4318. + void set_forward_method(methodOop m) { _forward_method = m; }
  4319. + bool has_forward_method() const { return forward_method() != NULL; }
  4320. + methodOop new_version() const {return _new_version; }
  4321. + void set_new_version(methodOop m) { _new_version = m; }
  4322. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4323. +
  4324. + methodOop old_version() const {return _old_version; };
  4325. + void set_old_version(methodOop m) {
  4326. + if (m == NULL) {
  4327. + _old_version = NULL;
  4328. + return;
  4329. + }
  4330. +
  4331. + assert(_old_version == NULL, "may only be set once");
  4332. + assert(this->code_size() == m->code_size(), "must have same code length");
  4333. + _old_version = m;
  4334. + }
  4335. +
  4336. + methodOop oldest_version() const {
  4337. + if(_old_version == NULL) return (methodOop)this;
  4338. + else {
  4339. + return old_version()->oldest_version();
  4340. + }
  4341. + }
  4342. +
  4343. // signature
  4344. Symbol* signature() const { return _constants->symbol_at(signature_index()); }
  4345. int signature_index() const { return constMethod()->signature_index(); }
  4346. @@ -670,6 +701,10 @@ class methodOopDesc : public oopDesc {
  4347. // Inline cache support
  4348. void cleanup_inline_caches();
  4349. + // (tw) Method forwarding support.
  4350. + bool is_in_code_section(int bci);
  4351. + int calculate_forward_bci(int bci, methodOop new_method);
  4352. +
  4353. // Find if klass for method is loaded
  4354. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4355. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4356. @@ -723,6 +758,9 @@ class methodOopDesc : public oopDesc {
  4357. // Garbage collection support
  4358. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4359. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4360. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4361. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4362. oop* adr_constants() const { return (oop*)&_constants; }
  4363. oop* adr_method_data() const { return (oop*)&_method_data; }
  4364. };
  4365. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4366. index 4d2f453..3ea0396 100644
  4367. --- a/src/share/vm/oops/oop.hpp
  4368. +++ b/src/share/vm/oops/oop.hpp
  4369. @@ -94,6 +94,7 @@ class oopDesc {
  4370. narrowOop* compressed_klass_addr();
  4371. void set_klass(klassOop k);
  4372. + void set_klass_no_check(klassOop k);
  4373. // For klass field compression
  4374. int klass_gap() const;
  4375. @@ -134,6 +135,7 @@ class oopDesc {
  4376. bool is_array() const;
  4377. bool is_objArray() const;
  4378. bool is_klass() const;
  4379. + bool is_instanceKlass() const;
  4380. bool is_thread() const;
  4381. bool is_method() const;
  4382. bool is_constMethod() const;
  4383. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4384. index a050f96..09258e1 100644
  4385. --- a/src/share/vm/oops/oop.inline.hpp
  4386. +++ b/src/share/vm/oops/oop.inline.hpp
  4387. @@ -115,6 +115,14 @@ inline void oopDesc::set_klass(klassOop k) {
  4388. }
  4389. }
  4390. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4391. + if (UseCompressedOops) {
  4392. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4393. + } else {
  4394. + oop_store_without_check(klass_addr(), (oop) k);
  4395. + }
  4396. +}
  4397. +
  4398. inline int oopDesc::klass_gap() const {
  4399. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4400. }
  4401. @@ -148,6 +156,7 @@ inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_
  4402. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4403. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4404. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4405. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4406. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4407. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4408. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4409. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4410. index 166bbd6..fc1025f 100644
  4411. --- a/src/share/vm/prims/jni.cpp
  4412. +++ b/src/share/vm/prims/jni.cpp
  4413. @@ -405,7 +405,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
  4414. }
  4415. }
  4416. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4417. - Handle(), &st, true,
  4418. + Handle(), &st, true, KlassHandle(),
  4419. CHECK_NULL);
  4420. if (TraceClassResolution && k != NULL) {
  4421. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4422. index 4c503fe..9b43779 100644
  4423. --- a/src/share/vm/prims/jvm.cpp
  4424. +++ b/src/share/vm/prims/jvm.cpp
  4425. @@ -866,7 +866,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
  4426. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4427. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4428. protection_domain, &st,
  4429. - verify != 0,
  4430. + verify != 0, KlassHandle(),
  4431. CHECK_NULL);
  4432. if (TraceClassResolution && k != NULL) {
  4433. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4434. index 46519bb..7fd634a 100644
  4435. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4436. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4437. @@ -290,7 +290,10 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4438. class_definitions[index].klass = jcls;
  4439. }
  4440. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4441. - VMThread::execute(&op);
  4442. + {
  4443. + MutexLocker sd_mutex(RedefineClasses_lock);
  4444. + VMThread::execute(&op);
  4445. + }
  4446. return (op.check_error());
  4447. } /* end RetransformClasses */
  4448. @@ -299,9 +302,12 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4449. // class_definitions - pre-checked for NULL
  4450. jvmtiError
  4451. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4452. -//TODO: add locking
  4453. +
  4454. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4455. - VMThread::execute(&op);
  4456. + {
  4457. + MutexLocker sd_mutex(RedefineClasses_lock);
  4458. + VMThread::execute(&op);
  4459. + }
  4460. return (op.check_error());
  4461. } /* end RedefineClasses */
  4462. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4463. index 5325073..247167a 100644
  4464. --- a/src/share/vm/prims/jvmtiExport.cpp
  4465. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4466. @@ -2307,7 +2307,7 @@ JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(N
  4467. // iterate over any code blob descriptors collected and post a
  4468. // DYNAMIC_CODE_GENERATED event to the profiler.
  4469. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4470. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4471. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4472. // iterate over any code blob descriptors that we collected
  4473. if (_code_blobs != NULL) {
  4474. for (int i=0; i<_code_blobs->length(); i++) {
  4475. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4476. index e0d809d..19a4413 100644
  4477. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4478. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4479. @@ -286,6 +286,8 @@ address JvmtiBreakpoint::getBcp() {
  4480. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4481. ((methodOopDesc*)_method->*meth_act)(_bci);
  4482. + // DCEVM: TODO: Check how we can implement this differently here!
  4483. +
  4484. // add/remove breakpoint to/from versions of the method that
  4485. // are EMCP. Directly or transitively obsolete methods are
  4486. // not saved in the PreviousVersionInfo.
  4487. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4488. index 295ed86..fdfc6f4 100644
  4489. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4490. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4491. @@ -30,491 +30,637 @@
  4492. #include "interpreter/rewriter.hpp"
  4493. #include "memory/gcLocker.hpp"
  4494. #include "memory/universe.inline.hpp"
  4495. -#include "oops/fieldStreams.hpp"
  4496. +#include "memory/cardTableRS.hpp"
  4497. #include "oops/klassVtable.hpp"
  4498. +#include "oops/fieldStreams.hpp"
  4499. #include "prims/jvmtiImpl.hpp"
  4500. #include "prims/jvmtiRedefineClasses.hpp"
  4501. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4502. #include "prims/methodComparator.hpp"
  4503. #include "runtime/deoptimization.hpp"
  4504. #include "runtime/relocator.hpp"
  4505. #include "utilities/bitMap.inline.hpp"
  4506. +#include "compiler/compileBroker.hpp"
  4507. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4508. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4509. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4510. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4511. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4512. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4513. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4514. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4515. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4516. +int* VM_RedefineClasses::_added_methods = NULL;
  4517. int VM_RedefineClasses::_matching_methods_length = 0;
  4518. int VM_RedefineClasses::_deleted_methods_length = 0;
  4519. int VM_RedefineClasses::_added_methods_length = 0;
  4520. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4521. +// Holds the revision number of the current class redefinition
  4522. +int VM_RedefineClasses::_revision_number = -1;
  4523. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4524. - const jvmtiClassDefinition *class_defs,
  4525. - JvmtiClassLoadKind class_load_kind) {
  4526. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4527. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4528. + RC_TIMER_START(_timer_total);
  4529. _class_count = class_count;
  4530. _class_defs = class_defs;
  4531. _class_load_kind = class_load_kind;
  4532. - _res = JVMTI_ERROR_NONE;
  4533. + _updated_oops = NULL;
  4534. + _result = JVMTI_ERROR_NONE;
  4535. }
  4536. -bool VM_RedefineClasses::doit_prologue() {
  4537. - if (_class_count == 0) {
  4538. - _res = JVMTI_ERROR_NONE;
  4539. - return false;
  4540. +VM_RedefineClasses::~VM_RedefineClasses() {
  4541. + {
  4542. + MonitorLockerEx ml(RedefinitionSync_lock);
  4543. + Threads::set_wait_at_instrumentation_entry(false);
  4544. + ml.notify_all();
  4545. + }
  4546. +
  4547. + unlock_threads();
  4548. + RC_TIMER_STOP(_timer_total);
  4549. +
  4550. + if (TimeRedefineClasses) {
  4551. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4552. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4553. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4554. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4555. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4556. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4557. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4558. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4559. + tty->print_cr("------------------------------------------------------------------");
  4560. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4561. }
  4562. - if (_class_defs == NULL) {
  4563. - _res = JVMTI_ERROR_NULL_POINTER;
  4564. - return false;
  4565. +}
  4566. +
  4567. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4568. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4569. +
  4570. + // Create array with all classes for which the redefine command was given
  4571. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4572. + for (int i=0; i<_class_count; i++) {
  4573. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4574. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4575. + klasses_to_redefine.append(klass_handle);
  4576. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4577. }
  4578. - for (int i = 0; i < _class_count; i++) {
  4579. - if (_class_defs[i].klass == NULL) {
  4580. - _res = JVMTI_ERROR_INVALID_CLASS;
  4581. - return false;
  4582. - }
  4583. - if (_class_defs[i].class_byte_count == 0) {
  4584. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4585. - return false;
  4586. - }
  4587. - if (_class_defs[i].class_bytes == NULL) {
  4588. - _res = JVMTI_ERROR_NULL_POINTER;
  4589. - return false;
  4590. +
  4591. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4592. + GrowableArray<instanceKlassHandle> affected_classes;
  4593. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4594. +
  4595. + // Trace affected classes
  4596. + if (RC_TRACE_ENABLED(0x00000001)) {
  4597. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4598. + affected_classes.length()));
  4599. + for (int i=0; i<affected_classes.length(); i++) {
  4600. + RC_TRACE(0x00000001, ("%s",
  4601. + affected_classes.at(i)->name()->as_C_string()));
  4602. }
  4603. }
  4604. - // Start timer after all the sanity checks; not quite accurate, but
  4605. - // better than adding a bunch of stop() calls.
  4606. - RC_TIMER_START(_timer_vm_op_prologue);
  4607. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4608. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4609. + all_affected_klasses->appendAll(&affected_classes);
  4610. - // We first load new class versions in the prologue, because somewhere down the
  4611. - // call chain it is required that the current thread is a Java thread.
  4612. - _res = load_new_class_versions(Thread::current());
  4613. - if (_res != JVMTI_ERROR_NONE) {
  4614. - // Free os::malloc allocated memory in load_new_class_version.
  4615. - os::free(_scratch_classes);
  4616. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4617. - return false;
  4618. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4619. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4620. + if (RC_TRACE_ENABLED(0x00000001)) {
  4621. + RC_TRACE(0x00000001, ("Redefine order: "));
  4622. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4623. + RC_TRACE(0x00000001, ("%s",
  4624. + all_affected_klasses->at(i)->name()->as_C_string()));
  4625. + }
  4626. }
  4627. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4628. - return true;
  4629. + return result;
  4630. }
  4631. -void VM_RedefineClasses::doit() {
  4632. - Thread *thread = Thread::current();
  4633. +// Searches for the class bytes of the given class and returns them as a byte array.
  4634. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4635. - if (UseSharedSpaces) {
  4636. - // Sharing is enabled so we remap the shared readonly space to
  4637. - // shared readwrite, private just in case we need to redefine
  4638. - // a shared class. We do the remap during the doit() phase of
  4639. - // the safepoint to be safer.
  4640. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4641. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4642. - ("failed to remap shared readonly space to readwrite, private"));
  4643. - _res = JVMTI_ERROR_INTERNAL;
  4644. - return;
  4645. + *not_changed = false;
  4646. +
  4647. + // Search for the index in the redefinition array that corresponds to the current class
  4648. + int j;
  4649. + for (j=0; j<_class_count; j++) {
  4650. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4651. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4652. + if (the_class_oop == the_class()) {
  4653. + break;
  4654. }
  4655. }
  4656. - for (int i = 0; i < _class_count; i++) {
  4657. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4658. - }
  4659. - // Disable any dependent concurrent compilations
  4660. - SystemDictionary::notice_modification();
  4661. + if (j == _class_count) {
  4662. - // Set flag indicating that some invariants are no longer true.
  4663. - // See jvmtiExport.hpp for detailed explanation.
  4664. - JvmtiExport::set_has_redefined_a_class();
  4665. + *not_changed = true;
  4666. -#ifdef ASSERT
  4667. - SystemDictionary::classes_do(check_class, thread);
  4668. -#endif
  4669. -}
  4670. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4671. + // so the user did not specify a different bytecode for that class.
  4672. -void VM_RedefineClasses::doit_epilogue() {
  4673. - // Free os::malloc allocated memory.
  4674. - // The memory allocated in redefine will be free'ed in next VM operation.
  4675. - os::free(_scratch_classes);
  4676. -
  4677. - if (RC_TRACE_ENABLED(0x00000004)) {
  4678. - // Used to have separate timers for "doit" and "all", but the timer
  4679. - // overhead skewed the measurements.
  4680. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4681. - _timer_rsc_phase2.milliseconds();
  4682. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4683. -
  4684. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4685. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4686. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4687. - RC_TRACE(0x00000004,
  4688. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4689. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4690. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4691. + // not cached, we need to reconstitute the class file from VM representation
  4692. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4693. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4694. +
  4695. + JvmtiClassFileReconstituter reconstituter(the_class);
  4696. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4697. + return reconstituter.get_error();
  4698. + }
  4699. +
  4700. + *class_byte_count = (jint)reconstituter.class_file_size();
  4701. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4702. +
  4703. + } else {
  4704. +
  4705. + // it is cached, get it from the cache
  4706. + *class_byte_count = the_class->get_cached_class_file_len();
  4707. + *class_bytes = the_class->get_cached_class_file_bytes();
  4708. + }
  4709. +
  4710. + } else {
  4711. +
  4712. + // Redefine with bytecodes at index j
  4713. + *class_bytes = _class_defs[j].class_bytes;
  4714. + *class_byte_count = _class_defs[j].class_byte_count;
  4715. }
  4716. +
  4717. + return JVMTI_ERROR_NONE;
  4718. }
  4719. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4720. - // classes for primitives cannot be redefined
  4721. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4722. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4723. +bool VM_RedefineClasses::doit_prologue() {
  4724. +
  4725. + _revision_number++;
  4726. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4727. +
  4728. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4729. + RC_TIMER_START(_timer_prologue);
  4730. +
  4731. + if (!check_arguments()) {
  4732. + RC_TIMER_STOP(_timer_prologue);
  4733. return false;
  4734. }
  4735. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4736. - // classes for arrays cannot be redefined
  4737. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4738. +
  4739. + // We first load new class versions in the prologue, because somewhere down the
  4740. + // call chain it is required that the current thread is a Java thread.
  4741. + _new_classes = new (ResourceObj::C_HEAP) GrowableArray<instanceKlassHandle>(5, true);
  4742. + _result = load_new_class_versions(Thread::current());
  4743. +
  4744. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4745. + if (_result != JVMTI_ERROR_NONE) {
  4746. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4747. + delete _new_classes;
  4748. + _new_classes = NULL;
  4749. + RC_TIMER_STOP(_timer_prologue);
  4750. return false;
  4751. }
  4752. +
  4753. + RC_TRACE(0x00000001, ("nearly finished"));
  4754. + VM_GC_Operation::doit_prologue();
  4755. + RC_TIMER_STOP(_timer_prologue);
  4756. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4757. return true;
  4758. }
  4759. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4760. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4761. -// direct CP entries, there is just the current entry to append. For
  4762. -// indirect and double-indirect CP entries, there are zero or more
  4763. -// referenced CP entries along with the current entry to append.
  4764. -// Indirect and double-indirect CP entries are handled by recursive
  4765. -// calls to append_entry() as needed. The referenced CP entries are
  4766. -// always appended to *merge_cp_p before the referee CP entry. These
  4767. -// referenced CP entries may already exist in *merge_cp_p in which case
  4768. -// there is nothing extra to append and only the current entry is
  4769. -// appended.
  4770. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4771. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4772. - TRAPS) {
  4773. -
  4774. - // append is different depending on entry tag type
  4775. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4776. -
  4777. - // The old verifier is implemented outside the VM. It loads classes,
  4778. - // but does not resolve constant pool entries directly so we never
  4779. - // see Class entries here with the old verifier. Similarly the old
  4780. - // verifier does not like Class entries in the input constant pool.
  4781. - // The split-verifier is implemented in the VM so it can optionally
  4782. - // and directly resolve constant pool entries to load classes. The
  4783. - // split-verifier can accept either Class entries or UnresolvedClass
  4784. - // entries in the input constant pool. We revert the appended copy
  4785. - // back to UnresolvedClass so that either verifier will be happy
  4786. - // with the constant pool entry.
  4787. - case JVM_CONSTANT_Class:
  4788. - {
  4789. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4790. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4791. - scratch_cp->klass_name_at(scratch_i));
  4792. -
  4793. - if (scratch_i != *merge_cp_length_p) {
  4794. - // The new entry in *merge_cp_p is at a different index than
  4795. - // the new entry in scratch_cp so we need to map the index values.
  4796. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4797. - }
  4798. - (*merge_cp_length_p)++;
  4799. - } break;
  4800. -
  4801. - // these are direct CP entries so they can be directly appended,
  4802. - // but double and long take two constant pool entries
  4803. - case JVM_CONSTANT_Double: // fall through
  4804. - case JVM_CONSTANT_Long:
  4805. - {
  4806. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4807. - THREAD);
  4808. -
  4809. - if (scratch_i != *merge_cp_length_p) {
  4810. - // The new entry in *merge_cp_p is at a different index than
  4811. - // the new entry in scratch_cp so we need to map the index values.
  4812. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4813. - }
  4814. - (*merge_cp_length_p) += 2;
  4815. - } break;
  4816. -
  4817. - // these are direct CP entries so they can be directly appended
  4818. - case JVM_CONSTANT_Float: // fall through
  4819. - case JVM_CONSTANT_Integer: // fall through
  4820. - case JVM_CONSTANT_Utf8: // fall through
  4821. -
  4822. - // This was an indirect CP entry, but it has been changed into
  4823. - // an interned string so this entry can be directly appended.
  4824. - case JVM_CONSTANT_String: // fall through
  4825. -
  4826. - // These were indirect CP entries, but they have been changed into
  4827. - // Symbol*s so these entries can be directly appended.
  4828. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4829. - case JVM_CONSTANT_UnresolvedString:
  4830. - {
  4831. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4832. - THREAD);
  4833. +// Checks basic properties of the arguments of the redefinition command.
  4834. +bool VM_RedefineClasses::check_arguments() {
  4835. - if (scratch_i != *merge_cp_length_p) {
  4836. - // The new entry in *merge_cp_p is at a different index than
  4837. - // the new entry in scratch_cp so we need to map the index values.
  4838. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4839. - }
  4840. - (*merge_cp_length_p)++;
  4841. - } break;
  4842. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4843. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4844. + for (int i = 0; i < _class_count; i++) {
  4845. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4846. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4847. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4848. + }
  4849. - // this is an indirect CP entry so it needs special handling
  4850. - case JVM_CONSTANT_NameAndType:
  4851. - {
  4852. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4853. - int new_name_ref_i = 0;
  4854. - bool match = (name_ref_i < *merge_cp_length_p) &&
  4855. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  4856. - THREAD);
  4857. - if (!match) {
  4858. - // forward reference in *merge_cp_p or not a direct match
  4859. + return true;
  4860. +}
  4861. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  4862. - THREAD);
  4863. - if (found_i != 0) {
  4864. - guarantee(found_i != name_ref_i,
  4865. - "compare_entry_to() and find_matching_entry() do not agree");
  4866. -
  4867. - // Found a matching entry somewhere else in *merge_cp_p so
  4868. - // just need a mapping entry.
  4869. - new_name_ref_i = found_i;
  4870. - map_index(scratch_cp, name_ref_i, found_i);
  4871. - } else {
  4872. - // no match found so we have to append this entry to *merge_cp_p
  4873. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  4874. - THREAD);
  4875. - // The above call to append_entry() can only append one entry
  4876. - // so the post call query of *merge_cp_length_p is only for
  4877. - // the sake of consistency.
  4878. - new_name_ref_i = *merge_cp_length_p - 1;
  4879. +jvmtiError VM_RedefineClasses::check_exception() const {
  4880. + Thread* THREAD = Thread::current();
  4881. + if (HAS_PENDING_EXCEPTION) {
  4882. +
  4883. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4884. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4885. + ex_name->as_C_string()));
  4886. + if (TraceRedefineClasses >= 1) {
  4887. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4888. + tty->print_cr("");
  4889. + }
  4890. + CLEAR_PENDING_EXCEPTION;
  4891. +
  4892. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4893. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4894. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4895. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4896. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4897. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4898. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4899. + // The message will be "XXX (wrong name: YYY)"
  4900. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4901. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4902. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4903. + } else {
  4904. + // Just in case more exceptions can be thrown..
  4905. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4906. + }
  4907. + }
  4908. +
  4909. + return JVMTI_ERROR_NONE;
  4910. +}
  4911. +
  4912. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4913. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4914. +
  4915. + ResourceMark rm(THREAD);
  4916. +
  4917. + RC_TRACE(0x00000001, ("==================================================================="));
  4918. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  4919. + _class_count));
  4920. +
  4921. + // Retrieve an array of all classes that need to be redefined
  4922. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4923. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4924. + if (err != JVMTI_ERROR_NONE) {
  4925. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  4926. + (int)err));
  4927. + return err;
  4928. + }
  4929. +
  4930. +
  4931. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4932. +
  4933. + _max_redefinition_flags = Klass::NoRedefinition;
  4934. + jvmtiError result = JVMTI_ERROR_NONE;
  4935. +
  4936. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4937. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  4938. + i+1, all_affected_klasses.length()));
  4939. +
  4940. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4941. + RC_TRACE(0x00000002, ("name=%s",
  4942. + the_class->name()->as_C_string()));
  4943. +
  4944. + the_class->link_class(THREAD);
  4945. + result = check_exception();
  4946. + if (result != JVMTI_ERROR_NONE) break;
  4947. +
  4948. + // Find new class bytes
  4949. + const unsigned char* class_bytes;
  4950. + jint class_byte_count;
  4951. + jvmtiError error;
  4952. + jboolean not_changed;
  4953. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4954. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  4955. + (int)error));
  4956. + result = error;
  4957. + break;
  4958. + }
  4959. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4960. +
  4961. +
  4962. + // Set redefined class handle in JvmtiThreadState class.
  4963. + // This redefined class is sent to agent event handler for class file
  4964. + // load hook event.
  4965. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4966. +
  4967. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  4968. +
  4969. + RC_TIMER_STOP(_timer_prologue);
  4970. + RC_TIMER_START(_timer_class_loading);
  4971. +
  4972. +
  4973. + // Parse the stream.
  4974. + Handle the_class_loader(THREAD, the_class->class_loader());
  4975. + Handle protection_domain(THREAD, the_class->protection_domain());
  4976. + Symbol* the_class_sym = the_class->name();
  4977. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4978. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  4979. + the_class_loader,
  4980. + protection_domain,
  4981. + &st,
  4982. + true,
  4983. + the_class,
  4984. + THREAD));
  4985. +
  4986. + not_changed = false;
  4987. +
  4988. + RC_TIMER_STOP(_timer_class_loading);
  4989. + RC_TIMER_START(_timer_prologue);
  4990. +
  4991. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  4992. + // Clear class_being_redefined just to be sure.
  4993. + state->clear_class_being_redefined();
  4994. +
  4995. + result = check_exception();
  4996. + if (result != JVMTI_ERROR_NONE) break;
  4997. +
  4998. +#ifdef ASSERT
  4999. +
  5000. + assert(new_class() != NULL, "Class could not be loaded!");
  5001. + assert(new_class() != the_class(), "must be different");
  5002. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5003. +
  5004. +
  5005. + objArrayOop k_interfaces = new_class->local_interfaces();
  5006. + for (int j=0; j<k_interfaces->length(); j++) {
  5007. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5008. + }
  5009. +
  5010. + if (!THREAD->is_Compiler_thread()) {
  5011. +
  5012. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5013. + the_class->name()->as_C_string(),
  5014. + (address)(the_class->class_loader()),
  5015. + (address)(the_class->protection_domain())));
  5016. + // If we are on the compiler thread, we must not try to resolve a class.
  5017. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5018. +
  5019. + if (systemLookup != NULL) {
  5020. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5021. +
  5022. +
  5023. + Klass *subklass = new_class()->klass_part()->subklass();
  5024. + while (subklass != NULL) {
  5025. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5026. + subklass = subklass->next_sibling();
  5027. }
  5028. + } else {
  5029. + // This can happen for reflection generated classes.. ?
  5030. + CLEAR_PENDING_EXCEPTION;
  5031. }
  5032. + }
  5033. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5034. - int new_signature_ref_i = 0;
  5035. - match = (signature_ref_i < *merge_cp_length_p) &&
  5036. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  5037. - signature_ref_i, THREAD);
  5038. - if (!match) {
  5039. - // forward reference in *merge_cp_p or not a direct match
  5040. -
  5041. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  5042. - *merge_cp_p, THREAD);
  5043. - if (found_i != 0) {
  5044. - guarantee(found_i != signature_ref_i,
  5045. - "compare_entry_to() and find_matching_entry() do not agree");
  5046. -
  5047. - // Found a matching entry somewhere else in *merge_cp_p so
  5048. - // just need a mapping entry.
  5049. - new_signature_ref_i = found_i;
  5050. - map_index(scratch_cp, signature_ref_i, found_i);
  5051. - } else {
  5052. - // no match found so we have to append this entry to *merge_cp_p
  5053. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  5054. - merge_cp_length_p, THREAD);
  5055. - // The above call to append_entry() can only append one entry
  5056. - // so the post call query of *merge_cp_length_p is only for
  5057. - // the sake of consistency.
  5058. - new_signature_ref_i = *merge_cp_length_p - 1;
  5059. - }
  5060. +#endif
  5061. +
  5062. + if (RC_TRACE_ENABLED(0x00000001)) {
  5063. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5064. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5065. + new_class->name()->as_C_string(),
  5066. + new_class->layout_helper(),
  5067. + the_class->layout_helper()));
  5068. }
  5069. + }
  5070. - // If the referenced entries already exist in *merge_cp_p, then
  5071. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5072. - // In that case, all we are appending is the current entry.
  5073. - if (new_name_ref_i == 0) {
  5074. - new_name_ref_i = name_ref_i;
  5075. - } else {
  5076. - RC_TRACE(0x00080000,
  5077. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5078. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5079. + // Set the new version of the class
  5080. + new_class->set_revision_number(_revision_number);
  5081. + new_class->set_redefinition_index(i);
  5082. + the_class->set_new_version(new_class());
  5083. + _new_classes->append(new_class);
  5084. +
  5085. + assert(new_class->new_version() == NULL, "");
  5086. +
  5087. + int redefinition_flags = Klass::NoRedefinition;
  5088. +
  5089. + if (not_changed) {
  5090. + redefinition_flags = Klass::NoRedefinition;
  5091. + } else if (AllowAdvancedClassRedefinition) {
  5092. + redefinition_flags = calculate_redefinition_flags(new_class);
  5093. + } else {
  5094. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5095. + if (allowed != JVMTI_ERROR_NONE) {
  5096. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5097. + result = allowed;
  5098. + break;
  5099. }
  5100. - if (new_signature_ref_i == 0) {
  5101. - new_signature_ref_i = signature_ref_i;
  5102. - } else {
  5103. - RC_TRACE(0x00080000,
  5104. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5105. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5106. + redefinition_flags = Klass::ModifyClass;
  5107. + }
  5108. +
  5109. + if (new_class->super() != NULL) {
  5110. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5111. + }
  5112. +
  5113. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5114. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5115. + }
  5116. +
  5117. + new_class->set_redefinition_flags(redefinition_flags);
  5118. +
  5119. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5120. +
  5121. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5122. + // TODO: Check if watch access flags of static fields are updated correctly.
  5123. + calculate_instance_update_information(_new_classes->at(i)());
  5124. + } else {
  5125. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5126. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5127. +
  5128. + fieldDescriptor fd_new;
  5129. + fieldDescriptor fd_old;
  5130. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5131. + fd_new.initialize(new_class(), fs.index());
  5132. + fd_old.initialize(new_class->old_version(), fs.index());
  5133. + transfer_special_access_flags(&fd_old, &fd_new);
  5134. }
  5135. + }
  5136. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5137. - new_name_ref_i, new_signature_ref_i);
  5138. - if (scratch_i != *merge_cp_length_p) {
  5139. - // The new entry in *merge_cp_p is at a different index than
  5140. - // the new entry in scratch_cp so we need to map the index values.
  5141. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5142. + if (RC_TRACE_ENABLED(0x00000008)) {
  5143. + if (new_class->super() != NULL) {
  5144. + RC_TRACE(0x00000008, ("Super class is %s",
  5145. + new_class->super()->klass_part()->name()->as_C_string()));
  5146. }
  5147. - (*merge_cp_length_p)++;
  5148. - } break;
  5149. + }
  5150. - // this is a double-indirect CP entry so it needs special handling
  5151. - case JVM_CONSTANT_Fieldref: // fall through
  5152. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5153. - case JVM_CONSTANT_Methodref:
  5154. - {
  5155. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5156. - int new_klass_ref_i = 0;
  5157. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  5158. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  5159. - THREAD);
  5160. - if (!match) {
  5161. - // forward reference in *merge_cp_p or not a direct match
  5162. +#ifdef ASSERT
  5163. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5164. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  5165. - THREAD);
  5166. - if (found_i != 0) {
  5167. - guarantee(found_i != klass_ref_i,
  5168. - "compare_entry_to() and find_matching_entry() do not agree");
  5169. -
  5170. - // Found a matching entry somewhere else in *merge_cp_p so
  5171. - // just need a mapping entry.
  5172. - new_klass_ref_i = found_i;
  5173. - map_index(scratch_cp, klass_ref_i, found_i);
  5174. - } else {
  5175. - // no match found so we have to append this entry to *merge_cp_p
  5176. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  5177. - THREAD);
  5178. - // The above call to append_entry() can only append one entry
  5179. - // so the post call query of *merge_cp_length_p is only for
  5180. - // the sake of consistency. Without the optimization where we
  5181. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  5182. - // could be appended.
  5183. - new_klass_ref_i = *merge_cp_length_p - 1;
  5184. - }
  5185. - }
  5186. + the_class->vtable()->verify(tty);
  5187. + new_class->vtable()->verify(tty);
  5188. +#endif
  5189. - int name_and_type_ref_i =
  5190. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5191. - int new_name_and_type_ref_i = 0;
  5192. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  5193. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  5194. - name_and_type_ref_i, THREAD);
  5195. - if (!match) {
  5196. - // forward reference in *merge_cp_p or not a direct match
  5197. -
  5198. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  5199. - *merge_cp_p, THREAD);
  5200. - if (found_i != 0) {
  5201. - guarantee(found_i != name_and_type_ref_i,
  5202. - "compare_entry_to() and find_matching_entry() do not agree");
  5203. -
  5204. - // Found a matching entry somewhere else in *merge_cp_p so
  5205. - // just need a mapping entry.
  5206. - new_name_and_type_ref_i = found_i;
  5207. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  5208. - } else {
  5209. - // no match found so we have to append this entry to *merge_cp_p
  5210. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  5211. - merge_cp_length_p, THREAD);
  5212. - // The above call to append_entry() can append more than
  5213. - // one entry so the post call query of *merge_cp_length_p
  5214. - // is required in order to get the right index for the
  5215. - // JVM_CONSTANT_NameAndType entry.
  5216. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  5217. + RC_TRACE(0x00000002, ("Verification done!"));
  5218. +
  5219. + if (i == all_affected_klasses.length() - 1) {
  5220. +
  5221. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5222. +
  5223. + RC_TIMER_STOP(_timer_prologue);
  5224. + lock_threads();
  5225. + RC_TIMER_START(_timer_prologue);
  5226. +
  5227. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5228. +
  5229. + klassOop initial_klass = all_affected_klasses.at(j)();
  5230. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5231. + Klass *cur_klass = initial_subklass;
  5232. + while(cur_klass != NULL) {
  5233. +
  5234. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5235. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5236. + if (!all_affected_klasses.contains(handle)) {
  5237. +
  5238. + int k = i + 1;
  5239. + for (; k<all_affected_klasses.length(); k++) {
  5240. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5241. + break;
  5242. + }
  5243. + }
  5244. + all_affected_klasses.insert_before(k, handle);
  5245. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5246. + cur_klass->name()->as_C_string()));
  5247. + }
  5248. + }
  5249. +
  5250. + cur_klass = cur_klass->next_sibling();
  5251. }
  5252. }
  5253. - // If the referenced entries already exist in *merge_cp_p, then
  5254. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  5255. - // 0. In that case, all we are appending is the current entry.
  5256. - if (new_klass_ref_i == 0) {
  5257. - new_klass_ref_i = klass_ref_i;
  5258. - }
  5259. - if (new_name_and_type_ref_i == 0) {
  5260. - new_name_and_type_ref_i = name_and_type_ref_i;
  5261. - }
  5262. + int new_count = all_affected_klasses.length() - 1 - i;
  5263. + if (new_count != 0) {
  5264. - const char *entry_name;
  5265. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5266. - case JVM_CONSTANT_Fieldref:
  5267. - entry_name = "Fieldref";
  5268. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5269. - new_name_and_type_ref_i);
  5270. - break;
  5271. - case JVM_CONSTANT_InterfaceMethodref:
  5272. - entry_name = "IFMethodref";
  5273. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5274. - new_klass_ref_i, new_name_and_type_ref_i);
  5275. - break;
  5276. - case JVM_CONSTANT_Methodref:
  5277. - entry_name = "Methodref";
  5278. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5279. - new_name_and_type_ref_i);
  5280. - break;
  5281. - default:
  5282. - guarantee(false, "bad switch");
  5283. - break;
  5284. + unlock_threads();
  5285. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5286. + new_count));
  5287. }
  5288. + }
  5289. + }
  5290. - if (klass_ref_i != new_klass_ref_i) {
  5291. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5292. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5293. - }
  5294. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5295. - RC_TRACE(0x00080000,
  5296. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5297. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5298. - new_name_and_type_ref_i));
  5299. - }
  5300. + if (result != JVMTI_ERROR_NONE) {
  5301. + rollback();
  5302. + return result;
  5303. + }
  5304. - if (scratch_i != *merge_cp_length_p) {
  5305. - // The new entry in *merge_cp_p is at a different index than
  5306. - // the new entry in scratch_cp so we need to map the index values.
  5307. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5308. - }
  5309. - (*merge_cp_length_p)++;
  5310. - } break;
  5311. + RC_TIMER_STOP(_timer_prologue);
  5312. + RC_TIMER_START(_timer_class_linking);
  5313. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5314. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5315. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5316. + instanceKlassHandle new_class(the_class->new_version());
  5317. - // At this stage, Class or UnresolvedClass could be here, but not
  5318. - // ClassIndex
  5319. - case JVM_CONSTANT_ClassIndex: // fall through
  5320. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5321. + i,
  5322. + all_affected_klasses.length(),
  5323. + the_class->name()->as_C_string()));
  5324. + new_class->link_class(THREAD);
  5325. - // Invalid is used as the tag for the second constant pool entry
  5326. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5327. - // not be seen by itself.
  5328. - case JVM_CONSTANT_Invalid: // fall through
  5329. + result = check_exception();
  5330. + if (result != JVMTI_ERROR_NONE) break;
  5331. + }
  5332. + RC_TIMER_STOP(_timer_class_linking);
  5333. + RC_TIMER_START(_timer_prologue);
  5334. - // At this stage, String or UnresolvedString could be here, but not
  5335. - // StringIndex
  5336. - case JVM_CONSTANT_StringIndex: // fall through
  5337. + if (result != JVMTI_ERROR_NONE) {
  5338. + rollback();
  5339. + return result;
  5340. + }
  5341. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5342. - // here
  5343. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5344. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5345. - default:
  5346. - {
  5347. - // leave a breadcrumb
  5348. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5349. - ShouldNotReachHere();
  5350. - } break;
  5351. - } // end switch tag value
  5352. -} // end append_entry()
  5353. +#ifdef ASSERT
  5354. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5355. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5356. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5357. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5358. + assert(new_version->new_version() == NULL, "Must be newest version");
  5359. +
  5360. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5361. + new_version()->print();
  5362. + new_version->super()->print();
  5363. + }
  5364. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5365. + }
  5366. +
  5367. + SystemDictionary::classes_do(check_class, THREAD);
  5368. +
  5369. +#endif
  5370. +
  5371. + RC_TRACE(0x00000001, ("Finished verification!"));
  5372. + return JVMTI_ERROR_NONE;
  5373. +}
  5374. +
  5375. +void VM_RedefineClasses::lock_threads() {
  5376. +
  5377. + RC_TIMER_START(_timer_wait_for_locks);
  5378. +
  5379. +
  5380. + JavaThread *javaThread = Threads::first();
  5381. + while (javaThread != NULL) {
  5382. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5383. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5384. + compilerThread->set_should_bailout(true);
  5385. + }
  5386. + javaThread = javaThread->next();
  5387. + }
  5388. + int cnt = 0;
  5389. + javaThread = Threads::first();
  5390. + while (javaThread != NULL) {
  5391. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5392. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5393. + compilerThread->compilation_mutex()->lock();
  5394. + cnt++;
  5395. + }
  5396. + javaThread = javaThread->next();
  5397. + }
  5398. +
  5399. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5400. +
  5401. + cnt = 0;
  5402. + javaThread = Threads::first();
  5403. + while (javaThread != NULL) {
  5404. + if (javaThread != Thread::current()) {
  5405. + javaThread->redefine_classes_mutex()->lock();
  5406. + }
  5407. + javaThread = javaThread->next();
  5408. + }
  5409. +
  5410. +
  5411. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5412. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5413. - typeArrayOop save;
  5414. + RC_TIMER_STOP(_timer_wait_for_locks);
  5415. +}
  5416. +
  5417. +void VM_RedefineClasses::unlock_threads() {
  5418. +
  5419. + int cnt = 0;
  5420. + JavaThread *javaThread = Threads::first();
  5421. + Thread *thread = Thread::current();
  5422. + while (javaThread != NULL) {
  5423. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5424. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5425. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5426. + compilerThread->compilation_mutex()->unlock();
  5427. + cnt++;
  5428. + }
  5429. + }
  5430. + javaThread = javaThread->next();
  5431. + }
  5432. - save = scratch_class->get_method_annotations_of(i);
  5433. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5434. - scratch_class->set_method_annotations_of(j, save);
  5435. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5436. - save = scratch_class->get_method_parameter_annotations_of(i);
  5437. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5438. - scratch_class->set_method_parameter_annotations_of(j, save);
  5439. + cnt = 0;
  5440. + javaThread = Threads::first();
  5441. + while (javaThread != NULL) {
  5442. + if (javaThread != Thread::current()) {
  5443. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5444. + javaThread->redefine_classes_mutex()->unlock();
  5445. + }
  5446. + }
  5447. + javaThread = javaThread->next();
  5448. + }
  5449. - save = scratch_class->get_method_default_annotations_of(i);
  5450. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5451. - scratch_class->set_method_default_annotations_of(j, save);
  5452. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5453. }
  5454. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5455. +
  5456. +
  5457. +
  5458. + // Compatibility mode => check for unsupported modification
  5459. +
  5460. +
  5461. + assert(scratch_class->old_version() != NULL, "must have old version");
  5462. + instanceKlassHandle the_class(scratch_class->old_version());
  5463. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5464. - instanceKlassHandle the_class,
  5465. - instanceKlassHandle scratch_class) {
  5466. int i;
  5467. // Check superclasses, or rather their names, since superclasses themselves can be
  5468. // requested to replace.
  5469. // Check for NULL superclass first since this might be java.lang.Object
  5470. if (the_class->super() != scratch_class->super() &&
  5471. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5472. - Klass::cast(the_class->super())->name() !=
  5473. - Klass::cast(scratch_class->super())->name())) {
  5474. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5475. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5476. + Klass::cast(the_class->super())->name() !=
  5477. + Klass::cast(scratch_class->super())->name())) {
  5478. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5479. }
  5480. // Check if the number, names and order of directly implemented interfaces are the same.
  5481. @@ -532,8 +678,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5482. }
  5483. for (i = 0; i < n_intfs; i++) {
  5484. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5485. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5486. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5487. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5488. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5489. }
  5490. }
  5491. @@ -682,12 +828,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5492. idnum_owner->set_method_idnum(new_num);
  5493. }
  5494. k_new_method->set_method_idnum(old_num);
  5495. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5496. }
  5497. }
  5498. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5499. - k_new_method->name_and_sig_as_C_string(), ni,
  5500. - k_old_method->name_and_sig_as_C_string(), oi));
  5501. // advance to next pair of methods
  5502. ++oi;
  5503. ++ni;
  5504. @@ -696,11 +838,11 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5505. // method added, see if it is OK
  5506. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5507. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5508. - // hack: private should be treated as final, but alas
  5509. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5510. - ) {
  5511. - // new methods must be private
  5512. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5513. + // hack: private should be treated as final, but alas
  5514. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5515. + ) {
  5516. + // new methods must be private
  5517. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5518. }
  5519. {
  5520. u2 num = the_class->next_method_idnum();
  5521. @@ -715,24 +857,19 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5522. idnum_owner->set_method_idnum(new_num);
  5523. }
  5524. k_new_method->set_method_idnum(num);
  5525. - swap_all_method_annotations(new_num, num, scratch_class);
  5526. }
  5527. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5528. - k_new_method->name_and_sig_as_C_string(), ni));
  5529. ++ni; // advance to next new method
  5530. break;
  5531. case deleted:
  5532. // method deleted, see if it is OK
  5533. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5534. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5535. - // hack: private should be treated as final, but alas
  5536. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5537. - ) {
  5538. - // deleted methods must be private
  5539. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5540. + // hack: private should be treated as final, but alas
  5541. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5542. + ) {
  5543. + // deleted methods must be private
  5544. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5545. }
  5546. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5547. - k_old_method->name_and_sig_as_C_string(), oi));
  5548. ++oi; // advance to next old method
  5549. break;
  5550. default:
  5551. @@ -743,2217 +880,1789 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5552. return JVMTI_ERROR_NONE;
  5553. }
  5554. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5555. -// Find new constant pool index value for old constant pool index value
  5556. -// by seaching the index map. Returns zero (0) if there is no mapped
  5557. -// value for the old constant pool index.
  5558. -int VM_RedefineClasses::find_new_index(int old_index) {
  5559. - if (_index_map_count == 0) {
  5560. - // map is empty so nothing can be found
  5561. - return 0;
  5562. - }
  5563. + int result = Klass::NoRedefinition;
  5564. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5565. - // The old_index is out of range so it is not mapped. This should
  5566. - // not happen in regular constant pool merging use, but it can
  5567. - // happen if a corrupt annotation is processed.
  5568. - return 0;
  5569. - }
  5570. - int value = _index_map_p->at(old_index);
  5571. - if (value == -1) {
  5572. - // the old_index is not mapped
  5573. - return 0;
  5574. +
  5575. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5576. + new_class->name()->as_C_string()));
  5577. +
  5578. + assert(new_class->old_version() != NULL, "must have old version");
  5579. + instanceKlassHandle the_class(new_class->old_version());
  5580. +
  5581. + // Check whether class is in the error init state.
  5582. + if (the_class->is_in_error_state()) {
  5583. + // TBD #5057930: special error code is needed in 1.6
  5584. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5585. }
  5586. - return value;
  5587. -} // end find_new_index()
  5588. + int i;
  5589. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5590. + // Check superclasses
  5591. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5592. + if (the_class->super() != new_class->super()) {
  5593. + // Super class changed
  5594. +
  5595. + klassOop cur_klass = the_class->super();
  5596. + while (cur_klass != NULL) {
  5597. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5598. + RC_TRACE(0x00000002, ("Removed super class %s",
  5599. + cur_klass->klass_part()->name()->as_C_string()));
  5600. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5601. +
  5602. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5603. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5604. + cur_klass->klass_part()->name()->as_C_string()));
  5605. + cur_klass->klass_part()->set_subtype_changed(true);
  5606. + }
  5607. + }
  5608. -// Returns true if the current mismatch is due to a resolved/unresolved
  5609. -// class pair. Otherwise, returns false.
  5610. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5611. - int index1, constantPoolHandle cp2, int index2) {
  5612. + cur_klass = cur_klass->klass_part()->super();
  5613. + }
  5614. - jbyte t1 = cp1->tag_at(index1).value();
  5615. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5616. - return false; // wrong entry type; not our special case
  5617. + cur_klass = new_class->super();
  5618. + while (cur_klass != NULL) {
  5619. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5620. + RC_TRACE(0x00000002, ("Added super class %s",
  5621. + cur_klass->klass_part()->name()->as_C_string()));
  5622. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5623. + }
  5624. + cur_klass = cur_klass->klass_part()->super();
  5625. + }
  5626. + }
  5627. +
  5628. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5629. + // Check interfaces
  5630. +
  5631. + // Interfaces removed?
  5632. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5633. + for (i = 0; i<old_interfaces->length(); i++) {
  5634. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5635. + if (!new_class->implements_interface_any_version(old_interface())) {
  5636. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5637. + RC_TRACE(0x00000002, ("Removed interface %s",
  5638. + old_interface->name()->as_C_string()));
  5639. +
  5640. + if (!old_interface->has_subtype_changed()) {
  5641. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5642. + old_interface->name()->as_C_string()));
  5643. + old_interface->set_subtype_changed(true);
  5644. + }
  5645. + }
  5646. }
  5647. - jbyte t2 = cp2->tag_at(index2).value();
  5648. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5649. - return false; // wrong entry type; not our special case
  5650. + // Interfaces added?
  5651. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5652. + for (i = 0; i<new_interfaces->length(); i++) {
  5653. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5654. + result = result | Klass::ModifyClass;
  5655. + RC_TRACE(0x00000002, ("Added interface %s",
  5656. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  5657. + }
  5658. }
  5659. - if (t1 == t2) {
  5660. - return false; // not a mismatch; not our special case
  5661. - }
  5662. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5663. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5664. - if (strcmp(s1, s2) != 0) {
  5665. - return false; // strings don't match; not our special case
  5666. + // Check whether class modifiers are the same.
  5667. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5668. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5669. + if (old_flags != new_flags) {
  5670. + // TODO (tw): Can this have any effects?
  5671. }
  5672. - return true; // made it through the gauntlet; this is our special case
  5673. -} // end is_unresolved_class_mismatch()
  5674. + // Check if the number, names, types and order of fields declared in these classes
  5675. + // are the same.
  5676. + JavaFieldStream old_fs(the_class);
  5677. + JavaFieldStream new_fs(new_class);
  5678. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5679. + // access
  5680. + old_flags = old_fs.access_flags().as_short();
  5681. + new_flags = new_fs.access_flags().as_short();
  5682. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5683. + // (tw) Can this have any effects?
  5684. + }
  5685. + // offset
  5686. + if (old_fs.offset() != new_fs.offset()) {
  5687. + result = result | Klass::ModifyInstances;
  5688. + }
  5689. + // name and signature
  5690. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5691. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5692. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5693. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5694. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5695. + result = result | Klass::ModifyInstances;
  5696. + }
  5697. + }
  5698. + if (!old_fs.done() || !new_fs.done()) {
  5699. + result = result | Klass::ModifyInstances;
  5700. + }
  5701. -// Returns true if the current mismatch is due to a resolved/unresolved
  5702. -// string pair. Otherwise, returns false.
  5703. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5704. - int index1, constantPoolHandle cp2, int index2) {
  5705. + // Do a parallel walk through the old and new methods. Detect
  5706. + // cases where they match (exist in both), have been added in
  5707. + // the new methods, or have been deleted (exist only in the
  5708. + // old methods). The class file parser places methods in order
  5709. + // by method name, but does not order overloaded methods by
  5710. + // signature. In order to determine what fate befell the methods,
  5711. + // this code places the overloaded new methods that have matching
  5712. + // old methods in the same order as the old methods and places
  5713. + // new overloaded methods at the end of overloaded methods of
  5714. + // that name. The code for this order normalization is adapted
  5715. + // from the algorithm used in instanceKlass::find_method().
  5716. + // Since we are swapping out of order entries as we find them,
  5717. + // we only have to search forward through the overloaded methods.
  5718. + // Methods which are added and have the same name as an existing
  5719. + // method (but different signature) will be put at the end of
  5720. + // the methods with that name, and the name mismatch code will
  5721. + // handle them.
  5722. + objArrayHandle k_old_methods(the_class->methods());
  5723. + objArrayHandle k_new_methods(new_class->methods());
  5724. + int n_old_methods = k_old_methods->length();
  5725. + int n_new_methods = k_new_methods->length();
  5726. - jbyte t1 = cp1->tag_at(index1).value();
  5727. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5728. - return false; // wrong entry type; not our special case
  5729. - }
  5730. + int ni = 0;
  5731. + int oi = 0;
  5732. + while (true) {
  5733. + methodOop k_old_method;
  5734. + methodOop k_new_method;
  5735. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  5736. - jbyte t2 = cp2->tag_at(index2).value();
  5737. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5738. - return false; // wrong entry type; not our special case
  5739. - }
  5740. + if (oi >= n_old_methods) {
  5741. + if (ni >= n_new_methods) {
  5742. + break; // we've looked at everything, done
  5743. + }
  5744. + // New method at the end
  5745. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5746. + method_was = added;
  5747. + } else if (ni >= n_new_methods) {
  5748. + // Old method, at the end, is deleted
  5749. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5750. + method_was = deleted;
  5751. + } else {
  5752. + // There are more methods in both the old and new lists
  5753. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5754. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5755. + if (k_old_method->name() != k_new_method->name()) {
  5756. + // Methods are sorted by method name, so a mismatch means added
  5757. + // or deleted
  5758. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  5759. + method_was = added;
  5760. + } else {
  5761. + method_was = deleted;
  5762. + }
  5763. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5764. + // Both the name and signature match
  5765. + method_was = matched;
  5766. + } else {
  5767. + // The name matches, but the signature doesn't, which means we have to
  5768. + // search forward through the new overloaded methods.
  5769. + int nj; // outside the loop for post-loop check
  5770. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5771. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5772. + if (k_old_method->name() != m->name()) {
  5773. + // reached another method name so no more overloaded methods
  5774. + method_was = deleted;
  5775. + break;
  5776. + }
  5777. + if (k_old_method->signature() == m->signature()) {
  5778. + // found a match so swap the methods
  5779. + k_new_methods->obj_at_put(ni, m);
  5780. + k_new_methods->obj_at_put(nj, k_new_method);
  5781. + k_new_method = m;
  5782. + method_was = matched;
  5783. + break;
  5784. + }
  5785. + }
  5786. - if (t1 == t2) {
  5787. - return false; // not a mismatch; not our special case
  5788. - }
  5789. + if (nj >= n_new_methods) {
  5790. + // reached the end without a match; so method was deleted
  5791. + method_was = deleted;
  5792. + }
  5793. + }
  5794. + }
  5795. - char *s1 = cp1->string_at_noresolve(index1);
  5796. - char *s2 = cp2->string_at_noresolve(index2);
  5797. - if (strcmp(s1, s2) != 0) {
  5798. - return false; // strings don't match; not our special case
  5799. + switch (method_was) {
  5800. + case matched:
  5801. + // methods match, be sure modifiers do too
  5802. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5803. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5804. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  5805. + // (tw) Can this have any effects? Probably yes on vtables?
  5806. + result = result | Klass::ModifyClass;
  5807. + }
  5808. + {
  5809. + u2 new_num = k_new_method->method_idnum();
  5810. + u2 old_num = k_old_method->method_idnum();
  5811. + if (new_num != old_num) {
  5812. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  5813. + if (idnum_owner != NULL) {
  5814. + // There is already a method assigned this idnum -- switch them
  5815. + idnum_owner->set_method_idnum(new_num);
  5816. + }
  5817. + k_new_method->set_method_idnum(old_num);
  5818. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  5819. + new_num,
  5820. + old_num));
  5821. + // swap_all_method_annotations(old_num, new_num, new_class);
  5822. + }
  5823. + }
  5824. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5825. + k_new_method->name_and_sig_as_C_string(), ni,
  5826. + k_old_method->name_and_sig_as_C_string(), oi));
  5827. + // advance to next pair of methods
  5828. + ++oi;
  5829. + ++ni;
  5830. + break;
  5831. + case added:
  5832. + // method added, see if it is OK
  5833. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5834. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5835. + // hack: private should be treated as final, but alas
  5836. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5837. + ) {
  5838. + // new methods must be private
  5839. + result = result | Klass::ModifyClass;
  5840. + }
  5841. + {
  5842. + u2 num = the_class->next_method_idnum();
  5843. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5844. + // cannot add any more methods
  5845. + result = result | Klass::ModifyClass;
  5846. + }
  5847. + u2 new_num = k_new_method->method_idnum();
  5848. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5849. + if (idnum_owner != NULL) {
  5850. + // There is already a method assigned this idnum -- switch them
  5851. + idnum_owner->set_method_idnum(new_num);
  5852. + }
  5853. + k_new_method->set_method_idnum(num);
  5854. + //swap_all_method_annotations(new_num, num, new_class);
  5855. + }
  5856. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  5857. + k_new_method->name_and_sig_as_C_string(), ni));
  5858. + ++ni; // advance to next new method
  5859. + break;
  5860. + case deleted:
  5861. + // method deleted, see if it is OK
  5862. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5863. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5864. + // hack: private should be treated as final, but alas
  5865. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5866. + ) {
  5867. + // deleted methods must be private
  5868. + result = result | Klass::ModifyClass;
  5869. + }
  5870. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  5871. + k_old_method->name_and_sig_as_C_string(), oi));
  5872. + ++oi; // advance to next old method
  5873. + break;
  5874. + default:
  5875. + ShouldNotReachHere();
  5876. + }
  5877. }
  5878. - return true; // made it through the gauntlet; this is our special case
  5879. -} // end is_unresolved_string_mismatch()
  5880. + if (new_class()->size() != new_class->old_version()->size()) {
  5881. + result |= Klass::ModifyClassSize;
  5882. + }
  5883. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  5884. + result |= Klass::ModifyInstanceSize;
  5885. + }
  5886. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5887. - // For consistency allocate memory using os::malloc wrapper.
  5888. - _scratch_classes = (instanceKlassHandle *)
  5889. - os::malloc(sizeof(instanceKlassHandle) * _class_count);
  5890. - if (_scratch_classes == NULL) {
  5891. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5892. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  5893. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  5894. + result |= Klass::HasInstanceTransformer;
  5895. }
  5896. - ResourceMark rm(THREAD);
  5897. + // (tw) Check method bodies to be able to return NoChange?
  5898. + return result;
  5899. +}
  5900. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5901. - // state can only be NULL if the current thread is exiting which
  5902. - // should not happen since we're trying to do a RedefineClasses
  5903. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5904. - for (int i = 0; i < _class_count; i++) {
  5905. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5906. - // classes for primitives cannot be redefined
  5907. - if (!is_modifiable_class(mirror)) {
  5908. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5909. - }
  5910. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5911. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5912. - Symbol* the_class_sym = the_class->name();
  5913. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  5914. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5915. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5916. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5917. - the_class->external_name(), _class_load_kind,
  5918. - os::available_memory() >> 10));
  5919. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  5920. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5921. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5922. + private:
  5923. - // Parse the stream.
  5924. - Handle the_class_loader(THREAD, the_class->class_loader());
  5925. - Handle protection_domain(THREAD, the_class->protection_domain());
  5926. - // Set redefined class handle in JvmtiThreadState class.
  5927. - // This redefined class is sent to agent event handler for class file
  5928. - // load hook event.
  5929. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5930. + GrowableArray<int> info;
  5931. + int curPosition;
  5932. + bool copy_backwards;
  5933. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5934. - the_class_loader,
  5935. - protection_domain,
  5936. - &st,
  5937. - THREAD);
  5938. - // Clear class_being_redefined just to be sure.
  5939. - state->clear_class_being_redefined();
  5940. + public:
  5941. - // TODO: if this is retransform, and nothing changed we can skip it
  5942. -
  5943. - instanceKlassHandle scratch_class (THREAD, k);
  5944. -
  5945. - if (HAS_PENDING_EXCEPTION) {
  5946. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5947. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5948. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5949. - ex_name->as_C_string()));
  5950. - CLEAR_PENDING_EXCEPTION;
  5951. -
  5952. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5953. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5954. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5955. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5956. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5957. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5958. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5959. - // The message will be "XXX (wrong name: YYY)"
  5960. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5961. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5962. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5963. - } else { // Just in case more exceptions can be thrown..
  5964. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5965. - }
  5966. - }
  5967. -
  5968. - // Ensure class is linked before redefine
  5969. - if (!the_class->is_linked()) {
  5970. - the_class->link_class(THREAD);
  5971. - if (HAS_PENDING_EXCEPTION) {
  5972. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5973. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5974. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5975. - ex_name->as_C_string()));
  5976. - CLEAR_PENDING_EXCEPTION;
  5977. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5978. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5979. - } else {
  5980. - return JVMTI_ERROR_INTERNAL;
  5981. - }
  5982. - }
  5983. + bool does_copy_backwards() {
  5984. + return copy_backwards;
  5985. }
  5986. - // Do the validity checks in compare_and_normalize_class_versions()
  5987. - // before verifying the byte codes. By doing these checks first, we
  5988. - // limit the number of functions that require redirection from
  5989. - // the_class to scratch_class. In particular, we don't have to
  5990. - // modify JNI GetSuperclass() and thus won't change its performance.
  5991. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5992. - scratch_class);
  5993. - if (res != JVMTI_ERROR_NONE) {
  5994. - return res;
  5995. - }
  5996. + UpdateFieldsEvolutionClosure(klassOop klass) {
  5997. - // verify what the caller passed us
  5998. - {
  5999. - // The bug 6214132 caused the verification to fail.
  6000. - // Information about the_class and scratch_class is temporarily
  6001. - // recorded into jvmtiThreadState. This data is used to redirect
  6002. - // the_class to scratch_class in the JVM_* functions called by the
  6003. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6004. - // description.
  6005. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6006. - Verifier::verify(
  6007. - scratch_class, Verifier::ThrowException, true, THREAD);
  6008. - }
  6009. -
  6010. - if (HAS_PENDING_EXCEPTION) {
  6011. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6012. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6013. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6014. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6015. - CLEAR_PENDING_EXCEPTION;
  6016. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6017. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6018. - } else {
  6019. - // tell the caller the bytecodes are bad
  6020. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6021. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6022. +
  6023. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6024. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6025. }
  6026. +
  6027. + info.append(base_offset);
  6028. + info.append(0);
  6029. + curPosition = base_offset;
  6030. + copy_backwards = false;
  6031. }
  6032. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6033. - if (res != JVMTI_ERROR_NONE) {
  6034. - return res;
  6035. + GrowableArray<int> &finish() {
  6036. + info.append(0);
  6037. + return info;
  6038. }
  6039. - if (VerifyMergedCPBytecodes) {
  6040. - // verify what we have done during constant pool merging
  6041. - {
  6042. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6043. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6044. + virtual void do_new_field(fieldDescriptor* fd){
  6045. + int alignment = fd->offset() - curPosition;
  6046. + if (alignment > 0) {
  6047. + // This field was aligned, so we need to make sure that we fill the gap
  6048. + fill(alignment);
  6049. }
  6050. - if (HAS_PENDING_EXCEPTION) {
  6051. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6052. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6053. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6054. - ("verify_byte_codes post merge-CP exception: '%s'",
  6055. - ex_name->as_C_string()));
  6056. - CLEAR_PENDING_EXCEPTION;
  6057. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6058. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6059. - } else {
  6060. - // tell the caller that constant pool merging screwed up
  6061. - return JVMTI_ERROR_INTERNAL;
  6062. - }
  6063. - }
  6064. + int size = size_of_type(fd->field_type());
  6065. + fill(size);
  6066. }
  6067. - Rewriter::rewrite(scratch_class, THREAD);
  6068. - if (!HAS_PENDING_EXCEPTION) {
  6069. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6070. - }
  6071. - if (HAS_PENDING_EXCEPTION) {
  6072. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6073. - CLEAR_PENDING_EXCEPTION;
  6074. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6075. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6076. + private:
  6077. +
  6078. + void fill(int size) {
  6079. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6080. + (*info.adr_at(info.length() - 1)) -= size;
  6081. } else {
  6082. - return JVMTI_ERROR_INTERNAL;
  6083. + info.append(-size);
  6084. }
  6085. +
  6086. + curPosition += size;
  6087. }
  6088. - _scratch_classes[i] = scratch_class;
  6089. + int size_of_type(BasicType type) {
  6090. + int size = 0;
  6091. + switch(type) {
  6092. + case T_BOOLEAN:
  6093. + size = sizeof(jboolean);
  6094. + break;
  6095. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6096. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6097. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6098. - the_class->external_name(), os::available_memory() >> 10));
  6099. - }
  6100. + case T_CHAR:
  6101. + size = (sizeof(jchar));
  6102. + break;
  6103. - return JVMTI_ERROR_NONE;
  6104. -}
  6105. + case T_FLOAT:
  6106. + size = (sizeof(jfloat));
  6107. + break;
  6108. + case T_DOUBLE:
  6109. + size = (sizeof(jdouble));
  6110. + break;
  6111. -// Map old_index to new_index as needed. scratch_cp is only needed
  6112. -// for RC_TRACE() calls.
  6113. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6114. - int old_index, int new_index) {
  6115. - if (find_new_index(old_index) != 0) {
  6116. - // old_index is already mapped
  6117. - return;
  6118. - }
  6119. + case T_BYTE:
  6120. + size = (sizeof(jbyte));
  6121. + break;
  6122. - if (old_index == new_index) {
  6123. - // no mapping is needed
  6124. - return;
  6125. - }
  6126. + case T_SHORT:
  6127. + size = (sizeof(jshort));
  6128. + break;
  6129. - _index_map_p->at_put(old_index, new_index);
  6130. - _index_map_count++;
  6131. + case T_INT:
  6132. + size = (sizeof(jint));
  6133. + break;
  6134. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6135. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6136. -} // end map_index()
  6137. + case T_LONG:
  6138. + size = (sizeof(jlong));
  6139. + break;
  6140. + case T_OBJECT:
  6141. + case T_ARRAY:
  6142. + if (UseCompressedOops) {
  6143. + size = sizeof(narrowOop);
  6144. + } else {
  6145. + size = (sizeof(oop));
  6146. + }
  6147. + break;
  6148. -// Merge old_cp and scratch_cp and return the results of the merge via
  6149. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6150. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6151. -// in *merge_cp_p. Also creates a map of indices from entries in
  6152. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6153. -// entries are only created for entries in scratch_cp that occupy a
  6154. -// different location in *merged_cp_p.
  6155. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6156. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6157. - int *merge_cp_length_p, TRAPS) {
  6158. + default:
  6159. + ShouldNotReachHere();
  6160. + }
  6161. - if (merge_cp_p == NULL) {
  6162. - assert(false, "caller must provide scatch constantPool");
  6163. - return false; // robustness
  6164. - }
  6165. - if (merge_cp_length_p == NULL) {
  6166. - assert(false, "caller must provide scatch CP length");
  6167. - return false; // robustness
  6168. - }
  6169. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6170. - // but the caller might be smart so make sure we have at least
  6171. - // the minimum.
  6172. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6173. - assert(false, "merge area too small");
  6174. - return false; // robustness
  6175. - }
  6176. + assert(size > 0, "");
  6177. + return size;
  6178. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6179. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6180. - scratch_cp->length()));
  6181. + }
  6182. +
  6183. + public:
  6184. - {
  6185. - // Pass 0:
  6186. - // The old_cp is copied to *merge_cp_p; this means that any code
  6187. - // using old_cp does not have to change. This work looks like a
  6188. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6189. - // handle one special case:
  6190. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6191. - // This will make verification happy.
  6192. -
  6193. - int old_i; // index into old_cp
  6194. -
  6195. - // index zero (0) is not used in constantPools
  6196. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6197. - // leave debugging crumb
  6198. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6199. - switch (old_tag) {
  6200. - case JVM_CONSTANT_Class:
  6201. - case JVM_CONSTANT_UnresolvedClass:
  6202. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6203. - // May be resolving while calling this so do the same for
  6204. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6205. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6206. - old_cp->klass_name_at(old_i));
  6207. - break;
  6208. + virtual void do_old_field(fieldDescriptor* fd){}
  6209. - case JVM_CONSTANT_Double:
  6210. - case JVM_CONSTANT_Long:
  6211. - // just copy the entry to *merge_cp_p, but double and long take
  6212. - // two constant pool entries
  6213. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6214. - old_i++;
  6215. - break;
  6216. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6217. - default:
  6218. - // just copy the entry to *merge_cp_p
  6219. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6220. - break;
  6221. + int alignment = new_fd->offset() - curPosition;
  6222. + if (alignment > 0) {
  6223. + // This field was aligned, so we need to make sure that we fill the gap
  6224. + fill(alignment);
  6225. }
  6226. - } // end for each old_cp entry
  6227. - // We don't need to sanity check that *merge_cp_length_p is within
  6228. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6229. - (*merge_cp_length_p) = old_i;
  6230. - }
  6231. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6232. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6233. - // merge_cp_len should be the same as old_cp->length() at this point
  6234. - // so this trace message is really a "warm-and-breathing" message.
  6235. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6236. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6237. + int offset = old_fd->offset();
  6238. + int size = size_of_type(old_fd->field_type());
  6239. - int scratch_i; // index into scratch_cp
  6240. - {
  6241. - // Pass 1a:
  6242. - // Compare scratch_cp entries to the old_cp entries that we have
  6243. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6244. - // exact duplicates (matching entry at same index) so we only
  6245. - // compare entries in the common indice range.
  6246. - int increment = 1;
  6247. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6248. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6249. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6250. - case JVM_CONSTANT_Double:
  6251. - case JVM_CONSTANT_Long:
  6252. - // double and long take two constant pool entries
  6253. - increment = 2;
  6254. - break;
  6255. -
  6256. - default:
  6257. - increment = 1;
  6258. - break;
  6259. + int prevEnd = -1;
  6260. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6261. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6262. }
  6263. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6264. - scratch_i, CHECK_0);
  6265. - if (match) {
  6266. - // found a match at the same index so nothing more to do
  6267. - continue;
  6268. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6269. - *merge_cp_p, scratch_i)) {
  6270. - // The mismatch in compare_entry_to() above is because of a
  6271. - // resolved versus unresolved class entry at the same index
  6272. - // with the same string value. Since Pass 0 reverted any
  6273. - // class entries to unresolved class entries in *merge_cp_p,
  6274. - // we go with the unresolved class entry.
  6275. - continue;
  6276. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6277. - *merge_cp_p, scratch_i)) {
  6278. - // The mismatch in compare_entry_to() above is because of a
  6279. - // resolved versus unresolved string entry at the same index
  6280. - // with the same string value. We can live with whichever
  6281. - // happens to be at scratch_i in *merge_cp_p.
  6282. - continue;
  6283. - }
  6284. -
  6285. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6286. - CHECK_0);
  6287. - if (found_i != 0) {
  6288. - guarantee(found_i != scratch_i,
  6289. - "compare_entry_to() and find_matching_entry() do not agree");
  6290. -
  6291. - // Found a matching entry somewhere else in *merge_cp_p so
  6292. - // just need a mapping entry.
  6293. - map_index(scratch_cp, scratch_i, found_i);
  6294. - continue;
  6295. - }
  6296. -
  6297. - // The find_matching_entry() call above could fail to find a match
  6298. - // due to a resolved versus unresolved class or string entry situation
  6299. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6300. - // However, we would have to call is_unresolved_*_mismatch() over
  6301. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6302. - // worth the time.
  6303. -
  6304. - // No match found so we have to append this entry and any unique
  6305. - // referenced entries to *merge_cp_p.
  6306. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6307. - CHECK_0);
  6308. - }
  6309. - }
  6310. -
  6311. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6312. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6313. - *merge_cp_length_p, scratch_i, _index_map_count));
  6314. -
  6315. - if (scratch_i < scratch_cp->length()) {
  6316. - // Pass 1b:
  6317. - // old_cp is smaller than scratch_cp so there are entries in
  6318. - // scratch_cp that we have not yet processed. We take care of
  6319. - // those now.
  6320. - int increment = 1;
  6321. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6322. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6323. - case JVM_CONSTANT_Double:
  6324. - case JVM_CONSTANT_Long:
  6325. - // double and long take two constant pool entries
  6326. - increment = 2;
  6327. - break;
  6328. -
  6329. - default:
  6330. - increment = 1;
  6331. - break;
  6332. + if (prevEnd == offset) {
  6333. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6334. + } else {
  6335. + info.append(size);
  6336. + info.append(offset);
  6337. }
  6338. - int found_i =
  6339. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6340. - if (found_i != 0) {
  6341. - // Found a matching entry somewhere else in *merge_cp_p so
  6342. - // just need a mapping entry.
  6343. - map_index(scratch_cp, scratch_i, found_i);
  6344. - continue;
  6345. + if (old_fd->offset() < new_fd->offset()) {
  6346. + copy_backwards = true;
  6347. }
  6348. - // No match found so we have to append this entry and any unique
  6349. - // referenced entries to *merge_cp_p.
  6350. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6351. - CHECK_0);
  6352. + transfer_special_access_flags(old_fd, new_fd);
  6353. +
  6354. + curPosition += size;
  6355. }
  6356. + };
  6357. +
  6358. + UpdateFieldsEvolutionClosure cl(new_version);
  6359. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6360. +
  6361. + GrowableArray<int> result = cl.finish();
  6362. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6363. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6364. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6365. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6366. - *merge_cp_length_p, scratch_i, _index_map_count));
  6367. + if (RC_TRACE_ENABLED(0x00000002)) {
  6368. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6369. + new_version->klass_part()->name()->as_C_string()));
  6370. + if (cl.does_copy_backwards()) {
  6371. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6372. + }
  6373. + for (int i=0; i<result.length(); i++) {
  6374. + int curNum = result.at(i);
  6375. + if (curNum < 0) {
  6376. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6377. + } else if (curNum > 0) {
  6378. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6379. + i++;
  6380. + } else {
  6381. + RC_TRACE(0x00000002, ("\tEND"));
  6382. + }
  6383. + }
  6384. }
  6385. +}
  6386. - return true;
  6387. -} // end merge_constant_pools()
  6388. -
  6389. -
  6390. -// Merge constant pools between the_class and scratch_class and
  6391. -// potentially rewrite bytecodes in scratch_class to use the merged
  6392. -// constant pool.
  6393. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6394. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6395. - TRAPS) {
  6396. - // worst case merged constant pool length is old and new combined
  6397. - int merge_cp_length = the_class->constants()->length()
  6398. - + scratch_class->constants()->length();
  6399. -
  6400. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6401. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6402. -
  6403. - // Constant pools are not easily reused so we allocate a new one
  6404. - // each time.
  6405. - // merge_cp is created unsafe for concurrent GC processing. It
  6406. - // should be marked safe before discarding it. Even though
  6407. - // garbage, if it crosses a card boundary, it may be scanned
  6408. - // in order to find the start of the first complete object on the card.
  6409. - constantPoolHandle merge_cp(THREAD,
  6410. - oopFactory::new_constantPool(merge_cp_length,
  6411. - oopDesc::IsUnsafeConc,
  6412. - THREAD));
  6413. - int orig_length = old_cp->orig_length();
  6414. - if (orig_length == 0) {
  6415. - // This old_cp is an actual original constant pool. We save
  6416. - // the original length in the merged constant pool so that
  6417. - // merge_constant_pools() can be more efficient. If a constant
  6418. - // pool has a non-zero orig_length() value, then that constant
  6419. - // pool was created by a merge operation in RedefineClasses.
  6420. - merge_cp->set_orig_length(old_cp->length());
  6421. - } else {
  6422. - // This old_cp is a merged constant pool from a previous
  6423. - // RedefineClasses() calls so just copy the orig_length()
  6424. - // value.
  6425. - merge_cp->set_orig_length(old_cp->orig_length());
  6426. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6427. + assert(FieldType::is_obj(signature), "");
  6428. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6429. +}
  6430. +
  6431. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6432. + if (klass->klass_part()->is_redefining()) {
  6433. + klass = klass->klass_part()->old_version();
  6434. }
  6435. - ResourceMark rm(THREAD);
  6436. - _index_map_count = 0;
  6437. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6438. + // We found an instance klass!
  6439. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6440. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6441. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6442. - &merge_cp_length, THREAD);
  6443. - if (!result) {
  6444. - // The merge can fail due to memory allocation failure or due
  6445. - // to robustness checks.
  6446. - return JVMTI_ERROR_INTERNAL;
  6447. - }
  6448. -
  6449. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6450. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6451. -
  6452. - if (_index_map_count == 0) {
  6453. - // there is nothing to map between the new and merged constant pools
  6454. -
  6455. - if (old_cp->length() == scratch_cp->length()) {
  6456. - // The old and new constant pools are the same length and the
  6457. - // index map is empty. This means that the three constant pools
  6458. - // are equivalent (but not the same). Unfortunately, the new
  6459. - // constant pool has not gone through link resolution nor have
  6460. - // the new class bytecodes gone through constant pool cache
  6461. - // rewriting so we can't use the old constant pool with the new
  6462. - // class.
  6463. -
  6464. - merge_cp()->set_is_conc_safe(true);
  6465. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6466. - } else if (old_cp->length() < scratch_cp->length()) {
  6467. - // The old constant pool has fewer entries than the new constant
  6468. - // pool and the index map is empty. This means the new constant
  6469. - // pool is a superset of the old constant pool. However, the old
  6470. - // class bytecodes have already gone through constant pool cache
  6471. - // rewriting so we can't use the new constant pool with the old
  6472. - // class.
  6473. -
  6474. - merge_cp()->set_is_conc_safe(true);
  6475. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6476. - } else {
  6477. - // The old constant pool has more entries than the new constant
  6478. - // pool and the index map is empty. This means that both the old
  6479. - // and merged constant pools are supersets of the new constant
  6480. - // pool.
  6481. -
  6482. - // Replace the new constant pool with a shrunken copy of the
  6483. - // merged constant pool; the previous new constant pool will
  6484. - // get GCed.
  6485. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6486. - THREAD);
  6487. - // drop local ref to the merged constant pool
  6488. - merge_cp()->set_is_conc_safe(true);
  6489. - merge_cp = constantPoolHandle();
  6490. + class MyFieldClosure : public FieldClosure {
  6491. +
  6492. + public:
  6493. +
  6494. + GrowableArray< Pair<int, klassOop> > *_arr;
  6495. +
  6496. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6497. + _arr = arr;
  6498. }
  6499. - } else {
  6500. - if (RC_TRACE_ENABLED(0x00040000)) {
  6501. - // don't want to loop unless we are tracing
  6502. - int count = 0;
  6503. - for (int i = 1; i < _index_map_p->length(); i++) {
  6504. - int value = _index_map_p->at(i);
  6505. -
  6506. - if (value != -1) {
  6507. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6508. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6509. - count++;
  6510. +
  6511. + virtual void do_field(fieldDescriptor* fd) {
  6512. + if (fd->field_type() == T_OBJECT) {
  6513. + Symbol* signature = fd->signature();
  6514. + if (FieldType::is_obj(signature)) {
  6515. + Symbol* name = signature_to_class_name(signature);
  6516. + klassOop field_klass;
  6517. + if (is_field_dangerous(name, fd, field_klass)) {
  6518. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6519. + fd->name()->as_C_string(),
  6520. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6521. + name->as_C_string()));
  6522. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6523. + }
  6524. }
  6525. +
  6526. + // Array fields can never be a problem!
  6527. }
  6528. }
  6529. - // We have entries mapped between the new and merged constant pools
  6530. - // so we have to rewrite some constant pool references.
  6531. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6532. - return JVMTI_ERROR_INTERNAL;
  6533. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6534. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6535. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6536. + if(field_klass != NULL) {
  6537. + if (field_klass->klass_part()->is_redefining()) {
  6538. + field_klass = field_klass->klass_part()->old_version();
  6539. + }
  6540. + if (field_klass->klass_part()->has_subtype_changed()) {
  6541. + return true;
  6542. + }
  6543. + }
  6544. + return false;
  6545. }
  6546. + };
  6547. +
  6548. + MyFieldClosure fieldClosure(&type_check_information);
  6549. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6550. - // Replace the new constant pool with a shrunken copy of the
  6551. - // merged constant pool so now the rewritten bytecodes have
  6552. - // valid references; the previous new constant pool will get
  6553. - // GCed.
  6554. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6555. - THREAD);
  6556. - merge_cp()->set_is_conc_safe(true);
  6557. + if (type_check_information.length() > 0) {
  6558. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6559. + cur_instance_klass->store_type_check_information(type_check_information);
  6560. }
  6561. - assert(old_cp()->is_conc_safe(), "Just checking");
  6562. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6563. +}
  6564. - return JVMTI_ERROR_NONE;
  6565. -} // end merge_cp_and_rewrite()
  6566. +bool VM_RedefineClasses::check_field_value_types() {
  6567. + Thread *THREAD = Thread::current();
  6568. + class CheckFieldTypesClosure : public ObjectClosure {
  6569. -// Rewrite constant pool references in klass scratch_class.
  6570. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6571. - TRAPS) {
  6572. + private:
  6573. - // rewrite constant pool references in the methods:
  6574. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6575. - // propagate failure back to caller
  6576. - return false;
  6577. - }
  6578. + bool _result;
  6579. - // rewrite constant pool references in the class_annotations:
  6580. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6581. - // propagate failure back to caller
  6582. - return false;
  6583. - }
  6584. + public:
  6585. - // rewrite constant pool references in the fields_annotations:
  6586. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6587. - // propagate failure back to caller
  6588. - return false;
  6589. - }
  6590. + CheckFieldTypesClosure() {
  6591. + _result = true;
  6592. + }
  6593. - // rewrite constant pool references in the methods_annotations:
  6594. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6595. - // propagate failure back to caller
  6596. - return false;
  6597. - }
  6598. + bool result() { return _result; }
  6599. - // rewrite constant pool references in the methods_parameter_annotations:
  6600. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6601. - THREAD)) {
  6602. - // propagate failure back to caller
  6603. - return false;
  6604. + virtual void do_object(oop obj) {
  6605. +
  6606. + if (!_result) {
  6607. + return;
  6608. + }
  6609. +
  6610. + if (obj->is_objArray()) {
  6611. +
  6612. + objArrayOop array = objArrayOop(obj);
  6613. +
  6614. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6615. +
  6616. + if (element_klass->klass_part()->has_subtype_changed()) {
  6617. + int length = array->length();
  6618. + for (int i=0; i<length; i++) {
  6619. + oop element = array->obj_at(i);
  6620. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6621. + // Check subtype relationship to static type of array
  6622. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6623. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6624. + element_klass->klass_part()->name()->as_C_string(),
  6625. + i,
  6626. + element->blueprint()->name()->as_C_string()));
  6627. + _result = false;
  6628. + break;
  6629. + }
  6630. + }
  6631. + }
  6632. + }
  6633. +
  6634. + } else {
  6635. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6636. + if (cur != NULL) {
  6637. + // Type check information exists for this oop
  6638. + while ((*cur).left() != -1) {
  6639. + check_field(obj, (*cur).left(), (*cur).right());
  6640. + cur++;
  6641. + }
  6642. + }
  6643. + }
  6644. + }
  6645. +
  6646. + void check_field(oop obj, int offset, klassOop static_type) {
  6647. + oop field_value = obj->obj_field(offset);
  6648. + if (field_value != NULL) {
  6649. + // Field is not null
  6650. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6651. + // We are OK
  6652. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6653. + obj->klass()->klass_part()->name()->as_C_string(),
  6654. + static_type->klass_part()->name()->as_C_string(),
  6655. + offset,
  6656. + field_value->klass()->klass_part()->name()->as_C_string()));
  6657. + } else {
  6658. + // Failure!
  6659. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6660. + obj->klass()->klass_part()->name()->as_C_string(),
  6661. + static_type->klass_part()->name()->as_C_string(),
  6662. + offset,
  6663. + field_value->klass()->klass_part()->name()->as_C_string()));
  6664. + _result = false;
  6665. + }
  6666. + }
  6667. + }
  6668. + };
  6669. +
  6670. + CheckFieldTypesClosure myObjectClosure;
  6671. +
  6672. + // make sure that heap is parsable (fills TLABs with filler objects)
  6673. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  6674. +
  6675. + // do the iteration
  6676. + // If this operation encounters a bad object when using CMS,
  6677. + // consider using safe_object_iterate() which avoids perm gen
  6678. + // objects that may contain bad references.
  6679. + Universe::heap()->object_iterate(&myObjectClosure);
  6680. +
  6681. + // when sharing is enabled we must iterate over the shared spaces
  6682. + if (UseSharedSpaces) {
  6683. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  6684. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  6685. + gen->ro_space()->object_iterate(&myObjectClosure);
  6686. + gen->rw_space()->object_iterate(&myObjectClosure);
  6687. }
  6688. - // rewrite constant pool references in the methods_default_annotations:
  6689. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6690. - THREAD)) {
  6691. - // propagate failure back to caller
  6692. - return false;
  6693. + return myObjectClosure.result();
  6694. +}
  6695. +
  6696. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  6697. + if (k->klass_part()->is_redefining()) {
  6698. + k = k->klass_part()->old_version();
  6699. }
  6700. - return true;
  6701. -} // end rewrite_cp_refs()
  6702. + // We found an instance klass!
  6703. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  6704. + cur_instance_klass->clear_type_check_information();
  6705. +}
  6706. +
  6707. +void VM_RedefineClasses::update_active_methods() {
  6708. +
  6709. + RC_TRACE(0x00000002, ("Updating active methods"));
  6710. + JavaThread *java_thread = Threads::first();
  6711. + while (java_thread != NULL) {
  6712. +
  6713. + int stack_depth = 0;
  6714. + if (java_thread->has_last_Java_frame()) {
  6715. +
  6716. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  6717. +
  6718. + // vframes are resource allocated
  6719. + Thread* current_thread = Thread::current();
  6720. + ResourceMark rm(current_thread);
  6721. + HandleMark hm(current_thread);
  6722. +
  6723. + RegisterMap reg_map(java_thread);
  6724. + frame f = java_thread->last_frame();
  6725. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6726. + frame* last_entry_frame = NULL;
  6727. +
  6728. + while (vf != NULL) {
  6729. + if (vf->is_java_frame()) {
  6730. + // java frame (interpreted, compiled, ...)
  6731. + javaVFrame *jvf = javaVFrame::cast(vf);
  6732. +
  6733. + if (!(jvf->method()->is_native())) {
  6734. + int bci = jvf->bci();
  6735. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  6736. + ResourceMark rm(Thread::current());
  6737. + HandleMark hm;
  6738. + instanceKlassHandle klass(jvf->method()->method_holder());
  6739. +
  6740. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6741. +
  6742. +
  6743. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  6744. + jvf->method()->name_and_sig_as_C_string()));
  6745. +
  6746. + if (RC_TRACE_ENABLED(0x01000000)) {
  6747. + int code_size = jvf->method()->code_size();
  6748. + char *code_base_old = (char*)jvf->method()->code_base();
  6749. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  6750. + for (int i=0; i<code_size; i++) {
  6751. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  6752. + }
  6753. + jvf->method()->print_codes_on(tty);
  6754. + jvf->method()->new_version()->print_codes_on(tty);
  6755. + }
  6756. +
  6757. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  6758. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  6759. +
  6760. +
  6761. + if (RC_TRACE_ENABLED(0x01000000)) {
  6762. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  6763. + tty->print_cr("old cp");
  6764. + for (int i=0; i<cp_old->length(); i++) {
  6765. + cp_old->entry_at(i)->print(tty, i);
  6766. + }
  6767. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  6768. + tty->print_cr("new cp");
  6769. + for (int i=0; i<cp_new->length(); i++) {
  6770. + cp_new->entry_at(i)->print(tty, i);
  6771. + }
  6772. + }
  6773. +
  6774. + iframe->set_method(jvf->method()->new_version(), bci);
  6775. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  6776. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  6777. + }
  6778. + }
  6779. + }
  6780. + vf = vf->sender();
  6781. + }
  6782. + }
  6783. -// Rewrite constant pool references in the methods.
  6784. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6785. - instanceKlassHandle scratch_class, TRAPS) {
  6786. + // Advance to next thread
  6787. + java_thread = java_thread->next();
  6788. + }
  6789. +}
  6790. - objArrayHandle methods(THREAD, scratch_class->methods());
  6791. +void VM_RedefineClasses::method_forwarding() {
  6792. +
  6793. + int forwarding_count = 0;
  6794. + JavaThread *java_thread = Threads::first();
  6795. + while (java_thread != NULL) {
  6796. +
  6797. + int stack_depth = 0;
  6798. + if (java_thread->has_last_Java_frame()) {
  6799. +
  6800. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  6801. +
  6802. + // vframes are resource allocated
  6803. + Thread* current_thread = Thread::current();
  6804. + ResourceMark rm(current_thread);
  6805. + HandleMark hm(current_thread);
  6806. +
  6807. + RegisterMap reg_map(java_thread);
  6808. + frame f = java_thread->last_frame();
  6809. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6810. + frame* last_entry_frame = NULL;
  6811. +
  6812. + while (vf != NULL) {
  6813. + if (vf->is_java_frame()) {
  6814. + // java frame (interpreted, compiled, ...)
  6815. + javaVFrame *jvf = javaVFrame::cast(vf);
  6816. +
  6817. + if (!(jvf->method()->is_native())) {
  6818. + RC_TRACE(0x00008000, ("found method: %s",
  6819. + jvf->method()->name()->as_C_string()));
  6820. + ResourceMark rm(Thread::current());
  6821. + HandleMark hm;
  6822. + instanceKlassHandle klass(jvf->method()->method_holder());
  6823. + methodOop m = jvf->method();
  6824. + int bci = jvf->bci();
  6825. + RC_TRACE(0x00008000, ("klass redef %d",
  6826. + klass->is_redefining()));
  6827. +
  6828. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  6829. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  6830. + m->name()->as_C_string()));
  6831. +
  6832. + klassOop new_klass = klass->newest_version();
  6833. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  6834. + RC_TRACE(0x00000002, ("%d %d",
  6835. + new_method,
  6836. + new_method->constMethod()->has_code_section_table()));
  6837. +
  6838. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  6839. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  6840. + new_method->name()->as_C_string()));
  6841. + m->set_forward_method(new_method);
  6842. + if (new_method->max_locals() != m->max_locals()) {
  6843. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  6844. + }
  6845. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  6846. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  6847. + if (jvf->is_interpreted_frame()) {
  6848. + if (m->is_in_code_section(bci)) {
  6849. + // We must transfer now and cannot delay until next NOP.
  6850. + int new_bci = m->calculate_forward_bci(bci, new_method);
  6851. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  6852. + RC_TRACE(0x00000002, ("Transfering execution of %s to new method old_bci=%d new_bci=%d",
  6853. + new_method->name()->as_C_string(),
  6854. + bci,
  6855. + new_bci));
  6856. + iframe->set_method(new_method, new_bci);
  6857. + } else {
  6858. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  6859. + new_method->name()->as_C_string(),
  6860. + bci));
  6861. + }
  6862. + } else {
  6863. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  6864. + new_method->name()->as_C_string()));
  6865. + }
  6866. + }
  6867. + }
  6868. + }
  6869. + }
  6870. + vf = vf->sender();
  6871. + }
  6872. + }
  6873. - if (methods.is_null() || methods->length() == 0) {
  6874. - // no methods so nothing to do
  6875. - return true;
  6876. + // Advance to next thread
  6877. + java_thread = java_thread->next();
  6878. }
  6879. - // rewrite constant pool references in the methods:
  6880. - for (int i = methods->length() - 1; i >= 0; i--) {
  6881. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  6882. - methodHandle new_method;
  6883. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  6884. - if (!new_method.is_null()) {
  6885. - // the method has been replaced so save the new method version
  6886. - methods->obj_at_put(i, new_method());
  6887. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  6888. + forwarding_count));
  6889. +}
  6890. +
  6891. +bool VM_RedefineClasses::check_method_stacks() {
  6892. +
  6893. + JavaThread *java_thread = Threads::first();
  6894. + while (java_thread != NULL) {
  6895. +
  6896. + int stack_depth = 0;
  6897. + if (java_thread->has_last_Java_frame()) {
  6898. +
  6899. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  6900. +
  6901. + // vframes are resource allocated
  6902. + Thread* current_thread = Thread::current();
  6903. + ResourceMark rm(current_thread);
  6904. + HandleMark hm(current_thread);
  6905. +
  6906. + RegisterMap reg_map(java_thread);
  6907. + frame f = java_thread->last_frame();
  6908. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6909. + frame* last_entry_frame = NULL;
  6910. +
  6911. + while (vf != NULL) {
  6912. + if (vf->is_java_frame()) {
  6913. + // java frame (interpreted, compiled, ...)
  6914. + javaVFrame *jvf = javaVFrame::cast(vf);
  6915. +
  6916. + if (!(jvf->method()->is_native())) {
  6917. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  6918. + ResourceMark rm(Thread::current());
  6919. + HandleMark hm;
  6920. + instanceKlassHandle klass(jvf->method()->method_holder());
  6921. +
  6922. + StackValueCollection *locals = jvf->locals();
  6923. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  6924. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  6925. +
  6926. + for (int i=0; i<locals->size(); i++) {
  6927. + StackValue *stack_value = locals->at(i);
  6928. + if (stack_value->type() == T_OBJECT) {
  6929. + Handle obj = stack_value->get_obj();
  6930. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  6931. +
  6932. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  6933. + bool result = false;
  6934. + methodOop method = jvf->method();
  6935. + if (method->has_localvariable_table()) {
  6936. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  6937. + for (int j=0; j<method->localvariable_table_length(); j++) {
  6938. +
  6939. + if (elem->slot == i) {
  6940. +
  6941. + // Matching index found
  6942. +
  6943. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  6944. +
  6945. + // Also in range!!
  6946. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  6947. + Symbol* klass_name = signature_to_class_name(signature);
  6948. +
  6949. + 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();
  6950. + klassOop cur = obj->klass()->klass_part()->newest_version();
  6951. +
  6952. + // Field is not null
  6953. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  6954. + // We are OK
  6955. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  6956. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  6957. + result = true;
  6958. + } else {
  6959. + // Failure!
  6960. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  6961. + local_klass->klass_part()->name()->as_C_string(),
  6962. + cur->klass_part()->name()->as_C_string()));
  6963. + return false;
  6964. + }
  6965. + }
  6966. + }
  6967. +
  6968. + elem++;
  6969. + }
  6970. + } else {
  6971. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  6972. + method->name_and_sig_as_C_string()));
  6973. + }
  6974. +
  6975. + if (!result) {
  6976. + return false;
  6977. + }
  6978. +
  6979. + RC_TRACE(0x00008000, ("Verifying class %s",
  6980. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  6981. +
  6982. + Symbol* exception_name;
  6983. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  6984. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  6985. +
  6986. + if (TraceRedefineClasses >= 4) {
  6987. + ClassVerifier::_verify_verbose = true;
  6988. + }
  6989. +
  6990. + Thread::current()->set_pretend_new_universe(true);
  6991. + ClassVerifier split_verifier(klass, message_buffer, message_buffer_len, Thread::current());
  6992. + split_verifier.verify_method(jvf->method(), Thread::current());
  6993. + exception_name = split_verifier.result();
  6994. + Thread::current()->set_pretend_new_universe(false);
  6995. +
  6996. + if (TraceRedefineClasses >= 4) {
  6997. + ClassVerifier::_verify_verbose = false;
  6998. + }
  6999. +
  7000. + if (exception_name != NULL) {
  7001. +
  7002. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7003. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7004. + RC_TRACE(0x00000001, ("Exception: %s",
  7005. + exception_name->as_C_string()));
  7006. + RC_TRACE(0x00000001, ("Message: %s",
  7007. + message_buffer));
  7008. + Thread::current()->clear_pending_exception();
  7009. + return false;
  7010. + }
  7011. +
  7012. + }
  7013. + }
  7014. + }
  7015. + }
  7016. + }
  7017. + vf = vf->sender();
  7018. + }
  7019. }
  7020. +
  7021. + // Advance to next thread
  7022. + java_thread = java_thread->next();
  7023. }
  7024. return true;
  7025. }
  7026. +bool VM_RedefineClasses::check_method(methodOop method) {
  7027. -// Rewrite constant pool references in the specific method. This code
  7028. -// was adapted from Rewriter::rewrite_method().
  7029. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  7030. - methodHandle *new_method_p, TRAPS) {
  7031. - *new_method_p = methodHandle(); // default is no new method
  7032. + return true;
  7033. +}
  7034. - // We cache a pointer to the bytecodes here in code_base. If GC
  7035. - // moves the methodOop, then the bytecodes will also move which
  7036. - // will likely cause a crash. We create a No_Safepoint_Verifier
  7037. - // object to detect whether we pass a possible safepoint in this
  7038. - // code block.
  7039. - No_Safepoint_Verifier nsv;
  7040. +// Warning: destroys redefinition level values of klasses.
  7041. +bool VM_RedefineClasses::check_loaded_methods() {
  7042. - // Bytecodes and their length
  7043. - address code_base = method->code_base();
  7044. - int code_length = method->code_size();
  7045. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7046. - int bc_length;
  7047. - for (int bci = 0; bci < code_length; bci += bc_length) {
  7048. - address bcp = code_base + bci;
  7049. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  7050. + private:
  7051. +
  7052. + bool _result;
  7053. + GrowableArray<klassOop> *_dangerous_klasses;
  7054. - bc_length = Bytecodes::length_for(c);
  7055. - if (bc_length == 0) {
  7056. - // More complicated bytecodes report a length of zero so
  7057. - // we have to try again a slightly different way.
  7058. - bc_length = Bytecodes::length_at(method(), bcp);
  7059. + public:
  7060. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7061. + _result = true;
  7062. + _dangerous_klasses = dangerous_klasses;
  7063. }
  7064. - assert(bc_length != 0, "impossible bytecode length");
  7065. + bool result() {
  7066. + return _result;
  7067. + }
  7068. - switch (c) {
  7069. - case Bytecodes::_ldc:
  7070. - {
  7071. - int cp_index = *(bcp + 1);
  7072. - int new_index = find_new_index(cp_index);
  7073. + bool is_class_dangerous(klassOop k) {
  7074. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7075. + }
  7076. - if (StressLdcRewrite && new_index == 0) {
  7077. - // If we are stressing ldc -> ldc_w rewriting, then we
  7078. - // always need a new_index value.
  7079. - new_index = cp_index;
  7080. - }
  7081. - if (new_index != 0) {
  7082. - // the original index is mapped so we have more work to do
  7083. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  7084. - // The new value can still use ldc instead of ldc_w
  7085. - // unless we are trying to stress ldc -> ldc_w rewriting
  7086. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7087. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7088. - bcp, cp_index, new_index));
  7089. - *(bcp + 1) = new_index;
  7090. - } else {
  7091. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7092. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  7093. - Bytecodes::name(c), bcp, cp_index, new_index));
  7094. - // the new value needs ldc_w instead of ldc
  7095. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  7096. - bcp = (address)inst_buffer;
  7097. - // construct new instruction sequence
  7098. - *bcp = Bytecodes::_ldc_w;
  7099. - bcp++;
  7100. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  7101. - // See comment below for difference between put_Java_u2()
  7102. - // and put_native_u2().
  7103. - Bytes::put_Java_u2(bcp, new_index);
  7104. -
  7105. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  7106. - methodHandle m;
  7107. - {
  7108. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  7109. -
  7110. - // ldc is 2 bytes and ldc_w is 3 bytes
  7111. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  7112. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  7113. - guarantee(false, "insert_space_at() failed");
  7114. + bool can_be_affected(instanceKlass *klass) {
  7115. +
  7116. + constantPoolOop cp = klass->constants();
  7117. +
  7118. + Thread *THREAD = Thread::current();
  7119. + klassOop k;
  7120. + Symbol* symbol;
  7121. +
  7122. + for (int i=1; i<cp->length(); i++) {
  7123. + jbyte tag = cp->tag_at(i).value();
  7124. + switch(tag) {
  7125. + case JVM_CONSTANT_Long:
  7126. + case JVM_CONSTANT_Double:
  7127. + i++;
  7128. + break;
  7129. +
  7130. + case JVM_CONSTANT_Utf8:
  7131. + case JVM_CONSTANT_Unicode:
  7132. + case JVM_CONSTANT_Integer:
  7133. + case JVM_CONSTANT_Float:
  7134. + case JVM_CONSTANT_String:
  7135. + case JVM_CONSTANT_Fieldref:
  7136. + case JVM_CONSTANT_Methodref:
  7137. + case JVM_CONSTANT_InterfaceMethodref:
  7138. + case JVM_CONSTANT_ClassIndex:
  7139. + case JVM_CONSTANT_UnresolvedString:
  7140. + case JVM_CONSTANT_StringIndex:
  7141. + case JVM_CONSTANT_UnresolvedClassInError:
  7142. + case JVM_CONSTANT_Object:
  7143. + // do nothing
  7144. + break;
  7145. +
  7146. + case JVM_CONSTANT_Class:
  7147. + k = cp->klass_at(i, CHECK_(true));
  7148. + if (is_class_dangerous(k)) {
  7149. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7150. + klass->name()->as_C_string(),
  7151. + i,
  7152. + k->klass_part()->name()->as_C_string()));
  7153. + return true;
  7154. + }
  7155. + break;
  7156. +
  7157. + case JVM_CONSTANT_NameAndType:
  7158. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7159. + if (symbol->byte_at(0) == '(') {
  7160. + // This must be a method
  7161. + SignatureStream signatureStream(symbol);
  7162. + while (true) {
  7163. +
  7164. + if (signatureStream.is_array()) {
  7165. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7166. + if (is_type_signature_dangerous(cur_signature)) {
  7167. + return true;
  7168. + }
  7169. + } else if (signatureStream.is_object()) {
  7170. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7171. + return true;
  7172. + }
  7173. + }
  7174. +
  7175. + if (signatureStream.at_return_type()) {
  7176. + break;
  7177. + }
  7178. +
  7179. + signatureStream.next();
  7180. }
  7181. +
  7182. + } else if (is_type_signature_dangerous(symbol)) {
  7183. + return true;
  7184. }
  7185. + break;
  7186. - // return the new method so that the caller can update
  7187. - // the containing class
  7188. - *new_method_p = method = m;
  7189. - // switch our bytecode processing loop from the old method
  7190. - // to the new method
  7191. - code_base = method->code_base();
  7192. - code_length = method->code_size();
  7193. - bcp = code_base + bci;
  7194. - c = (Bytecodes::Code)(*bcp);
  7195. - bc_length = Bytecodes::length_for(c);
  7196. - assert(bc_length != 0, "sanity check");
  7197. - } // end we need ldc_w instead of ldc
  7198. - } // end if there is a mapped index
  7199. - } break;
  7200. -
  7201. - // these bytecodes have a two-byte constant pool index
  7202. - case Bytecodes::_anewarray : // fall through
  7203. - case Bytecodes::_checkcast : // fall through
  7204. - case Bytecodes::_getfield : // fall through
  7205. - case Bytecodes::_getstatic : // fall through
  7206. - case Bytecodes::_instanceof : // fall through
  7207. - case Bytecodes::_invokeinterface: // fall through
  7208. - case Bytecodes::_invokespecial : // fall through
  7209. - case Bytecodes::_invokestatic : // fall through
  7210. - case Bytecodes::_invokevirtual : // fall through
  7211. - case Bytecodes::_ldc_w : // fall through
  7212. - case Bytecodes::_ldc2_w : // fall through
  7213. - case Bytecodes::_multianewarray : // fall through
  7214. - case Bytecodes::_new : // fall through
  7215. - case Bytecodes::_putfield : // fall through
  7216. - case Bytecodes::_putstatic :
  7217. - {
  7218. - address p = bcp + 1;
  7219. - int cp_index = Bytes::get_Java_u2(p);
  7220. - int new_index = find_new_index(cp_index);
  7221. - if (new_index != 0) {
  7222. - // the original index is mapped so update w/ new value
  7223. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7224. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7225. - bcp, cp_index, new_index));
  7226. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7227. - // situation because it is reusing the constant pool index
  7228. - // location for a native index into the constantPoolCache.
  7229. - // Since we are updating the constant pool index prior to
  7230. - // verification and constantPoolCache initialization, we
  7231. - // need to keep the new index in Java byte order.
  7232. - Bytes::put_Java_u2(p, new_index);
  7233. + case JVM_CONSTANT_UnresolvedClass:
  7234. + symbol = cp->unresolved_klass_at(i);
  7235. + if (is_symbol_dangerous(symbol)) {
  7236. + return true;
  7237. + }
  7238. + break;
  7239. +
  7240. + default:
  7241. + ShouldNotReachHere();
  7242. }
  7243. - } break;
  7244. + }
  7245. +
  7246. + return false;
  7247. }
  7248. - } // end for each bytecode
  7249. -} // end rewrite_cp_refs_in_method()
  7250. + bool is_type_signature_dangerous(Symbol* signature) {
  7251. + // This must be a field type
  7252. + if (FieldType::is_obj(signature)) {
  7253. + Symbol* name = signature_to_class_name(signature);
  7254. + if (is_symbol_dangerous(name)) {
  7255. + return true;
  7256. + }
  7257. + } else if (FieldType::is_array(signature)) {
  7258. + //jint dimension;
  7259. + //Symbol* object_key;
  7260. + FieldArrayInfo fd;
  7261. + FieldType::get_array_info(signature, fd, Thread::current());
  7262. + if (is_symbol_dangerous(fd.object_key())) {
  7263. + return true;
  7264. + }
  7265. + }
  7266. + return false;
  7267. + }
  7268. +
  7269. + bool is_symbol_dangerous(Symbol* symbol) {
  7270. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7271. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7272. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7273. + i,
  7274. + symbol->as_C_string()));
  7275. + return true;
  7276. + }
  7277. + }
  7278. + return false;
  7279. + }
  7280. +
  7281. + virtual void do_object(oop obj) {
  7282. +
  7283. + if (!_result) return;
  7284. +
  7285. + klassOop klassObj = (klassOop)obj;
  7286. + Thread *THREAD = Thread::current();
  7287. +
  7288. + // We found an instance klass!
  7289. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7290. + instanceKlassHandle handle(klassObj);
  7291. +
  7292. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7293. +
  7294. + if (!can_be_affected(klass)) {
  7295. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7296. + return;
  7297. + }
  7298. +
  7299. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7300. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7301. + _result = false;
  7302. + return;
  7303. + }
  7304. +
  7305. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7306. +
  7307. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7308. +
  7309. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7310. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7311. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7312. + //PENDING_EXCEPTION->print();
  7313. + CLEAR_PENDING_EXCEPTION;
  7314. + _result = false;
  7315. + }
  7316. +
  7317. + /*int method_count = klass->methods()->length();
  7318. + for (int i=0; i<method_count; i++) {
  7319. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7320. + if (!check_method(cur_method)) {
  7321. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7322. + }
  7323. + }*/
  7324. + }
  7325. + };
  7326. -// Rewrite constant pool references in the class_annotations field.
  7327. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7328. - instanceKlassHandle scratch_class, TRAPS) {
  7329. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7330. - typeArrayHandle class_annotations(THREAD,
  7331. - scratch_class->class_annotations());
  7332. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7333. - // no class_annotations so nothing to do
  7334. - return true;
  7335. + GrowableArray<klassOop> dangerous_klasses;
  7336. + for (int i=0; i<_new_classes->length(); i++) {
  7337. + instanceKlassHandle handle = _new_classes->at(i);
  7338. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7339. + dangerous_klasses.append(handle());
  7340. + }
  7341. }
  7342. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7343. - ("class_annotations length=%d", class_annotations->length()));
  7344. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7345. + Thread::current()->set_pretend_new_universe(true);
  7346. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7347. + Thread::current()->set_pretend_new_universe(false);
  7348. +
  7349. - int byte_i = 0; // byte index into class_annotations
  7350. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7351. - THREAD);
  7352. + return checkLoadedMethodsClosure.result();
  7353. }
  7354. +bool VM_RedefineClasses::check_type_consistency() {
  7355. +
  7356. + Universe::set_verify_in_progress(true);
  7357. +
  7358. + SystemDictionary::classes_do(calculate_type_check_information);
  7359. + bool result = check_field_value_types();
  7360. + SystemDictionary::classes_do(clear_type_check_information);
  7361. + if (!result) {
  7362. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7363. + Universe::set_verify_in_progress(false);
  7364. + return false;
  7365. + }
  7366. +
  7367. + result = check_method_stacks();
  7368. + if (!result) {
  7369. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7370. + Universe::set_verify_in_progress(false);
  7371. + return false;
  7372. + }
  7373. +
  7374. + result = check_loaded_methods();
  7375. + if (!result) {
  7376. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7377. + Universe::set_verify_in_progress(false);
  7378. + return false;
  7379. + }
  7380. +
  7381. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7382. + Universe::set_verify_in_progress(false);
  7383. + return true;
  7384. +}
  7385. -// Rewrite constant pool references in an annotations typeArray. This
  7386. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7387. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7388. -//
  7389. -// annotations_typeArray {
  7390. -// u2 num_annotations;
  7391. -// annotation annotations[num_annotations];
  7392. -// }
  7393. -//
  7394. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7395. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7396. +void VM_RedefineClasses::rollback() {
  7397. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7398. + SystemDictionary::rollback_redefinition();
  7399. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7400. - // not enough room for num_annotations field
  7401. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7402. - ("length() is too small for num_annotations field"));
  7403. - return false;
  7404. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7405. + for (int i=0; i<_new_classes->length(); i++) {
  7406. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7407. }
  7408. - u2 num_annotations = Bytes::get_Java_u2((address)
  7409. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7410. - byte_i_ref += 2;
  7411. + for (int i=0; i<_new_classes->length(); i++) {
  7412. + instanceKlassHandle new_class = _new_classes->at(i);
  7413. + new_class->set_redefining(false);
  7414. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7415. + new_class->set_old_version(NULL);
  7416. + }
  7417. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7418. - ("num_annotations=%d", num_annotations));
  7419. +}
  7420. - int calc_num_annotations = 0;
  7421. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7422. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7423. - byte_i_ref, THREAD)) {
  7424. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7425. - ("bad annotation_struct at %d", calc_num_annotations));
  7426. - // propagate failure back to caller
  7427. - return false;
  7428. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7429. + T heap_oop = oopDesc::load_heap_oop(p);
  7430. + if (!oopDesc::is_null(heap_oop)) {
  7431. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7432. + if (obj->is_instanceKlass()) {
  7433. + klassOop klass = (klassOop)obj;
  7434. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7435. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7436. + obj = klass->klass_part()->new_version();
  7437. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7438. + }
  7439. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7440. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7441. + // java.lang.Class instances.
  7442. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7443. + if (klass_oop != NULL) {
  7444. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7445. + obj = klass_oop->new_version()->java_mirror();
  7446. + } else if (klass_oop->klass_part()->is_redefining()) {
  7447. + obj = klass_oop->java_mirror();
  7448. + }
  7449. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7450. +
  7451. +
  7452. + // FIXME: DCEVM: better implementation?
  7453. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7454. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7455. + // case we need to run write barrier to make sure card table is properly updated. This will
  7456. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7457. + if (Universe::heap()->is_in_reserved(p)) {
  7458. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7459. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7460. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7461. + CardTableRS* _rs = (CardTableRS*)rs;
  7462. + _rs->inline_write_ref_field_gc(p, obj);
  7463. + }
  7464. + }
  7465. + }
  7466. }
  7467. }
  7468. - assert(num_annotations == calc_num_annotations, "sanity check");
  7469. +}
  7470. - return true;
  7471. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7472. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7473. + markOop first_mark = first->mark();
  7474. + markOop second_mark = second->mark();
  7475. + first->set_mark(second_mark);
  7476. + second->set_mark(first_mark);
  7477. +}
  7478. +void VM_RedefineClasses::doit() {
  7479. + Thread *thread = Thread::current();
  7480. -// Rewrite constant pool references in the annotation struct portion of
  7481. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7482. -// the 2nd-edition of the VM spec:
  7483. -//
  7484. -// struct annotation {
  7485. -// u2 type_index;
  7486. -// u2 num_element_value_pairs;
  7487. -// {
  7488. -// u2 element_name_index;
  7489. -// element_value value;
  7490. -// } element_value_pairs[num_element_value_pairs];
  7491. -// }
  7492. -//
  7493. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7494. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7495. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7496. - // not enough room for smallest annotation_struct
  7497. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7498. - ("length() is too small for annotation_struct"));
  7499. - return false;
  7500. - }
  7501. + RC_TRACE(0x00000001, ("Entering doit!"));
  7502. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7503. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7504. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7505. - annotations_typeArray->byte_at_addr(
  7506. - byte_i_ref));
  7507. - byte_i_ref += 2;
  7508. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7509. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7510. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7511. - num_element_value_pairs));
  7512. + RC_TIMER_START(_timer_check_type);
  7513. - int calc_num_element_value_pairs = 0;
  7514. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7515. - calc_num_element_value_pairs++) {
  7516. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7517. - // not enough room for another element_name_index, let alone
  7518. - // the rest of another component
  7519. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7520. - ("length() is too small for element_name_index"));
  7521. - return false;
  7522. + if (!check_type_consistency()) {
  7523. + // (tw) TODO: Rollback the class redefinition
  7524. + rollback();
  7525. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7526. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7527. + RC_TIMER_STOP(_timer_check_type);
  7528. + return;
  7529. }
  7530. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7531. - annotations_typeArray, byte_i_ref,
  7532. - "mapped old element_name_index=%d", THREAD);
  7533. + RC_TIMER_STOP(_timer_check_type);
  7534. +
  7535. + } else {
  7536. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7537. + }
  7538. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7539. - ("element_name_index=%d", element_name_index));
  7540. + if (UseMethodForwardPoints) {
  7541. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7542. + method_forwarding();
  7543. + }
  7544. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7545. - byte_i_ref, THREAD)) {
  7546. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7547. - ("bad element_value at %d", calc_num_element_value_pairs));
  7548. - // propagate failure back to caller
  7549. - return false;
  7550. + if (UseSharedSpaces) {
  7551. + // Sharing is enabled so we remap the shared readonly space to
  7552. + // shared readwrite, private just in case we need to redefine
  7553. + // a shared class. We do the remap during the doit() phase of
  7554. + // the safepoint to be safer.
  7555. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7556. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7557. + _result = JVMTI_ERROR_INTERNAL;
  7558. + return;
  7559. }
  7560. - } // end for each component
  7561. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7562. - "sanity check");
  7563. + }
  7564. - return true;
  7565. -} // end rewrite_cp_refs_in_annotation_struct()
  7566. -
  7567. -
  7568. -// Rewrite a constant pool reference at the current position in
  7569. -// annotations_typeArray if needed. Returns the original constant
  7570. -// pool reference if a rewrite was not needed or the new constant
  7571. -// pool reference if a rewrite was needed.
  7572. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7573. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7574. - const char * trace_mesg, TRAPS) {
  7575. -
  7576. - address cp_index_addr = (address)
  7577. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7578. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7579. - u2 new_cp_index = find_new_index(old_cp_index);
  7580. - if (new_cp_index != 0) {
  7581. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7582. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7583. - old_cp_index = new_cp_index;
  7584. - }
  7585. - byte_i_ref += 2;
  7586. - return old_cp_index;
  7587. -}
  7588. + RC_TIMER_START(_timer_prepare_redefinition);
  7589. + for (int i = 0; i < _new_classes->length(); i++) {
  7590. + redefine_single_class(_new_classes->at(i), thread);
  7591. + }
  7592. + // Deoptimize all compiled code that depends on this class
  7593. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7594. -// Rewrite constant pool references in the element_value portion of an
  7595. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7596. -// the 2nd-edition of the VM spec:
  7597. -//
  7598. -// struct element_value {
  7599. -// u1 tag;
  7600. -// union {
  7601. -// u2 const_value_index;
  7602. -// {
  7603. -// u2 type_name_index;
  7604. -// u2 const_name_index;
  7605. -// } enum_const_value;
  7606. -// u2 class_info_index;
  7607. -// annotation annotation_value;
  7608. -// struct {
  7609. -// u2 num_values;
  7610. -// element_value values[num_values];
  7611. -// } array_value;
  7612. -// } value;
  7613. -// }
  7614. -//
  7615. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7616. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7617. + // Adjust constantpool caches and vtables for all classes
  7618. + // that reference methods of the evolved class.
  7619. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7620. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7621. - // not enough room for a tag let alone the rest of an element_value
  7622. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7623. - ("length() is too small for a tag"));
  7624. - return false;
  7625. - }
  7626. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7627. + RC_TIMER_START(_timer_redefinition);
  7628. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7629. - byte_i_ref++;
  7630. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7631. -
  7632. - switch (tag) {
  7633. - // These BaseType tag values are from Table 4.2 in VM spec:
  7634. - case 'B': // byte
  7635. - case 'C': // char
  7636. - case 'D': // double
  7637. - case 'F': // float
  7638. - case 'I': // int
  7639. - case 'J': // long
  7640. - case 'S': // short
  7641. - case 'Z': // boolean
  7642. -
  7643. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7644. - // the VM spec:
  7645. - case 's':
  7646. - {
  7647. - // For the above tag values (including the BaseType values),
  7648. - // value.const_value_index is right union field.
  7649. + class ChangePointersOopClosure : public OopClosure {
  7650. + virtual void do_oop(oop* o) {
  7651. + do_oop_work(o);
  7652. + }
  7653. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7654. - // not enough room for a const_value_index
  7655. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7656. - ("length() is too small for a const_value_index"));
  7657. - return false;
  7658. + virtual void do_oop(narrowOop* o) {
  7659. + do_oop_work(o);
  7660. }
  7661. + };
  7662. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  7663. - annotations_typeArray, byte_i_ref,
  7664. - "mapped old const_value_index=%d", THREAD);
  7665. + class ChangePointersObjectClosure : public ObjectClosure {
  7666. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7667. - ("const_value_index=%d", const_value_index));
  7668. - } break;
  7669. + private:
  7670. - case 'e':
  7671. - {
  7672. - // for the above tag value, value.enum_const_value is right union field
  7673. + OopClosure *_closure;
  7674. + bool _needs_instance_update;
  7675. + GrowableArray<oop> *_updated_oops;
  7676. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  7677. - // not enough room for a enum_const_value
  7678. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7679. - ("length() is too small for a enum_const_value"));
  7680. - return false;
  7681. - }
  7682. + public:
  7683. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7684. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  7685. - annotations_typeArray, byte_i_ref,
  7686. - "mapped old type_name_index=%d", THREAD);
  7687. + bool needs_instance_update() {
  7688. + return _needs_instance_update;
  7689. + }
  7690. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  7691. - annotations_typeArray, byte_i_ref,
  7692. - "mapped old const_name_index=%d", THREAD);
  7693. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7694. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7695. - ("type_name_index=%d const_name_index=%d", type_name_index,
  7696. - const_name_index));
  7697. - } break;
  7698. + virtual void do_object(oop obj) {
  7699. + if (!obj->is_instanceKlass()) {
  7700. + obj->oop_iterate(_closure);
  7701. +
  7702. + if (obj->blueprint()->is_redefining()) {
  7703. - case 'c':
  7704. - {
  7705. - // for the above tag value, value.class_info_index is right union field
  7706. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7707. + if (_updated_oops == NULL) {
  7708. + _updated_oops = new (ResourceObj::C_HEAP) GrowableArray<oop>(100, true);
  7709. + }
  7710. + _updated_oops->append(obj);
  7711. + }
  7712. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7713. - // not enough room for a class_info_index
  7714. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7715. - ("length() is too small for a class_info_index"));
  7716. - return false;
  7717. - }
  7718. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7719. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  7720. - annotations_typeArray, byte_i_ref,
  7721. - "mapped old class_info_index=%d", THREAD);
  7722. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7723. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7724. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7725. - ("class_info_index=%d", class_info_index));
  7726. - } break;
  7727. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7728. + // We need an instance update => set back to old klass
  7729. + _needs_instance_update = true;
  7730. - case '@':
  7731. - // For the above tag value, value.attr_value is the right union
  7732. - // field. This is a nested annotation.
  7733. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7734. - byte_i_ref, THREAD)) {
  7735. - // propagate failure back to caller
  7736. - return false;
  7737. - }
  7738. - break;
  7739. + } else {
  7740. + MarkSweep::update_fields(obj, obj);
  7741. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7742. + }
  7743. + }
  7744. + }
  7745. - case '[':
  7746. - {
  7747. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7748. - // not enough room for a num_values field
  7749. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7750. - ("length() is too small for a num_values field"));
  7751. - return false;
  7752. - }
  7753. -
  7754. - // For the above tag value, value.array_value is the right union
  7755. - // field. This is an array of nested element_value.
  7756. - u2 num_values = Bytes::get_Java_u2((address)
  7757. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7758. - byte_i_ref += 2;
  7759. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  7760. -
  7761. - int calc_num_values = 0;
  7762. - for (; calc_num_values < num_values; calc_num_values++) {
  7763. - if (!rewrite_cp_refs_in_element_value(
  7764. - annotations_typeArray, byte_i_ref, THREAD)) {
  7765. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7766. - ("bad nested element_value at %d", calc_num_values));
  7767. - // propagate failure back to caller
  7768. - return false;
  7769. + } else {
  7770. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  7771. + if (klass->is_redefining()) {
  7772. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  7773. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  7774. + old_klass->constants()->set_pool_holder(klass->old_version());
  7775. +
  7776. + // Initialize the new class! Special static initialization that does not execute the
  7777. + // static constructor but copies static field values from the old class if name
  7778. + // and signature of a static field match.
  7779. + klass->initialize_redefined_class();
  7780. + }
  7781. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  7782. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  7783. + // idubrov: will get new version of that class
  7784. + //klass->iterate_static_fields(_closure);
  7785. }
  7786. }
  7787. - assert(num_values == calc_num_values, "sanity check");
  7788. - } break;
  7789. + };
  7790. - default:
  7791. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  7792. - return false;
  7793. - } // end decode tag field
  7794. + ChangePointersOopClosure oopClosure;
  7795. + ChangePointersObjectClosure objectClosure(&oopClosure);
  7796. - return true;
  7797. -} // end rewrite_cp_refs_in_element_value()
  7798. + {
  7799. + SharedHeap::heap()->gc_prologue(true);
  7800. + Universe::root_oops_do(&oopClosure);
  7801. + Universe::heap()->object_iterate(&objectClosure);
  7802. + SharedHeap::heap()->gc_epilogue(false);
  7803. + }
  7804. + // Swap marks to have same hashcodes
  7805. + for (int i=0; i<_new_classes->length(); i++) {
  7806. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  7807. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  7808. + }
  7809. -// Rewrite constant pool references in a fields_annotations field.
  7810. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  7811. - instanceKlassHandle scratch_class, TRAPS) {
  7812. + _updated_oops = objectClosure.updated_oops();
  7813. - objArrayHandle fields_annotations(THREAD,
  7814. - scratch_class->fields_annotations());
  7815. + if (objectClosure.needs_instance_update()){
  7816. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  7817. - // no fields_annotations so nothing to do
  7818. - return true;
  7819. + // Do a full garbage collection to update the instance sizes accordingly
  7820. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  7821. + Universe::set_redefining_gc_run(true);
  7822. + JvmtiGCMarker jgcm;
  7823. + notify_gc_begin(true);
  7824. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  7825. + notify_gc_end();
  7826. + Universe::set_redefining_gc_run(false);
  7827. + RC_TRACE(0x00000001, ("GC done!"));
  7828. }
  7829. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7830. - ("fields_annotations length=%d", fields_annotations->length()));
  7831. - for (int i = 0; i < fields_annotations->length(); i++) {
  7832. - typeArrayHandle field_annotations(THREAD,
  7833. - (typeArrayOop)fields_annotations->obj_at(i));
  7834. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  7835. - // this field does not have any annotations so skip it
  7836. - continue;
  7837. - }
  7838. -
  7839. - int byte_i = 0; // byte index into field_annotations
  7840. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  7841. - THREAD)) {
  7842. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7843. - ("bad field_annotations at %d", i));
  7844. - // propagate failure back to caller
  7845. - return false;
  7846. + if (RC_TRACE_ENABLED(0x00000001)) {
  7847. + if (_updated_oops != NULL) {
  7848. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  7849. + } else {
  7850. + RC_TRACE(0x00000001, ("No objects updated!"));
  7851. }
  7852. }
  7853. - return true;
  7854. -} // end rewrite_cp_refs_in_fields_annotations()
  7855. -
  7856. + // Unmark klassOops as "redefining"
  7857. + for (int i=0; i<_new_classes->length(); i++) {
  7858. + klassOop cur = _new_classes->at(i)();
  7859. + _new_classes->at(i)->set_redefining(false);
  7860. + _new_classes->at(i)->clear_update_information();
  7861. + _new_classes->at(i)->update_supers_to_newest_version();
  7862. -// Rewrite constant pool references in a methods_annotations field.
  7863. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  7864. - instanceKlassHandle scratch_class, TRAPS) {
  7865. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  7866. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7867. - objArrayHandle methods_annotations(THREAD,
  7868. - scratch_class->methods_annotations());
  7869. -
  7870. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  7871. - // no methods_annotations so nothing to do
  7872. - return true;
  7873. - }
  7874. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  7875. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7876. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7877. - ("methods_annotations length=%d", methods_annotations->length()));
  7878. + oop new_mirror = _new_classes->at(i)->java_mirror();
  7879. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  7880. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  7881. - for (int i = 0; i < methods_annotations->length(); i++) {
  7882. - typeArrayHandle method_annotations(THREAD,
  7883. - (typeArrayOop)methods_annotations->obj_at(i));
  7884. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  7885. - // this method does not have any annotations so skip it
  7886. - continue;
  7887. + // Transfer init state
  7888. + instanceKlass::ClassState state = instanceKlass::cast(cur->old_version())->init_state();
  7889. + if (state > instanceKlass::linked) {
  7890. + instanceKlass::cast(cur)->call_class_initializer(thread);
  7891. + }
  7892. }
  7893. + }
  7894. - int byte_i = 0; // byte index into method_annotations
  7895. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  7896. - THREAD)) {
  7897. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7898. - ("bad method_annotations at %d", i));
  7899. - // propagate failure back to caller
  7900. - return false;
  7901. - }
  7902. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  7903. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  7904. }
  7905. - return true;
  7906. -} // end rewrite_cp_refs_in_methods_annotations()
  7907. + // Disable any dependent concurrent compilations
  7908. + SystemDictionary::notice_modification();
  7909. + // Set flag indicating that some invariants are no longer true.
  7910. + // See jvmtiExport.hpp for detailed explanation.
  7911. + JvmtiExport::set_has_redefined_a_class();
  7912. -// Rewrite constant pool references in a methods_parameter_annotations
  7913. -// field. This "structure" is adapted from the
  7914. -// RuntimeVisibleParameterAnnotations_attribute described in section
  7915. -// 4.8.17 of the 2nd-edition of the VM spec:
  7916. -//
  7917. -// methods_parameter_annotations_typeArray {
  7918. -// u1 num_parameters;
  7919. -// {
  7920. -// u2 num_annotations;
  7921. -// annotation annotations[num_annotations];
  7922. -// } parameter_annotations[num_parameters];
  7923. -// }
  7924. -//
  7925. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  7926. - instanceKlassHandle scratch_class, TRAPS) {
  7927. + // Clean up caches in the compiler interface and compiler threads
  7928. + CompileBroker::cleanup_after_redefinition();
  7929. - objArrayHandle methods_parameter_annotations(THREAD,
  7930. - scratch_class->methods_parameter_annotations());
  7931. +#ifdef ASSERT
  7932. - if (methods_parameter_annotations.is_null()
  7933. - || methods_parameter_annotations->length() == 0) {
  7934. - // no methods_parameter_annotations so nothing to do
  7935. - return true;
  7936. - }
  7937. + // Universe::verify();
  7938. + // JNIHandles::verify();
  7939. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7940. - ("methods_parameter_annotations length=%d",
  7941. - methods_parameter_annotations->length()));
  7942. + SystemDictionary::classes_do(check_class, thread);
  7943. +#endif
  7944. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  7945. - typeArrayHandle method_parameter_annotations(THREAD,
  7946. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  7947. - if (method_parameter_annotations.is_null()
  7948. - || method_parameter_annotations->length() == 0) {
  7949. - // this method does not have any parameter annotations so skip it
  7950. - continue;
  7951. - }
  7952. + update_active_methods();
  7953. + RC_TIMER_STOP(_timer_redefinition);
  7954. - if (method_parameter_annotations->length() < 1) {
  7955. - // not enough room for a num_parameters field
  7956. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7957. - ("length() is too small for a num_parameters field at %d", i));
  7958. - return false;
  7959. - }
  7960. +}
  7961. - int byte_i = 0; // byte index into method_parameter_annotations
  7962. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  7963. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  7964. - byte_i++;
  7965. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  7966. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  7967. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7968. - ("num_parameters=%d", num_parameters));
  7969. - int calc_num_parameters = 0;
  7970. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  7971. - if (!rewrite_cp_refs_in_annotations_typeArray(
  7972. - method_parameter_annotations, byte_i, THREAD)) {
  7973. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7974. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  7975. - // propagate failure back to caller
  7976. - return false;
  7977. - }
  7978. + while (curArrayKlass != NULL) {
  7979. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  7980. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  7981. + curArrayKlass->update_supers_to_newest_version();
  7982. +
  7983. + curArrayKlass = NULL;
  7984. + if (higher_dimension != NULL) {
  7985. + curArrayKlass = arrayKlass::cast(higher_dimension);
  7986. }
  7987. - assert(num_parameters == calc_num_parameters, "sanity check");
  7988. }
  7989. - return true;
  7990. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  7991. +}
  7992. +void VM_RedefineClasses::doit_epilogue() {
  7993. -// Rewrite constant pool references in a methods_default_annotations
  7994. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  7995. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  7996. -//
  7997. -// methods_default_annotations_typeArray {
  7998. -// element_value default_value;
  7999. -// }
  8000. -//
  8001. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8002. - instanceKlassHandle scratch_class, TRAPS) {
  8003. + RC_TIMER_START(_timer_vm_op_epilogue);
  8004. - objArrayHandle methods_default_annotations(THREAD,
  8005. - scratch_class->methods_default_annotations());
  8006. + unlock_threads();
  8007. - if (methods_default_annotations.is_null()
  8008. - || methods_default_annotations->length() == 0) {
  8009. - // no methods_default_annotations so nothing to do
  8010. - return true;
  8011. - }
  8012. + ResourceMark mark;
  8013. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8014. - ("methods_default_annotations length=%d",
  8015. - methods_default_annotations->length()));
  8016. + VM_GC_Operation::doit_epilogue();
  8017. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  8018. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8019. - typeArrayHandle method_default_annotations(THREAD,
  8020. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8021. - if (method_default_annotations.is_null()
  8022. - || method_default_annotations->length() == 0) {
  8023. - // this method does not have any default annotations so skip it
  8024. - continue;
  8025. - }
  8026. + GrowableArray<methodHandle> instanceTransformerMethods;
  8027. - int byte_i = 0; // byte index into method_default_annotations
  8028. + // Call static transformers
  8029. + for (int i=0; i<_new_classes->length(); i++) {
  8030. +
  8031. + instanceKlassHandle klass = _new_classes->at(i);
  8032. +
  8033. + // Find instance transformer method
  8034. - if (!rewrite_cp_refs_in_element_value(
  8035. - method_default_annotations, byte_i, THREAD)) {
  8036. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8037. - ("bad default element_value at %d", i));
  8038. - // propagate failure back to caller
  8039. - return false;
  8040. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8041. +
  8042. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  8043. + klassOop cur_klass = klass();
  8044. + while (cur_klass != NULL) {
  8045. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  8046. + if (method != NULL) {
  8047. + methodHandle instanceTransformerMethod(method);
  8048. + instanceTransformerMethods.append(instanceTransformerMethod);
  8049. + break;
  8050. + } else {
  8051. + cur_klass = cur_klass->klass_part()->super();
  8052. + }
  8053. + }
  8054. + assert(cur_klass != NULL, "must have instance transformer method");
  8055. + } else {
  8056. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  8057. }
  8058. }
  8059. - return true;
  8060. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8061. + // Call instance transformers
  8062. + if (_updated_oops != NULL) {
  8063. -// Rewrite constant pool references in the method's stackmap table.
  8064. -// These "structures" are adapted from the StackMapTable_attribute that
  8065. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8066. -// (dated 2005.10.26):
  8067. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8068. -//
  8069. -// stack_map {
  8070. -// u2 number_of_entries;
  8071. -// stack_map_frame entries[number_of_entries];
  8072. -// }
  8073. -//
  8074. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8075. - methodHandle method, TRAPS) {
  8076. -
  8077. - if (!method->has_stackmap_table()) {
  8078. - return;
  8079. - }
  8080. -
  8081. - typeArrayOop stackmap_data = method->stackmap_data();
  8082. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8083. - address stackmap_end = stackmap_p + stackmap_data->length();
  8084. -
  8085. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8086. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8087. - stackmap_p += 2;
  8088. -
  8089. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8090. - ("number_of_entries=%u", number_of_entries));
  8091. -
  8092. - // walk through each stack_map_frame
  8093. - u2 calc_number_of_entries = 0;
  8094. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8095. - // The stack_map_frame structure is a u1 frame_type followed by
  8096. - // 0 or more bytes of data:
  8097. - //
  8098. - // union stack_map_frame {
  8099. - // same_frame;
  8100. - // same_locals_1_stack_item_frame;
  8101. - // same_locals_1_stack_item_frame_extended;
  8102. - // chop_frame;
  8103. - // same_frame_extended;
  8104. - // append_frame;
  8105. - // full_frame;
  8106. - // }
  8107. -
  8108. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8109. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8110. - // issues the following warning for the first if-statement below:
  8111. - //
  8112. - // "warning: comparison is always true due to limited range of data type"
  8113. - //
  8114. - u4 frame_type = *stackmap_p;
  8115. - stackmap_p++;
  8116. -
  8117. - // same_frame {
  8118. - // u1 frame_type = SAME; /* 0-63 */
  8119. - // }
  8120. - if (frame_type >= 0 && frame_type <= 63) {
  8121. - // nothing more to do for same_frame
  8122. - }
  8123. -
  8124. - // same_locals_1_stack_item_frame {
  8125. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8126. - // verification_type_info stack[1];
  8127. - // }
  8128. - else if (frame_type >= 64 && frame_type <= 127) {
  8129. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8130. - calc_number_of_entries, frame_type, THREAD);
  8131. - }
  8132. -
  8133. - // reserved for future use
  8134. - else if (frame_type >= 128 && frame_type <= 246) {
  8135. - // nothing more to do for reserved frame_types
  8136. - }
  8137. -
  8138. - // same_locals_1_stack_item_frame_extended {
  8139. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8140. - // u2 offset_delta;
  8141. - // verification_type_info stack[1];
  8142. - // }
  8143. - else if (frame_type == 247) {
  8144. - stackmap_p += 2;
  8145. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8146. - calc_number_of_entries, frame_type, THREAD);
  8147. - }
  8148. -
  8149. - // chop_frame {
  8150. - // u1 frame_type = CHOP; /* 248-250 */
  8151. - // u2 offset_delta;
  8152. - // }
  8153. - else if (frame_type >= 248 && frame_type <= 250) {
  8154. - stackmap_p += 2;
  8155. - }
  8156. -
  8157. - // same_frame_extended {
  8158. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8159. - // u2 offset_delta;
  8160. - // }
  8161. - else if (frame_type == 251) {
  8162. - stackmap_p += 2;
  8163. - }
  8164. -
  8165. - // append_frame {
  8166. - // u1 frame_type = APPEND; /* 252-254 */
  8167. - // u2 offset_delta;
  8168. - // verification_type_info locals[frame_type - 251];
  8169. - // }
  8170. - else if (frame_type >= 252 && frame_type <= 254) {
  8171. - assert(stackmap_p + 2 <= stackmap_end,
  8172. - "no room for offset_delta");
  8173. - stackmap_p += 2;
  8174. - u1 len = frame_type - 251;
  8175. - for (u1 i = 0; i < len; i++) {
  8176. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8177. - calc_number_of_entries, frame_type, THREAD);
  8178. - }
  8179. - }
  8180. -
  8181. - // full_frame {
  8182. - // u1 frame_type = FULL_FRAME; /* 255 */
  8183. - // u2 offset_delta;
  8184. - // u2 number_of_locals;
  8185. - // verification_type_info locals[number_of_locals];
  8186. - // u2 number_of_stack_items;
  8187. - // verification_type_info stack[number_of_stack_items];
  8188. - // }
  8189. - else if (frame_type == 255) {
  8190. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8191. - "no room for smallest full_frame");
  8192. - stackmap_p += 2;
  8193. -
  8194. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8195. - stackmap_p += 2;
  8196. -
  8197. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8198. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8199. - calc_number_of_entries, frame_type, THREAD);
  8200. - }
  8201. -
  8202. - // Use the largest size for the number_of_stack_items, but only get
  8203. - // the right number of bytes.
  8204. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8205. - stackmap_p += 2;
  8206. -
  8207. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8208. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8209. - calc_number_of_entries, frame_type, THREAD);
  8210. - }
  8211. - }
  8212. - } // end while there is a stack_map_frame
  8213. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8214. -} // end rewrite_cp_refs_in_stack_map_table()
  8215. -
  8216. -
  8217. -// Rewrite constant pool references in the verification type info
  8218. -// portion of the method's stackmap table. These "structures" are
  8219. -// adapted from the StackMapTable_attribute that is described in
  8220. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8221. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8222. -//
  8223. -// The verification_type_info structure is a u1 tag followed by 0 or
  8224. -// more bytes of data:
  8225. -//
  8226. -// union verification_type_info {
  8227. -// Top_variable_info;
  8228. -// Integer_variable_info;
  8229. -// Float_variable_info;
  8230. -// Long_variable_info;
  8231. -// Double_variable_info;
  8232. -// Null_variable_info;
  8233. -// UninitializedThis_variable_info;
  8234. -// Object_variable_info;
  8235. -// Uninitialized_variable_info;
  8236. -// }
  8237. -//
  8238. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8239. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8240. - u1 frame_type, TRAPS) {
  8241. -
  8242. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8243. - u1 tag = *stackmap_p_ref;
  8244. - stackmap_p_ref++;
  8245. -
  8246. - switch (tag) {
  8247. - // Top_variable_info {
  8248. - // u1 tag = ITEM_Top; /* 0 */
  8249. - // }
  8250. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8251. - case 0: // fall through
  8252. -
  8253. - // Integer_variable_info {
  8254. - // u1 tag = ITEM_Integer; /* 1 */
  8255. - // }
  8256. - case ITEM_Integer: // fall through
  8257. -
  8258. - // Float_variable_info {
  8259. - // u1 tag = ITEM_Float; /* 2 */
  8260. - // }
  8261. - case ITEM_Float: // fall through
  8262. -
  8263. - // Double_variable_info {
  8264. - // u1 tag = ITEM_Double; /* 3 */
  8265. - // }
  8266. - case ITEM_Double: // fall through
  8267. -
  8268. - // Long_variable_info {
  8269. - // u1 tag = ITEM_Long; /* 4 */
  8270. - // }
  8271. - case ITEM_Long: // fall through
  8272. -
  8273. - // Null_variable_info {
  8274. - // u1 tag = ITEM_Null; /* 5 */
  8275. - // }
  8276. - case ITEM_Null: // fall through
  8277. -
  8278. - // UninitializedThis_variable_info {
  8279. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8280. - // }
  8281. - case ITEM_UninitializedThis:
  8282. - // nothing more to do for the above tag types
  8283. - break;
  8284. + for (int i=0; i<_updated_oops->length(); i++) {
  8285. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  8286. + Handle cur(_updated_oops->at(i));
  8287. + instanceKlassHandle klass(cur->klass());
  8288. - // Object_variable_info {
  8289. - // u1 tag = ITEM_Object; /* 7 */
  8290. - // u2 cpool_index;
  8291. - // }
  8292. - case ITEM_Object:
  8293. - {
  8294. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8295. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8296. - u2 new_cp_index = find_new_index(cpool_index);
  8297. - if (new_cp_index != 0) {
  8298. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8299. - ("mapped old cpool_index=%d", cpool_index));
  8300. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8301. - cpool_index = new_cp_index;
  8302. - }
  8303. - stackmap_p_ref += 2;
  8304. -
  8305. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8306. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8307. - frame_type, cpool_index));
  8308. - } break;
  8309. -
  8310. - // Uninitialized_variable_info {
  8311. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8312. - // u2 offset;
  8313. - // }
  8314. - case ITEM_Uninitialized:
  8315. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8316. - stackmap_p_ref += 2;
  8317. - break;
  8318. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8319. - default:
  8320. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8321. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8322. - ShouldNotReachHere();
  8323. - break;
  8324. - } // end switch (tag)
  8325. -} // end rewrite_cp_refs_in_verification_type_info()
  8326. -
  8327. -
  8328. -// Change the constant pool associated with klass scratch_class to
  8329. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8330. -// are copied from scratch_cp to a smaller constant pool and the
  8331. -// smaller constant pool is associated with scratch_class.
  8332. -void VM_RedefineClasses::set_new_constant_pool(
  8333. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8334. - int scratch_cp_length, bool shrink, TRAPS) {
  8335. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  8336. -
  8337. - if (shrink) {
  8338. - // scratch_cp is a merged constant pool and has enough space for a
  8339. - // worst case merge situation. We want to associate the minimum
  8340. - // sized constant pool with the klass to save space.
  8341. - constantPoolHandle smaller_cp(THREAD,
  8342. - oopFactory::new_constantPool(scratch_cp_length,
  8343. - oopDesc::IsUnsafeConc,
  8344. - THREAD));
  8345. - // preserve orig_length() value in the smaller copy
  8346. - int orig_length = scratch_cp->orig_length();
  8347. - assert(orig_length != 0, "sanity check");
  8348. - smaller_cp->set_orig_length(orig_length);
  8349. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8350. - scratch_cp = smaller_cp;
  8351. - smaller_cp()->set_is_conc_safe(true);
  8352. - }
  8353. -
  8354. - // attach new constant pool to klass
  8355. - scratch_cp->set_pool_holder(scratch_class());
  8356. -
  8357. - // attach klass to new constant pool
  8358. - scratch_class->set_constants(scratch_cp());
  8359. -
  8360. - int i; // for portability
  8361. -
  8362. - // update each field in klass to use new constant pool indices as needed
  8363. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8364. - jshort cur_index = fs.name_index();
  8365. - jshort new_index = find_new_index(cur_index);
  8366. - if (new_index != 0) {
  8367. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8368. - ("field-name_index change: %d to %d", cur_index, new_index));
  8369. - fs.set_name_index(new_index);
  8370. - }
  8371. - cur_index = fs.signature_index();
  8372. - new_index = find_new_index(cur_index);
  8373. - if (new_index != 0) {
  8374. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8375. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8376. - fs.set_signature_index(new_index);
  8377. - }
  8378. - cur_index = fs.initval_index();
  8379. - new_index = find_new_index(cur_index);
  8380. - if (new_index != 0) {
  8381. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8382. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8383. - fs.set_initval_index(new_index);
  8384. - }
  8385. - cur_index = fs.generic_signature_index();
  8386. - new_index = find_new_index(cur_index);
  8387. - if (new_index != 0) {
  8388. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8389. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8390. - fs.set_generic_signature_index(new_index);
  8391. - }
  8392. - } // end for each field
  8393. -
  8394. - // Update constant pool indices in the inner classes info to use
  8395. - // new constant indices as needed. The inner classes info is a
  8396. - // quadruple:
  8397. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8398. - typeArrayOop inner_class_list = scratch_class->inner_classes();
  8399. - int icl_length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
  8400. - if (icl_length > 0) {
  8401. - typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
  8402. - for (int i = 0; i < icl_length;
  8403. - i += instanceKlass::inner_class_next_offset) {
  8404. - int cur_index = inner_class_list_h->ushort_at(i
  8405. - + instanceKlass::inner_class_inner_class_info_offset);
  8406. - if (cur_index == 0) {
  8407. - continue; // JVM spec. allows null inner class refs so skip it
  8408. - }
  8409. - int new_index = find_new_index(cur_index);
  8410. - if (new_index != 0) {
  8411. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8412. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8413. - inner_class_list_h->ushort_at_put(i
  8414. - + instanceKlass::inner_class_inner_class_info_offset, new_index);
  8415. - }
  8416. - cur_index = inner_class_list_h->ushort_at(i
  8417. - + instanceKlass::inner_class_outer_class_info_offset);
  8418. - new_index = find_new_index(cur_index);
  8419. - if (new_index != 0) {
  8420. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8421. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8422. - inner_class_list_h->ushort_at_put(i
  8423. - + instanceKlass::inner_class_outer_class_info_offset, new_index);
  8424. - }
  8425. - cur_index = inner_class_list_h->ushort_at(i
  8426. - + instanceKlass::inner_class_inner_name_offset);
  8427. - new_index = find_new_index(cur_index);
  8428. - if (new_index != 0) {
  8429. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8430. - ("inner_name change: %d to %d", cur_index, new_index));
  8431. - inner_class_list_h->ushort_at_put(i
  8432. - + instanceKlass::inner_class_inner_name_offset, new_index);
  8433. - }
  8434. - } // end for each inner class
  8435. - } // end if we have inner classes
  8436. -
  8437. - // Attach each method in klass to the new constant pool and update
  8438. - // to use new constant pool indices as needed:
  8439. - objArrayHandle methods(THREAD, scratch_class->methods());
  8440. - for (i = methods->length() - 1; i >= 0; i--) {
  8441. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8442. - method->set_constants(scratch_cp());
  8443. -
  8444. - int new_index = find_new_index(method->name_index());
  8445. - if (new_index != 0) {
  8446. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8447. - ("method-name_index change: %d to %d", method->name_index(),
  8448. - new_index));
  8449. - method->set_name_index(new_index);
  8450. - }
  8451. - new_index = find_new_index(method->signature_index());
  8452. - if (new_index != 0) {
  8453. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8454. - ("method-signature_index change: %d to %d",
  8455. - method->signature_index(), new_index));
  8456. - method->set_signature_index(new_index);
  8457. - }
  8458. - new_index = find_new_index(method->generic_signature_index());
  8459. - if (new_index != 0) {
  8460. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8461. - ("method-generic_signature_index change: %d to %d",
  8462. - method->generic_signature_index(), new_index));
  8463. - method->set_generic_signature_index(new_index);
  8464. - }
  8465. -
  8466. - // Update constant pool indices in the method's checked exception
  8467. - // table to use new constant indices as needed.
  8468. - int cext_length = method->checked_exceptions_length();
  8469. - if (cext_length > 0) {
  8470. - CheckedExceptionElement * cext_table =
  8471. - method->checked_exceptions_start();
  8472. - for (int j = 0; j < cext_length; j++) {
  8473. - int cur_index = cext_table[j].class_cp_index;
  8474. - int new_index = find_new_index(cur_index);
  8475. - if (new_index != 0) {
  8476. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8477. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8478. - cext_table[j].class_cp_index = (u2)new_index;
  8479. - }
  8480. - } // end for each checked exception table entry
  8481. - } // end if there are checked exception table entries
  8482. -
  8483. - // Update each catch type index in the method's exception table
  8484. - // to use new constant pool indices as needed. The exception table
  8485. - // holds quadruple entries of the form:
  8486. - // (beg_bci, end_bci, handler_bci, klass_index)
  8487. - const int beg_bci_offset = 0;
  8488. - const int end_bci_offset = 1;
  8489. - const int handler_bci_offset = 2;
  8490. - const int klass_index_offset = 3;
  8491. - const int entry_size = 4;
  8492. -
  8493. - typeArrayHandle ex_table (THREAD, method->exception_table());
  8494. - int ext_length = ex_table->length();
  8495. - assert(ext_length % entry_size == 0, "exception table format has changed");
  8496. -
  8497. - for (int j = 0; j < ext_length; j += entry_size) {
  8498. - int cur_index = ex_table->int_at(j + klass_index_offset);
  8499. - int new_index = find_new_index(cur_index);
  8500. - if (new_index != 0) {
  8501. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8502. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8503. - ex_table->int_at_put(j + klass_index_offset, new_index);
  8504. - }
  8505. - } // end for each exception table entry
  8506. -
  8507. - // Update constant pool indices in the method's local variable
  8508. - // table to use new constant indices as needed. The local variable
  8509. - // table hold sextuple entries of the form:
  8510. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8511. - int lvt_length = method->localvariable_table_length();
  8512. - if (lvt_length > 0) {
  8513. - LocalVariableTableElement * lv_table =
  8514. - method->localvariable_table_start();
  8515. - for (int j = 0; j < lvt_length; j++) {
  8516. - int cur_index = lv_table[j].name_cp_index;
  8517. - int new_index = find_new_index(cur_index);
  8518. - if (new_index != 0) {
  8519. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8520. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8521. - lv_table[j].name_cp_index = (u2)new_index;
  8522. - }
  8523. - cur_index = lv_table[j].descriptor_cp_index;
  8524. - new_index = find_new_index(cur_index);
  8525. - if (new_index != 0) {
  8526. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8527. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8528. - new_index));
  8529. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8530. - }
  8531. - cur_index = lv_table[j].signature_cp_index;
  8532. - new_index = find_new_index(cur_index);
  8533. - if (new_index != 0) {
  8534. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8535. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8536. - lv_table[j].signature_cp_index = (u2)new_index;
  8537. - }
  8538. - } // end for each local variable table entry
  8539. - } // end if there are local variable table entries
  8540. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  8541. +
  8542. + RC_TRACE(0x00008000, ("executing transformer method"));
  8543. +
  8544. + Thread *__the_thread__ = Thread::current();
  8545. + JavaValue result(T_VOID);
  8546. + JavaCallArguments args(cur);
  8547. + JavaCalls::call(&result,
  8548. + method,
  8549. + &args,
  8550. + THREAD);
  8551. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8552. - } // end for each method
  8553. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8554. -} // end set_new_constant_pool()
  8555. + // TODO: What to do with an exception here?
  8556. + if (HAS_PENDING_EXCEPTION) {
  8557. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  8558. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  8559. + ex_name->as_C_string()));
  8560. + CLEAR_PENDING_EXCEPTION;
  8561. + }
  8562. + }
  8563. + }
  8564. + delete _updated_oops;
  8565. + _updated_oops = NULL;
  8566. + }
  8567. -// Unevolving classes may point to methods of the_class directly
  8568. -// from their constant pool caches, itables, and/or vtables. We
  8569. -// use the SystemDictionary::classes_do() facility and this helper
  8570. -// to fix up these pointers.
  8571. -//
  8572. -// Note: We currently don't support updating the vtable in
  8573. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8574. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8575. - oop initiating_loader, TRAPS) {
  8576. - Klass *k = k_oop->klass_part();
  8577. - if (k->oop_is_instance()) {
  8578. - HandleMark hm(THREAD);
  8579. - instanceKlass *ik = (instanceKlass *) k;
  8580. + // Free the array of scratch classes
  8581. + delete _new_classes;
  8582. + _new_classes = NULL;
  8583. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  8584. - // HotSpot specific optimization! HotSpot does not currently
  8585. - // support delegation from the bootstrap class loader to a
  8586. - // user-defined class loader. This means that if the bootstrap
  8587. - // class loader is the initiating class loader, then it will also
  8588. - // be the defining class loader. This also means that classes
  8589. - // loaded by the bootstrap class loader cannot refer to classes
  8590. - // loaded by a user-defined class loader. Note: a user-defined
  8591. - // class loader can delegate to the bootstrap class loader.
  8592. - //
  8593. - // If the current class being redefined has a user-defined class
  8594. - // loader as its defining class loader, then we can skip all
  8595. - // classes loaded by the bootstrap class loader.
  8596. - bool is_user_defined =
  8597. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8598. - if (is_user_defined && ik->class_loader() == NULL) {
  8599. - return;
  8600. - }
  8601. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  8602. +}
  8603. - // This is a very busy routine. We don't want too much tracing
  8604. - // printed out.
  8605. - bool trace_name_printed = false;
  8606. -
  8607. - // Very noisy: only enable this call if you are trying to determine
  8608. - // that a specific class gets found by this routine.
  8609. - // RC_TRACE macro has an embedded ResourceMark
  8610. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8611. - // ("adjust check: name=%s", ik->external_name()));
  8612. - // trace_name_printed = true;
  8613. -
  8614. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8615. - // if one exists. We discard scratch_class and we don't keep an
  8616. - // instanceKlass around to hold obsolete methods so we don't have
  8617. - // any other instanceKlass embedded vtables to update. The vtable
  8618. - // holds the methodOops for virtual (but not final) methods.
  8619. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8620. - // ik->vtable() creates a wrapper object; rm cleans it up
  8621. - ResourceMark rm(THREAD);
  8622. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8623. - _matching_new_methods,
  8624. - _matching_methods_length,
  8625. - &trace_name_printed);
  8626. - }
  8627. -
  8628. - // If the current class has an itable and we are either redefining an
  8629. - // interface or if the current class is a subclass of the_class, then
  8630. - // we potentially have to fix the itable. If we are redefining an
  8631. - // interface, then we have to call adjust_method_entries() for
  8632. - // every instanceKlass that has an itable since there isn't a
  8633. - // subclass relationship between an interface and an instanceKlass.
  8634. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8635. - || ik->is_subclass_of(_the_class_oop))) {
  8636. - // ik->itable() creates a wrapper object; rm cleans it up
  8637. - ResourceMark rm(THREAD);
  8638. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8639. - _matching_new_methods,
  8640. - _matching_methods_length,
  8641. - &trace_name_printed);
  8642. - }
  8643. -
  8644. - // The constant pools in other classes (other_cp) can refer to
  8645. - // methods in the_class. We have to update method information in
  8646. - // other_cp's cache. If other_cp has a previous version, then we
  8647. - // have to repeat the process for each previous version. The
  8648. - // constant pool cache holds the methodOops for non-virtual
  8649. - // methods and for virtual, final methods.
  8650. - //
  8651. - // Special case: if the current class is the_class, then new_cp
  8652. - // has already been attached to the_class and old_cp has already
  8653. - // been added as a previous version. The new_cp doesn't have any
  8654. - // cached references to old methods so it doesn't need to be
  8655. - // updated. We can simply start with the previous version(s) in
  8656. - // that case.
  8657. - constantPoolHandle other_cp;
  8658. - constantPoolCacheOop cp_cache;
  8659. -
  8660. - if (k_oop != _the_class_oop) {
  8661. - // this klass' constant pool cache may need adjustment
  8662. - other_cp = constantPoolHandle(ik->constants());
  8663. - cp_cache = other_cp->cache();
  8664. - if (cp_cache != NULL) {
  8665. - cp_cache->adjust_method_entries(_matching_old_methods,
  8666. - _matching_new_methods,
  8667. - _matching_methods_length,
  8668. - &trace_name_printed);
  8669. - }
  8670. - }
  8671. - {
  8672. - ResourceMark rm(THREAD);
  8673. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  8674. - // contain a GrowableArray of handles. We have to clean up the
  8675. - // GrowableArray _after_ the PreviousVersionWalker destructor
  8676. - // has destroyed the handles.
  8677. - {
  8678. - // the previous versions' constant pool caches may need adjustment
  8679. - PreviousVersionWalker pvw(ik);
  8680. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  8681. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  8682. - other_cp = pv_info->prev_constant_pool_handle();
  8683. - cp_cache = other_cp->cache();
  8684. - if (cp_cache != NULL) {
  8685. - cp_cache->adjust_method_entries(_matching_old_methods,
  8686. - _matching_new_methods,
  8687. - _matching_methods_length,
  8688. - &trace_name_printed);
  8689. - }
  8690. - }
  8691. - } // pvw is cleaned up
  8692. - } // rm is cleaned up
  8693. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  8694. + // classes for primitives cannot be redefined
  8695. + if (java_lang_Class::is_primitive(klass_mirror)) {
  8696. + return false;
  8697. + }
  8698. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  8699. + // classes for arrays cannot be redefined
  8700. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  8701. + return false;
  8702. }
  8703. + return true;
  8704. }
  8705. -void VM_RedefineClasses::update_jmethod_ids() {
  8706. - for (int j = 0; j < _matching_methods_length; ++j) {
  8707. - methodOop old_method = _matching_old_methods[j];
  8708. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  8709. - if (jmid != NULL) {
  8710. - // There is a jmethodID, change it to point to the new method
  8711. - methodHandle new_method_h(_matching_new_methods[j]);
  8712. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  8713. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  8714. - "should be replaced");
  8715. - }
  8716. +#ifdef ASSERT
  8717. +
  8718. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8719. + klassOop k_oop = k_oop_latest;
  8720. + while (k_oop != NULL) {
  8721. +
  8722. + instanceKlassHandle k_handle(THREAD, k_oop);
  8723. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  8724. + k_oop = k_oop->klass_part()->old_version();
  8725. }
  8726. }
  8727. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  8728. - BitMap *emcp_methods, int * emcp_method_count_p) {
  8729. - *emcp_method_count_p = 0;
  8730. - int obsolete_count = 0;
  8731. - int old_index = 0;
  8732. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8733. - methodOop old_method = _matching_old_methods[j];
  8734. - methodOop new_method = _matching_new_methods[j];
  8735. - methodOop old_array_method;
  8736. -
  8737. - // Maintain an old_index into the _old_methods array by skipping
  8738. - // deleted methods
  8739. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8740. - != old_method) {
  8741. - ++old_index;
  8742. - }
  8743. -
  8744. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8745. - // The EMCP definition from JSR-163 requires the bytecodes to be
  8746. - // the same with the exception of constant pool indices which may
  8747. - // differ. However, the constants referred to by those indices
  8748. - // must be the same.
  8749. - //
  8750. - // We use methods_EMCP() for comparison since constant pool
  8751. - // merging can remove duplicate constant pool entries that were
  8752. - // present in the old method and removed from the rewritten new
  8753. - // method. A faster binary comparison function would consider the
  8754. - // old and new methods to be different when they are actually
  8755. - // EMCP.
  8756. - //
  8757. - // The old and new methods are EMCP and you would think that we
  8758. - // could get rid of one of them here and now and save some space.
  8759. - // However, the concept of EMCP only considers the bytecodes and
  8760. - // the constant pool entries in the comparison. Other things,
  8761. - // e.g., the line number table (LNT) or the local variable table
  8762. - // (LVT) don't count in the comparison. So the new (and EMCP)
  8763. - // method can have a new LNT that we need so we can't just
  8764. - // overwrite the new method with the old method.
  8765. - //
  8766. - // When this routine is called, we have already attached the new
  8767. - // methods to the_class so the old methods are effectively
  8768. - // overwritten. However, if an old method is still executing,
  8769. - // then the old method cannot be collected until sometime after
  8770. - // the old method call has returned. So the overwriting of old
  8771. - // methods by new methods will save us space except for those
  8772. - // (hopefully few) old methods that are still executing.
  8773. - //
  8774. - // A method refers to a constMethodOop and this presents another
  8775. - // possible avenue to space savings. The constMethodOop in the
  8776. - // new method contains possibly new attributes (LNT, LVT, etc).
  8777. - // At first glance, it seems possible to save space by replacing
  8778. - // the constMethodOop in the old method with the constMethodOop
  8779. - // from the new method. The old and new methods would share the
  8780. - // same constMethodOop and we would save the space occupied by
  8781. - // the old constMethodOop. However, the constMethodOop contains
  8782. - // a back reference to the containing method. Sharing the
  8783. - // constMethodOop between two methods could lead to confusion in
  8784. - // the code that uses the back reference. This would lead to
  8785. - // brittle code that could be broken in non-obvious ways now or
  8786. - // in the future.
  8787. - //
  8788. - // Another possibility is to copy the constMethodOop from the new
  8789. - // method to the old method and then overwrite the new method with
  8790. - // the old method. Since the constMethodOop contains the bytecodes
  8791. - // for the method embedded in the oop, this option would change
  8792. - // the bytecodes out from under any threads executing the old
  8793. - // method and make the thread's bcp invalid. Since EMCP requires
  8794. - // that the bytecodes be the same modulo constant pool indices, it
  8795. - // is straight forward to compute the correct new bcp in the new
  8796. - // constMethodOop from the old bcp in the old constMethodOop. The
  8797. - // time consuming part would be searching all the frames in all
  8798. - // of the threads to find all of the calls to the old method.
  8799. - //
  8800. - // It looks like we will have to live with the limited savings
  8801. - // that we get from effectively overwriting the old methods
  8802. - // when the new methods are attached to the_class.
  8803. -
  8804. - // track which methods are EMCP for add_previous_version() call
  8805. - emcp_methods->set_bit(old_index);
  8806. - (*emcp_method_count_p)++;
  8807. -
  8808. - // An EMCP method is _not_ obsolete. An obsolete method has a
  8809. - // different jmethodID than the current method. An EMCP method
  8810. - // has the same jmethodID as the current method. Having the
  8811. - // same jmethodID for all EMCP versions of a method allows for
  8812. - // a consistent view of the EMCP methods regardless of which
  8813. - // EMCP method you happen to have in hand. For example, a
  8814. - // breakpoint set in one EMCP method will work for all EMCP
  8815. - // versions of the method including the current one.
  8816. - } else {
  8817. - // mark obsolete methods as such
  8818. - old_method->set_is_obsolete();
  8819. - obsolete_count++;
  8820. +#endif
  8821. - // obsolete methods need a unique idnum
  8822. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  8823. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  8824. -// u2 old_num = old_method->method_idnum();
  8825. - old_method->set_method_idnum(num);
  8826. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  8827. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  8828. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  8829. +// do that, they assume that cache entry is resolved already.
  8830. +static void unpatch_bytecode(methodOop method) {
  8831. + RawBytecodeStream bcs(method);
  8832. + Bytecodes::Code code;
  8833. + Bytecodes::Code java_code;
  8834. + while (!bcs.is_last_bytecode()) {
  8835. + code = bcs.raw_next();
  8836. + address bcp = bcs.bcp();
  8837. +
  8838. + if (code == Bytecodes::_breakpoint) {
  8839. + int bci = method->bci_from(bcp);
  8840. + code = method->orig_bytecode_at(bci);
  8841. + java_code = Bytecodes::java_code(code);
  8842. + if (code != java_code &&
  8843. + (java_code == Bytecodes::_getfield ||
  8844. + java_code == Bytecodes::_putfield ||
  8845. + java_code == Bytecodes::_aload_0)) {
  8846. + // Let breakpoint table handling unpatch bytecode
  8847. + method->set_orig_bytecode_at(bci, java_code);
  8848. }
  8849. - // With tracing we try not to "yack" too much. The position of
  8850. - // this trace assumes there are fewer obsolete methods than
  8851. - // EMCP methods.
  8852. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  8853. - old_method->name()->as_C_string(),
  8854. - old_method->signature()->as_C_string()));
  8855. + } else {
  8856. + java_code = Bytecodes::java_code(code);
  8857. + if (code != java_code &&
  8858. + (java_code == Bytecodes::_getfield ||
  8859. + java_code == Bytecodes::_putfield ||
  8860. + java_code == Bytecodes::_aload_0)) {
  8861. + *bcp = java_code;
  8862. + }
  8863. + }
  8864. +
  8865. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  8866. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  8867. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  8868. + assert(code2 == Bytecodes::_fast_igetfield ||
  8869. + code2 == Bytecodes::_fast_agetfield ||
  8870. + code2 == Bytecodes::_fast_fgetfield, "");
  8871. + *(bcp + 1) = Bytecodes::java_code(code2);
  8872. }
  8873. - old_method->set_is_old();
  8874. - }
  8875. - for (int i = 0; i < _deleted_methods_length; ++i) {
  8876. - methodOop old_method = _deleted_methods[i];
  8877. -
  8878. - assert(old_method->vtable_index() < 0,
  8879. - "cannot delete methods with vtable entries");;
  8880. -
  8881. - // Mark all deleted methods as old and obsolete
  8882. - old_method->set_is_old();
  8883. - old_method->set_is_obsolete();
  8884. - ++obsolete_count;
  8885. - // With tracing we try not to "yack" too much. The position of
  8886. - // this trace assumes there are fewer obsolete methods than
  8887. - // EMCP methods.
  8888. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  8889. - old_method->name()->as_C_string(),
  8890. - old_method->signature()->as_C_string()));
  8891. - }
  8892. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  8893. - "sanity check");
  8894. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  8895. - obsolete_count));
  8896. + }
  8897. }
  8898. -// This internal class transfers the native function registration from old methods
  8899. -// to new methods. It is designed to handle both the simple case of unchanged
  8900. -// native methods and the complex cases of native method prefixes being added and/or
  8901. -// removed.
  8902. -// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  8903. -//
  8904. -// This class is used after the new methods have been installed in "the_class".
  8905. -//
  8906. -// So, for example, the following must be handled. Where 'm' is a method and
  8907. -// a number followed by an underscore is a prefix.
  8908. -//
  8909. -// Old Name New Name
  8910. -// Simple transfer to new method m -> m
  8911. -// Add prefix m -> 1_m
  8912. -// Remove prefix 1_m -> m
  8913. -// Simultaneous add of prefixes m -> 3_2_1_m
  8914. -// Simultaneous removal of prefixes 3_2_1_m -> m
  8915. -// Simultaneous add and remove 1_m -> 2_m
  8916. -// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8917. +// Unevolving classes may point to old methods directly
  8918. +// from their constant pool caches, itables, and/or vtables. We
  8919. +// use the SystemDictionary::classes_do() facility and this helper
  8920. +// to fix up these pointers. Additional field offsets and vtable indices
  8921. +// in the constant pool cache entries are fixed.
  8922. //
  8923. -class TransferNativeFunctionRegistration {
  8924. - private:
  8925. - instanceKlassHandle the_class;
  8926. - int prefix_count;
  8927. - char** prefixes;
  8928. +// Note: We currently don't support updating the vtable in
  8929. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8930. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8931. + klassOop k_oop = k_oop_latest;
  8932. + while (k_oop != NULL) {
  8933. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  8934. +/*
  8935. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8936. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8937. - // Recursively search the binary tree of possibly prefixed method names.
  8938. - // Iteration could be used if all agents were well behaved. Full tree walk is
  8939. - // more resilent to agents not cleaning up intermediate methods.
  8940. - // Branch at each depth in the binary tree is:
  8941. - // (1) without the prefix.
  8942. - // (2) with the prefix.
  8943. - // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  8944. - methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  8945. - Symbol* signature) {
  8946. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  8947. - if (name_symbol != NULL) {
  8948. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  8949. - if (method != NULL) {
  8950. - // Even if prefixed, intermediate methods must exist.
  8951. - if (method->is_native()) {
  8952. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  8953. - return method;
  8954. - }
  8955. - if (depth < prefix_count) {
  8956. - // Try applying further prefixes (other than this one).
  8957. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  8958. - if (method != NULL) {
  8959. - return method; // found
  8960. - }
  8961. + for (int i=0; i<_matching_methods_length; i++) {
  8962. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  8963. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  8964. + }*/
  8965. - // Try adding this prefix to the method name and see if it matches
  8966. - // another method name.
  8967. - char* prefix = prefixes[depth];
  8968. - size_t prefix_len = strlen(prefix);
  8969. - size_t trial_len = name_len + prefix_len;
  8970. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  8971. - strcpy(trial_name_str, prefix);
  8972. - strcat(trial_name_str, name_str);
  8973. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  8974. - signature);
  8975. - if (method != NULL) {
  8976. - // If found along this branch, it was prefixed, mark as such
  8977. - method->set_is_prefixed_native();
  8978. - return method; // found
  8979. - }
  8980. - }
  8981. - }
  8982. - }
  8983. - return NULL; // This whole branch bore nothing
  8984. - }
  8985. + Klass *k = k_oop->klass_part();
  8986. + if (k->oop_is_instance()) {
  8987. + HandleMark hm(THREAD);
  8988. + instanceKlass *ik = (instanceKlass *) k;
  8989. - // Return the method name with old prefixes stripped away.
  8990. - char* method_name_without_prefixes(methodOop method) {
  8991. - Symbol* name = method->name();
  8992. - char* name_str = name->as_utf8();
  8993. + constantPoolHandle other_cp;
  8994. + constantPoolCacheOop cp_cache;
  8995. - // Old prefixing may be defunct, strip prefixes, if any.
  8996. - for (int i = prefix_count-1; i >= 0; i--) {
  8997. - char* prefix = prefixes[i];
  8998. - size_t prefix_len = strlen(prefix);
  8999. - if (strncmp(prefix, name_str, prefix_len) == 0) {
  9000. - name_str += prefix_len;
  9001. - }
  9002. - }
  9003. - return name_str;
  9004. - }
  9005. + other_cp = constantPoolHandle(ik->constants());
  9006. - // Strip any prefixes off the old native method, then try to find a
  9007. - // (possibly prefixed) new native that matches it.
  9008. - methodOop strip_and_search_for_new_native(methodOop method) {
  9009. - ResourceMark rm;
  9010. - char* name_str = method_name_without_prefixes(method);
  9011. - return search_prefix_name_space(0, name_str, strlen(name_str),
  9012. - method->signature());
  9013. - }
  9014. + for (int i=0; i<other_cp->length(); i++) {
  9015. + if (other_cp->tag_at(i).is_klass()) {
  9016. + klassOop klass = other_cp->klass_at(i, THREAD);
  9017. + if (klass->klass_part()->new_version() != NULL) {
  9018. +
  9019. + // (tw) TODO: check why/if this is necessary
  9020. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9021. + }
  9022. + klass = other_cp->klass_at(i, THREAD);
  9023. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9024. + }
  9025. + }
  9026. - public:
  9027. + cp_cache = other_cp->cache();
  9028. - // Construct a native method transfer processor for this class.
  9029. - TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9030. - assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  9031. + if (cp_cache != NULL) {
  9032. + cp_cache->adjust_entries(NULL,
  9033. + NULL,
  9034. + 0);
  9035. + }
  9036. - the_class = _the_class;
  9037. - prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  9038. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9039. + if (RewriteBytecodes) {
  9040. + ik->methods_do(unpatch_bytecode);
  9041. + }
  9042. + }
  9043. + k_oop = k_oop->klass_part()->old_version();
  9044. }
  9045. +}
  9046. - // Attempt to transfer any of the old or deleted methods that are native
  9047. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  9048. - for (int j = 0; j < methods_length; j++) {
  9049. - methodOop old_method = old_methods[j];
  9050. +void VM_RedefineClasses::update_jmethod_ids() {
  9051. + for (int j = 0; j < _matching_methods_length; ++j) {
  9052. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9053. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9054. +
  9055. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9056. + if (old_method->new_version() != NULL && jmid == NULL) {
  9057. + // (tw) Have to create jmethodID in this case
  9058. + jmid = old_method->jmethod_id();
  9059. + }
  9060. +
  9061. + if (jmid != NULL) {
  9062. + // There is a jmethodID, change it to point to the new method
  9063. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9064. + if (old_method->new_version() == NULL) {
  9065. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9066. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9067. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9068. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9069. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9070. + } else {
  9071. + jmethodID mid = new_method_h->jmethod_id();
  9072. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9073. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9074. - if (old_method->is_native() && old_method->has_native_function()) {
  9075. - methodOop new_method = strip_and_search_for_new_native(old_method);
  9076. - if (new_method != NULL) {
  9077. - // Actually set the native function in the new method.
  9078. - // Redefine does not send events (except CFLH), certainly not this
  9079. - // behind the scenes re-registration.
  9080. - new_method->set_native_function(old_method->native_function(),
  9081. - !methodOopDesc::native_bind_event_is_interesting);
  9082. - }
  9083. }
  9084. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9085. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9086. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9087. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9088. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9089. +
  9090. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9091. }
  9092. }
  9093. -};
  9094. -
  9095. -// Don't lose the association between a native method and its JNI function.
  9096. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  9097. - TransferNativeFunctionRegistration transfer(the_class);
  9098. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  9099. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  9100. }
  9101. +
  9102. // Deoptimize all compiled code that depends on this class.
  9103. //
  9104. // If the can_redefine_classes capability is obtained in the onload
  9105. @@ -2974,7 +2683,10 @@ void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9106. // All dependencies have been recorded from startup or this is a second or
  9107. // subsequent use of RedefineClasses
  9108. - if (JvmtiExport::all_dependencies_are_recorded()) {
  9109. +
  9110. + // For now deopt all
  9111. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9112. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9113. Universe::flush_evol_dependents_on(k_h);
  9114. } else {
  9115. CodeCache::mark_all_nmethods_for_deoptimization();
  9116. @@ -2997,10 +2709,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9117. methodOop old_method;
  9118. methodOop new_method;
  9119. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9120. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9121. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  9122. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9123. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9124. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9125. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9126. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9127. _matching_methods_length = 0;
  9128. _deleted_methods_length = 0;
  9129. @@ -3015,36 +2727,36 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9130. }
  9131. // New method at the end
  9132. new_method = (methodOop) _new_methods->obj_at(nj);
  9133. - _added_methods[_added_methods_length++] = new_method;
  9134. + _added_methods[_added_methods_length++] = nj;
  9135. ++nj;
  9136. } else if (nj >= _new_methods->length()) {
  9137. // Old method, at the end, is deleted
  9138. old_method = (methodOop) _old_methods->obj_at(oj);
  9139. - _deleted_methods[_deleted_methods_length++] = old_method;
  9140. + _deleted_methods[_deleted_methods_length++] = oj;
  9141. ++oj;
  9142. } else {
  9143. old_method = (methodOop) _old_methods->obj_at(oj);
  9144. new_method = (methodOop) _new_methods->obj_at(nj);
  9145. if (old_method->name() == new_method->name()) {
  9146. if (old_method->signature() == new_method->signature()) {
  9147. - _matching_old_methods[_matching_methods_length ] = old_method;
  9148. - _matching_new_methods[_matching_methods_length++] = new_method;
  9149. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9150. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9151. ++nj;
  9152. ++oj;
  9153. } else {
  9154. // added overloaded have already been moved to the end,
  9155. // so this is a deleted overloaded method
  9156. - _deleted_methods[_deleted_methods_length++] = old_method;
  9157. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9158. ++oj;
  9159. }
  9160. } else { // names don't match
  9161. if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9162. // new method
  9163. - _added_methods[_added_methods_length++] = new_method;
  9164. + _added_methods[_added_methods_length++] = nj;//new_method;
  9165. ++nj;
  9166. } else {
  9167. // deleted method
  9168. - _deleted_methods[_deleted_methods_length++] = old_method;
  9169. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9170. ++oj;
  9171. }
  9172. }
  9173. @@ -3052,6 +2764,8 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9174. }
  9175. assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9176. assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9177. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9178. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9179. }
  9180. @@ -3059,287 +2773,184 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9181. // Install the redefinition of a class:
  9182. // - house keeping (flushing breakpoints and caches, deoptimizing
  9183. // dependent compiled code)
  9184. -// - replacing parts in the_class with parts from scratch_class
  9185. -// - adding a weak reference to track the obsolete but interesting
  9186. -// parts of the_class
  9187. // - adjusting constant pool caches and vtables in other classes
  9188. -// that refer to methods in the_class. These adjustments use the
  9189. -// SystemDictionary::classes_do() facility which only allows
  9190. -// a helper method to be specified. The interesting parameters
  9191. -// that we would like to pass to the helper method are saved in
  9192. -// static global fields in the VM operation.
  9193. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  9194. - instanceKlassHandle scratch_class, TRAPS) {
  9195. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9196. +
  9197. + ResourceMark rm(THREAD);
  9198. - RC_TIMER_START(_timer_rsc_phase1);
  9199. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9200. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9201. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  9202. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  9203. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  9204. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9205. #ifndef JVMTI_KERNEL
  9206. // Remove all breakpoints in methods of this class
  9207. JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9208. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  9209. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9210. #endif // !JVMTI_KERNEL
  9211. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  9212. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9213. // We are redefining java.lang.reflect.Method. Method.invoke() is
  9214. // cached and users of the cache care about each active version of
  9215. // the method so we have to track this previous version.
  9216. // Do this before methods get switched
  9217. Universe::reflect_invoke_cache()->add_previous_version(
  9218. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9219. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9220. }
  9221. - // Deoptimize all compiled code that depends on this class
  9222. - flush_dependent_code(the_class, THREAD);
  9223. -
  9224. - _old_methods = the_class->methods();
  9225. - _new_methods = scratch_class->methods();
  9226. - _the_class_oop = the_class_oop;
  9227. + _old_methods = the_old_class->methods();
  9228. + _new_methods = the_new_class->methods();
  9229. + _the_class_oop = the_old_class();
  9230. compute_added_deleted_matching_methods();
  9231. - update_jmethod_ids();
  9232. -
  9233. - // Attach new constant pool to the original klass. The original
  9234. - // klass still refers to the old constant pool (for now).
  9235. - scratch_class->constants()->set_pool_holder(the_class());
  9236. -
  9237. -#if 0
  9238. - // In theory, with constant pool merging in place we should be able
  9239. - // to save space by using the new, merged constant pool in place of
  9240. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  9241. - // the klass version we are replacing now and any constant pool(s) in
  9242. - // previous versions of klass. Nice theory, doesn't work in practice.
  9243. - // When this code is enabled, even simple programs throw NullPointer
  9244. - // exceptions. I'm guessing that this is caused by some constant pool
  9245. - // cache difference between the new, merged constant pool and the
  9246. - // constant pool that was just being used by the klass. I'm keeping
  9247. - // this code around to archive the idea, but the code has to remain
  9248. - // disabled for now.
  9249. -
  9250. - // Attach each old method to the new constant pool. This can be
  9251. - // done here since we are past the bytecode verification and
  9252. - // constant pool optimization phases.
  9253. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  9254. - methodOop method = (methodOop)_old_methods->obj_at(i);
  9255. - method->set_constants(scratch_class->constants());
  9256. - }
  9257. -
  9258. - {
  9259. - // walk all previous versions of the klass
  9260. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  9261. - PreviousVersionWalker pvw(ik);
  9262. - instanceKlassHandle ikh;
  9263. - do {
  9264. - ikh = pvw.next_previous_version();
  9265. - if (!ikh.is_null()) {
  9266. - ik = ikh();
  9267. -
  9268. - // attach previous version of klass to the new constant pool
  9269. - ik->set_constants(scratch_class->constants());
  9270. -
  9271. - // Attach each method in the previous version of klass to the
  9272. - // new constant pool
  9273. - objArrayOop prev_methods = ik->methods();
  9274. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  9275. - methodOop method = (methodOop)prev_methods->obj_at(i);
  9276. - method->set_constants(scratch_class->constants());
  9277. - }
  9278. - }
  9279. - } while (!ikh.is_null());
  9280. - }
  9281. -#endif
  9282. -
  9283. - // Replace methods and constantpool
  9284. - the_class->set_methods(_new_methods);
  9285. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  9286. - // and to be able to undo operation easily.
  9287. -
  9288. - constantPoolOop old_constants = the_class->constants();
  9289. - the_class->set_constants(scratch_class->constants());
  9290. - scratch_class->set_constants(old_constants); // See the previous comment.
  9291. -#if 0
  9292. - // We are swapping the guts of "the new class" with the guts of "the
  9293. - // class". Since the old constant pool has just been attached to "the
  9294. - // new class", it seems logical to set the pool holder in the old
  9295. - // constant pool also. However, doing this will change the observable
  9296. - // class hierarchy for any old methods that are still executing. A
  9297. - // method can query the identity of its "holder" and this query uses
  9298. - // the method's constant pool link to find the holder. The change in
  9299. - // holding class from "the class" to "the new class" can confuse
  9300. - // things.
  9301. - //
  9302. - // Setting the old constant pool's holder will also cause
  9303. - // verification done during vtable initialization below to fail.
  9304. - // During vtable initialization, the vtable's class is verified to be
  9305. - // a subtype of the method's holder. The vtable's class is "the
  9306. - // class" and the method's holder is gotten from the constant pool
  9307. - // link in the method itself. For "the class"'s directly implemented
  9308. - // methods, the method holder is "the class" itself (as gotten from
  9309. - // the new constant pool). The check works fine in this case. The
  9310. - // check also works fine for methods inherited from super classes.
  9311. - //
  9312. - // Miranda methods are a little more complicated. A miranda method is
  9313. - // provided by an interface when the class implementing the interface
  9314. - // does not provide its own method. These interfaces are implemented
  9315. - // internally as an instanceKlass. These special instanceKlasses
  9316. - // share the constant pool of the class that "implements" the
  9317. - // interface. By sharing the constant pool, the method holder of a
  9318. - // miranda method is the class that "implements" the interface. In a
  9319. - // non-redefine situation, the subtype check works fine. However, if
  9320. - // the old constant pool's pool holder is modified, then the check
  9321. - // fails because there is no class hierarchy relationship between the
  9322. - // vtable's class and "the new class".
  9323. -
  9324. - old_constants->set_pool_holder(scratch_class());
  9325. -#endif
  9326. // track which methods are EMCP for add_previous_version() call below
  9327. - BitMap emcp_methods(_old_methods->length());
  9328. +
  9329. + // (tw) TODO: Check if we need the concept of EMCP?
  9330. + BitMap emcp_methods(_old_methods->length());
  9331. int emcp_method_count = 0;
  9332. emcp_methods.clear(); // clears 0..(length() - 1)
  9333. +
  9334. + // We need to mark methods as old!!
  9335. check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9336. - transfer_old_native_function_registrations(the_class);
  9337. -
  9338. - // The class file bytes from before any retransformable agents mucked
  9339. - // with them was cached on the scratch class, move to the_class.
  9340. - // Note: we still want to do this if nothing needed caching since it
  9341. - // should get cleared in the_class too.
  9342. - if (the_class->get_cached_class_file_bytes() == 0) {
  9343. - // the_class doesn't have a cache yet so copy it
  9344. - the_class->set_cached_class_file(
  9345. - scratch_class->get_cached_class_file_bytes(),
  9346. - scratch_class->get_cached_class_file_len());
  9347. - }
  9348. -#ifndef PRODUCT
  9349. - else {
  9350. - assert(the_class->get_cached_class_file_bytes() ==
  9351. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  9352. - assert(the_class->get_cached_class_file_len() ==
  9353. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  9354. - }
  9355. -#endif
  9356. + update_jmethod_ids();
  9357. - // Replace inner_classes
  9358. - typeArrayOop old_inner_classes = the_class->inner_classes();
  9359. - the_class->set_inner_classes(scratch_class->inner_classes());
  9360. - scratch_class->set_inner_classes(old_inner_classes);
  9361. + // keep track of previous versions of this class
  9362. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9363. + emcp_method_count);
  9364. - // Initialize the vtable and interface table after
  9365. - // methods have been rewritten
  9366. - {
  9367. - ResourceMark rm(THREAD);
  9368. - // no exception should happen here since we explicitly
  9369. - // do not check loader constraints.
  9370. - // compare_and_normalize_class_versions has already checked:
  9371. - // - classloaders unchanged, signatures unchanged
  9372. - // - all instanceKlasses for redefined classes reused & contents updated
  9373. - the_class->vtable()->initialize_vtable(false, THREAD);
  9374. - the_class->itable()->initialize_itable(false, THREAD);
  9375. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  9376. - }
  9377. + // TODO:
  9378. + transfer_old_native_function_registrations(the_old_class);
  9379. - // Leave arrays of jmethodIDs and itable index cache unchanged
  9380. - // Copy the "source file name" attribute from new class version
  9381. - the_class->set_source_file_name(scratch_class->source_file_name());
  9382. +#ifdef ASSERT
  9383. - // Copy the "source debug extension" attribute from new class version
  9384. - the_class->set_source_debug_extension(
  9385. - scratch_class->source_debug_extension());
  9386. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9387. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9388. - // Use of javac -g could be different in the old and the new
  9389. - if (scratch_class->access_flags().has_localvariable_table() !=
  9390. - the_class->access_flags().has_localvariable_table()) {
  9391. + //JNIHandles::verify();
  9392. - AccessFlags flags = the_class->access_flags();
  9393. - if (scratch_class->access_flags().has_localvariable_table()) {
  9394. - flags.set_has_localvariable_table();
  9395. - } else {
  9396. - flags.clear_has_localvariable_table();
  9397. - }
  9398. - the_class->set_access_flags(flags);
  9399. - }
  9400. -
  9401. - // Replace class annotation fields values
  9402. - typeArrayOop old_class_annotations = the_class->class_annotations();
  9403. - the_class->set_class_annotations(scratch_class->class_annotations());
  9404. - scratch_class->set_class_annotations(old_class_annotations);
  9405. -
  9406. - // Replace fields annotation fields values
  9407. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  9408. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  9409. - scratch_class->set_fields_annotations(old_fields_annotations);
  9410. -
  9411. - // Replace methods annotation fields values
  9412. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  9413. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  9414. - scratch_class->set_methods_annotations(old_methods_annotations);
  9415. -
  9416. - // Replace methods parameter annotation fields values
  9417. - objArrayOop old_methods_parameter_annotations =
  9418. - the_class->methods_parameter_annotations();
  9419. - the_class->set_methods_parameter_annotations(
  9420. - scratch_class->methods_parameter_annotations());
  9421. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  9422. -
  9423. - // Replace methods default annotation fields values
  9424. - objArrayOop old_methods_default_annotations =
  9425. - the_class->methods_default_annotations();
  9426. - the_class->set_methods_default_annotations(
  9427. - scratch_class->methods_default_annotations());
  9428. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  9429. -
  9430. - // Replace minor version number of class file
  9431. - u2 old_minor_version = the_class->minor_version();
  9432. - the_class->set_minor_version(scratch_class->minor_version());
  9433. - scratch_class->set_minor_version(old_minor_version);
  9434. -
  9435. - // Replace major version number of class file
  9436. - u2 old_major_version = the_class->major_version();
  9437. - the_class->set_major_version(scratch_class->major_version());
  9438. - scratch_class->set_major_version(old_major_version);
  9439. -
  9440. - // Replace CP indexes for class and name+type of enclosing method
  9441. - u2 old_class_idx = the_class->enclosing_method_class_index();
  9442. - u2 old_method_idx = the_class->enclosing_method_method_index();
  9443. - the_class->set_enclosing_method_indices(
  9444. - scratch_class->enclosing_method_class_index(),
  9445. - scratch_class->enclosing_method_method_index());
  9446. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  9447. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9448. - // keep track of previous versions of this class
  9449. - the_class->add_previous_version(scratch_class, &emcp_methods,
  9450. - emcp_method_count);
  9451. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9452. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9453. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9454. - RC_TIMER_STOP(_timer_rsc_phase1);
  9455. - RC_TIMER_START(_timer_rsc_phase2);
  9456. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9457. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9458. + }
  9459. - // Adjust constantpool caches and vtables for all classes
  9460. - // that reference methods of the evolved class.
  9461. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  9462. + _old_methods->verify();
  9463. + _new_methods->verify();
  9464. - if (the_class->oop_map_cache() != NULL) {
  9465. - // Flush references to any obsolete methods from the oop map cache
  9466. - // so that obsolete methods are not pinned.
  9467. - the_class->oop_map_cache()->flush_obsolete_entries();
  9468. - }
  9469. + the_new_class->vtable()->verify(tty);
  9470. + the_old_class->vtable()->verify(tty);
  9471. +
  9472. +#endif
  9473. // increment the classRedefinedCount field in the_class and in any
  9474. // direct and indirect subclasses of the_class
  9475. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  9476. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9477. +
  9478. +}
  9479. +
  9480. +
  9481. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9482. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9483. + *emcp_method_count_p = 0;
  9484. + int obsolete_count = 0;
  9485. + int old_index = 0;
  9486. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9487. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9488. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9489. + methodOop old_array_method;
  9490. +
  9491. + // Maintain an old_index into the _old_methods array by skipping
  9492. + // deleted methods
  9493. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9494. + != old_method) {
  9495. + ++old_index;
  9496. + }
  9497. +
  9498. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9499. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9500. + // the same with the exception of constant pool indices which may
  9501. + // differ. However, the constants referred to by those indices
  9502. + // must be the same.
  9503. + //
  9504. + // We use methods_EMCP() for comparison since constant pool
  9505. + // merging can remove duplicate constant pool entries that were
  9506. + // present in the old method and removed from the rewritten new
  9507. + // method. A faster binary comparison function would consider the
  9508. + // old and new methods to be different when they are actually
  9509. + // EMCP.
  9510. +
  9511. + // track which methods are EMCP for add_previous_version() call
  9512. + emcp_methods->set_bit(old_index);
  9513. + (*emcp_method_count_p)++;
  9514. +
  9515. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9516. + // different jmethodID than the current method. An EMCP method
  9517. + // has the same jmethodID as the current method. Having the
  9518. + // same jmethodID for all EMCP versions of a method allows for
  9519. + // a consistent view of the EMCP methods regardless of which
  9520. + // EMCP method you happen to have in hand. For example, a
  9521. + // breakpoint set in one EMCP method will work for all EMCP
  9522. + // versions of the method including the current one.
  9523. +
  9524. + old_method->set_new_version(new_method);
  9525. + new_method->set_old_version(old_method);
  9526. +
  9527. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9528. +
  9529. + // Transfer breakpoints
  9530. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9531. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9532. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9533. + RC_TRACE(0x00000002, ("%d / %d",
  9534. + bp->match(old_method), bp->match(new_method)));
  9535. + if (bp->match(old_method)) {
  9536. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9537. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9538. + new_method->set_breakpoint(bp->bci());
  9539. + }
  9540. + }
  9541. +
  9542. +
  9543. - // RC_TRACE macro has an embedded ResourceMark
  9544. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  9545. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  9546. - the_class->external_name(),
  9547. - java_lang_Class::classRedefinedCount(the_class_mirror),
  9548. - os::available_memory() >> 10));
  9549. + } else {
  9550. + // mark obsolete methods as such
  9551. + old_method->set_is_obsolete();
  9552. + obsolete_count++;
  9553. +
  9554. + // With tracing we try not to "yack" too much. The position of
  9555. + // this trace assumes there are fewer obsolete methods than
  9556. + // EMCP methods.
  9557. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9558. + old_method->name()->as_C_string(),
  9559. + old_method->signature()->as_C_string()));
  9560. + }
  9561. + old_method->set_is_old();
  9562. + }
  9563. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9564. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9565. - RC_TIMER_STOP(_timer_rsc_phase2);
  9566. -} // end redefine_single_class()
  9567. + //assert(old_method->vtable_index() < 0,
  9568. + // "cannot delete methods with vtable entries");;
  9569. + // Mark all deleted methods as old and obsolete
  9570. + old_method->set_is_old();
  9571. + old_method->set_is_obsolete();
  9572. + ++obsolete_count;
  9573. + // With tracing we try not to "yack" too much. The position of
  9574. + // this trace assumes there are fewer obsolete methods than
  9575. + // EMCP methods.
  9576. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9577. + old_method->name()->as_C_string(),
  9578. + old_method->signature()->as_C_string()));
  9579. + }
  9580. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9581. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9582. +}
  9583. // Increment the classRedefinedCount field in the specific instanceKlass
  9584. // and in all direct and indirect subclasses.
  9585. @@ -3348,94 +2959,324 @@ void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9586. klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9587. int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9588. java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9589. -
  9590. - if (class_oop != _the_class_oop) {
  9591. - // _the_class_oop count is printed at end of redefine_single_class()
  9592. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  9593. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  9594. - }
  9595. -
  9596. - for (Klass *subk = ik->subklass(); subk != NULL;
  9597. - subk = subk->next_sibling()) {
  9598. - if (subk->oop_is_instance()) {
  9599. - // Only update instanceKlasses
  9600. - instanceKlass *subik = (instanceKlass*)subk;
  9601. - // recursively do subclasses of the current subclass
  9602. - increment_class_counter(subik, THREAD);
  9603. - }
  9604. - }
  9605. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9606. }
  9607. #ifndef PRODUCT
  9608. -void VM_RedefineClasses::check_class(klassOop k_oop,
  9609. - oop initiating_loader, TRAPS) {
  9610. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9611. Klass *k = k_oop->klass_part();
  9612. if (k->oop_is_instance()) {
  9613. HandleMark hm(THREAD);
  9614. instanceKlass *ik = (instanceKlass *) k;
  9615. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9616. if (ik->vtable_length() > 0) {
  9617. ResourceMark rm(THREAD);
  9618. if (!ik->vtable()->check_no_old_entries()) {
  9619. - tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  9620. - ik->vtable()->dump_vtable();
  9621. - dump_methods();
  9622. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9623. + k_oop->size()));
  9624. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9625. + ik->signature_name()));
  9626. assert(false, "OLD method found");
  9627. }
  9628. +
  9629. + ik->vtable()->verify(tty, true);
  9630. }
  9631. }
  9632. }
  9633. -void VM_RedefineClasses::dump_methods() {
  9634. - int j;
  9635. - tty->print_cr("_old_methods --");
  9636. - for (j = 0; j < _old_methods->length(); ++j) {
  9637. - methodOop m = (methodOop) _old_methods->obj_at(j);
  9638. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9639. - m->access_flags().print_on(tty);
  9640. - tty->print(" -- ");
  9641. - m->print_name(tty);
  9642. - tty->cr();
  9643. - }
  9644. - tty->print_cr("_new_methods --");
  9645. - for (j = 0; j < _new_methods->length(); ++j) {
  9646. - methodOop m = (methodOop) _new_methods->obj_at(j);
  9647. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9648. - m->access_flags().print_on(tty);
  9649. - tty->print(" -- ");
  9650. - m->print_name(tty);
  9651. - tty->cr();
  9652. +#endif
  9653. +
  9654. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9655. +{
  9656. + assert(original_klasses != NULL && result != NULL, "");
  9657. + this->_original_klasses = original_klasses;
  9658. + this->_result = result;
  9659. + SystemDictionary::classes_do(this);
  9660. +}
  9661. +
  9662. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9663. +{
  9664. + klassOop klass = (klassOop)obj;
  9665. + assert(!_result->contains(klass), "must not occur more than once!");
  9666. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9667. +
  9668. + for(int i=0; i<_original_klasses->length(); i++) {
  9669. + instanceKlassHandle cur = _original_klasses->at(i);
  9670. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9671. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9672. + _result->append(klass);
  9673. + break;
  9674. + }
  9675. + }
  9676. +}
  9677. +
  9678. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9679. +{
  9680. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9681. +
  9682. + for (int i=0; i<class_count; i++) {
  9683. +
  9684. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9685. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9686. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9687. + Handle the_class_loader(THREAD, the_class->class_loader());
  9688. + Handle protection_domain(THREAD, the_class->protection_domain());
  9689. +
  9690. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9691. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9692. + ClassFileParser cfp(&st);
  9693. +
  9694. + GrowableArray<Symbol*> symbolArr;
  9695. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9696. + the_class->name()->as_C_string()));
  9697. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9698. +
  9699. + for (int j=0; j<symbolArr.length(); j++) {
  9700. + Symbol* sym = symbolArr.at(j);
  9701. +
  9702. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9703. +
  9704. + for (int k=0; k<arr->length(); k++) {
  9705. + klassOop curOop = arr->at(k)();
  9706. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9707. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9708. + RC_TRACE(0x00000002, ("Found class to link"));
  9709. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9710. + break;
  9711. }
  9712. - tty->print_cr("_matching_(old/new)_methods --");
  9713. - for (j = 0; j < _matching_methods_length; ++j) {
  9714. - methodOop m = _matching_old_methods[j];
  9715. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9716. - m->access_flags().print_on(tty);
  9717. - tty->print(" -- ");
  9718. - m->print_name(tty);
  9719. - tty->cr();
  9720. - m = _matching_new_methods[j];
  9721. - tty->print(" (%5d) ", m->vtable_index());
  9722. - m->access_flags().print_on(tty);
  9723. - tty->cr();
  9724. + }
  9725. + }
  9726. + }
  9727. +
  9728. +
  9729. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9730. +
  9731. + for (int i=0; i<affected->length(); i++) {
  9732. +
  9733. + instanceKlassHandle klass = affected->at(i);
  9734. +
  9735. + klassOop superKlass = klass->super();
  9736. + if (affected->contains(superKlass)) {
  9737. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9738. + }
  9739. +
  9740. + objArrayOop superInterfaces = klass->local_interfaces();
  9741. + for (int j=0; j<superInterfaces->length(); j++) {
  9742. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9743. + if (arr->contains(interfaceKlass)) {
  9744. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9745. + }
  9746. + }
  9747. + }
  9748. +
  9749. + if (RC_TRACE_ENABLED(0x00000002)) {
  9750. + RC_TRACE(0x00000002, ("Identified links: "));
  9751. + for (int i=0; i<links->length(); i++) {
  9752. + RC_TRACE(0x00000002, ("%s to %s",
  9753. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9754. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9755. + }
  9756. + }
  9757. +
  9758. + for (int i=0; i<arr->length(); i++) {
  9759. +
  9760. + int j;
  9761. + for (j=i; j<arr->length(); j++) {
  9762. +
  9763. + int k;
  9764. + for (k=0; k<links->length(); k++) {
  9765. +
  9766. + klassOop k1 = links->adr_at(k)->right();
  9767. + klassOop k2 = arr->at(j)();
  9768. + if (k1 == k2) {
  9769. + break;
  9770. }
  9771. - tty->print_cr("_deleted_methods --");
  9772. - for (j = 0; j < _deleted_methods_length; ++j) {
  9773. - methodOop m = _deleted_methods[j];
  9774. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9775. - m->access_flags().print_on(tty);
  9776. - tty->print(" -- ");
  9777. - m->print_name(tty);
  9778. - tty->cr();
  9779. + }
  9780. +
  9781. + if (k == links->length()) {
  9782. + break;
  9783. + }
  9784. + }
  9785. +
  9786. + if (j == arr->length()) {
  9787. + // circle detected
  9788. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9789. + }
  9790. +
  9791. + for (int k=0; k<links->length(); k++) {
  9792. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9793. + links->at_put(k, links->at(links->length() - 1));
  9794. + links->remove_at(links->length() - 1);
  9795. + k--;
  9796. + }
  9797. + }
  9798. +
  9799. + instanceKlassHandle tmp = arr->at(j);
  9800. + arr->at_put(j, arr->at(i));
  9801. + arr->at_put(i, tmp);
  9802. + }
  9803. +
  9804. + return JVMTI_ERROR_NONE;
  9805. +}
  9806. +
  9807. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9808. +
  9809. + if (_updated_oops != NULL) {
  9810. + for (int i=0; i<_updated_oops->length(); i++) {
  9811. + closure->do_oop(_updated_oops->adr_at(i));
  9812. + }
  9813. + }
  9814. +}
  9815. +
  9816. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9817. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9818. + to->set_is_field_access_watched(from->is_field_access_watched());
  9819. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9820. + RC_TRACE(0x00000002, ("Transfered watch for field %s",
  9821. + from->name()->as_C_string()));
  9822. + }
  9823. + update_klass_field_access_flag(to);
  9824. +}
  9825. +
  9826. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9827. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9828. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9829. + fi->set_access_flags(fd->access_flags().as_short());
  9830. +}
  9831. +
  9832. +
  9833. +// This internal class transfers the native function registration from old methods
  9834. +// to new methods. It is designed to handle both the simple case of unchanged
  9835. +// native methods and the complex cases of native method prefixes being added and/or
  9836. +// removed.
  9837. +// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  9838. +//
  9839. +// This class is used after the new methods have been installed in "the_class".
  9840. +//
  9841. +// So, for example, the following must be handled. Where 'm' is a method and
  9842. +// a number followed by an underscore is a prefix.
  9843. +//
  9844. +// Old Name New Name
  9845. +// Simple transfer to new method m -> m
  9846. +// Add prefix m -> 1_m
  9847. +// Remove prefix 1_m -> m
  9848. +// Simultaneous add of prefixes m -> 3_2_1_m
  9849. +// Simultaneous removal of prefixes 3_2_1_m -> m
  9850. +// Simultaneous add and remove 1_m -> 2_m
  9851. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9852. +//
  9853. +class TransferNativeFunctionRegistration {
  9854. +private:
  9855. + instanceKlassHandle the_class;
  9856. + int prefix_count;
  9857. + char** prefixes;
  9858. +
  9859. + // Recursively search the binary tree of possibly prefixed method names.
  9860. + // Iteration could be used if all agents were well behaved. Full tree walk is
  9861. + // more resilent to agents not cleaning up intermediate methods.
  9862. + // Branch at each depth in the binary tree is:
  9863. + // (1) without the prefix.
  9864. + // (2) with the prefix.
  9865. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9866. + methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9867. + Symbol* signature) {
  9868. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9869. + if (name_symbol != NULL) {
  9870. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  9871. + if (method != NULL) {
  9872. + // Even if prefixed, intermediate methods must exist.
  9873. + if (method->is_native()) {
  9874. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9875. + return method;
  9876. + }
  9877. + if (depth < prefix_count) {
  9878. + // Try applying further prefixes (other than this one).
  9879. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9880. + if (method != NULL) {
  9881. + return method; // found
  9882. + }
  9883. +
  9884. + // Try adding this prefix to the method name and see if it matches
  9885. + // another method name.
  9886. + char* prefix = prefixes[depth];
  9887. + size_t prefix_len = strlen(prefix);
  9888. + size_t trial_len = name_len + prefix_len;
  9889. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9890. + strcpy(trial_name_str, prefix);
  9891. + strcat(trial_name_str, name_str);
  9892. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9893. + signature);
  9894. + if (method != NULL) {
  9895. + // If found along this branch, it was prefixed, mark as such
  9896. + method->set_is_prefixed_native();
  9897. + return method; // found
  9898. + }
  9899. + }
  9900. }
  9901. - tty->print_cr("_added_methods --");
  9902. - for (j = 0; j < _added_methods_length; ++j) {
  9903. - methodOop m = _added_methods[j];
  9904. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9905. - m->access_flags().print_on(tty);
  9906. - tty->print(" -- ");
  9907. - m->print_name(tty);
  9908. - tty->cr();
  9909. + }
  9910. + return NULL; // This whole branch bore nothing
  9911. + }
  9912. +
  9913. + // Return the method name with old prefixes stripped away.
  9914. + char* method_name_without_prefixes(methodOop method) {
  9915. + Symbol* name = method->name();
  9916. + char* name_str = name->as_utf8();
  9917. +
  9918. + // Old prefixing may be defunct, strip prefixes, if any.
  9919. + for (int i = prefix_count-1; i >= 0; i--) {
  9920. + char* prefix = prefixes[i];
  9921. + size_t prefix_len = strlen(prefix);
  9922. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  9923. + name_str += prefix_len;
  9924. + }
  9925. + }
  9926. + return name_str;
  9927. + }
  9928. +
  9929. + // Strip any prefixes off the old native method, then try to find a
  9930. + // (possibly prefixed) new native that matches it.
  9931. + methodOop strip_and_search_for_new_native(methodOop method) {
  9932. + ResourceMark rm;
  9933. + char* name_str = method_name_without_prefixes(method);
  9934. + return search_prefix_name_space(0, name_str, strlen(name_str),
  9935. + method->signature());
  9936. + }
  9937. +
  9938. +public:
  9939. +
  9940. + // Construct a native method transfer processor for this class.
  9941. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9942. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  9943. +
  9944. + the_class = _the_class;
  9945. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  9946. + }
  9947. +
  9948. + // Attempt to transfer any of the old or deleted methods that are native
  9949. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  9950. + for (int j = 0; j < methods_length; j++) {
  9951. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  9952. +
  9953. + if (old_method->is_native() && old_method->has_native_function()) {
  9954. + methodOop new_method = strip_and_search_for_new_native(old_method);
  9955. + if (new_method != NULL) {
  9956. + // Actually set the native function in the new method.
  9957. + // Redefine does not send events (except CFLH), certainly not this
  9958. + // behind the scenes re-registration.
  9959. + new_method->set_native_function(old_method->native_function(),
  9960. + !methodOopDesc::native_bind_event_is_interesting);
  9961. +
  9962. + RC_TRACE(0x00008000, ("Transfering native function for method %s", old_method->name()->as_C_string()));
  9963. }
  9964. + }
  9965. + }
  9966. + }
  9967. +};
  9968. +
  9969. +// Don't lose the association between a native method and its JNI function.
  9970. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  9971. + TransferNativeFunctionRegistration transfer(old_klass);
  9972. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  9973. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  9974. }
  9975. -#endif
  9976. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  9977. index c5f4bdd..88fdbac 100644
  9978. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  9979. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  9980. @@ -1,26 +1,29 @@
  9981. /*
  9982. - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  9983. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9984. - *
  9985. - * This code is free software; you can redistribute it and/or modify it
  9986. - * under the terms of the GNU General Public License version 2 only, as
  9987. - * published by the Free Software Foundation.
  9988. - *
  9989. - * This code is distributed in the hope that it will be useful, but WITHOUT
  9990. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9991. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9992. - * version 2 for more details (a copy is included in the LICENSE file that
  9993. - * accompanied this code).
  9994. - *
  9995. - * You should have received a copy of the GNU General Public License version
  9996. - * 2 along with this work; if not, write to the Free Software Foundation,
  9997. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9998. - *
  9999. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10000. - * or visit www.oracle.com if you need additional information or have any
  10001. - * questions.
  10002. - *
  10003. - */
  10004. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10005. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10006. +*
  10007. +* This code is free software; you can redistribute it and/or modify it
  10008. +* under the terms of the GNU General Public License version 2 only, as
  10009. +* published by the Free Software Foundation.
  10010. +*
  10011. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10012. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10013. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10014. +* version 2 for more details (a copy is included in the LICENSE file that
  10015. +* accompanied this code).
  10016. +*
  10017. +* You should have received a copy of the GNU General Public License version
  10018. +* 2 along with this work; if not, write to the Free Software Foundation,
  10019. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10020. +*
  10021. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10022. +* or visit www.oracle.com if you need additional information or have any
  10023. +* questions.
  10024. +*
  10025. +*/
  10026. +
  10027. +// New version that allows arbitrary changes to already loaded classes.
  10028. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10029. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10030. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10031. @@ -32,331 +35,28 @@
  10032. #include "oops/objArrayOop.hpp"
  10033. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10034. #include "runtime/vm_operations.hpp"
  10035. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10036. -// Introduction:
  10037. -//
  10038. -// The RedefineClasses() API is used to change the definition of one or
  10039. -// more classes. While the API supports redefining more than one class
  10040. -// in a single call, in general, the API is discussed in the context of
  10041. -// changing the definition of a single current class to a single new
  10042. -// class. For clarity, the current class is will always be called
  10043. -// "the_class" and the new class will always be called "scratch_class".
  10044. -//
  10045. -// The name "the_class" is used because there is only one structure
  10046. -// that represents a specific class; redefinition does not replace the
  10047. -// structure, but instead replaces parts of the structure. The name
  10048. -// "scratch_class" is used because the structure that represents the
  10049. -// new definition of a specific class is simply used to carry around
  10050. -// the parts of the new definition until they are used to replace the
  10051. -// appropriate parts in the_class. Once redefinition of a class is
  10052. -// complete, scratch_class is thrown away.
  10053. -//
  10054. -//
  10055. -// Implementation Overview:
  10056. -//
  10057. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10058. -// does the real work. The work is split in varying degrees between
  10059. -// doit_prologue(), doit() and doit_epilogue().
  10060. -//
  10061. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10062. -// safepoint. It does parameter verification and loads scratch_class
  10063. -// which involves:
  10064. -// - parsing the incoming class definition using the_class' class
  10065. -// loader and security context
  10066. -// - linking scratch_class
  10067. -// - merging constant pools and rewriting bytecodes as needed
  10068. -// for the merged constant pool
  10069. -// - verifying the bytecodes in scratch_class
  10070. -// - setting up the constant pool cache and rewriting bytecodes
  10071. -// as needed to use the cache
  10072. -// - finally, scratch_class is compared to the_class to verify
  10073. -// that it is a valid replacement class
  10074. -// - if everything is good, then scratch_class is saved in an
  10075. -// instance field in the VM operation for the doit() call
  10076. -//
  10077. -// Note: A JavaThread must do the above work.
  10078. -//
  10079. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10080. -// the new class definition(s) which involves:
  10081. -// - retrieving the scratch_class from the instance field in the
  10082. -// VM operation
  10083. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10084. -// dependent compiled code)
  10085. -// - replacing parts in the_class with parts from scratch_class
  10086. -// - adding weak reference(s) to track the obsolete but interesting
  10087. -// parts of the_class
  10088. -// - adjusting constant pool caches and vtables in other classes
  10089. -// that refer to methods in the_class. These adjustments use the
  10090. -// SystemDictionary::classes_do() facility which only allows
  10091. -// a helper method to be specified. The interesting parameters
  10092. -// that we would like to pass to the helper method are saved in
  10093. -// static global fields in the VM operation.
  10094. -// - telling the SystemDictionary to notice our changes
  10095. -//
  10096. -// Note: the above work must be done by the VMThread to be safe.
  10097. -//
  10098. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10099. -// is finished and the safepoint is done. It simply cleans up
  10100. -// memory allocated in doit_prologue() and used in doit().
  10101. -//
  10102. -//
  10103. -// Constant Pool Details:
  10104. -//
  10105. -// When the_class is redefined, we cannot just replace the constant
  10106. -// pool in the_class with the constant pool from scratch_class because
  10107. -// that could confuse obsolete methods that may still be running.
  10108. -// Instead, the constant pool from the_class, old_cp, is merged with
  10109. -// the constant pool from scratch_class, scratch_cp. The resulting
  10110. -// constant pool, merge_cp, replaces old_cp in the_class.
  10111. -//
  10112. -// The key part of any merging algorithm is the entry comparison
  10113. -// function so we have to know the types of entries in a constant pool
  10114. -// in order to merge two of them together. Constant pools can contain
  10115. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10116. -// is not presently used so we only have to worry about the other 11
  10117. -// entry types. For the purposes of constant pool merging, it is
  10118. -// helpful to know that the 11 entry types fall into 3 different
  10119. -// subtypes: "direct", "indirect" and "double-indirect".
  10120. -//
  10121. -// Direct CP entries contain data and do not contain references to
  10122. -// other CP entries. The following are direct CP entries:
  10123. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10124. -//
  10125. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10126. -// and no other data. The following are indirect CP entries:
  10127. -// JVM_CONSTANT_{Class,NameAndType,String}
  10128. -//
  10129. -// Double-indirect CP entries contain two references to indirect CP
  10130. -// entries and no other data. The following are double-indirect CP
  10131. -// entries:
  10132. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10133. -//
  10134. -// When comparing entries between two constant pools, the entry types
  10135. -// are compared first and if they match, then further comparisons are
  10136. -// made depending on the entry subtype. Comparing direct CP entries is
  10137. -// simply a matter of comparing the data associated with each entry.
  10138. -// Comparing both indirect and double-indirect CP entries requires
  10139. -// recursion.
  10140. -//
  10141. -// Fortunately, the recursive combinations are limited because indirect
  10142. -// CP entries can only refer to direct CP entries and double-indirect
  10143. -// CP entries can only refer to indirect CP entries. The following is
  10144. -// an example illustration of the deepest set of indirections needed to
  10145. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10146. -//
  10147. -// JVM_CONSTANT_Fieldref {
  10148. -// class_index => JVM_CONSTANT_Class {
  10149. -// name_index => JVM_CONSTANT_Utf8 {
  10150. -// <data-1>
  10151. -// }
  10152. -// }
  10153. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10154. -// name_index => JVM_CONSTANT_Utf8 {
  10155. -// <data-2>
  10156. -// }
  10157. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10158. -// <data-3>
  10159. -// }
  10160. -// }
  10161. -// }
  10162. -//
  10163. -// The above illustration is not a data structure definition for any
  10164. -// computer language. The curly braces ('{' and '}') are meant to
  10165. -// delimit the context of the "fields" in the CP entry types shown.
  10166. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10167. -// "=>", e.g., the class_index is used to indirectly reference a
  10168. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10169. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10170. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10171. -// have to do a total of 5 indirections just to get to the CP entries
  10172. -// that contain the interesting pieces of data and then we have to
  10173. -// fetch the three pieces of data. This means we have to do a total of
  10174. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10175. -// entries.
  10176. -//
  10177. -// Here is the indirection, data and dereference count for each entry
  10178. -// type:
  10179. -//
  10180. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10181. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10182. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10183. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10184. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10185. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10186. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10187. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10188. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10189. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10190. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10191. -//
  10192. -// So different subtypes of CP entries require different amounts of
  10193. -// work for a proper comparison.
  10194. -//
  10195. -// Now that we've talked about the different entry types and how to
  10196. -// compare them we need to get back to merging. This is not a merge in
  10197. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10198. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10199. -// preserving entry order. Next we append all the unique entries from
  10200. -// scratch_cp to merge_cp and we track the index changes from the
  10201. -// location in scratch_cp to the possibly new location in merge_cp.
  10202. -// When we are done, any obsolete code that is still running that
  10203. -// uses old_cp should not be able to observe any difference if it
  10204. -// were to use merge_cp. As for the new code in scratch_class, it is
  10205. -// modified to use the appropriate index values in merge_cp before it
  10206. -// is used to replace the code in the_class.
  10207. -//
  10208. -// There is one small complication in copying the entries from old_cp
  10209. -// to merge_cp. Two of the CP entry types are special in that they are
  10210. -// lazily resolved. Before explaining the copying complication, we need
  10211. -// to digress into CP entry resolution.
  10212. -//
  10213. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10214. -// the class file, but are not stored in memory as such until they are
  10215. -// resolved. The entries are not resolved unless they are used because
  10216. -// resolution is expensive. During class file parsing the entries are
  10217. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10218. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10219. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10220. -// have been parsed, but the index values in the entries have not been
  10221. -// validated. After the entire constant pool has been parsed, the index
  10222. -// values can be validated and then the entries are converted into
  10223. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10224. -// entries. During this conversion process, the UTF8 values that are
  10225. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10226. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10227. -// entries are modified to refer to the Symbol*s. This optimization
  10228. -// eliminates one level of indirection for those two CP entry types and
  10229. -// gets the entries ready for verification. During class file parsing
  10230. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10231. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10232. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10233. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10234. -// entries.
  10235. -//
  10236. -// Now we can get back to the copying complication. When we copy
  10237. -// entries from old_cp to merge_cp, we have to revert any
  10238. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10239. -// or verification will fail.
  10240. -//
  10241. -// It is important to explicitly state that the merging algorithm
  10242. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10243. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10244. -// entries in the merge_cp. This is done both to make verification
  10245. -// happy and to avoid adding more brittleness between RedefineClasses
  10246. -// and the constant pool cache. By allowing the constant pool cache
  10247. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10248. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10249. -// about those algorithms in RedefineClasses.
  10250. -//
  10251. -// Appending unique entries from scratch_cp to merge_cp is straight
  10252. -// forward for direct CP entries and most indirect CP entries. For the
  10253. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10254. -// indirect CP entry types, the presence of more than one piece of
  10255. -// interesting data makes appending the entries more complicated.
  10256. -//
  10257. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10258. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10259. -// If the index in scratch_cp is different than the destination index
  10260. -// in merge_cp, then the change in index value is tracked.
  10261. -//
  10262. -// Note: the above discussion for the direct CP entries also applies
  10263. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10264. -//
  10265. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10266. -// one data element at the end of the recursion, we know that we have
  10267. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10268. -// unique then it is appended to merge_cp before the current entry.
  10269. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10270. -// is updated to refer to the duplicate entry in merge_cp before it is
  10271. -// appended to merge_cp. Again, any changes in index values are tracked
  10272. -// as needed.
  10273. -//
  10274. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10275. -// types is theoretical. Since those entry types have already been
  10276. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10277. -// they are handled as direct CP entries.
  10278. -//
  10279. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10280. -// data elements at the end of the recursions, we know that we have
  10281. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10282. -// entries are appended to merge_cp before the current entry. For any
  10283. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10284. -// updated to refer to the duplicate entry in merge_cp before it is
  10285. -// appended to merge_cp. Again, any changes in index values are tracked
  10286. -// as needed.
  10287. -//
  10288. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10289. -// types, since there are two indirect CP entries and three data
  10290. -// elements at the end of the recursions, we know that we have between
  10291. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10292. -// above for an example of all six entries. The uniqueness algorithm
  10293. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10294. -// covered above. Any unique entries are appended to merge_cp before
  10295. -// the current entry. For any entries that are not unique, the current
  10296. -// entry is updated to refer to the duplicate entry in merge_cp before
  10297. -// it is appended to merge_cp. Again, any changes in index values are
  10298. -// tracked as needed.
  10299. -//
  10300. -//
  10301. -// Other Details:
  10302. -//
  10303. -// Details for other parts of RedefineClasses need to be written.
  10304. -// This is a placeholder section.
  10305. -//
  10306. -//
  10307. -// Open Issues (in no particular order):
  10308. -//
  10309. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10310. -//
  10311. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10312. -// domain since the initial version. This has been changed to pass
  10313. -// the_class->protection_domain(). This change has been tested with
  10314. -// all NSK tests and nothing broke, but what will adding it now break
  10315. -// in ways that we don't test?
  10316. -//
  10317. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10318. -// (indirect) use of the Relocator class that the max instruction
  10319. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10320. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10321. -// what it does to the bytecodes. More investigation is needed.
  10322. -//
  10323. -// - java.lang.Object methods can be called on arrays. This is
  10324. -// implemented via the arrayKlassOop vtable which we don't
  10325. -// update. For example, if we redefine java.lang.Object.toString(),
  10326. -// then the new version of the method will not be called for array
  10327. -// objects.
  10328. -//
  10329. -// - How do we know if redefine_single_class() and the guts of
  10330. -// instanceKlass are out of sync? I don't think this can be
  10331. -// automated, but we should probably order the work in
  10332. -// redefine_single_class() to match the order of field
  10333. -// definitions in instanceKlass. We also need to add some
  10334. -// comments about keeping things in sync.
  10335. -//
  10336. -// - set_new_constant_pool() is huge and we should consider refactoring
  10337. -// it into smaller chunks of work.
  10338. -//
  10339. -// - The exception table update code in set_new_constant_pool() defines
  10340. -// const values that are also defined in a local context elsewhere.
  10341. -// The same literal values are also used in elsewhere. We need to
  10342. -// coordinate a cleanup of these constants with Runtime.
  10343. -//
  10344. -
  10345. -class VM_RedefineClasses: public VM_Operation {
  10346. +#define RC_ABORT(error) { _result = error; return false; }
  10347. +
  10348. +class VM_RedefineClasses: public VM_GC_Operation {
  10349. private:
  10350. +
  10351. // These static fields are needed by SystemDictionary::classes_do()
  10352. // facility and the adjust_cpool_cache_and_vtable() helper:
  10353. static objArrayOop _old_methods;
  10354. static objArrayOop _new_methods;
  10355. - static methodOop* _matching_old_methods;
  10356. - static methodOop* _matching_new_methods;
  10357. - static methodOop* _deleted_methods;
  10358. - static methodOop* _added_methods;
  10359. + static int* _matching_old_methods;
  10360. + static int* _matching_new_methods;
  10361. + static int* _deleted_methods;
  10362. + static int* _added_methods;
  10363. static int _matching_methods_length;
  10364. static int _deleted_methods_length;
  10365. static int _added_methods_length;
  10366. static klassOop _the_class_oop;
  10367. + static int _revision_number;
  10368. +
  10369. // The instance fields are used to pass information from
  10370. // doit_prologue() to doit() and doit_epilogue().
  10371. jint _class_count;
  10372. @@ -370,36 +70,29 @@ class VM_RedefineClasses: public VM_Operation {
  10373. // _index_map_p contains any entries.
  10374. int _index_map_count;
  10375. intArray * _index_map_p;
  10376. - // ptr to _class_count scratch_classes
  10377. - instanceKlassHandle * _scratch_classes;
  10378. - jvmtiError _res;
  10379. + GrowableArray<instanceKlassHandle>* _new_classes;
  10380. + GrowableArray<oop>* _updated_oops;
  10381. + jvmtiError _result;
  10382. + int _max_redefinition_flags;
  10383. // Performance measurement support. These timers do not cover all
  10384. // the work done for JVM/TI RedefineClasses() but they do cover
  10385. // the heavy lifting.
  10386. - elapsedTimer _timer_rsc_phase1;
  10387. - elapsedTimer _timer_rsc_phase2;
  10388. - elapsedTimer _timer_vm_op_prologue;
  10389. -
  10390. - // These routines are roughly in call order unless otherwise noted.
  10391. -
  10392. - // Load the caller's new class definition(s) into _scratch_classes.
  10393. - // Constant pool merging work is done here as needed. Also calls
  10394. - // compare_and_normalize_class_versions() to verify the class
  10395. - // definition(s).
  10396. + elapsedTimer _timer_total;
  10397. + elapsedTimer _timer_prologue;
  10398. + elapsedTimer _timer_class_linking;
  10399. + elapsedTimer _timer_class_loading;
  10400. + elapsedTimer _timer_check_type;
  10401. + elapsedTimer _timer_prepare_redefinition;
  10402. + elapsedTimer _timer_wait_for_locks;
  10403. + elapsedTimer _timer_redefinition;
  10404. + elapsedTimer _timer_vm_op_epilogue;
  10405. +
  10406. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  10407. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  10408. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  10409. jvmtiError load_new_class_versions(TRAPS);
  10410. - // Verify that the caller provided class definition(s) that meet
  10411. - // the restrictions of RedefineClasses. Normalize the order of
  10412. - // overloaded methods as needed.
  10413. - jvmtiError compare_and_normalize_class_versions(
  10414. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  10415. -
  10416. - // Swap annotations[i] with annotations[j]
  10417. - // Used by compare_and_normalize_class_versions() when normalizing
  10418. - // overloaded methods or changing idnum as when adding or deleting methods.
  10419. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  10420. -
  10421. // Figure out which new methods match old methods in name and signature,
  10422. // which methods have been added, and which are no longer present
  10423. void compute_added_deleted_matching_methods();
  10424. @@ -407,96 +100,100 @@ class VM_RedefineClasses: public VM_Operation {
  10425. // Change jmethodIDs to point to the new methods
  10426. void update_jmethod_ids();
  10427. - // In addition to marking methods as obsolete, this routine
  10428. - // records which methods are EMCP (Equivalent Module Constant
  10429. - // Pool) in the emcp_methods BitMap and returns the number of
  10430. - // EMCP methods via emcp_method_count_p. This information is
  10431. - // used when information about the previous version of the_class
  10432. - // is squirreled away.
  10433. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  10434. - int * emcp_method_count_p);
  10435. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10436. + class FindAffectedKlassesClosure : public ObjectClosure {
  10437. +
  10438. + private:
  10439. + GrowableArray<instanceKlassHandle> *_original_klasses;
  10440. + GrowableArray<instanceKlassHandle> *_result;
  10441. +
  10442. + public:
  10443. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  10444. +
  10445. + virtual void do_object(oop obj);
  10446. + };
  10447. +
  10448. - // Unevolving classes may point to methods of the_class directly
  10449. - // from their constant pool caches, itables, and/or vtables. We
  10450. - // use the SystemDictionary::classes_do() facility and this helper
  10451. - // to fix up these pointers.
  10452. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  10453. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  10454. // Install the redefinition of a class
  10455. - void redefine_single_class(jclass the_jclass,
  10456. - instanceKlassHandle scratch_class, TRAPS);
  10457. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  10458. // Increment the classRedefinedCount field in the specific instanceKlass
  10459. // and in all direct and indirect subclasses.
  10460. void increment_class_counter(instanceKlass *ik, TRAPS);
  10461. - // Support for constant pool merging (these routines are in alpha
  10462. - // order):
  10463. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  10464. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10465. - int find_new_index(int old_index);
  10466. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  10467. - constantPoolHandle cp2, int index2);
  10468. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  10469. - constantPoolHandle cp2, int index2);
  10470. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  10471. - bool merge_constant_pools(constantPoolHandle old_cp,
  10472. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  10473. - int *merge_cp_length_p, TRAPS);
  10474. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  10475. - instanceKlassHandle scratch_class, TRAPS);
  10476. - u2 rewrite_cp_ref_in_annotation_data(
  10477. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  10478. - const char * trace_mesg, TRAPS);
  10479. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  10480. - bool rewrite_cp_refs_in_annotation_struct(
  10481. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10482. - bool rewrite_cp_refs_in_annotations_typeArray(
  10483. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  10484. - bool rewrite_cp_refs_in_class_annotations(
  10485. - instanceKlassHandle scratch_class, TRAPS);
  10486. - bool rewrite_cp_refs_in_element_value(
  10487. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10488. - bool rewrite_cp_refs_in_fields_annotations(
  10489. - instanceKlassHandle scratch_class, TRAPS);
  10490. - void rewrite_cp_refs_in_method(methodHandle method,
  10491. - methodHandle * new_method_p, TRAPS);
  10492. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  10493. - bool rewrite_cp_refs_in_methods_annotations(
  10494. - instanceKlassHandle scratch_class, TRAPS);
  10495. - bool rewrite_cp_refs_in_methods_default_annotations(
  10496. - instanceKlassHandle scratch_class, TRAPS);
  10497. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  10498. - instanceKlassHandle scratch_class, TRAPS);
  10499. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  10500. - void rewrite_cp_refs_in_verification_type_info(
  10501. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  10502. - u1 frame_size, TRAPS);
  10503. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  10504. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  10505. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  10506. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS) PRODUCT_RETURN;
  10507. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  10508. +
  10509. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  10510. +
  10511. +#ifdef ASSERT
  10512. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  10513. +#endif
  10514. +
  10515. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  10516. + void calculate_instance_update_information(klassOop new_version);
  10517. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  10518. - static void dump_methods() PRODUCT_RETURN;
  10519. + static void calculate_type_check_information(klassOop k);
  10520. + static void clear_type_check_information(klassOop k);
  10521. public:
  10522. - VM_RedefineClasses(jint class_count,
  10523. - const jvmtiClassDefinition *class_defs,
  10524. - JvmtiClassLoadKind class_load_kind);
  10525. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  10526. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  10527. + virtual ~VM_RedefineClasses();
  10528. +
  10529. + bool check_arguments();
  10530. bool doit_prologue();
  10531. void doit();
  10532. void doit_epilogue();
  10533. + void rollback();
  10534. - bool allow_nested_vm_operations() const { return true; }
  10535. - jvmtiError check_error() { return _res; }
  10536. + jvmtiError check_exception() const;
  10537. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  10538. + bool skip_operation() const { return false; }
  10539. + bool allow_nested_vm_operations() const { return true; }
  10540. + jvmtiError check_error() { return _result; }
  10541. +
  10542. + void update_active_methods();
  10543. +
  10544. + // Checks for type consistency after hierarchy change
  10545. + bool check_type_consistency();
  10546. + void calculate_type_check_information();
  10547. + bool check_field_value_types();
  10548. + void clear_type_check_information();
  10549. + bool check_method_stacks();
  10550. + bool check_loaded_methods();
  10551. + bool check_method(methodOop method);
  10552. + static Symbol* signature_to_class_name(Symbol* signature);
  10553. +
  10554. + void method_forwarding();
  10555. +
  10556. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  10557. // Modifiable test must be shared between IsModifiableClass query
  10558. // and redefine implementation
  10559. static bool is_modifiable_class(oop klass_mirror);
  10560. +
  10561. + // Method used during garbage collection, the VM operation must iterate over all oops.
  10562. + void oops_do(OopClosure* f);
  10563. +
  10564. + // Utility methods for transfering field access flags
  10565. +
  10566. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  10567. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  10568. +
  10569. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10570. +
  10571. + void lock_threads();
  10572. + void unlock_threads();
  10573. +
  10574. + template <class T> static void do_oop_work(T* p);
  10575. +
  10576. + static void swap_marks(oop first, oop second);
  10577. +
  10578. };
  10579. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10580. +
  10581. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  10582. index 60eaf97..38d3194 100644
  10583. --- a/src/share/vm/prims/methodComparator.cpp
  10584. +++ b/src/share/vm/prims/methodComparator.cpp
  10585. @@ -65,6 +65,37 @@ bool MethodComparator::methods_EMCP(methodOop old_method, methodOop new_method)
  10586. if (! args_same(c_old, c_new))
  10587. return false;
  10588. }
  10589. +
  10590. + // DCEVM: Added exception table comparison to EMCP comparison
  10591. +
  10592. + typeArrayOop ex_old = old_method->constMethod()->exception_table();
  10593. + typeArrayOop ex_new = new_method->constMethod()->exception_table();
  10594. +
  10595. + if (ex_old == NULL && ex_new != NULL) return false;
  10596. + if (ex_old != NULL && ex_new == NULL) return false;
  10597. +
  10598. + if (ex_old != NULL && ex_new != NULL && ex_old->length() == ex_new->length()) {
  10599. + // Per entry:
  10600. + /* start */
  10601. + /* limit */
  10602. + /* goto pc */
  10603. + /* cp index */
  10604. + for (int i=0; i<ex_old->length(); i++) {
  10605. + int old_val = ex_old->int_at(i);
  10606. + int new_val = ex_new->int_at(i);
  10607. + if ((i + 1) % 4 == 0) {
  10608. + if (old_val == 0 || new_val == 0) {
  10609. + if (old_val != new_val) return false;
  10610. + } else if ((_old_cp->klass_at_noresolve(old_val) != _new_cp->klass_at_noresolve(new_val)))
  10611. + return false;
  10612. + } else {
  10613. + if (old_val != new_val) {
  10614. + return false;
  10615. + }
  10616. + }
  10617. + }
  10618. + }
  10619. +
  10620. return true;
  10621. }
  10622. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  10623. index f8c627d..aa95bd4 100644
  10624. --- a/src/share/vm/prims/nativeLookup.cpp
  10625. +++ b/src/share/vm/prims/nativeLookup.cpp
  10626. @@ -35,6 +35,7 @@
  10627. #include "oops/symbol.hpp"
  10628. #include "prims/jvm_misc.hpp"
  10629. #include "prims/nativeLookup.hpp"
  10630. +#include "prims/jvmtiRedefineClasses.hpp"
  10631. #include "runtime/arguments.hpp"
  10632. #include "runtime/handles.inline.hpp"
  10633. #include "runtime/javaCalls.hpp"
  10634. @@ -53,7 +54,6 @@
  10635. # include "os_bsd.inline.hpp"
  10636. #endif
  10637. -
  10638. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  10639. char* bytes = (char*)name->bytes() + begin;
  10640. char* end_bytes = (char*)name->bytes() + end;
  10641. @@ -136,6 +136,40 @@ static JNINativeMethod lookup_special_native_methods[] = {
  10642. { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) }
  10643. };
  10644. +// Helper function to call redefineClasses from Java Code
  10645. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  10646. + ResourceMark rm(THREAD);
  10647. +
  10648. + JavaThread* current_thread = JavaThread::current();
  10649. + jbyte* bytecodes = NULL;
  10650. + const int class_count = 1;
  10651. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  10652. +
  10653. + {
  10654. + ThreadToNativeFromVM ttnfv(thread);
  10655. + jboolean is_copy = JNI_FALSE;
  10656. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  10657. + class_definitions[0].klass = target;
  10658. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  10659. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  10660. + }
  10661. +
  10662. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  10663. + VMThread::execute(&op);
  10664. + int result = op.check_error();
  10665. +
  10666. + {
  10667. + ThreadToNativeFromVM ttnfv(thread);
  10668. + if (env->ExceptionOccurred()) {
  10669. + return -1;
  10670. + }
  10671. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  10672. + }
  10673. +
  10674. + return result;
  10675. +JVM_END
  10676. +
  10677. +
  10678. static address lookup_special_native(char* jni_name) {
  10679. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  10680. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  10681. @@ -175,6 +209,9 @@ address NativeLookup::lookup_style(methodHandle method, char* pure_name, const c
  10682. return entry;
  10683. }
  10684. }
  10685. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  10686. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  10687. + }
  10688. // Otherwise call static method findNative in ClassLoader
  10689. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  10690. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  10691. index 1d3b887..aa223a4 100644
  10692. --- a/src/share/vm/runtime/arguments.cpp
  10693. +++ b/src/share/vm/runtime/arguments.cpp
  10694. @@ -1747,6 +1747,15 @@ bool Arguments::check_gc_consistency() {
  10695. status = false;
  10696. }
  10697. + // (tw) Must use serial GC
  10698. + if (!UseSerialGC && i >= 1) {
  10699. + jio_fprintf(defaultStream::error_stream(),
  10700. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  10701. + status = false;
  10702. + } else {
  10703. + UseSerialGC = true;
  10704. + }
  10705. +
  10706. return status;
  10707. }
  10708. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  10709. index 0e2a983..0adca35 100644
  10710. --- a/src/share/vm/runtime/deoptimization.cpp
  10711. +++ b/src/share/vm/runtime/deoptimization.cpp
  10712. @@ -595,6 +595,38 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
  10713. // Cleanup thread deopt data
  10714. cleanup_deopt_info(thread, array);
  10715. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  10716. + {
  10717. + ResourceMark res_mark;
  10718. +
  10719. + // Verify that the just-unpacked frames match the interpreter's
  10720. + // notions of expression stack and locals
  10721. + vframeArray* cur_array = thread->vframe_array_last();
  10722. + RegisterMap rm(thread, false);
  10723. + rm.set_include_argument_oops(false);
  10724. + for (int i = 0; i < cur_array->frames(); i++) {
  10725. + vframeArrayElement* el = cur_array->element(i);
  10726. + frame* frame = el->iframe();
  10727. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  10728. + RegisterMap reg_map(thread);
  10729. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  10730. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  10731. + methodOop method = iframe->method();
  10732. + int bci = iframe->bci();
  10733. + method = method->newest_version();
  10734. + iframe->set_method(method, bci);
  10735. +
  10736. + methodOop forward_method = method->forward_method();
  10737. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  10738. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  10739. + if (TraceRedefineClasses >= 2) {
  10740. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  10741. + }
  10742. + iframe->set_method(forward_method, new_bci);
  10743. + }
  10744. + }
  10745. + }
  10746. +
  10747. #ifndef PRODUCT
  10748. if (VerifyStack) {
  10749. ResourceMark res_mark;
  10750. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  10751. index 7ae9aa8..e9ca96c 100644
  10752. --- a/src/share/vm/runtime/frame.cpp
  10753. +++ b/src/share/vm/runtime/frame.cpp
  10754. @@ -403,6 +403,12 @@ void frame::interpreter_frame_set_method(methodOop method) {
  10755. *interpreter_frame_method_addr() = method;
  10756. }
  10757. +// (tw) Sets constant pool cache oop
  10758. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  10759. + assert(is_interpreted_frame(), "interpreted frame expected");
  10760. + *interpreter_frame_cache_addr() = cp;
  10761. +}
  10762. +
  10763. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  10764. assert(is_interpreted_frame(), "Not an interpreted frame");
  10765. if (ProfileInterpreter) {
  10766. @@ -418,19 +424,27 @@ void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  10767. // The bcx was just converted from bci to bcp.
  10768. // Convert the mdx in parallel.
  10769. methodDataOop mdo = interpreter_frame_method()->method_data();
  10770. - assert(mdo != NULL, "");
  10771. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10772. - address mdp = mdo->di_to_dp(mdi);
  10773. - interpreter_frame_set_mdx((intptr_t)mdp);
  10774. + if (mdo == NULL) {
  10775. + interpreter_frame_set_mdx(0);
  10776. + } else {
  10777. + assert(mdo != NULL, "");
  10778. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10779. + address mdp = mdo->di_to_dp(mdi);
  10780. + interpreter_frame_set_mdx((intptr_t)mdp);
  10781. + }
  10782. }
  10783. } else {
  10784. if (is_now_bci) {
  10785. // The bcx was just converted from bcp to bci.
  10786. // Convert the mdx in parallel.
  10787. methodDataOop mdo = interpreter_frame_method()->method_data();
  10788. - assert(mdo != NULL, "");
  10789. - int mdi = mdo->dp_to_di((address)mdx);
  10790. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10791. + if (mdo == NULL) {
  10792. + interpreter_frame_set_mdx(0);
  10793. + } else {
  10794. + assert(mdo != NULL, "");
  10795. + int mdi = mdo->dp_to_di((address)mdx);
  10796. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10797. + }
  10798. }
  10799. }
  10800. }
  10801. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  10802. index c55380e..342dec7 100644
  10803. --- a/src/share/vm/runtime/frame.hpp
  10804. +++ b/src/share/vm/runtime/frame.hpp
  10805. @@ -346,6 +346,7 @@ class frame VALUE_OBJ_CLASS_SPEC {
  10806. // Method & constant pool cache
  10807. methodOop interpreter_frame_method() const;
  10808. void interpreter_frame_set_method(methodOop method);
  10809. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  10810. methodOop* interpreter_frame_method_addr() const;
  10811. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  10812. #ifdef PPC
  10813. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  10814. index e41e2e3..b39ffc9 100644
  10815. --- a/src/share/vm/runtime/globals.hpp
  10816. +++ b/src/share/vm/runtime/globals.hpp
  10817. @@ -1309,9 +1309,23 @@ class CommandLineFlags {
  10818. product(bool, StressLdcRewrite, false, \
  10819. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  10820. \
  10821. + product(bool, UseMethodForwardPoints, false, \
  10822. + "Use method forward points") \
  10823. + \
  10824. + product(intx, MethodForwardPointsMaxLocals, 300, \
  10825. + "Maximum number of locals in forwarding method") \
  10826. + \
  10827. + product(intx, MethodForwardPointsMaxStack, 300, \
  10828. + "Maximum number of stack slots in forwarding method") \
  10829. + \
  10830. product(intx, TraceRedefineClasses, 0, \
  10831. "Trace level for JVMTI RedefineClasses") \
  10832. \
  10833. + product(bool, TimeRedefineClasses, false, \
  10834. + "Measure timing for JVMTI RedefineClasses") \
  10835. + \
  10836. + product(bool, AllowAdvancedClassRedefinition, true, \
  10837. + "Allow advanced class redefinition beyond swapping method bodies")\
  10838. develop(bool, StressMethodComparator, false, \
  10839. "run the MethodComparator on all loaded methods") \
  10840. \
  10841. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  10842. index e1001ee..b034760 100644
  10843. --- a/src/share/vm/runtime/interfaceSupport.hpp
  10844. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  10845. @@ -296,7 +296,7 @@ class ThreadToNativeFromVM : public ThreadStateTransition {
  10846. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  10847. // We are leaving the VM at this point and going directly to native code.
  10848. // Block, if we are in the middle of a safepoint synchronization.
  10849. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  10850. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  10851. thread->frame_anchor()->make_walkable(thread);
  10852. trans_and_fence(_thread_in_vm, _thread_in_native);
  10853. // Check for pending. async. exceptions or suspends.
  10854. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  10855. index edbba98..4a27925 100644
  10856. --- a/src/share/vm/runtime/javaCalls.cpp
  10857. +++ b/src/share/vm/runtime/javaCalls.cpp
  10858. @@ -60,7 +60,7 @@ JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, Ja
  10859. bool clear_pending_exception = true;
  10860. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  10861. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  10862. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  10863. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  10864. _result = result;
  10865. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  10866. index 3cbcaca..30839d7 100644
  10867. --- a/src/share/vm/runtime/jniHandles.cpp
  10868. +++ b/src/share/vm/runtime/jniHandles.cpp
  10869. @@ -112,6 +112,10 @@ jobject JNIHandles::make_weak_global(Handle obj) {
  10870. }
  10871. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  10872. + if (mh->newest_version() != mh()) {
  10873. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  10874. + return (jmethodID) make_weak_global(mh_new);
  10875. + }
  10876. return (jmethodID) make_weak_global(mh);
  10877. }
  10878. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  10879. index 9fc1560..03706c9 100644
  10880. --- a/src/share/vm/runtime/mutex.cpp
  10881. +++ b/src/share/vm/runtime/mutex.cpp
  10882. @@ -1227,7 +1227,7 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
  10883. // in increasing rank order (modulo any native ranks)
  10884. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  10885. if (tmp->next() != NULL) {
  10886. - assert(tmp->rank() == Mutex::native ||
  10887. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  10888. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  10889. }
  10890. }
  10891. @@ -1247,7 +1247,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
  10892. // in increasing rank order (modulo any native ranks)
  10893. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  10894. if (tmp->next() != NULL) {
  10895. - assert(tmp->rank() == Mutex::native ||
  10896. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  10897. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  10898. }
  10899. }
  10900. @@ -1310,6 +1310,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
  10901. // already hold Terminator_lock - may happen because of periodic safepoints
  10902. if (this->rank() != Mutex::native &&
  10903. this->rank() != Mutex::suspend_resume &&
  10904. + this->rank() != Mutex::redefine_classes &&
  10905. locks != NULL && locks->rank() <= this->rank() &&
  10906. !SafepointSynchronize::is_at_safepoint() &&
  10907. this != Interrupt_lock && this != ProfileVM_lock &&
  10908. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  10909. index 66a3295..a053204 100644
  10910. --- a/src/share/vm/runtime/mutex.hpp
  10911. +++ b/src/share/vm/runtime/mutex.hpp
  10912. @@ -109,7 +109,8 @@ class Monitor : public CHeapObj {
  10913. barrier = safepoint + 1,
  10914. nonleaf = barrier + 1,
  10915. max_nonleaf = nonleaf + 900,
  10916. - native = max_nonleaf + 1
  10917. + native = max_nonleaf + 1,
  10918. + redefine_classes = native + 1
  10919. };
  10920. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  10921. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  10922. index f1911ea..ef85adf 100644
  10923. --- a/src/share/vm/runtime/mutexLocker.cpp
  10924. +++ b/src/share/vm/runtime/mutexLocker.cpp
  10925. @@ -49,6 +49,7 @@
  10926. // Consider using GCC's __read_mostly.
  10927. Mutex* Patching_lock = NULL;
  10928. +Mutex* RedefineClasses_lock = NULL;
  10929. Monitor* SystemDictionary_lock = NULL;
  10930. Mutex* PackageTable_lock = NULL;
  10931. Mutex* CompiledIC_lock = NULL;
  10932. @@ -90,6 +91,7 @@ Mutex* Shared_SATB_Q_lock = NULL;
  10933. Mutex* DirtyCardQ_FL_lock = NULL;
  10934. Monitor* DirtyCardQ_CBL_mon = NULL;
  10935. Mutex* Shared_DirtyCardQ_lock = NULL;
  10936. +Monitor* RedefinitionSync_lock = NULL;
  10937. Mutex* ParGCRareEvent_lock = NULL;
  10938. Mutex* EvacFailureStack_lock = NULL;
  10939. Mutex* DerivedPointerTableGC_lock = NULL;
  10940. @@ -205,6 +207,7 @@ void mutex_init() {
  10941. def(HotCardCache_lock , Mutex , special , true );
  10942. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  10943. }
  10944. + def(RedefinitionSync_lock , Monitor , leaf , false );
  10945. def(ParGCRareEvent_lock , Mutex , leaf , true );
  10946. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  10947. def(CodeCache_lock , Mutex , special, true );
  10948. @@ -279,6 +282,7 @@ void mutex_init() {
  10949. def(Debug2_lock , Mutex , nonleaf+4, true );
  10950. def(Debug3_lock , Mutex , nonleaf+4, true );
  10951. def(ProfileVM_lock , Monitor, nonleaf+4, false); // used for profiling of the VMThread
  10952. + def(RedefineClasses_lock , Mutex, nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  10953. def(CompileThread_lock , Monitor, nonleaf+5, false );
  10954. def(JfrQuery_lock , Monitor, nonleaf, true); // JFR locks, keep these in consecutive order
  10955. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  10956. index 846b2d4..c20d12d 100644
  10957. --- a/src/share/vm/runtime/mutexLocker.hpp
  10958. +++ b/src/share/vm/runtime/mutexLocker.hpp
  10959. @@ -43,6 +43,8 @@
  10960. // Mutexes used in the VM.
  10961. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  10962. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  10963. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  10964. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  10965. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  10966. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  10967. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  10968. index 29858be..d37e928 100644
  10969. --- a/src/share/vm/runtime/reflection.cpp
  10970. +++ b/src/share/vm/runtime/reflection.cpp
  10971. @@ -469,7 +469,8 @@ bool Reflection::verify_class_access(klassOop current_class, klassOop new_class,
  10972. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  10973. if ( JDK_Version::is_gte_jdk14x_version()
  10974. && UseNewReflection
  10975. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  10976. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  10977. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  10978. return true;
  10979. }
  10980. @@ -525,6 +526,12 @@ bool Reflection::verify_field_access(klassOop current_class,
  10981. AccessFlags access,
  10982. bool classloader_only,
  10983. bool protected_restriction) {
  10984. +
  10985. + // (tw) Decide accessibility based on active version
  10986. + if (current_class != NULL) {
  10987. + current_class = current_class->klass_part()->active_version();
  10988. + }
  10989. +
  10990. // Verify that current_class can access a field of field_class, where that
  10991. // field's access bits are "access". We assume that we've already verified
  10992. // that current_class can access field_class.
  10993. @@ -566,7 +573,8 @@ bool Reflection::verify_field_access(klassOop current_class,
  10994. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  10995. if ( JDK_Version::is_gte_jdk14x_version()
  10996. && UseNewReflection
  10997. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  10998. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  10999. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11000. return true;
  11001. }
  11002. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11003. index 503ad07..623cf8a 100644
  11004. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11005. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11006. @@ -1139,7 +1139,20 @@ methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
  11007. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11008. int retry_count = 0;
  11009. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11010. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11011. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11012. +
  11013. + // DCEVM: If we are executing an old method, this is OK!
  11014. + {
  11015. + ResourceMark rm(thread);
  11016. + RegisterMap cbl_map(thread, false);
  11017. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11018. +
  11019. + CodeBlob* caller_cb = caller_frame.cb();
  11020. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11021. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11022. + if (caller_nm->method()->is_old()) break;
  11023. + }
  11024. +
  11025. // If has a pending exception then there is no need to re-try to
  11026. // resolve this method.
  11027. // If the method has been redefined, we need to try again.
  11028. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11029. index 7676682..d2862bd 100644
  11030. --- a/src/share/vm/runtime/thread.cpp
  11031. +++ b/src/share/vm/runtime/thread.cpp
  11032. @@ -212,6 +212,8 @@ Thread::Thread() {
  11033. set_self_raw_id(0);
  11034. set_lgrp_id(-1);
  11035. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11036. +
  11037. // allocated data structures
  11038. set_osthread(NULL);
  11039. set_resource_area(new ResourceArea());
  11040. @@ -246,6 +248,7 @@ Thread::Thread() {
  11041. omFreeProvision = 32 ;
  11042. omInUseList = NULL ;
  11043. omInUseCount = 0 ;
  11044. + _pretend_new_universe = false;
  11045. #ifdef ASSERT
  11046. _visited_for_critical_count = false;
  11047. @@ -857,6 +860,15 @@ bool Thread::owns_locks_but_compiled_lock() const {
  11048. return false;
  11049. }
  11050. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11051. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11052. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11053. + return true;
  11054. + }
  11055. + }
  11056. + return false;
  11057. +}
  11058. +
  11059. #endif
  11060. @@ -1507,7 +1519,7 @@ void JavaThread::run() {
  11061. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11062. assert(JavaThread::current() == this, "sanity check");
  11063. - assert(!Thread::current()->owns_locks(), "sanity check");
  11064. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11065. DTRACE_THREAD_PROBE(start, this);
  11066. @@ -3045,7 +3057,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  11067. // Create a CompilerThread
  11068. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11069. -: JavaThread(&compiler_thread_entry) {
  11070. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11071. _env = NULL;
  11072. _log = NULL;
  11073. _task = NULL;
  11074. @@ -3053,6 +3065,7 @@ CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11075. _counters = counters;
  11076. _buffer_blob = NULL;
  11077. _scanned_nmethod = NULL;
  11078. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11079. #ifndef PRODUCT
  11080. _ideal_graph_printer = NULL;
  11081. @@ -3082,6 +3095,7 @@ int Threads::_number_of_threads = 0;
  11082. int Threads::_number_of_non_daemon_threads = 0;
  11083. int Threads::_return_code = 0;
  11084. size_t JavaThread::_stack_size_at_create = 0;
  11085. +bool Threads::_wait_at_instrumentation_entry = false;
  11086. // All JavaThreads
  11087. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11088. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11089. index 7846cc0..a8bf2c5 100644
  11090. --- a/src/share/vm/runtime/thread.hpp
  11091. +++ b/src/share/vm/runtime/thread.hpp
  11092. @@ -197,11 +197,14 @@ class Thread: public ThreadShadow {
  11093. void enter_signal_handler() { _num_nested_signal++; }
  11094. void leave_signal_handler() { _num_nested_signal--; }
  11095. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11096. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11097. private:
  11098. // Debug tracing
  11099. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11100. + Mutex* _redefine_classes_mutex;
  11101. +
  11102. // Active_handles points to a block of handles
  11103. JNIHandleBlock* _active_handles;
  11104. @@ -522,10 +525,15 @@ public:
  11105. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11106. int _lgrp_id;
  11107. +
  11108. + bool _pretend_new_universe;
  11109. +
  11110. public:
  11111. // Stack overflow support
  11112. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11113. + 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; } }
  11114. + bool pretend_new_universe() { return _pretend_new_universe; }
  11115. void set_stack_base(address base) { _stack_base = base; }
  11116. size_t stack_size() const { return _stack_size; }
  11117. void set_stack_size(size_t size) { _stack_size = size; }
  11118. @@ -563,6 +571,7 @@ public:
  11119. void print_owned_locks() const { print_owned_locks_on(tty); }
  11120. Monitor* owned_locks() const { return _owned_locks; }
  11121. bool owns_locks() const { return owned_locks() != NULL; }
  11122. + bool owns_locks_but_redefine_classes_lock() const;
  11123. bool owns_locks_but_compiled_lock() const;
  11124. // Deadlock detection
  11125. @@ -1745,6 +1754,8 @@ class CompilerThread : public JavaThread {
  11126. CompileTask* _task;
  11127. CompileQueue* _queue;
  11128. BufferBlob* _buffer_blob;
  11129. + bool _should_bailout;
  11130. + Mutex* _compilation_mutex;
  11131. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11132. @@ -1754,12 +1765,16 @@ class CompilerThread : public JavaThread {
  11133. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11134. + bool should_bailout() const { return _should_bailout; }
  11135. + void set_should_bailout(bool b) { _should_bailout = false; }
  11136. +
  11137. bool is_Compiler_thread() const { return true; }
  11138. // Hide this compiler thread from external view.
  11139. bool is_hidden_from_external_view() const { return true; }
  11140. CompileQueue* queue() { return _queue; }
  11141. CompilerCounters* counters() { return _counters; }
  11142. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11143. // Get/set the thread's compilation environment.
  11144. ciEnv* env() { return _env; }
  11145. @@ -1814,6 +1829,7 @@ class Threads: AllStatic {
  11146. static int _number_of_threads;
  11147. static int _number_of_non_daemon_threads;
  11148. static int _return_code;
  11149. + static bool _wait_at_instrumentation_entry;
  11150. public:
  11151. // Thread management
  11152. @@ -1825,6 +1841,9 @@ class Threads: AllStatic {
  11153. static JavaThread* first() { return _thread_list; }
  11154. static void threads_do(ThreadClosure* tc);
  11155. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11156. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11157. +
  11158. // Initializes the vm and creates the vm thread
  11159. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11160. static void convert_vm_init_libraries_to_agents();
  11161. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11162. index 323d735..ec1f8ca 100644
  11163. --- a/src/share/vm/runtime/vframe.cpp
  11164. +++ b/src/share/vm/runtime/vframe.cpp
  11165. @@ -253,6 +253,46 @@ methodOop interpretedVFrame::method() const {
  11166. return fr().interpreter_frame_method();
  11167. }
  11168. +// (tw) Sets interpreter frame method.
  11169. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11170. + methodOop old_method = fr().interpreter_frame_method();
  11171. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11172. + if (old_method == new_method) return;
  11173. + u_char *old_bcp = bcp();
  11174. + int old_bci = bci();
  11175. + fr().interpreter_frame_set_method(new_method);
  11176. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11177. + u_char *new_bcp = new_method->code_base() + new_bci;
  11178. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11179. +
  11180. + set_bcp(new_bcp);
  11181. +
  11182. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11183. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11184. +
  11185. + switch (code) {
  11186. + case Bytecodes::_invokevirtual :
  11187. + case Bytecodes::_invokespecial :
  11188. + case Bytecodes::_invokestatic :
  11189. + case Bytecodes::_invokeinterface: {
  11190. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11191. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11192. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11193. + break;
  11194. + }
  11195. +
  11196. + case Bytecodes::_invokedynamic: {
  11197. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11198. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11199. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11200. + break;
  11201. + }
  11202. + }
  11203. +
  11204. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11205. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11206. +}
  11207. +
  11208. StackValueCollection* interpretedVFrame::locals() const {
  11209. int length = method()->max_locals();
  11210. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11211. index badfea5..edbc5c7 100644
  11212. --- a/src/share/vm/runtime/vframe.hpp
  11213. +++ b/src/share/vm/runtime/vframe.hpp
  11214. @@ -163,6 +163,7 @@ class interpretedVFrame: public javaVFrame {
  11215. StackValueCollection* locals() const;
  11216. StackValueCollection* expressions() const;
  11217. GrowableArray<MonitorInfo*>* monitors() const;
  11218. + void set_method(methodOop method, int new_bci);
  11219. void set_locals(StackValueCollection* values) const;
  11220. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11221. index d4fced2..9efee22 100644
  11222. --- a/src/share/vm/runtime/vmThread.cpp
  11223. +++ b/src/share/vm/runtime/vmThread.cpp
  11224. @@ -671,6 +671,9 @@ void VMThread::execute(VM_Operation* op) {
  11225. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11226. Thread::oops_do(f, cf);
  11227. _vm_queue->oops_do(f);
  11228. + if (_cur_vm_operation != NULL) {
  11229. + _cur_vm_operation->oops_do(f);
  11230. + }
  11231. }
  11232. //------------------------------------------------------------------------------------------------------------------
  11233. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11234. index 874d8e5..d860aa9 100644
  11235. --- a/src/share/vm/utilities/exceptions.cpp
  11236. +++ b/src/share/vm/utilities/exceptions.cpp
  11237. @@ -251,6 +251,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* h_name,
  11238. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11239. assert(!thread->has_pending_exception(), "already has exception");
  11240. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11241. + Thread::current()->set_pretend_new_universe(false);
  11242. Handle h_exception;
  11243. // Resolve exception klass
  11244. @@ -298,6 +300,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* h_name,
  11245. h_exception = Handle(thread, thread->pending_exception());
  11246. thread->clear_pending_exception();
  11247. }
  11248. +
  11249. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11250. return h_exception;
  11251. }
  11252. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11253. index 34972be..49fc03d 100644
  11254. --- a/src/share/vm/utilities/growableArray.hpp
  11255. +++ b/src/share/vm/utilities/growableArray.hpp
  11256. @@ -135,6 +135,33 @@ class GenericGrowableArray : public ResourceObj {
  11257. assert(on_stack(), "fast ResourceObj path only");
  11258. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11259. }
  11260. +
  11261. +};
  11262. +
  11263. +template<class E, class F> class Pair : public StackObj
  11264. +{
  11265. +private:
  11266. + E _left;
  11267. + F _right;
  11268. +
  11269. +public:
  11270. +
  11271. + Pair() {
  11272. +
  11273. + }
  11274. +
  11275. + Pair(E left, F right) {
  11276. + this->_left = left;
  11277. + this->_right = right;
  11278. + }
  11279. +
  11280. + E left() {
  11281. + return _left;
  11282. + }
  11283. +
  11284. + F right() {
  11285. + return _right;
  11286. + }
  11287. };
  11288. template<class E> class GrowableArray : public GenericGrowableArray {