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

full-jdk7u79-b15.patch 505KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372
  1. # HG changeset patch
  2. # Parent 882f6c762ac5352a0d94efcea46c8f9a917ceb08
  3. diff -r 882f6c762ac5 make/bsd/makefiles/gcc.make
  4. --- a/make/bsd/makefiles/gcc.make Thu Jul 09 23:10:04 2015 -0700
  5. +++ b/make/bsd/makefiles/gcc.make Thu Jul 09 23:18:17 2015 -0700
  6. @@ -117,7 +117,10 @@
  7. CFLAGS += -fno-rtti
  8. CFLAGS += -fno-exceptions
  9. CFLAGS += -pthread
  10. -CFLAGS += -fcheck-new
  11. +## well, strictly speaking we should check for clang not Darwin
  12. +ifneq ($(OS_VENDOR), Darwin)
  13. + CFLAGS += -fcheck-new
  14. +endif
  15. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  16. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  17. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  18. diff -r 882f6c762ac5 src/cpu/x86/vm/templateTable_x86_32.cpp
  19. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Thu Jul 09 23:10:04 2015 -0700
  20. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Thu Jul 09 23:18:17 2015 -0700
  21. @@ -2109,6 +2109,22 @@
  22. // resolve first time through
  23. address entry;
  24. switch (bytecode()) {
  25. + case Bytecodes::_fast_agetfield : // fall through
  26. + case Bytecodes::_fast_bgetfield : // fall through
  27. + case Bytecodes::_fast_cgetfield : // fall through
  28. + case Bytecodes::_fast_dgetfield : // fall through
  29. + case Bytecodes::_fast_fgetfield : // fall through
  30. + case Bytecodes::_fast_igetfield : // fall through
  31. + case Bytecodes::_fast_lgetfield : // fall through
  32. + case Bytecodes::_fast_sgetfield : // fall through
  33. + case Bytecodes::_fast_aputfield : // fall through
  34. + case Bytecodes::_fast_bputfield : // fall through
  35. + case Bytecodes::_fast_cputfield : // fall through
  36. + case Bytecodes::_fast_dputfield : // fall through
  37. + case Bytecodes::_fast_fputfield : // fall through
  38. + case Bytecodes::_fast_iputfield : // fall through
  39. + case Bytecodes::_fast_lputfield : // fall through
  40. + case Bytecodes::_fast_sputfield : // fall through
  41. case Bytecodes::_getstatic : // fall through
  42. case Bytecodes::_putstatic : // fall through
  43. case Bytecodes::_getfield : // fall through
  44. @@ -2211,6 +2227,7 @@
  45. // Correct values of the cache and index registers are preserved.
  46. void TemplateTable::jvmti_post_field_access(Register cache,
  47. Register index,
  48. + int byte_no,
  49. bool is_static,
  50. bool has_tos) {
  51. if (JvmtiExport::can_post_field_access()) {
  52. @@ -2237,7 +2254,11 @@
  53. // cache: cache entry pointer
  54. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  55. rax, cache);
  56. - __ get_cache_and_index_at_bcp(cache, index, 1);
  57. +
  58. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  59. + __ restore_bcp();
  60. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  61. +
  62. __ bind(L1);
  63. }
  64. }
  65. @@ -2258,7 +2279,7 @@
  66. const Register flags = rax;
  67. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  68. - jvmti_post_field_access(cache, index, is_static, false);
  69. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  70. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  71. if (!is_static) pop_and_check_object(obj);
  72. @@ -2393,7 +2414,7 @@
  73. // The registers cache and index expected to be set before call.
  74. // The function may destroy various registers, just not the cache and index registers.
  75. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  76. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  77. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  78. @@ -2451,7 +2472,11 @@
  79. // rcx: jvalue object on the stack
  80. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  81. rbx, rax, rcx);
  82. - __ get_cache_and_index_at_bcp(cache, index, 1);
  83. +
  84. + // (tw) Redefinition might have occured => reresolve the cp entry.
  85. + __ restore_bcp();
  86. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  87. +
  88. __ bind(L1);
  89. }
  90. }
  91. @@ -2467,7 +2492,7 @@
  92. const Register flags = rax;
  93. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  94. - jvmti_post_field_mod(cache, index, is_static);
  95. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  96. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  97. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  98. @@ -2818,6 +2843,11 @@
  99. // rcx: cache entry pointer
  100. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  101. __ pop_ptr(rax); // restore object pointer
  102. +
  103. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  104. + __ restore_bcp();
  105. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  106. +
  107. __ bind(L1);
  108. }
  109. @@ -3008,6 +3038,26 @@
  110. __ bind(notFinal);
  111. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  112. + Label notOld;
  113. + __ movl(rax, flags);
  114. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  115. + __ jcc(Assembler::zero, notOld);
  116. +
  117. + // Need a null check here!
  118. + __ null_check(recv);
  119. +
  120. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  121. + // DCEVM: TODO: Check if we can improve performance by inlining.
  122. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  123. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  124. +
  125. + // profile this call
  126. + __ profile_final_call(rax);
  127. + __ jump_from_interpreted(method, rdx);
  128. +
  129. + __ bind(notOld);
  130. +
  131. // get receiver klass
  132. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  133. __ load_klass(rax, recv);
  134. @@ -3093,6 +3143,31 @@
  135. invokevirtual_helper(rbx, rcx, rdx);
  136. __ bind(notMethod);
  137. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  138. + //__ movl(rax, rdx);
  139. + Label notOld;
  140. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  141. + __ jcc(Assembler::zero, notOld);
  142. +
  143. + // Get receiver klass into rdx - also a null check
  144. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  145. + __ verify_oop(rdx);
  146. +
  147. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  148. + // DCEVM: TODO: Check if we can improve performance by inlining.
  149. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  150. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  151. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  152. +
  153. + // DCEVM: TODO: Check if resolved method could be null.
  154. +
  155. + // profile this call
  156. + __ profile_virtual_call(rdx, rsi, rdi);
  157. +
  158. + __ jump_from_interpreted(rbx, rdx);
  159. +
  160. + __ bind(notOld);
  161. +
  162. // Get receiver klass into rdx - also a null check
  163. __ restore_locals(); // restore rdi
  164. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  165. diff -r 882f6c762ac5 src/cpu/x86/vm/templateTable_x86_64.cpp
  166. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Thu Jul 09 23:10:04 2015 -0700
  167. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Thu Jul 09 23:18:17 2015 -0700
  168. @@ -2151,6 +2151,22 @@
  169. // resolve first time through
  170. address entry;
  171. switch (bytecode()) {
  172. + case Bytecodes::_fast_agetfield : // fall through
  173. + case Bytecodes::_fast_bgetfield : // fall through
  174. + case Bytecodes::_fast_cgetfield : // fall through
  175. + case Bytecodes::_fast_dgetfield : // fall through
  176. + case Bytecodes::_fast_fgetfield : // fall through
  177. + case Bytecodes::_fast_igetfield : // fall through
  178. + case Bytecodes::_fast_lgetfield : // fall through
  179. + case Bytecodes::_fast_sgetfield : // fall through
  180. + case Bytecodes::_fast_aputfield : // fall through
  181. + case Bytecodes::_fast_bputfield : // fall through
  182. + case Bytecodes::_fast_cputfield : // fall through
  183. + case Bytecodes::_fast_dputfield : // fall through
  184. + case Bytecodes::_fast_fputfield : // fall through
  185. + case Bytecodes::_fast_iputfield : // fall through
  186. + case Bytecodes::_fast_lputfield : // fall through
  187. + case Bytecodes::_fast_sputfield : // fall through
  188. case Bytecodes::_getstatic:
  189. case Bytecodes::_putstatic:
  190. case Bytecodes::_getfield:
  191. @@ -2267,7 +2283,7 @@
  192. // The registers cache and index expected to be set before call.
  193. // Correct values of the cache and index registers are preserved.
  194. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  195. - bool is_static, bool has_tos) {
  196. + int byte_no, bool is_static, bool has_tos) {
  197. // do the JVMTI work here to avoid disturbing the register state below
  198. // We use c_rarg registers here because we want to use the register used in
  199. // the call to the VM
  200. @@ -2298,7 +2314,11 @@
  201. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  202. InterpreterRuntime::post_field_access),
  203. c_rarg1, c_rarg2, c_rarg3);
  204. - __ get_cache_and_index_at_bcp(cache, index, 1);
  205. +
  206. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  207. + __ restore_bcp();
  208. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  209. +
  210. __ bind(L1);
  211. }
  212. }
  213. @@ -2320,7 +2340,7 @@
  214. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  215. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  216. - jvmti_post_field_access(cache, index, is_static, false);
  217. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  218. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  219. if (!is_static) {
  220. @@ -2455,7 +2475,7 @@
  221. // The registers cache and index expected to be set before call.
  222. // The function may destroy various registers, just not the cache and index registers.
  223. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  224. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  225. transition(vtos, vtos);
  226. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  227. @@ -2507,7 +2527,11 @@
  228. CAST_FROM_FN_PTR(address,
  229. InterpreterRuntime::post_field_modification),
  230. c_rarg1, c_rarg2, c_rarg3);
  231. - __ get_cache_and_index_at_bcp(cache, index, 1);
  232. +
  233. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  234. + __ restore_bcp();
  235. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  236. +
  237. __ bind(L1);
  238. }
  239. }
  240. @@ -2523,7 +2547,7 @@
  241. const Register bc = c_rarg3;
  242. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  243. - jvmti_post_field_mod(cache, index, is_static);
  244. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  245. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  246. // [jk] not needed currently
  247. @@ -2837,6 +2861,11 @@
  248. InterpreterRuntime::post_field_access),
  249. c_rarg1, c_rarg2);
  250. __ pop_ptr(rax); // restore object pointer
  251. +
  252. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  253. + __ restore_bcp();
  254. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  255. +
  256. __ bind(L1);
  257. }
  258. @@ -3073,6 +3102,26 @@
  259. __ bind(notFinal);
  260. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  261. + Label notOld;
  262. + __ movl(rax, flags);
  263. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  264. + __ jcc(Assembler::zero, notOld);
  265. +
  266. + // Need a null check here!
  267. + __ null_check(recv);
  268. +
  269. + // 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)
  270. + // DCEVM: TODO: Check if we can improve performance by inlining.
  271. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  272. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  273. +
  274. + // profile this call
  275. + __ profile_final_call(rax);
  276. + __ jump_from_interpreted(method, rdx);
  277. +
  278. + __ bind(notOld);
  279. +
  280. // get receiver klass
  281. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  282. __ load_klass(rax, recv);
  283. @@ -3156,6 +3205,35 @@
  284. invokevirtual_helper(rbx, rcx, rdx);
  285. __ bind(notMethod);
  286. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  287. + Label notOld;
  288. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  289. + __ jcc(Assembler::zero, notOld);
  290. +
  291. + // 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)
  292. + // DCEVM: TODO: Check if we can improve performance by inlining.
  293. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  294. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  295. + // DCEVM: FIXME: What exactly should we store here?
  296. + __ push(rcx); // destroyed by Linux arguments passing conventions
  297. + __ movptr(r14, rcx);
  298. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  299. + __ pop(rcx);
  300. +
  301. + // Get receiver klass into rdx - also a null check
  302. + __ restore_locals(); // restore r14
  303. + __ load_klass(rdx, rcx);
  304. + __ verify_oop(rdx);
  305. +
  306. + // DCEVM: TODO: Check if resolved method could be null.
  307. +
  308. + // profile this call
  309. + __ profile_virtual_call(rdx, r13, r14);
  310. +
  311. + __ jump_from_interpreted(rbx, rdx);
  312. +
  313. + __ bind(notOld);
  314. +
  315. // Get receiver klass into rdx - also a null check
  316. __ restore_locals(); // restore r14
  317. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  318. diff -r 882f6c762ac5 src/share/vm/c1/c1_Compilation.hpp
  319. --- a/src/share/vm/c1/c1_Compilation.hpp Thu Jul 09 23:10:04 2015 -0700
  320. +++ b/src/share/vm/c1/c1_Compilation.hpp Thu Jul 09 23:18:17 2015 -0700
  321. @@ -242,8 +242,8 @@
  322. #define BAILOUT(msg) { bailout(msg); return; }
  323. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  324. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  325. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  326. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  327. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  328. class InstructionMark: public StackObj {
  329. diff -r 882f6c762ac5 src/share/vm/ci/ciEnv.cpp
  330. --- a/src/share/vm/ci/ciEnv.cpp Thu Jul 09 23:10:04 2015 -0700
  331. +++ b/src/share/vm/ci/ciEnv.cpp Thu Jul 09 23:18:17 2015 -0700
  332. @@ -1172,3 +1172,11 @@
  333. // If memory is low, we stop compiling methods.
  334. record_method_not_compilable("out of memory");
  335. }
  336. +
  337. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  338. +void ciEnv::cleanup_after_redefinition() {
  339. +
  340. + if (_factory != NULL) {
  341. + _factory->cleanup_after_redefinition();
  342. + }
  343. +}
  344. diff -r 882f6c762ac5 src/share/vm/ci/ciEnv.hpp
  345. --- a/src/share/vm/ci/ciEnv.hpp Thu Jul 09 23:10:04 2015 -0700
  346. +++ b/src/share/vm/ci/ciEnv.hpp Thu Jul 09 23:18:17 2015 -0700
  347. @@ -417,6 +417,8 @@
  348. void record_failure(const char* reason);
  349. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  350. void record_out_of_memory_failure();
  351. +
  352. + void cleanup_after_redefinition();
  353. };
  354. #endif // SHARE_VM_CI_CIENV_HPP
  355. diff -r 882f6c762ac5 src/share/vm/ci/ciObjectFactory.cpp
  356. --- a/src/share/vm/ci/ciObjectFactory.cpp Thu Jul 09 23:10:04 2015 -0700
  357. +++ b/src/share/vm/ci/ciObjectFactory.cpp Thu Jul 09 23:18:17 2015 -0700
  358. @@ -296,6 +296,11 @@
  359. // into the table. We need to recompute our index.
  360. index = find(keyHandle(), _ci_objects);
  361. }
  362. +
  363. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  364. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  365. + return _ci_objects->at(index);
  366. + }
  367. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  368. insert(index, new_object, _ci_objects);
  369. return new_object;
  370. @@ -764,3 +769,50 @@
  371. _unloaded_instances->length(),
  372. _unloaded_klasses->length());
  373. }
  374. +
  375. +// DCEVM: Resoring the ciObject arrays after class redefinition
  376. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  377. +
  378. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  379. + oop last = NULL;
  380. + for (int j = 0; j< objects->length(); j++) {
  381. + oop o = objects->at(j)->get_oop();
  382. + if (last >= o) {
  383. + int cur_last_index = j - 1;
  384. + oop cur_last = last;
  385. + while (cur_last >= o) {
  386. +
  387. + // Swap the two objects to guarantee ordering
  388. + ciObject *tmp = objects->at(cur_last_index);
  389. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  390. + objects->at_put(cur_last_index + 1, tmp);
  391. +
  392. + // Decrement index to move one step to the left
  393. + cur_last_index--;
  394. + if (cur_last_index < 0) {
  395. + break;
  396. + }
  397. + cur_last = objects->at(cur_last_index)->get_oop();
  398. + }
  399. + } else {
  400. + assert(last < o, "out of order");
  401. + last = o;
  402. + }
  403. + }
  404. +
  405. +#ifdef ASSERT
  406. + if (CIObjectFactoryVerify) {
  407. + oop last = NULL;
  408. + for (int j = 0; j< objects->length(); j++) {
  409. + oop o = objects->at(j)->get_oop();
  410. + assert(last < o, "out of order");
  411. + last = o;
  412. + }
  413. + }
  414. +#endif // ASSERT
  415. +}
  416. +
  417. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  418. +void ciObjectFactory::cleanup_after_redefinition() {
  419. + sort_ci_objects(_ci_objects);
  420. +}
  421. diff -r 882f6c762ac5 src/share/vm/ci/ciObjectFactory.hpp
  422. --- a/src/share/vm/ci/ciObjectFactory.hpp Thu Jul 09 23:10:04 2015 -0700
  423. +++ b/src/share/vm/ci/ciObjectFactory.hpp Thu Jul 09 23:18:17 2015 -0700
  424. @@ -38,6 +38,7 @@
  425. class ciObjectFactory : public ResourceObj {
  426. friend class VMStructs;
  427. friend class ciEnv;
  428. + friend class CompileBroker;
  429. private:
  430. static volatile bool _initialized;
  431. @@ -137,6 +138,11 @@
  432. void print_contents();
  433. void print();
  434. +
  435. +private:
  436. +
  437. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  438. + void cleanup_after_redefinition();
  439. };
  440. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  441. diff -r 882f6c762ac5 src/share/vm/classfile/classFileParser.cpp
  442. --- a/src/share/vm/classfile/classFileParser.cpp Thu Jul 09 23:10:04 2015 -0700
  443. +++ b/src/share/vm/classfile/classFileParser.cpp Thu Jul 09 23:18:17 2015 -0700
  444. @@ -795,6 +795,7 @@
  445. Handle class_loader,
  446. Handle protection_domain,
  447. Symbol* class_name,
  448. + KlassHandle old_klass,
  449. TRAPS) {
  450. ClassFileStream* cfs = stream();
  451. assert(length > 0, "only called for length>0");
  452. @@ -813,6 +814,9 @@
  453. interface_index, CHECK_(nullHandle));
  454. if (cp->tag_at(interface_index).is_klass()) {
  455. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  456. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  457. + interf = KlassHandle(THREAD, interf->newest_version());
  458. + }
  459. } else {
  460. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  461. @@ -825,6 +829,9 @@
  462. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  463. unresolved_klass, class_loader, protection_domain,
  464. false, CHECK_(nullHandle));
  465. + if (!old_klass.is_null()) {
  466. + k = k->klass_part()->newest_version();
  467. + }
  468. interf = KlassHandle(THREAD, k);
  469. }
  470. @@ -1923,6 +1930,8 @@
  471. int runtime_invisible_parameter_annotations_length = 0;
  472. u1* annotation_default = NULL;
  473. int annotation_default_length = 0;
  474. + u2 code_section_table_length;
  475. + typeArrayHandle code_section_table;
  476. // Parse code and exceptions attribute
  477. u2 method_attributes_count = cfs->get_u2_fast();
  478. @@ -2092,6 +2101,24 @@
  479. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  480. stackmap_data = typeArrayHandle(THREAD, sm);
  481. parsed_stackmap_attribute = true;
  482. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  483. + int length = code_attribute_length;
  484. + int value_count = length / sizeof(u2);
  485. + int line_count = length / 3;
  486. + if (TraceRedefineClasses >= 3) {
  487. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  488. + }
  489. + code_section_table_length = value_count;
  490. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  491. + code_section_table->set_length(value_count);
  492. +
  493. + for (int i = 0; i < value_count; ++i) {
  494. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  495. + code_section_table->short_at_put(i, value);
  496. + if (TraceRedefineClasses >= 4) {
  497. + tty->print_cr("Code section table at %d: %d", i, value);
  498. + }
  499. + }
  500. } else {
  501. // Skip unknown attributes
  502. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  503. @@ -2216,6 +2243,18 @@
  504. }
  505. #endif
  506. + // DCEVM: TODO: Get a different solution for the problem of method forward
  507. + // points and variable sized interpreter frames.
  508. + if (UseMethodForwardPoints) {
  509. + if (max_stack > MethodForwardPointsMaxStack) {
  510. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  511. + }
  512. + if (max_locals > MethodForwardPointsMaxLocals) {
  513. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  514. + }
  515. + max_stack = MethodForwardPointsMaxStack;
  516. + max_locals = MethodForwardPointsMaxLocals;
  517. + }
  518. // Fill in code attribute information
  519. m->set_max_stack(max_stack);
  520. m->set_max_locals(max_locals);
  521. @@ -2229,6 +2268,8 @@
  522. */
  523. m->constMethod()->set_stackmap_data(stackmap_data());
  524. + m->constMethod()->set_code_section_table(code_section_table());
  525. +
  526. // Copy byte codes
  527. m->set_code(code_start);
  528. @@ -2825,6 +2866,15 @@
  529. "Invalid Deprecated classfile attribute length %u in class file %s",
  530. attribute_length, CHECK);
  531. }
  532. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  533. + // DCEVM: Check for deleted field attribute
  534. + _field_redefinition_policy = cfs->get_u1_fast();
  535. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  536. + // DCEVM: Check for deleted static field attribute
  537. + _static_field_redefinition_policy = cfs->get_u1_fast();
  538. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  539. + // DCEVM: Check for deleted method attribute
  540. + _method_redefinition_policy = cfs->get_u1_fast();
  541. } else if (_major_version >= JAVA_1_5_VERSION) {
  542. if (tag == vmSymbols::tag_signature()) {
  543. if (attribute_length != 2) {
  544. @@ -2929,6 +2979,17 @@
  545. }
  546. k->set_inner_classes(_inner_classes());
  547. k->set_class_annotations(_annotations());
  548. +
  549. +
  550. + if (_field_redefinition_policy != 0xff) {
  551. + k->set_field_redefinition_policy(_field_redefinition_policy);
  552. + }
  553. + if (_static_field_redefinition_policy != 0xff) {
  554. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  555. + }
  556. + if (_method_redefinition_policy != 0xff) {
  557. + k->set_method_redefinition_policy(_method_redefinition_policy);
  558. + }
  559. }
  560. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  561. @@ -2952,9 +3013,126 @@
  562. }
  563. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  564. +// them in a growable array.
  565. +void ClassFileParser::findSuperSymbols(Symbol* name,
  566. + Handle class_loader,
  567. + Handle protection_domain,
  568. + KlassHandle old_klass,
  569. + GrowableArray<Symbol*> &handles,
  570. + TRAPS) {
  571. +
  572. + _cp_patches = NULL;
  573. + // So that JVMTI can cache class file in the state before retransformable agents
  574. + // have modified it
  575. + unsigned char *cached_class_file_bytes = NULL;
  576. +
  577. + ClassFileStream* cfs = stream();
  578. +
  579. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  580. +
  581. + instanceKlassHandle nullHandle;
  582. +
  583. + // Save the class file name for easier error message printing.
  584. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  585. +
  586. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  587. + // Magic value
  588. + u4 magic = cfs->get_u4_fast();
  589. + if (magic != JAVA_CLASSFILE_MAGIC) {
  590. + // Invalid class file!
  591. + return;
  592. + }
  593. +
  594. + // Version numbers
  595. + u2 minor_version = cfs->get_u2_fast();
  596. + u2 major_version = cfs->get_u2_fast();
  597. +
  598. + // Check version numbers - we check this even with verifier off
  599. + if (!is_supported_version(major_version, minor_version)) {
  600. +
  601. + // Unsupported version!
  602. + return;
  603. + }
  604. +
  605. + _major_version = major_version;
  606. + _minor_version = minor_version;
  607. +
  608. +
  609. + // Check if verification needs to be relaxed for this class file
  610. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  611. + _relax_verify = Verifier::relax_verify_for(class_loader());
  612. + _need_verify = false;
  613. +
  614. + // Constant pool
  615. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  616. + int cp_size = cp->length();
  617. +
  618. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  619. +
  620. + // Access flags
  621. + AccessFlags access_flags;
  622. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  623. +
  624. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  625. + // Set abstract bit for old class files for backward compatibility
  626. + flags |= JVM_ACC_ABSTRACT;
  627. + }
  628. + access_flags.set_flags(flags);
  629. +
  630. + // This class and superclass
  631. + instanceKlassHandle super_klass;
  632. + u2 this_class_index = cfs->get_u2_fast();
  633. + check_property(
  634. + valid_cp_range(this_class_index, cp_size) &&
  635. + cp->tag_at(this_class_index).is_unresolved_klass(),
  636. + "Invalid this class index %u in constant pool in class file %s",
  637. + this_class_index, CHECK);
  638. +
  639. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  640. + assert(class_name != NULL, "class_name can't be null");
  641. +
  642. + // Update _class_name which could be null previously to be class_name
  643. + _class_name = class_name;
  644. +
  645. + // DCEVM: DO NOT release all handles when parsing is done
  646. + {// HandleMark hm(THREAD);
  647. +
  648. + // Checks if name in class file matches requested name
  649. + if (name != NULL && class_name != name) {
  650. + return;
  651. + }
  652. +
  653. + u2 super_class_index = cfs->get_u2_fast();
  654. +
  655. + if (super_class_index != 0) {
  656. + Symbol* super_class = cp->klass_name_at(super_class_index);
  657. + handles.append(super_class);
  658. + } else {
  659. + // DCEVM: This redefinition must be for the Object class.
  660. + }
  661. +
  662. + // Interfaces
  663. + u2 itfs_len = cfs->get_u2_fast();
  664. + objArrayHandle local_interfaces;
  665. + if (itfs_len == 0) {
  666. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  667. + } else {
  668. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  669. + }
  670. +
  671. + for (int i=0; i<local_interfaces->length(); i++) {
  672. + oop o = local_interfaces->obj_at(i);
  673. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  674. + handles.append(interface_handle);
  675. + }
  676. + }
  677. +}
  678. +
  679. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  680. Handle class_loader,
  681. Handle protection_domain,
  682. + KlassHandle old_klass,
  683. KlassHandle host_klass,
  684. GrowableArray<Handle>* cp_patches,
  685. TempNewSymbol& parsed_name,
  686. @@ -3005,10 +3183,13 @@
  687. unsigned char* ptr = cfs->buffer();
  688. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  689. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  690. + Thread::current()->set_pretend_new_universe(false);
  691. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  692. &ptr, &end_ptr,
  693. &cached_class_file_bytes,
  694. &cached_class_file_length);
  695. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  696. if (ptr != cfs->buffer()) {
  697. // JVMTI agent has modified class file data.
  698. @@ -3164,7 +3345,11 @@
  699. // However, make sure it is not an array type.
  700. bool is_array = false;
  701. if (cp->tag_at(super_class_index).is_klass()) {
  702. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  703. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  704. + if (!old_klass.is_null()) {
  705. + resolved_klass = resolved_klass->klass_part()->newest_version();
  706. + }
  707. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  708. if (_need_verify)
  709. is_array = super_klass->oop_is_array();
  710. } else if (_need_verify) {
  711. @@ -3182,7 +3367,7 @@
  712. if (itfs_len == 0) {
  713. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  714. } else {
  715. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  716. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  717. }
  718. u2 java_fields_count = 0;
  719. @@ -3237,7 +3422,9 @@
  720. protection_domain,
  721. true,
  722. CHECK_(nullHandle));
  723. -
  724. + if (!old_klass.is_null()) {
  725. + k = k->klass_part()->newest_version();
  726. + }
  727. KlassHandle kh (THREAD, k);
  728. super_klass = instanceKlassHandle(THREAD, kh());
  729. }
  730. @@ -3626,6 +3813,19 @@
  731. rt = REF_NONE;
  732. } else {
  733. rt = super_klass->reference_type();
  734. +
  735. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  736. + if (name == vmSymbols::java_lang_ref_Reference()) {
  737. + rt = REF_OTHER;
  738. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  739. + rt = REF_SOFT;
  740. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  741. + rt = REF_WEAK;
  742. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  743. + rt = REF_FINAL;
  744. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  745. + rt = REF_PHANTOM;
  746. + }
  747. }
  748. // We can now create the basic klassOop for this klass
  749. @@ -3726,7 +3926,7 @@
  750. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  751. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  752. - set_precomputed_flags(this_klass);
  753. + set_precomputed_flags(this_klass, old_klass);
  754. // reinitialize modifiers, using the InnerClasses attribute
  755. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  756. @@ -3749,6 +3949,10 @@
  757. // Allocate mirror and initialize static fields
  758. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  759. + if (rt == REF_OTHER) {
  760. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  761. + }
  762. +
  763. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  764. false /* not shared class */);
  765. @@ -3891,7 +4095,7 @@
  766. }
  767. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  768. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  769. klassOop super = k->super();
  770. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  771. @@ -3899,7 +4103,9 @@
  772. if (!_has_empty_finalizer) {
  773. if (_has_finalizer ||
  774. (super != NULL && super->klass_part()->has_finalizer())) {
  775. - k->set_has_finalizer();
  776. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  777. + k->set_has_finalizer();
  778. + }
  779. }
  780. }
  781. @@ -3915,7 +4121,7 @@
  782. // Check if this klass supports the java.lang.Cloneable interface
  783. if (SystemDictionary::Cloneable_klass_loaded()) {
  784. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  785. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  786. k->set_is_cloneable();
  787. }
  788. }
  789. diff -r 882f6c762ac5 src/share/vm/classfile/classFileParser.hpp
  790. --- a/src/share/vm/classfile/classFileParser.hpp Thu Jul 09 23:10:04 2015 -0700
  791. +++ b/src/share/vm/classfile/classFileParser.hpp Thu Jul 09 23:18:17 2015 -0700
  792. @@ -64,6 +64,9 @@
  793. int _sde_length;
  794. typeArrayHandle _inner_classes;
  795. typeArrayHandle _annotations;
  796. + u1 _field_redefinition_policy;
  797. + u1 _static_field_redefinition_policy;
  798. + u1 _method_redefinition_policy;
  799. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  800. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  801. @@ -151,6 +154,7 @@
  802. Handle class_loader,
  803. Handle protection_domain,
  804. Symbol* class_name,
  805. + KlassHandle old_klass,
  806. TRAPS);
  807. // Field parsing
  808. @@ -239,7 +243,7 @@
  809. unsigned int nonstatic_oop_map_count,
  810. int* nonstatic_oop_offsets,
  811. unsigned int* nonstatic_oop_counts);
  812. - void set_precomputed_flags(instanceKlassHandle k);
  813. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  814. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  815. objArrayHandle local_ifs, TRAPS);
  816. @@ -345,7 +349,12 @@
  817. public:
  818. // Constructor
  819. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  820. + ClassFileParser(ClassFileStream* st) {
  821. + set_stream(st);
  822. + _field_redefinition_policy = 0xff;
  823. + _static_field_redefinition_policy = 0xff;
  824. + _method_redefinition_policy = 0xff;
  825. + }
  826. // Parse .class file and return new klassOop. The klassOop is not hooked up
  827. // to the system dictionary or any other structures, so a .class file can
  828. @@ -357,21 +366,33 @@
  829. instanceKlassHandle parseClassFile(Symbol* name,
  830. Handle class_loader,
  831. Handle protection_domain,
  832. + KlassHandle old_klass,
  833. TempNewSymbol& parsed_name,
  834. bool verify,
  835. TRAPS) {
  836. KlassHandle no_host_klass;
  837. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  838. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  839. }
  840. instanceKlassHandle parseClassFile(Symbol* name,
  841. Handle class_loader,
  842. Handle protection_domain,
  843. + KlassHandle old_klass,
  844. KlassHandle host_klass,
  845. GrowableArray<Handle>* cp_patches,
  846. TempNewSymbol& parsed_name,
  847. bool verify,
  848. TRAPS);
  849. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  850. +
  851. + // DCEVM: Creates symbol handles for the super class and the interfaces
  852. + void findSuperSymbols(Symbol* name,
  853. + Handle class_loader,
  854. + Handle protection_domain,
  855. + KlassHandle old_klass,
  856. + GrowableArray<Symbol*> &handles,
  857. + TRAPS);
  858. +
  859. // Verifier checks
  860. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  861. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  862. diff -r 882f6c762ac5 src/share/vm/classfile/classLoader.cpp
  863. --- a/src/share/vm/classfile/classLoader.cpp Thu Jul 09 23:10:04 2015 -0700
  864. +++ b/src/share/vm/classfile/classLoader.cpp Thu Jul 09 23:18:17 2015 -0700
  865. @@ -915,6 +915,7 @@
  866. instanceKlassHandle result = parser.parseClassFile(h_name,
  867. class_loader,
  868. protection_domain,
  869. + KlassHandle(),
  870. parsed_name,
  871. false,
  872. CHECK_(h));
  873. diff -r 882f6c762ac5 src/share/vm/classfile/dictionary.cpp
  874. --- a/src/share/vm/classfile/dictionary.cpp Thu Jul 09 23:10:04 2015 -0700
  875. +++ b/src/share/vm/classfile/dictionary.cpp Thu Jul 09 23:18:17 2015 -0700
  876. @@ -326,6 +326,21 @@
  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 @@
  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 @@
  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 @@
  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 @@
  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 -r 882f6c762ac5 src/share/vm/classfile/dictionary.hpp
  964. --- a/src/share/vm/classfile/dictionary.hpp Thu Jul 09 23:10:04 2015 -0700
  965. +++ b/src/share/vm/classfile/dictionary.hpp Thu Jul 09 23:18:17 2015 -0700
  966. @@ -73,6 +73,10 @@
  967. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  968. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  969. +
  970. + void rollback_redefinition();
  971. +
  972. klassOop find_class(int index, unsigned int hash,
  973. Symbol* name, Handle loader);
  974. @@ -89,6 +93,7 @@
  975. void classes_do(void f(klassOop, TRAPS), TRAPS);
  976. void classes_do(void f(klassOop, oop));
  977. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  978. + void classes_do(ObjectClosure *closure);
  979. void methods_do(void f(methodOop));
  980. @@ -105,6 +110,7 @@
  981. bool do_unloading(BoolObjectClosure* is_alive);
  982. // Protection domains
  983. + static klassOop intercept_for_version(klassOop k);
  984. klassOop find(int index, unsigned int hash, Symbol* name,
  985. Handle loader, Handle protection_domain, TRAPS);
  986. bool is_valid_protection_domain(int index, unsigned int hash,
  987. diff -r 882f6c762ac5 src/share/vm/classfile/javaClasses.cpp
  988. --- a/src/share/vm/classfile/javaClasses.cpp Thu Jul 09 23:10:04 2015 -0700
  989. +++ b/src/share/vm/classfile/javaClasses.cpp Thu Jul 09 23:18:17 2015 -0700
  990. @@ -1798,7 +1798,7 @@
  991. klassOop klass = SystemDictionary::reflect_Method_klass();
  992. // This class is eagerly initialized during VM initialization, since we keep a refence
  993. // to one of the methods
  994. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  995. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  996. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  997. }
  998. diff -r 882f6c762ac5 src/share/vm/classfile/javaClasses.hpp
  999. --- a/src/share/vm/classfile/javaClasses.hpp Thu Jul 09 23:10:04 2015 -0700
  1000. +++ b/src/share/vm/classfile/javaClasses.hpp Thu Jul 09 23:18:17 2015 -0700
  1001. @@ -213,7 +213,6 @@
  1002. class java_lang_Class : AllStatic {
  1003. friend class VMStructs;
  1004. -
  1005. private:
  1006. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1007. diff -r 882f6c762ac5 src/share/vm/classfile/loaderConstraints.cpp
  1008. --- a/src/share/vm/classfile/loaderConstraints.cpp Thu Jul 09 23:10:04 2015 -0700
  1009. +++ b/src/share/vm/classfile/loaderConstraints.cpp Thu Jul 09 23:18:17 2015 -0700
  1010. @@ -449,7 +449,7 @@
  1011. if (k != NULL) {
  1012. // We found the class in the system dictionary, so we should
  1013. // make sure that the klassOop matches what we already have.
  1014. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1015. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1016. } else {
  1017. // If we don't find the class in the system dictionary, it
  1018. // has to be in the placeholders table.
  1019. diff -r 882f6c762ac5 src/share/vm/classfile/loaderConstraints.hpp
  1020. --- a/src/share/vm/classfile/loaderConstraints.hpp Thu Jul 09 23:10:04 2015 -0700
  1021. +++ b/src/share/vm/classfile/loaderConstraints.hpp Thu Jul 09 23:18:17 2015 -0700
  1022. @@ -106,7 +106,7 @@
  1023. klassOop klass() { return literal(); }
  1024. klassOop* klass_addr() { return literal_addr(); }
  1025. - void set_klass(klassOop k) { set_literal(k); }
  1026. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1027. LoaderConstraintEntry* next() {
  1028. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1029. diff -r 882f6c762ac5 src/share/vm/classfile/systemDictionary.cpp
  1030. --- a/src/share/vm/classfile/systemDictionary.cpp Thu Jul 09 23:10:04 2015 -0700
  1031. +++ b/src/share/vm/classfile/systemDictionary.cpp Thu Jul 09 23:18:17 2015 -0700
  1032. @@ -157,6 +157,7 @@
  1033. // can return a null klass
  1034. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1035. }
  1036. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1037. return klass;
  1038. }
  1039. @@ -199,7 +200,8 @@
  1040. // Forwards to resolve_instance_class_or_null
  1041. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1042. - assert(!THREAD->is_Compiler_thread(),
  1043. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1044. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1045. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1046. class_name->as_C_string(),
  1047. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1048. @@ -961,6 +963,7 @@
  1049. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1050. class_loader,
  1051. protection_domain,
  1052. + KlassHandle(),
  1053. host_klass,
  1054. cp_patches,
  1055. parsed_name,
  1056. @@ -1022,7 +1025,14 @@
  1057. Handle protection_domain,
  1058. ClassFileStream* st,
  1059. bool verify,
  1060. + KlassHandle old_class,
  1061. TRAPS) {
  1062. + bool redefine_classes_locked = false;
  1063. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1064. + Thread::current()->redefine_classes_mutex()->lock();
  1065. + redefine_classes_locked = true;
  1066. + }
  1067. +
  1068. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1069. // or all classloaders with UnsyncloadClass do not acquire lock here
  1070. bool DoObjectLock = true;
  1071. @@ -1050,9 +1060,14 @@
  1072. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1073. class_loader,
  1074. protection_domain,
  1075. + old_class,
  1076. parsed_name,
  1077. verify,
  1078. THREAD);
  1079. + if (!old_class.is_null() && !k.is_null()) {
  1080. + k->set_redefining(true);
  1081. + k->set_old_version(old_class());
  1082. + }
  1083. const char* pkg = "java/";
  1084. if (!HAS_PENDING_EXCEPTION &&
  1085. @@ -1087,13 +1102,18 @@
  1086. // Add class just loaded
  1087. // If a class loader supports parallel classloading handle parallel define requests
  1088. // find_or_define_instance_class may return a different instanceKlass
  1089. - if (is_parallelCapable(class_loader)) {
  1090. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1091. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1092. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1093. } else {
  1094. - define_instance_class(k, THREAD);
  1095. + define_instance_class(k, old_class, THREAD);
  1096. }
  1097. }
  1098. + if (redefine_classes_locked) {
  1099. + Thread::current()->redefine_classes_mutex()->unlock();
  1100. + }
  1101. +
  1102. // If parsing the class file or define_instance_class failed, we
  1103. // need to remove the placeholder added on our behalf. But we
  1104. // must make sure parsed_name is valid first (it won't be if we had
  1105. @@ -1122,7 +1142,7 @@
  1106. MutexLocker mu(SystemDictionary_lock, THREAD);
  1107. klassOop check = find_class(parsed_name, class_loader);
  1108. - assert(check == k(), "should be present in the dictionary");
  1109. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1110. klassOop check2 = find_class(h_name, h_loader);
  1111. assert(check == check2, "name inconsistancy in SystemDictionary");
  1112. @@ -1349,7 +1369,11 @@
  1113. }
  1114. }
  1115. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1116. +void SystemDictionary::rollback_redefinition() {
  1117. + dictionary()->rollback_redefinition();
  1118. +}
  1119. +
  1120. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1121. Handle class_loader_h(THREAD, k->class_loader());
  1122. @@ -1376,13 +1400,23 @@
  1123. Symbol* name_h = k->name();
  1124. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1125. int d_index = dictionary()->hash_to_index(d_hash);
  1126. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1127. +
  1128. + // DCEVM: Update version of the klassOop in the system dictionary
  1129. + // TODO: Check for thread safety!
  1130. + if (!old_class.is_null()) {
  1131. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1132. + assert (ok, "must have found old class and updated!");
  1133. + }
  1134. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1135. +
  1136. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1137. // Register class just loaded with class loader (placed in Vector)
  1138. // Note we do this before updating the dictionary, as this can
  1139. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1140. // class in the dictionary and will not update the class hierarchy).
  1141. - if (k->class_loader() != NULL) {
  1142. + // (tw) Only register if not redefining a class.
  1143. + if (k->class_loader() != NULL && old_class.is_null()) {
  1144. methodHandle m(THREAD, Universe::loader_addClass_method());
  1145. JavaValue result(T_VOID);
  1146. JavaCallArguments args(class_loader_h);
  1147. @@ -1408,8 +1442,9 @@
  1148. }
  1149. k->eager_initialize(THREAD);
  1150. + // (tw) Only notify jvmti if not redefining a class.
  1151. // notify jvmti
  1152. - if (JvmtiExport::should_post_class_load()) {
  1153. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1154. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1155. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1156. @@ -1482,7 +1517,7 @@
  1157. }
  1158. }
  1159. - define_instance_class(k, THREAD);
  1160. + define_instance_class(k, KlassHandle(), THREAD);
  1161. Handle linkage_exception = Handle(); // null handle
  1162. @@ -1613,6 +1648,14 @@
  1163. Universe::flush_dependents_on(k);
  1164. }
  1165. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1166. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1167. + assert(k.not_null(), "just checking");
  1168. +
  1169. + k->remove_from_sibling_list();
  1170. +
  1171. + // TODO: Remove from interfaces.
  1172. +}
  1173. // ----------------------------------------------------------------------------
  1174. // GC support
  1175. @@ -1702,7 +1745,8 @@
  1176. }
  1177. -void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1178. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1179. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1180. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1181. f->do_oop((oop*) &_well_known_klasses[k]);
  1182. }
  1183. @@ -1716,6 +1760,23 @@
  1184. }
  1185. }
  1186. + // TODO: Check if we need to call FilterFieldsMap
  1187. +}
  1188. +
  1189. +void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1190. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1191. + f->do_oop((oop*) &_well_known_klasses[k]);
  1192. + }
  1193. +
  1194. + {
  1195. + for (int i = 0; i < T_VOID+1; i++) {
  1196. + if (_box_klasses[i] != NULL) {
  1197. + assert(i >= T_BOOLEAN, "checking");
  1198. + f->do_oop((oop*) &_box_klasses[i]);
  1199. + }
  1200. + }
  1201. + }
  1202. +
  1203. // The basic type mirrors would have already been processed in
  1204. // Universe::oops_do(), via a call to shared_oops_do(), so should
  1205. // not be processed again.
  1206. @@ -1734,6 +1795,11 @@
  1207. dictionary()->classes_do(f);
  1208. }
  1209. +// (tw) Iterate over all classes in the dictionary.
  1210. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1211. + dictionary()->classes_do(closure);
  1212. +}
  1213. +
  1214. // Added for initialize_itable_for_klass
  1215. // Just the classes from defining class loaders
  1216. // Don't iterate over placeholders
  1217. @@ -1870,7 +1936,9 @@
  1218. // Preload ref klasses and set reference types
  1219. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1220. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1221. +
  1222. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1223. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1224. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
  1225. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1226. @@ -1957,7 +2025,11 @@
  1227. // also holds array classes
  1228. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1229. - if ((defining == true) || (k() != check)) {
  1230. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1231. + ResourceMark rm(Thread::current());
  1232. + 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());
  1233. + k()->print();
  1234. + check->print();
  1235. linkage_error = "loader (instance of %s): attempted duplicate class "
  1236. "definition for name: \"%s\"";
  1237. } else {
  1238. diff -r 882f6c762ac5 src/share/vm/classfile/systemDictionary.hpp
  1239. --- a/src/share/vm/classfile/systemDictionary.hpp Thu Jul 09 23:10:04 2015 -0700
  1240. +++ b/src/share/vm/classfile/systemDictionary.hpp Thu Jul 09 23:18:17 2015 -0700
  1241. @@ -270,7 +270,7 @@
  1242. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1243. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1244. Handle protection_domain,
  1245. - ClassFileStream* st, bool verify, TRAPS);
  1246. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1247. // Lookup an already loaded class. If not found NULL is returned.
  1248. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1249. @@ -311,6 +311,8 @@
  1250. // Iterate over all klasses in dictionary
  1251. // Just the classes from defining class loaders
  1252. static void classes_do(void f(klassOop));
  1253. + static void classes_do(ObjectClosure *closure);
  1254. + static void preloaded_classes_do(OopClosure *closure);
  1255. // Added for initialize_itable_for_klass to handle exceptions
  1256. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1257. // All classes, and their class loaders
  1258. @@ -417,6 +419,8 @@
  1259. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1260. }
  1261. + static void rollback_redefinition();
  1262. +
  1263. public:
  1264. #define WK_KLASS_DECLARE(name, symbol, option) \
  1265. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1266. @@ -598,11 +602,11 @@
  1267. // after waiting, but before reentering SystemDictionary_lock
  1268. // to preserve lock order semantics.
  1269. static void double_lock_wait(Handle lockObject, TRAPS);
  1270. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1271. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1272. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1273. Handle class_loader,
  1274. instanceKlassHandle k, TRAPS);
  1275. - static instanceKlassHandle load_shared_class(Symbol* class_name,
  1276. + static instanceKlassHandle load_shared_class(Symbol* class_name, // after waiting, but before reentering SystemDictionary_lock,
  1277. Handle class_loader, TRAPS);
  1278. static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
  1279. Handle class_loader, TRAPS);
  1280. @@ -617,12 +621,16 @@
  1281. // Setup link to hierarchy
  1282. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1283. +public:
  1284. + // Remove link to hierarchy
  1285. + static void remove_from_hierarchy(instanceKlassHandle k);
  1286. +
  1287. +private:
  1288. // event based tracing
  1289. static void post_class_load_event(const Ticks& start_time, instanceKlassHandle k,
  1290. Handle initiating_loader);
  1291. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1292. -private:
  1293. // We pass in the hashtable index so we can calculate it outside of
  1294. // the SystemDictionary_lock.
  1295. diff -r 882f6c762ac5 src/share/vm/classfile/verifier.cpp
  1296. --- a/src/share/vm/classfile/verifier.cpp Thu Jul 09 23:10:04 2015 -0700
  1297. +++ b/src/share/vm/classfile/verifier.cpp Thu Jul 09 23:18:17 2015 -0700
  1298. @@ -106,7 +106,7 @@
  1299. return !need_verify;
  1300. }
  1301. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1302. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1303. HandleMark hm;
  1304. ResourceMark rm(THREAD);
  1305. @@ -117,7 +117,8 @@
  1306. const char* klassName = klass->external_name();
  1307. bool can_failover = FailOverToOldVerifier &&
  1308. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1309. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1310. + may_use_old_verifier;
  1311. // If the class should be verified, first see if we can use the split
  1312. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1313. @@ -138,6 +139,7 @@
  1314. tty->print_cr(
  1315. "Fail over class verification to old verifier for: %s", klassName);
  1316. }
  1317. + assert(may_use_old_verifier, "");
  1318. exception_name = inference_verify(
  1319. klass, message_buffer, message_buffer_len, THREAD);
  1320. }
  1321. @@ -145,6 +147,7 @@
  1322. exception_message = split_verifier.exception_message();
  1323. }
  1324. } else {
  1325. + assert(may_use_old_verifier, "");
  1326. exception_name = inference_verify(
  1327. klass, message_buffer, message_buffer_len, THREAD);
  1328. }
  1329. @@ -159,6 +162,9 @@
  1330. }
  1331. tty->print_cr("End class verification for: %s", klassName);
  1332. }
  1333. + } else if (TraceClassInitialization) {
  1334. + // (tw) Output not verified classes
  1335. + tty->print_cr("Class %s was not verified", klassName);
  1336. }
  1337. if (HAS_PENDING_EXCEPTION) {
  1338. @@ -210,7 +216,7 @@
  1339. // NOTE: this is called too early in the bootstrapping process to be
  1340. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1341. (refl_magic_klass == NULL ||
  1342. - !klass->is_subtype_of(refl_magic_klass) ||
  1343. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1344. VerifyReflectionBytecodes)
  1345. );
  1346. }
  1347. @@ -517,7 +523,7 @@
  1348. ClassVerifier::ClassVerifier(
  1349. instanceKlassHandle klass, TRAPS)
  1350. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1351. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1352. _this_type = VerificationType::reference_type(klass->name());
  1353. // Create list to hold symbols in reference area.
  1354. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1355. @@ -547,7 +553,7 @@
  1356. _klass->external_name());
  1357. }
  1358. - objArrayHandle methods(THREAD, _klass->methods());
  1359. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1360. int num_methods = methods->length();
  1361. for (int index = 0; index < num_methods; index++) {
  1362. @@ -2668,7 +2674,10 @@
  1363. VerificationType stack_object_type =
  1364. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1365. if (current_type() != stack_object_type) {
  1366. - assert(cp->cache() == NULL, "not rewritten yet");
  1367. +
  1368. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1369. + //assert(cp->cache() == NULL, "not rewritten yet");
  1370. +
  1371. Symbol* ref_class_name =
  1372. cp->klass_name_at(cp->klass_ref_index_at(index));
  1373. // See the comments in verify_field_instructions() for
  1374. diff -r 882f6c762ac5 src/share/vm/classfile/verifier.hpp
  1375. --- a/src/share/vm/classfile/verifier.hpp Thu Jul 09 23:10:04 2015 -0700
  1376. +++ b/src/share/vm/classfile/verifier.hpp Thu Jul 09 23:18:17 2015 -0700
  1377. @@ -48,7 +48,7 @@
  1378. * Otherwise, no exception is thrown and the return indicates the
  1379. * error.
  1380. */
  1381. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1382. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1383. // Return false if the class is loaded by the bootstrap loader,
  1384. // or if defineClass was called requesting skipping verification
  1385. @@ -257,7 +257,10 @@
  1386. ErrorContext _error_context; // contains information about an error
  1387. +public:
  1388. void verify_method(methodHandle method, TRAPS);
  1389. +
  1390. +private:
  1391. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1392. void verify_exception_handler_table(u4 code_length, char* code_data,
  1393. int& min, int& max, TRAPS);
  1394. @@ -341,6 +344,7 @@
  1395. VerificationType object_type() const;
  1396. + instanceKlassHandle _klass_to_verify;
  1397. instanceKlassHandle _klass; // the class being verified
  1398. methodHandle _method; // current method being verified
  1399. VerificationType _this_type; // the verification type of the current class
  1400. diff -r 882f6c762ac5 src/share/vm/classfile/vmSymbols.hpp
  1401. --- a/src/share/vm/classfile/vmSymbols.hpp Thu Jul 09 23:10:04 2015 -0700
  1402. +++ b/src/share/vm/classfile/vmSymbols.hpp Thu Jul 09 23:18:17 2015 -0700
  1403. @@ -139,6 +139,10 @@
  1404. template(tag_annotation_default, "AnnotationDefault") \
  1405. template(tag_enclosing_method, "EnclosingMethod") \
  1406. template(tag_bootstrap_methods, "BootstrapMethods") \
  1407. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1408. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1409. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1410. + template(tag_code_sections, "CodeSections") \
  1411. \
  1412. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1413. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1414. @@ -380,6 +384,10 @@
  1415. template(oop_size_name, "oop_size") \
  1416. template(static_oop_field_count_name, "static_oop_field_count") \
  1417. \
  1418. + /* mutator in case of class redefinition */ \
  1419. + template(static_transformer_name, "$staticTransformer") \
  1420. + template(transformer_name, "$transformer") \
  1421. + \
  1422. /* non-intrinsic name/signature pairs: */ \
  1423. template(register_method_name, "register") \
  1424. do_alias(register_method_signature, object_void_signature) \
  1425. diff -r 882f6c762ac5 src/share/vm/compiler/compileBroker.cpp
  1426. --- a/src/share/vm/compiler/compileBroker.cpp Thu Jul 09 23:10:04 2015 -0700
  1427. +++ b/src/share/vm/compiler/compileBroker.cpp Thu Jul 09 23:18:17 2015 -0700
  1428. @@ -1181,6 +1181,14 @@
  1429. int comp_level,
  1430. methodHandle hot_method, int hot_count,
  1431. const char* comment, Thread* THREAD) {
  1432. + JavaThread* thread = JavaThread::current();
  1433. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1434. + return NULL; // FIXME: DCEVM: should we do something else?
  1435. + }
  1436. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1437. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1438. + }
  1439. +
  1440. // make sure arguments make sense
  1441. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1442. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1443. @@ -1260,6 +1268,7 @@
  1444. }
  1445. // RedefineClasses() has replaced this method; just return
  1446. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1447. if (method->is_old()) {
  1448. return NULL;
  1449. }
  1450. @@ -1592,6 +1601,8 @@
  1451. // Never compile a method if breakpoints are present in it
  1452. if (method()->number_of_breakpoints() == 0) {
  1453. + thread->compilation_mutex()->lock();
  1454. + thread->set_should_bailout(false);
  1455. // Compile the method.
  1456. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1457. #ifdef COMPILER1
  1458. @@ -1615,6 +1626,7 @@
  1459. // After compilation is disabled, remove remaining methods from queue
  1460. method->clear_queued_for_compilation();
  1461. }
  1462. + thread->compilation_mutex()->unlock();
  1463. }
  1464. }
  1465. }
  1466. @@ -2165,3 +2177,15 @@
  1467. st->cr();
  1468. #endif
  1469. }
  1470. +
  1471. +// (tw) Clean up compiler interface after a class redefinition step
  1472. +void CompileBroker::cleanup_after_redefinition() {
  1473. + int num_threads = _method_threads->length();
  1474. +
  1475. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1476. + for (int i=0; i<num_threads; i++) {
  1477. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1478. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1479. + }
  1480. + }
  1481. +}
  1482. diff -r 882f6c762ac5 src/share/vm/compiler/compileBroker.hpp
  1483. --- a/src/share/vm/compiler/compileBroker.hpp Thu Jul 09 23:10:04 2015 -0700
  1484. +++ b/src/share/vm/compiler/compileBroker.hpp Thu Jul 09 23:18:17 2015 -0700
  1485. @@ -408,6 +408,7 @@
  1486. static void print_compiler_threads_on(outputStream* st);
  1487. + static void cleanup_after_redefinition();
  1488. static int get_total_compile_count() { return _total_compile_count; }
  1489. static int get_total_bailout_count() { return _total_bailout_count; }
  1490. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1491. diff -r 882f6c762ac5 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1492. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Thu Jul 09 23:10:04 2015 -0700
  1493. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Thu Jul 09 23:18:17 2015 -0700
  1494. @@ -162,6 +162,13 @@
  1495. }
  1496. }
  1497. +
  1498. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1499. + CompactPoint* cp, HeapWord* compact_top) {
  1500. + ShouldNotReachHere();
  1501. + return NULL;
  1502. +}
  1503. +
  1504. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1505. // update the block offset table. Removed initialize_threshold call because
  1506. // CFLS does not use a block offset array for contiguous spaces.
  1507. diff -r 882f6c762ac5 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1508. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Thu Jul 09 23:10:04 2015 -0700
  1509. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Thu Jul 09 23:18:17 2015 -0700
  1510. @@ -149,6 +149,7 @@
  1511. // Support for compacting cms
  1512. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1513. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1514. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1515. // Initialization helpers.
  1516. diff -r 882f6c762ac5 src/share/vm/gc_implementation/shared/markSweep.cpp
  1517. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Thu Jul 09 23:10:04 2015 -0700
  1518. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Thu Jul 09 23:18:17 2015 -0700
  1519. @@ -32,6 +32,8 @@
  1520. #include "oops/objArrayKlass.inline.hpp"
  1521. #include "oops/oop.inline.hpp"
  1522. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1523. +
  1524. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1525. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1526. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1527. @@ -357,3 +359,86 @@
  1528. }
  1529. #endif
  1530. +
  1531. +// (tw) Copy the rescued objects to their destination address after compaction.
  1532. +void MarkSweep::copy_rescued_objects_back() {
  1533. +
  1534. + if (_rescued_oops != NULL) {
  1535. +
  1536. + for (int i=0; i<_rescued_oops->length(); i++) {
  1537. + oop rescued_obj = _rescued_oops->at(i);
  1538. +
  1539. + int size = rescued_obj->size();
  1540. + oop new_obj = rescued_obj->forwardee();
  1541. +
  1542. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1543. + MarkSweep::update_fields(rescued_obj, new_obj);
  1544. + } else {
  1545. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1546. + }
  1547. +
  1548. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1549. +
  1550. + new_obj->init_mark();
  1551. + assert(new_obj->is_oop(), "must be a valid oop");
  1552. + }
  1553. + _rescued_oops->clear();
  1554. + _rescued_oops = NULL;
  1555. + }
  1556. +}
  1557. +
  1558. +// (tw) Update instances of a class whose fields changed.
  1559. +void MarkSweep::update_fields(oop q, oop new_location) {
  1560. +
  1561. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1562. +
  1563. + klassOop old_klass_oop = q->klass();
  1564. + klassOop new_klass_oop = q->blueprint()->new_version();
  1565. +
  1566. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1567. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1568. +
  1569. + int size = q->size_given_klass(old_klass);
  1570. + int new_size = q->size_given_klass(new_klass);
  1571. +
  1572. + oop tmp_obj = q;
  1573. +
  1574. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1575. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1576. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1577. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1578. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1579. + }
  1580. + }
  1581. +
  1582. + int *cur = new_klass_oop->klass_part()->update_information();
  1583. +
  1584. + tmp_obj->set_klass_no_check(new_klass_oop);
  1585. +
  1586. + if (cur == NULL) {
  1587. + assert(size == new_size, "just checking");
  1588. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1589. + } else {
  1590. + int destOffset = 0;
  1591. + while (*cur != 0) {
  1592. + if (*cur > 0) {
  1593. + int size = *cur;
  1594. + cur++;
  1595. + int offset = *cur;
  1596. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1597. + destOffset += size;
  1598. + cur++;
  1599. + } else {
  1600. + assert(*cur < 0, "");
  1601. + int skip = -*cur;
  1602. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1603. + destOffset += skip;
  1604. + cur++;
  1605. + }
  1606. + }
  1607. + }
  1608. +
  1609. + if (tmp_obj != q) {
  1610. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1611. + }
  1612. +}
  1613. diff -r 882f6c762ac5 src/share/vm/gc_implementation/shared/markSweep.hpp
  1614. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp Thu Jul 09 23:10:04 2015 -0700
  1615. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp Thu Jul 09 23:18:17 2015 -0700
  1616. @@ -117,8 +117,12 @@
  1617. friend class AdjustPointerClosure;
  1618. friend class KeepAliveClosure;
  1619. friend class VM_MarkSweep;
  1620. + friend class GenMarkSweep;
  1621. friend void marksweep_init();
  1622. +public:
  1623. + static GrowableArray<oop>* _rescued_oops;
  1624. +
  1625. //
  1626. // Vars
  1627. //
  1628. @@ -208,6 +212,8 @@
  1629. template <class T> static inline void mark_and_push(T* p);
  1630. static inline void push_objarray(oop obj, size_t index);
  1631. + static void copy_rescued_objects_back();
  1632. + static void update_fields(oop q, oop new_location);
  1633. static void follow_stack(); // Empty marking stack.
  1634. static void preserve_mark(oop p, markOop mark);
  1635. diff -r 882f6c762ac5 src/share/vm/interpreter/interpreterRuntime.cpp
  1636. --- a/src/share/vm/interpreter/interpreterRuntime.cpp Thu Jul 09 23:10:04 2015 -0700
  1637. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Thu Jul 09 23:18:17 2015 -0700
  1638. @@ -402,7 +402,7 @@
  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. @@ -656,6 +656,82 @@
  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("Transferring 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. @@ -684,6 +760,10 @@
  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 -r 882f6c762ac5 src/share/vm/interpreter/interpreterRuntime.hpp
  1741. --- a/src/share/vm/interpreter/interpreterRuntime.hpp Thu Jul 09 23:10:04 2015 -0700
  1742. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Thu Jul 09 23:18:17 2015 -0700
  1743. @@ -141,6 +141,9 @@
  1744. static void post_method_entry(JavaThread *thread);
  1745. static void post_method_exit (JavaThread *thread);
  1746. static int interpreter_contains(address pc);
  1747. + static void forward_method(JavaThread *thread);
  1748. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1749. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1750. // Native signature handlers
  1751. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1752. diff -r 882f6c762ac5 src/share/vm/interpreter/linkResolver.cpp
  1753. --- a/src/share/vm/interpreter/linkResolver.cpp Thu Jul 09 23:10:04 2015 -0700
  1754. +++ b/src/share/vm/interpreter/linkResolver.cpp Thu Jul 09 23:18:17 2015 -0700
  1755. @@ -153,8 +153,8 @@
  1756. // Klass resolution
  1757. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1758. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1759. - sel_klass->as_klassOop(),
  1760. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1761. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1762. true)) {
  1763. ResourceMark rm(THREAD);
  1764. Exceptions::fthrow(
  1765. @@ -346,7 +346,7 @@
  1766. // We'll check for the method name first, as that's most likely
  1767. // to be false (so we'll short-circuit out of these tests).
  1768. if (sel_method->name() == vmSymbols::clone_name() &&
  1769. - sel_klass() == SystemDictionary::Object_klass() &&
  1770. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1771. resolved_klass->oop_is_array()) {
  1772. // We need to change "protected" to "public".
  1773. assert(flags.is_protected(), "clone not protected?");
  1774. @@ -412,6 +412,154 @@
  1775. }
  1776. }
  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() && !resolved_klass->oop_is_array()) {
  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. + Handle nested_exception;
  1795. +
  1796. + // 2. lookup method in resolved klass and its super klasses
  1797. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1798. +
  1799. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1800. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1801. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1802. +
  1803. + if (resolved_method.is_null()) {
  1804. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1805. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1806. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1807. + if (HAS_PENDING_EXCEPTION) {
  1808. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1809. + CLEAR_PENDING_EXCEPTION;
  1810. + }
  1811. + }
  1812. + }
  1813. + }
  1814. +}
  1815. +
  1816. +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) {
  1817. +
  1818. + // First attempt unversioned
  1819. + sel_klass = KlassHandle(Thread::current(), resolved_klass->find_field(field_name, field_sig, &fd));
  1820. +
  1821. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1822. +
  1823. + // 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).
  1824. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1825. + if (is_static) {
  1826. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1827. + }
  1828. +
  1829. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1830. +
  1831. + if (redefinition_policy != Klass::DynamicCheck) {
  1832. +
  1833. + if (redefinition_policy == Klass::AccessOldMembers) {
  1834. + // Forget looked up fields
  1835. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1836. + }
  1837. +
  1838. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1839. +
  1840. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1841. +
  1842. + // Select correct version for resolved klass.
  1843. + find_correct_resolved_klass(resolved_klass, current_klass);
  1844. +
  1845. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1846. +
  1847. + // FIXME: idubrov
  1848. + //if (sel_klass.is_null()) {
  1849. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1850. + //} else {
  1851. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1852. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1853. + //}
  1854. + }
  1855. + }
  1856. + }
  1857. +}
  1858. +
  1859. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1860. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1861. +
  1862. + // First attempt unversioned
  1863. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1864. +
  1865. + // (tw) Are we in an old method that wants to see a different view on the world?
  1866. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1867. +
  1868. + // 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).
  1869. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1870. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1871. +
  1872. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1873. +
  1874. + // We do not throw the exception
  1875. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1876. + // Forget any new member lookup
  1877. + resolved_method = methodHandle(THREAD, NULL);
  1878. + }
  1879. +
  1880. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1881. +
  1882. + if (resolved_method.is_null()) {
  1883. +
  1884. + // Select correct version for resolved klass.
  1885. + find_correct_resolved_klass(resolved_klass, current_klass);
  1886. +
  1887. + // Now do the lookup in a second attempt with a different resolved klass.
  1888. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1889. +
  1890. + // FIXME: idubrov
  1891. + //IF_TRACE_RC2 {
  1892. + // ResourceMark rm(THREAD);
  1893. + // if (resolved_method.is_null()) {
  1894. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1895. + // } else {
  1896. + // assert(resolved_method->is_old(), "must be old method!");
  1897. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1898. + // }
  1899. + //}
  1900. + }
  1901. + }
  1902. + }
  1903. +
  1904. + if (resolved_method.is_null()) {
  1905. + // no method found
  1906. + ResourceMark rm(THREAD);
  1907. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1908. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1909. + method_name,
  1910. + method_signature));
  1911. + }
  1912. +}
  1913. +
  1914. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1915. + int current_klass_revision = current_klass->revision_number();
  1916. + int resolved_klass_revision = resolved_klass->revision_number();
  1917. + // FIXME: idubrov
  1918. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1919. +
  1920. + while (resolved_klass->revision_number() > current_klass_revision) {
  1921. + assert(resolved_klass->old_version(), "must have old version");
  1922. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1923. + }
  1924. +}
  1925. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1926. Symbol* method_name, Symbol* method_signature,
  1927. KlassHandle current_klass, bool check_access, TRAPS) {
  1928. @@ -424,35 +572,8 @@
  1929. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1930. }
  1931. - Handle nested_exception;
  1932. -
  1933. - // 2. lookup method in resolved klass and its super klasses
  1934. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1935. -
  1936. - if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1937. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1938. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1939. -
  1940. - if (resolved_method.is_null()) {
  1941. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1942. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1943. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1944. - if (HAS_PENDING_EXCEPTION) {
  1945. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1946. - CLEAR_PENDING_EXCEPTION;
  1947. - }
  1948. - }
  1949. - }
  1950. -
  1951. - if (resolved_method.is_null()) {
  1952. - // 4. method lookup failed
  1953. - ResourceMark rm(THREAD);
  1954. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1955. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1956. - method_name,
  1957. - method_signature),
  1958. - nested_exception);
  1959. - }
  1960. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1961. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1962. // 5. check if method is concrete
  1963. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1964. @@ -520,7 +641,10 @@
  1965. }
  1966. // lookup method in this interface or its super, java.lang.Object
  1967. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1968. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1969. +
  1970. +
  1971. +
  1972. if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1973. // lookup method in all the super-interfaces
  1974. @@ -621,9 +745,14 @@
  1975. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1976. }
  1977. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  1978. +
  1979. // Resolve instance field
  1980. fieldDescriptor fd; // find_field initializes fd if found
  1981. - KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
  1982. +
  1983. + KlassHandle sel_klass;
  1984. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  1985. +
  1986. // check if field exists; i.e., if a klass containing the field def has been selected
  1987. if (sel_klass.is_null()){
  1988. ResourceMark rm(THREAD);
  1989. @@ -631,7 +760,6 @@
  1990. }
  1991. // check access
  1992. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  1993. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  1994. // check for errors
  1995. @@ -643,7 +771,7 @@
  1996. }
  1997. // Final fields can only be accessed from its own class.
  1998. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1999. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2000. THROW(vmSymbols::java_lang_IllegalAccessError());
  2001. }
  2002. @@ -848,7 +976,7 @@
  2003. bool check_access, bool check_null_and_abstract, TRAPS) {
  2004. methodHandle resolved_method;
  2005. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2006. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2007. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2008. }
  2009. // throws linktime exceptions
  2010. @@ -878,6 +1006,7 @@
  2011. KlassHandle resolved_klass,
  2012. Handle recv,
  2013. KlassHandle recv_klass,
  2014. + KlassHandle current_klass,
  2015. bool check_null_and_abstract,
  2016. TRAPS) {
  2017. @@ -926,10 +1055,44 @@
  2018. // recv_klass might be an arrayKlassOop but all vtables start at
  2019. // the same place. The cast is to avoid virtual call and assertion.
  2020. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2021. - selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2022. +
  2023. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2024. + // have anything in common, as the receiver type could've been hotswapped.
  2025. + // Does not always work (method could be resolved with correct dynamic type and later
  2026. + // be called at the same place with a wrong dynamic type).
  2027. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2028. +
  2029. + // The vTable must be based on the view of the world of the resolved method
  2030. + klassOop method_holder = resolved_method->method_holder();
  2031. +
  2032. + if (method_holder->klass_part()->new_version() != NULL) {
  2033. + // We are executing in old code
  2034. + // FIXME: idubrov
  2035. + //TRACE_RC2("Calling a method in old code");
  2036. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2037. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2038. + }
  2039. + }
  2040. +
  2041. + if (inst->is_subtype_of(method_holder)) {
  2042. + selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2043. + } else {
  2044. +
  2045. + tty->print_cr("Failure:");
  2046. + inst->as_klassOop()->print();
  2047. + inst->super()->print();
  2048. + juint off = inst->super_check_offset();
  2049. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2050. + sup->print();
  2051. + method_holder->print();
  2052. +
  2053. + bool b = inst->is_subtype_of(method_holder);
  2054. + 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!");
  2055. + }
  2056. }
  2057. }
  2058. +
  2059. // check if method exists
  2060. if (selected_method.is_null()) {
  2061. ResourceMark rm(THREAD);
  2062. diff -r 882f6c762ac5 src/share/vm/interpreter/linkResolver.hpp
  2063. --- a/src/share/vm/interpreter/linkResolver.hpp Thu Jul 09 23:10:04 2015 -0700
  2064. +++ b/src/share/vm/interpreter/linkResolver.hpp Thu Jul 09 23:18:17 2015 -0700
  2065. @@ -110,7 +110,11 @@
  2066. // It does all necessary link-time checks & throws exceptions if necessary.
  2067. class LinkResolver: AllStatic {
  2068. - private:
  2069. +private:
  2070. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2071. + 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);
  2072. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2073. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2074. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2075. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2076. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2077. @@ -133,7 +137,7 @@
  2078. 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);
  2079. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2080. - 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);
  2081. + 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);
  2082. 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);
  2083. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2084. diff -r 882f6c762ac5 src/share/vm/interpreter/templateTable.hpp
  2085. --- a/src/share/vm/interpreter/templateTable.hpp Thu Jul 09 23:10:04 2015 -0700
  2086. +++ b/src/share/vm/interpreter/templateTable.hpp Thu Jul 09 23:18:17 2015 -0700
  2087. @@ -329,8 +329,8 @@
  2088. static void shouldnotreachhere();
  2089. // jvmti support
  2090. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2091. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2092. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2093. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2094. static void jvmti_post_fast_field_mod();
  2095. // debugging of TemplateGenerator
  2096. diff -r 882f6c762ac5 src/share/vm/memory/genMarkSweep.cpp
  2097. --- a/src/share/vm/memory/genMarkSweep.cpp Thu Jul 09 23:10:04 2015 -0700
  2098. +++ b/src/share/vm/memory/genMarkSweep.cpp Thu Jul 09 23:18:17 2015 -0700
  2099. @@ -421,6 +421,7 @@
  2100. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2101. // here (perm_gen first rather than last), so we tell the validate code
  2102. // to use a higher index (saved from phase2) when verifying perm_gen.
  2103. + assert(_rescued_oops == NULL, "must be empty before processing");
  2104. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2105. Generation* pg = gch->perm_gen();
  2106. @@ -433,10 +434,14 @@
  2107. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2108. + MarkSweep::copy_rescued_objects_back();
  2109. +
  2110. GenCompactClosure blk;
  2111. gch->generation_iterate(&blk, true);
  2112. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2113. + MarkSweep::copy_rescued_objects_back();
  2114. +
  2115. pg->post_compact(); // Shared spaces verification.
  2116. }
  2117. diff -r 882f6c762ac5 src/share/vm/memory/permGen.cpp
  2118. --- a/src/share/vm/memory/permGen.cpp Thu Jul 09 23:10:04 2015 -0700
  2119. +++ b/src/share/vm/memory/permGen.cpp Thu Jul 09 23:18:17 2015 -0700
  2120. @@ -57,7 +57,12 @@
  2121. for (;;) {
  2122. {
  2123. - MutexLocker ml(Heap_lock);
  2124. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2125. + Monitor *lock = Heap_lock;
  2126. + if (SafepointSynchronize::is_at_safepoint()) {
  2127. + lock = NULL;
  2128. + }
  2129. + MutexLockerEx ml(lock);
  2130. if ((obj = gen->allocate(size, false)) != NULL) {
  2131. return obj;
  2132. }
  2133. diff -r 882f6c762ac5 src/share/vm/memory/space.cpp
  2134. --- a/src/share/vm/memory/space.cpp Thu Jul 09 23:10:04 2015 -0700
  2135. +++ b/src/share/vm/memory/space.cpp Thu Jul 09 23:18:17 2015 -0700
  2136. @@ -378,6 +378,31 @@
  2137. _compaction_top = bottom();
  2138. }
  2139. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2140. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2141. +CompactPoint* cp, HeapWord* compact_top) {
  2142. + // First check if we should switch compaction space
  2143. + assert(this == cp->space, "'this' should be current compaction space.");
  2144. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2145. + while (size > compaction_max_size) {
  2146. + // switch to next compaction space
  2147. + cp->space->set_compaction_top(compact_top);
  2148. + cp->space = cp->space->next_compaction_space();
  2149. + if (cp->space == NULL) {
  2150. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2151. + assert(cp->gen != NULL, "compaction must succeed");
  2152. + cp->space = cp->gen->first_compaction_space();
  2153. + assert(cp->space != NULL, "generation must have a first compaction space");
  2154. + }
  2155. + compact_top = cp->space->bottom();
  2156. + cp->space->set_compaction_top(compact_top);
  2157. + cp->threshold = cp->space->initialize_threshold();
  2158. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2159. + }
  2160. +
  2161. + return compact_top;
  2162. +}
  2163. +
  2164. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2165. CompactPoint* cp, HeapWord* compact_top) {
  2166. // q is alive
  2167. @@ -401,7 +426,7 @@
  2168. }
  2169. // store the forwarding pointer into the mark word
  2170. - if ((HeapWord*)q != compact_top) {
  2171. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2172. q->forward_to(oop(compact_top));
  2173. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2174. } else {
  2175. @@ -449,7 +474,208 @@
  2176. // Faster object search.
  2177. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2178. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2179. + if (!Universe::is_redefining_gc_run()) {
  2180. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2181. + return;
  2182. + }
  2183. +
  2184. + /* Compute the new addresses for the live objects and store it in the mark
  2185. + * Used by universe::mark_sweep_phase2()
  2186. + */
  2187. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2188. +
  2189. + /* We're sure to be here before any objects are compacted into this
  2190. + * space, so this is a good time to initialize this:
  2191. + */
  2192. + set_compaction_top(bottom());
  2193. +
  2194. + if (cp->space == NULL) {
  2195. + assert(cp->gen != NULL, "need a generation");
  2196. + assert(cp->threshold == NULL, "just checking");
  2197. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2198. + cp->space = cp->gen->first_compaction_space();
  2199. + compact_top = cp->space->bottom();
  2200. + cp->space->set_compaction_top(compact_top);
  2201. + cp->threshold = cp->space->initialize_threshold();
  2202. + } else {
  2203. + compact_top = cp->space->compaction_top();
  2204. + }
  2205. +
  2206. + /* We allow some amount of garbage towards the bottom of the space, so
  2207. + * we don't start compacting before there is a significant gain to be made.
  2208. + * Occasionally, we want to ensure a full compaction, which is determined
  2209. + * by the MarkSweepAlwaysCompactCount parameter.
  2210. + */
  2211. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2212. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2213. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2214. +
  2215. + size_t allowed_deadspace = 0;
  2216. + if (skip_dead) {
  2217. + int ratio = (int)allowed_dead_ratio();
  2218. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2219. + }
  2220. +
  2221. + HeapWord* q = bottom();
  2222. + HeapWord* t = end();
  2223. +
  2224. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2225. + live object. */
  2226. + HeapWord* first_dead = end();/* The first dead object. */
  2227. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2228. + first header of preceding free area. */
  2229. + _first_dead = first_dead;
  2230. +
  2231. + const intx interval = PrefetchScanIntervalInBytes;
  2232. +
  2233. + while (q < t) {
  2234. + assert(!block_is_obj(q) ||
  2235. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2236. + oop(q)->mark()->has_bias_pattern(),
  2237. + "these are the only valid states during a mark sweep");
  2238. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2239. + /* prefetch beyond q */
  2240. + Prefetch::write(q, interval);
  2241. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2242. + size_t size = block_size(q);
  2243. +
  2244. + // DCEVM: begin
  2245. + //////////////////////////////////////////////////////////////////////////
  2246. + size_t forward_size = size;
  2247. +
  2248. + // Compute the forward sizes and leave out objects whose position could
  2249. + // possibly overlap other objects.
  2250. +
  2251. + // DCEVM: There is a new version of the class of q => different size
  2252. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2253. +
  2254. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2255. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2256. + forward_size = new_size;
  2257. + }
  2258. +
  2259. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2260. +
  2261. + bool rescueing = false;
  2262. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2263. + if (MarkSweep::_rescued_oops == NULL) {
  2264. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2265. + }
  2266. + // FIXME: idubrov
  2267. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2268. + MarkSweep::_rescued_oops->append(oop(q));
  2269. + } else {
  2270. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2271. + }
  2272. +
  2273. + if ((size != forward_size || rescueing) && q < first_dead) {
  2274. + // (tw) This object moves => first_dead must be set to here!
  2275. + first_dead = q;
  2276. + }
  2277. + //////////////////////////////////////////////////////////////////////////
  2278. + q += size;
  2279. + end_of_live = q;
  2280. + } else {
  2281. + /* run over all the contiguous dead objects */
  2282. + HeapWord* end = q;
  2283. + do {
  2284. + /* prefetch beyond end */
  2285. + Prefetch::write(end, interval);
  2286. + end += block_size(end);
  2287. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2288. +
  2289. + /* see if we might want to pretend this object is alive so that
  2290. + * we don't have to compact quite as often.
  2291. + */
  2292. + if (allowed_deadspace > 0 && q == compact_top) {
  2293. + size_t sz = pointer_delta(end, q);
  2294. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2295. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2296. + q = end;
  2297. + end_of_live = end;
  2298. + continue;
  2299. + }
  2300. + }
  2301. +
  2302. + /* otherwise, it really is a free region. */
  2303. +
  2304. + /* for the previous LiveRange, record the end of the live objects. */
  2305. + if (liveRange) {
  2306. + liveRange->set_end(q);
  2307. + }
  2308. +
  2309. + /* record the current LiveRange object.
  2310. + * liveRange->start() is overlaid on the mark word.
  2311. + */
  2312. + liveRange = (LiveRange*)q;
  2313. + liveRange->set_start(end);
  2314. + liveRange->set_end(end);
  2315. +
  2316. + /* see if this is the first dead region. */
  2317. + if (q < first_dead) {
  2318. + first_dead = q;
  2319. + }
  2320. +
  2321. + /* move on to the next object */
  2322. + q = end;
  2323. + }
  2324. + }
  2325. +
  2326. + //////////////////////////////////////////////////////////////////////////
  2327. + // Compute the forwarding addresses for the objects that need to be
  2328. + // rescued.
  2329. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2330. + if (MarkSweep::_rescued_oops != NULL) {
  2331. + // FIXME: idubrov
  2332. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2333. +
  2334. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2335. + oop q = MarkSweep::_rescued_oops->at(i);
  2336. +
  2337. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2338. + size_t size = block_size((HeapWord*)q);
  2339. +
  2340. + size_t forward_size = size;
  2341. +
  2342. + // (tw) There is a new version of the class of q => different size
  2343. + if (oop(q)->blueprint()->new_version() != NULL) {
  2344. +
  2345. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2346. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2347. + forward_size = new_size;
  2348. + }
  2349. +
  2350. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2351. + assert(compact_top <= t, "must not write over end of space!");
  2352. + }
  2353. + MarkSweep::_rescued_oops->clear();
  2354. + MarkSweep::_rescued_oops = NULL;
  2355. + }
  2356. + //////////////////////////////////////////////////////////////////////////
  2357. +
  2358. + assert(q == t, "just checking");
  2359. + if (liveRange != NULL) {
  2360. + liveRange->set_end(q);
  2361. + }
  2362. + _end_of_live = end_of_live;
  2363. + if (end_of_live < first_dead) {
  2364. + first_dead = end_of_live;
  2365. + }
  2366. + _first_dead = first_dead;
  2367. +
  2368. +// FIXME: idubrov
  2369. +// if (_first_dead > top()) {
  2370. +// _first_dead = top();
  2371. +// }
  2372. +//
  2373. +// if (_end_of_live > top()) {
  2374. +// _end_of_live = top();
  2375. +// }
  2376. + assert(_first_dead <= top(), "Must be smaller equal");
  2377. + assert(_end_of_live <= top(), "Must be smaller equal");
  2378. +
  2379. + /* save the compaction_top of the compaction space. */
  2380. + cp->space->set_compaction_top(compact_top);
  2381. }
  2382. void Space::adjust_pointers() {
  2383. @@ -490,17 +716,313 @@
  2384. assert(q == t, "just checking");
  2385. }
  2386. +
  2387. +#ifdef ASSERT
  2388. +
  2389. +int CompactibleSpace::space_index(oop obj) {
  2390. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2391. +
  2392. + if (heap->is_in_permanent(obj)) {
  2393. + return -1;
  2394. + }
  2395. +
  2396. + int index = 0;
  2397. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2398. + Generation* gen = heap->get_gen(i);
  2399. + CompactibleSpace* space = gen->first_compaction_space();
  2400. + while (space != NULL) {
  2401. + if (space->is_in_reserved(obj)) {
  2402. + return index;
  2403. + }
  2404. + space = space->next_compaction_space();
  2405. + index++;
  2406. + }
  2407. + }
  2408. +
  2409. + tty->print_cr("could not compute space_index for %08xh", obj);
  2410. + index = 0;
  2411. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2412. + Generation* gen = heap->get_gen(i);
  2413. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2414. +
  2415. + CompactibleSpace* space = gen->first_compaction_space();
  2416. + while (space != NULL) {
  2417. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2418. + space = space->next_compaction_space();
  2419. + index++;
  2420. + }
  2421. + }
  2422. +
  2423. + ShouldNotReachHere();
  2424. + return 0;
  2425. +}
  2426. +#endif
  2427. +
  2428. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2429. +
  2430. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2431. +
  2432. + if (old_obj->is_perm()) {
  2433. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2434. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2435. + return true;
  2436. + }
  2437. + }
  2438. +
  2439. + int size = old_obj->size();
  2440. + int original_size = size;
  2441. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2442. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2443. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2444. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2445. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2446. + }
  2447. +
  2448. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2449. +
  2450. + if (is_in_reserved(new_obj)) {
  2451. + // Old and new address are in same space, so just compare the address.
  2452. + // Must rescue if object moves towards the top of the space.
  2453. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2454. + return normalComparison;
  2455. +
  2456. + } else {
  2457. +
  2458. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2459. +
  2460. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2461. + if (tenured_gen->is_in_reserved(new_obj)) {
  2462. + // Must never rescue when moving from the new into the old generation.
  2463. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2464. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2465. + return false;
  2466. +
  2467. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2468. + // Must always rescue when moving from the old into the new generation.
  2469. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2470. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2471. + return true;
  2472. +
  2473. + } else {
  2474. + // In the new generation, eden is located before the from space, so a
  2475. + // simple pointer comparison is sufficient.
  2476. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2477. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2478. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2479. + return normalComparison;
  2480. + }
  2481. + }
  2482. +}
  2483. +
  2484. +oop CompactibleSpace::rescue(oop old_obj) {
  2485. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2486. +
  2487. + int size = old_obj->size();
  2488. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2489. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2490. +
  2491. + if (MarkSweep::_rescued_oops == NULL) {
  2492. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2493. + }
  2494. +
  2495. + MarkSweep::_rescued_oops->append(rescued_obj);
  2496. + return rescued_obj;
  2497. +}
  2498. +
  2499. void CompactibleSpace::adjust_pointers() {
  2500. // Check first is there is any work to do.
  2501. if (used() == 0) {
  2502. return; // Nothing to do.
  2503. }
  2504. + /* adjust all the interior pointers to point at the new locations of objects
  2505. + * Used by MarkSweep::mark_sweep_phase3() */
  2506. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  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 -r 882f6c762ac5 src/share/vm/memory/space.hpp
  2696. --- a/src/share/vm/memory/space.hpp Thu Jul 09 23:10:04 2015 -0700
  2697. +++ b/src/share/vm/memory/space.hpp Thu Jul 09 23:18:17 2015 -0700
  2698. @@ -445,6 +445,9 @@
  2699. // indicates when the next such action should be taken.
  2700. virtual void prepare_for_compaction(CompactPoint* cp);
  2701. // MarkSweep support phase3
  2702. + DEBUG_ONLY(int space_index(oop obj));
  2703. + bool must_rescue(oop old_obj, oop new_obj);
  2704. + oop rescue(oop old_obj);
  2705. virtual void adjust_pointers();
  2706. // MarkSweep support phase4
  2707. virtual void compact();
  2708. @@ -475,6 +478,10 @@
  2709. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2710. HeapWord* compact_top);
  2711. + // (tw)
  2712. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2713. + HeapWord* compact_top);
  2714. +
  2715. // Return a size with adjusments as required of the space.
  2716. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2717. diff -r 882f6c762ac5 src/share/vm/memory/universe.cpp
  2718. --- a/src/share/vm/memory/universe.cpp Thu Jul 09 23:10:04 2015 -0700
  2719. +++ b/src/share/vm/memory/universe.cpp Thu Jul 09 23:18:17 2015 -0700
  2720. @@ -100,6 +100,8 @@
  2721. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2722. #endif
  2723. +bool Universe::_is_redefining_gc_run = false;
  2724. +
  2725. // Known objects
  2726. klassOop Universe::_boolArrayKlassObj = NULL;
  2727. klassOop Universe::_byteArrayKlassObj = NULL;
  2728. @@ -204,6 +206,38 @@
  2729. f(systemObjArrayKlassObj());
  2730. }
  2731. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2732. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2733. +
  2734. + class AlwaysTrueClosure: public BoolObjectClosure {
  2735. + public:
  2736. + void do_object(oop p) { ShouldNotReachHere(); }
  2737. + bool do_object_b(oop p) { return true; }
  2738. + };
  2739. + AlwaysTrueClosure always_true;
  2740. +
  2741. + // General strong roots
  2742. + Universe::oops_do(oopClosure);
  2743. + JNIHandles::oops_do(oopClosure);
  2744. + Threads::oops_do(oopClosure, NULL);
  2745. + ObjectSynchronizer::oops_do(oopClosure);
  2746. + FlatProfiler::oops_do(oopClosure);
  2747. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2748. + JvmtiExport::oops_do(oopClosure);
  2749. + // SO_AllClasses
  2750. + SystemDictionary::oops_do(oopClosure);
  2751. +
  2752. + // Now adjust pointers in remaining weak roots. (All of which should
  2753. + // have been cleared if they pointed to non-surviving objects.)
  2754. + // Global (weak) JNI handles
  2755. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2756. +
  2757. + CodeCache::oops_do(oopClosure);
  2758. + StringTable::oops_do(oopClosure);
  2759. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2760. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2761. +}
  2762. +
  2763. void Universe::oops_do(OopClosure* f, bool do_all) {
  2764. f->do_oop((oop*) &_int_mirror);
  2765. diff -r 882f6c762ac5 src/share/vm/memory/universe.hpp
  2766. --- a/src/share/vm/memory/universe.hpp Thu Jul 09 23:10:04 2015 -0700
  2767. +++ b/src/share/vm/memory/universe.hpp Thu Jul 09 23:18:17 2015 -0700
  2768. @@ -127,6 +127,8 @@
  2769. friend class SystemDictionary;
  2770. friend class VMStructs;
  2771. friend class CompactingPermGenGen;
  2772. + friend class Space;
  2773. + friend class ContiguousSpace;
  2774. friend class VM_PopulateDumpSharedSpace;
  2775. friend jint universe_init();
  2776. @@ -258,7 +260,18 @@
  2777. static void compute_verify_oop_data();
  2778. + static bool _is_redefining_gc_run;
  2779. +
  2780. public:
  2781. +
  2782. + static bool is_redefining_gc_run() {
  2783. + return _is_redefining_gc_run;
  2784. + }
  2785. +
  2786. + static void set_redefining_gc_run(bool b) {
  2787. + _is_redefining_gc_run = b;
  2788. + }
  2789. +
  2790. // Known classes in the VM
  2791. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2792. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2793. @@ -403,6 +416,8 @@
  2794. // Iteration
  2795. + static void root_oops_do(OopClosure *f);
  2796. +
  2797. // Apply "f" to the addresses of all the direct heap pointers maintained
  2798. // as static fields of "Universe".
  2799. static void oops_do(OopClosure* f, bool do_all = false);
  2800. @@ -419,6 +434,7 @@
  2801. // Debugging
  2802. static bool verify_in_progress() { return _verify_in_progress; }
  2803. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2804. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  2805. static void verify(const char* prefix, bool silent = VerifySilently) {
  2806. verify(VerifyOption_Default, prefix, silent);
  2807. diff -r 882f6c762ac5 src/share/vm/oops/arrayKlass.cpp
  2808. --- a/src/share/vm/oops/arrayKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  2809. +++ b/src/share/vm/oops/arrayKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  2810. @@ -136,9 +136,9 @@
  2811. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2812. // An array is a subtype of Serializable, Clonable, and Object
  2813. - return k == SystemDictionary::Object_klass()
  2814. - || k == SystemDictionary::Cloneable_klass()
  2815. - || k == SystemDictionary::Serializable_klass();
  2816. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2817. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2818. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2819. }
  2820. diff -r 882f6c762ac5 src/share/vm/oops/constMethodKlass.cpp
  2821. --- a/src/share/vm/oops/constMethodKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  2822. +++ b/src/share/vm/oops/constMethodKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  2823. @@ -102,6 +102,7 @@
  2824. constMethodOop cm = constMethodOop(obj);
  2825. MarkSweep::mark_and_push(cm->adr_constants());
  2826. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2827. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2828. // Performance tweak: We skip iterating over the klass pointer since we
  2829. // know that Universe::constMethodKlassObj never moves.
  2830. }
  2831. @@ -113,6 +114,7 @@
  2832. constMethodOop cm_oop = constMethodOop(obj);
  2833. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2834. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2835. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2836. // Performance tweak: We skip iterating over the klass pointer since we
  2837. // know that Universe::constMethodKlassObj never moves.
  2838. }
  2839. @@ -123,6 +125,7 @@
  2840. constMethodOop cm = constMethodOop(obj);
  2841. blk->do_oop(cm->adr_constants());
  2842. blk->do_oop(cm->adr_stackmap_data());
  2843. + blk->do_oop(cm->adr_code_section_table());
  2844. // Get size before changing pointers.
  2845. // Don't call size() or oop_size() since that is a virtual call.
  2846. int size = cm->object_size();
  2847. @@ -138,6 +141,8 @@
  2848. if (mr.contains(adr)) blk->do_oop(adr);
  2849. adr = cm->adr_stackmap_data();
  2850. if (mr.contains(adr)) blk->do_oop(adr);
  2851. + adr = cm->adr_code_section_table();
  2852. + if (mr.contains(adr)) blk->do_oop(adr);
  2853. // Get size before changing pointers.
  2854. // Don't call size() or oop_size() since that is a virtual call.
  2855. int size = cm->object_size();
  2856. @@ -152,6 +157,7 @@
  2857. constMethodOop cm = constMethodOop(obj);
  2858. MarkSweep::adjust_pointer(cm->adr_constants());
  2859. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2860. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2861. // Get size before changing pointers.
  2862. // Don't call size() or oop_size() since that is a virtual call.
  2863. int size = cm->object_size();
  2864. diff -r 882f6c762ac5 src/share/vm/oops/constMethodOop.hpp
  2865. --- a/src/share/vm/oops/constMethodOop.hpp Thu Jul 09 23:10:04 2015 -0700
  2866. +++ b/src/share/vm/oops/constMethodOop.hpp Thu Jul 09 23:18:17 2015 -0700
  2867. @@ -129,7 +129,7 @@
  2868. public:
  2869. oop* oop_block_beg() const { return adr_constants(); }
  2870. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2871. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2872. private:
  2873. //
  2874. @@ -141,6 +141,9 @@
  2875. // Raw stackmap data for the method
  2876. typeArrayOop _stackmap_data;
  2877. + // (tw) Table mapping code sections for method forward points.
  2878. + typeArrayOop _code_section_table;
  2879. +
  2880. //
  2881. // End of the oop block.
  2882. //
  2883. @@ -195,6 +198,28 @@
  2884. }
  2885. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2886. + // code section table
  2887. + typeArrayOop code_section_table() const { return _code_section_table; }
  2888. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2889. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2890. + static const int ValuesPerCodeSectionEntry = 3;
  2891. + int code_section_entries() const {
  2892. + if (!has_code_section_table()) return 0;
  2893. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2894. + }
  2895. +
  2896. + int code_section_new_index_at(int index) const {
  2897. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2898. + }
  2899. +
  2900. + int code_section_original_index_at(int index) const {
  2901. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2902. + }
  2903. +
  2904. + int code_section_length_at(int index) const {
  2905. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2906. + }
  2907. +
  2908. void init_fingerprint() {
  2909. const uint64_t initval = CONST64(0x8000000000000000);
  2910. _fingerprint = initval;
  2911. @@ -301,6 +326,7 @@
  2912. // Garbage collection support
  2913. oop* adr_constants() const { return (oop*)&_constants; }
  2914. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2915. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2916. bool is_conc_safe() { return _is_conc_safe; }
  2917. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2918. diff -r 882f6c762ac5 src/share/vm/oops/cpCacheOop.cpp
  2919. --- a/src/share/vm/oops/cpCacheOop.cpp Thu Jul 09 23:10:04 2015 -0700
  2920. +++ b/src/share/vm/oops/cpCacheOop.cpp Thu Jul 09 23:18:17 2015 -0700
  2921. @@ -37,9 +37,15 @@
  2922. // Implememtation of ConstantPoolCacheEntry
  2923. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2924. + _flags = other->_flags; // flags
  2925. +}
  2926. +
  2927. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2928. assert(0 < index && index < 0x10000, "sanity check");
  2929. _indices = index;
  2930. + _f1 = NULL;
  2931. + _f2 = 0;
  2932. assert(constant_pool_index() == index, "");
  2933. }
  2934. @@ -162,7 +168,8 @@
  2935. int vtable_index) {
  2936. assert(!is_secondary_entry(), "");
  2937. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2938. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2939. + // (tw) No longer valid assert
  2940. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2941. int byte_no = -1;
  2942. bool change_to_virtual = false;
  2943. @@ -183,6 +190,7 @@
  2944. set_method_flags(as_TosState(method->result_type()),
  2945. ( 1 << is_vfinal_shift) |
  2946. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2947. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2948. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2949. method()->size_of_parameters());
  2950. set_f2_as_vfinal_method(method());
  2951. @@ -190,9 +198,13 @@
  2952. assert(vtable_index >= 0, "valid index");
  2953. assert(!method->is_final_method(), "sanity");
  2954. set_method_flags(as_TosState(method->result_type()),
  2955. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2956. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2957. method()->size_of_parameters());
  2958. set_f2(vtable_index);
  2959. +
  2960. + // (tw) save method holder in f1 for virtual calls
  2961. + set_f1(method());
  2962. }
  2963. byte_no = 2;
  2964. break;
  2965. @@ -206,7 +218,8 @@
  2966. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  2967. set_method_flags(as_TosState(method->result_type()),
  2968. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  2969. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  2970. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2971. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  2972. method()->size_of_parameters());
  2973. set_f1(method());
  2974. byte_no = 1;
  2975. @@ -259,7 +272,7 @@
  2976. set_f1(interf);
  2977. set_f2(index);
  2978. set_method_flags(as_TosState(method->result_type()),
  2979. - 0, // no option bits
  2980. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  2981. method()->size_of_parameters());
  2982. set_bytecode_1(Bytecodes::_invokeinterface);
  2983. }
  2984. @@ -520,27 +533,12 @@
  2985. // If this constantPoolCacheEntry refers to old_method then update it
  2986. // to refer to new_method.
  2987. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  2988. - methodOop new_method, bool * trace_name_printed) {
  2989. + methodOop new_method) {
  2990. if (is_vfinal()) {
  2991. - // virtual and final so _f2 contains method ptr instead of vtable index
  2992. - if (f2_as_vfinal_method() == old_method) {
  2993. - // match old_method so need an update
  2994. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  2995. - _f2 = (intptr_t)new_method;
  2996. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  2997. - if (!(*trace_name_printed)) {
  2998. - // RC_TRACE_MESG macro has an embedded ResourceMark
  2999. - RC_TRACE_MESG(("adjust: name=%s",
  3000. - Klass::cast(old_method->method_holder())->external_name()));
  3001. - *trace_name_printed = true;
  3002. - }
  3003. - // RC_TRACE macro has an embedded ResourceMark
  3004. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3005. - new_method->name()->as_C_string(),
  3006. - new_method->signature()->as_C_string()));
  3007. - }
  3008. -
  3009. + // virtual and final so f2() contains method ptr instead of vtable index
  3010. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3011. + initialize_entry(constant_pool_index());
  3012. return true;
  3013. }
  3014. @@ -548,84 +546,27 @@
  3015. return false;
  3016. }
  3017. - if ((oop)_f1 == NULL) {
  3018. - // NULL f1() means this is a virtual entry so bail out
  3019. - // We are assuming that the vtable index does not need change.
  3020. + // (tw) check how to update interface methods!
  3021. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3022. +
  3023. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3024. + initialize_entry(constant_pool_index());
  3025. + return true;
  3026. + }
  3027. +
  3028. return false;
  3029. }
  3030. if ((oop)_f1 == old_method) {
  3031. _f1 = new_method;
  3032. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3033. - if (!(*trace_name_printed)) {
  3034. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3035. - RC_TRACE_MESG(("adjust: name=%s",
  3036. - Klass::cast(old_method->method_holder())->external_name()));
  3037. - *trace_name_printed = true;
  3038. - }
  3039. - // RC_TRACE macro has an embedded ResourceMark
  3040. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3041. - new_method->name()->as_C_string(),
  3042. - new_method->signature()->as_C_string()));
  3043. - }
  3044. -
  3045. return true;
  3046. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3047. + initialize_entry(constant_pool_index());
  3048. }
  3049. return false;
  3050. }
  3051. -// a constant pool cache entry should never contain old or obsolete methods
  3052. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3053. - if (is_vfinal()) {
  3054. - // virtual and final so _f2 contains method ptr instead of vtable index
  3055. - methodOop m = (methodOop)_f2;
  3056. - // Return false if _f2 refers to an old or an obsolete method.
  3057. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3058. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3059. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3060. - // _f1 == NULL || !_f1->is_method() are OK here
  3061. - return true;
  3062. - }
  3063. -
  3064. - methodOop m = (methodOop)_f1;
  3065. - // return false if _f1 refers to an old or an obsolete method
  3066. - return (!m->is_old() && !m->is_obsolete());
  3067. -}
  3068. -
  3069. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3070. - if (!is_method_entry()) {
  3071. - // not a method entry so not interesting by default
  3072. - return false;
  3073. - }
  3074. -
  3075. - methodOop m = NULL;
  3076. - if (is_vfinal()) {
  3077. - // virtual and final so _f2 contains method ptr instead of vtable index
  3078. - m = f2_as_vfinal_method();
  3079. - } else if (is_f1_null()) {
  3080. - // NULL _f1 means this is a virtual entry so also not interesting
  3081. - return false;
  3082. - } else {
  3083. - oop f1 = _f1; // _f1 is volatile
  3084. - if (!f1->is_method()) {
  3085. - // _f1 can also contain a klassOop for an interface
  3086. - return false;
  3087. - }
  3088. - m = f1_as_method();
  3089. - }
  3090. -
  3091. - assert(m != NULL && m->is_method(), "sanity check");
  3092. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3093. - // robustness for above sanity checks or method is not in
  3094. - // the interesting class
  3095. - return false;
  3096. - }
  3097. -
  3098. - // the method is in the interesting class so the entry is interesting
  3099. - return true;
  3100. -}
  3101. -
  3102. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3103. // print separator
  3104. if (index == 0) st->print_cr(" -------------");
  3105. @@ -663,60 +604,18 @@
  3106. }
  3107. }
  3108. -// RedefineClasses() API support:
  3109. -// If any entry of this constantPoolCache points to any of
  3110. -// old_methods, replace it with the corresponding new_method.
  3111. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3112. - int methods_length, bool * trace_name_printed) {
  3113. -
  3114. - if (methods_length == 0) {
  3115. - // nothing to do if there are no methods
  3116. - return;
  3117. - }
  3118. -
  3119. - // get shorthand for the interesting class
  3120. - klassOop old_holder = old_methods[0]->method_holder();
  3121. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3122. + int methods_length) {
  3123. for (int i = 0; i < length(); i++) {
  3124. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3125. - // skip uninteresting methods
  3126. - continue;
  3127. - }
  3128. -
  3129. - // The constantPoolCache contains entries for several different
  3130. - // things, but we only care about methods. In fact, we only care
  3131. - // about methods in the same class as the one that contains the
  3132. - // old_methods. At this point, we have an interesting entry.
  3133. -
  3134. - for (int j = 0; j < methods_length; j++) {
  3135. - methodOop old_method = old_methods[j];
  3136. - methodOop new_method = new_methods[j];
  3137. -
  3138. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3139. - trace_name_printed)) {
  3140. - // current old_method matched this entry and we updated it so
  3141. - // break out and get to the next interesting entry if there one
  3142. - break;
  3143. - }
  3144. + if (entry_at(i)->is_field_entry()) {
  3145. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3146. + // point to changed fields
  3147. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3148. + } else if(entry_at(i)->is_method_entry() && !entry_at(i)->is_secondary_entry()) {
  3149. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3150. }
  3151. }
  3152. }
  3153. -// the constant pool cache should never contain old or obsolete methods
  3154. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3155. - for (int i = 1; i < length(); i++) {
  3156. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3157. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3158. - return false;
  3159. - }
  3160. - }
  3161. - return true;
  3162. -}
  3163. -void constantPoolCacheOopDesc::dump_cache() {
  3164. - for (int i = 1; i < length(); i++) {
  3165. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3166. - entry_at(i)->print(tty, i);
  3167. - }
  3168. - }
  3169. -}
  3170. diff -r 882f6c762ac5 src/share/vm/oops/cpCacheOop.hpp
  3171. --- a/src/share/vm/oops/cpCacheOop.hpp Thu Jul 09 23:10:04 2015 -0700
  3172. +++ b/src/share/vm/oops/cpCacheOop.hpp Thu Jul 09 23:18:17 2015 -0700
  3173. @@ -136,7 +136,8 @@
  3174. void set_bytecode_2(Bytecodes::Code code);
  3175. void set_f1(oop f1) {
  3176. oop existing_f1 = _f1; // read once
  3177. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3178. + // (tw) need to relax assertion for redefinition
  3179. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3180. oop_store(&_f1, f1);
  3181. }
  3182. void release_set_f1(oop f1);
  3183. @@ -174,6 +175,7 @@
  3184. tos_state_mask = right_n_bits(tos_state_bits),
  3185. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3186. // misc. option bits; can be any bit position in [16..27]
  3187. + is_old_method_shift = 19,
  3188. is_vfinal_shift = 20,
  3189. is_volatile_shift = 21,
  3190. is_final_shift = 22,
  3191. @@ -207,6 +209,8 @@
  3192. void initialize_entry(int original_index); // initialize primary entry
  3193. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3194. + void copy_from(ConstantPoolCacheEntry *other);
  3195. +
  3196. void set_field( // sets entry to resolved field state
  3197. Bytecodes::Code get_code, // the bytecode used for reading the field
  3198. Bytecodes::Code put_code, // the bytecode used for writing the field
  3199. @@ -368,10 +372,7 @@
  3200. // trace_name_printed is set to true if the current call has
  3201. // printed the klass name so that other routines in the adjust_*
  3202. // group don't print the klass name.
  3203. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3204. - bool * trace_name_printed);
  3205. - bool check_no_old_or_obsolete_entries();
  3206. - bool is_interesting_method_entry(klassOop k);
  3207. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3208. // Debugging & Printing
  3209. void print (outputStream* st, int index) const;
  3210. @@ -492,16 +493,9 @@
  3211. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3212. }
  3213. - // RedefineClasses() API support:
  3214. - // If any entry of this constantPoolCache points to any of
  3215. - // old_methods, replace it with the corresponding new_method.
  3216. - // trace_name_printed is set to true if the current call has
  3217. - // printed the klass name so that other routines in the adjust_*
  3218. - // group don't print the klass name.
  3219. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3220. - int methods_length, bool * trace_name_printed);
  3221. - bool check_no_old_or_obsolete_entries();
  3222. - void dump_cache();
  3223. + // (tw) Update method and field references
  3224. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3225. + int methods_length);
  3226. };
  3227. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3228. diff -r 882f6c762ac5 src/share/vm/oops/instanceKlass.cpp
  3229. --- a/src/share/vm/oops/instanceKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  3230. +++ b/src/share/vm/oops/instanceKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  3231. @@ -250,12 +250,118 @@
  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. @@ -362,7 +468,13 @@
  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. @@ -400,7 +512,8 @@
  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. @@ -673,6 +786,18 @@
  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. @@ -801,7 +926,25 @@
  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. @@ -949,6 +1092,137 @@
  3416. }
  3417. }
  3418. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3419. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  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(), mtClass);
  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(), mtClass);
  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(), mtClass);
  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. @@ -1368,6 +1642,20 @@
  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. @@ -1527,6 +1815,13 @@
  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. @@ -2417,6 +2712,9 @@
  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 -r 882f6c762ac5 src/share/vm/oops/instanceKlass.hpp
  3595. --- a/src/share/vm/oops/instanceKlass.hpp Thu Jul 09 23:10:04 2015 -0700
  3596. +++ b/src/share/vm/oops/instanceKlass.hpp Thu Jul 09 23:18:17 2015 -0700
  3597. @@ -102,6 +102,22 @@
  3598. virtual void do_field(fieldDescriptor* fd) = 0;
  3599. };
  3600. +// (tw) Iterates over the fields of the old and new class
  3601. +class FieldEvolutionClosure : public StackObj {
  3602. +public:
  3603. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3604. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3605. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3606. +};
  3607. +
  3608. +// (tw) Iterates over the methods of the old and new class
  3609. +class MethodEvolutionClosure : public StackObj {
  3610. +public:
  3611. + virtual void do_new_method(methodOop oop) = 0;
  3612. + virtual void do_old_method(methodOop oop) = 0;
  3613. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3614. +};
  3615. +
  3616. #ifndef PRODUCT
  3617. // Print fields.
  3618. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3619. @@ -287,6 +303,11 @@
  3620. // _idnum_allocated_count.
  3621. u1 _init_state; // state of class
  3622. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3623. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3624. + // information is cached.
  3625. + bool _fields_not_changed;
  3626. +
  3627. u1 _reference_type; // reference type
  3628. // embedded Java vtable follows here
  3629. @@ -454,6 +475,7 @@
  3630. // initialization (virtuals from Klass)
  3631. bool should_be_initialized() const; // means that initialize should be called
  3632. void initialize(TRAPS);
  3633. + void initialize_redefined_class();
  3634. void link_class(TRAPS);
  3635. bool link_class_or_fail(TRAPS); // returns false on failure
  3636. void unlink_class();
  3637. @@ -631,6 +653,7 @@
  3638. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3639. size_t *length_p, jmethodID* id_p);
  3640. jmethodID jmethod_id_or_null(methodOop method);
  3641. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3642. // cached itable index support
  3643. void set_cached_itable_index(size_t idnum, int index);
  3644. @@ -713,6 +736,7 @@
  3645. // subclass/subinterface checks
  3646. bool implements_interface(klassOop k) const;
  3647. + bool implements_interface_any_version(klassOop k) const;
  3648. // Access to the implementor of an interface.
  3649. klassOop implementor() const
  3650. @@ -762,6 +786,12 @@
  3651. void do_local_static_fields(FieldClosure* cl);
  3652. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3653. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3654. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3655. + void store_update_information(GrowableArray<int> &values);
  3656. + void clear_update_information();
  3657. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3658. + void clear_type_check_information();
  3659. +
  3660. void methods_do(void f(methodOop method));
  3661. void array_klasses_do(void f(klassOop k));
  3662. diff -r 882f6c762ac5 src/share/vm/oops/instanceKlassKlass.cpp
  3663. --- a/src/share/vm/oops/instanceKlassKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  3664. +++ b/src/share/vm/oops/instanceKlassKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  3665. @@ -480,6 +480,28 @@
  3666. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3667. klassKlass::oop_print_on(obj, st);
  3668. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3669. +
  3670. + st->print(BULLET"revision: %d", ik->revision_number());
  3671. +
  3672. + if (ik->new_version() != NULL) {
  3673. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3674. + }
  3675. +
  3676. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3677. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3678. + }
  3679. +
  3680. + if (ik->old_version() != NULL) {
  3681. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3682. + }
  3683. +
  3684. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3685. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3686. + }
  3687. +
  3688. + st->cr();
  3689. +
  3690. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3691. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3692. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3693. @@ -663,7 +685,7 @@
  3694. }
  3695. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3696. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3697. - guarantee(sib->super() == super, "siblings should have same superklass");
  3698. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3699. sib = sib->next_sibling();
  3700. }
  3701. diff -r 882f6c762ac5 src/share/vm/oops/instanceRefKlass.cpp
  3702. --- a/src/share/vm/oops/instanceRefKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  3703. +++ b/src/share/vm/oops/instanceRefKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  3704. @@ -455,10 +455,13 @@
  3705. instanceKlass* ik = instanceKlass::cast(k);
  3706. // Check that we have the right class
  3707. - debug_only(static bool first_time = true);
  3708. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3709. - "Invalid update of maps");
  3710. - debug_only(first_time = false);
  3711. +
  3712. + // (tw) Asserts no longer valid for class redefinition
  3713. + // debug_only(static bool first_time = true);
  3714. +
  3715. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3716. + // "Invalid update of maps");
  3717. + //debug_only(first_time = false);
  3718. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3719. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3720. diff -r 882f6c762ac5 src/share/vm/oops/klass.cpp
  3721. --- a/src/share/vm/oops/klass.cpp Thu Jul 09 23:10:04 2015 -0700
  3722. +++ b/src/share/vm/oops/klass.cpp Thu Jul 09 23:18:17 2015 -0700
  3723. @@ -55,6 +55,26 @@
  3724. return false;
  3725. }
  3726. +void Klass::update_supers_to_newest_version() {
  3727. +
  3728. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3729. +
  3730. + for (uint i=0; i<primary_super_limit(); i++) {
  3731. + klassOop cur = _primary_supers[i];
  3732. + if (cur != NULL) {
  3733. + _primary_supers[i] = cur->klass_part()->newest_version();
  3734. + }
  3735. + }
  3736. +
  3737. + // Scan the array-of-objects
  3738. + int cnt = secondary_supers()->length();
  3739. + for (int i = 0; i < cnt; i++) {
  3740. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3741. + if (cur != NULL) {
  3742. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3743. + }
  3744. + }
  3745. +}
  3746. bool Klass::search_secondary_supers(klassOop k) const {
  3747. // Put some extra logic here out-of-line, before the search proper.
  3748. // This cuts down the size of the inline method.
  3749. @@ -170,6 +190,16 @@
  3750. kl->set_alloc_size(0);
  3751. TRACE_INIT_ID(kl);
  3752. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3753. + kl->set_redefining(false);
  3754. + kl->set_new_version(NULL);
  3755. + kl->set_old_version(NULL);
  3756. + kl->set_redefinition_index(-1);
  3757. + kl->set_revision_number(-1);
  3758. + kl->set_field_redefinition_policy(DynamicCheck);
  3759. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3760. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3761. +
  3762. kl->set_prototype_header(markOopDesc::prototype());
  3763. kl->set_biased_lock_revocation_count(0);
  3764. kl->set_last_biased_lock_bulk_revocation_time(0);
  3765. @@ -241,7 +271,7 @@
  3766. set_super(NULL);
  3767. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3768. assert(super_depth() == 0, "Object must already be initialized properly");
  3769. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3770. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3771. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3772. "initialize this only once to a non-trivial value");
  3773. set_super(k);
  3774. diff -r 882f6c762ac5 src/share/vm/oops/klass.hpp
  3775. --- a/src/share/vm/oops/klass.hpp Thu Jul 09 23:10:04 2015 -0700
  3776. +++ b/src/share/vm/oops/klass.hpp Thu Jul 09 23:18:17 2015 -0700
  3777. @@ -171,6 +171,7 @@
  3778. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3779. };
  3780. +template<class L, class R> class Pair;
  3781. class Klass : public Klass_vtbl {
  3782. friend class VMStructs;
  3783. @@ -223,6 +224,39 @@
  3784. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3785. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3786. + // (tw) Different class redefinition flags of code evolution.
  3787. + enum RedefinitionFlags {
  3788. +
  3789. + // This class is not redefined at all!
  3790. + NoRedefinition,
  3791. +
  3792. + // There are changes to the class meta data.
  3793. + ModifyClass = 1,
  3794. +
  3795. + // The size of the class meta data changes.
  3796. + ModifyClassSize = ModifyClass << 1,
  3797. +
  3798. + // There are change to the instance format.
  3799. + ModifyInstances = ModifyClassSize << 1,
  3800. +
  3801. + // The size of instances changes.
  3802. + ModifyInstanceSize = ModifyInstances << 1,
  3803. +
  3804. + // A super type of this class is removed.
  3805. + RemoveSuperType = ModifyInstanceSize << 1,
  3806. +
  3807. + // This class (or one of its super classes) has an instance transformer method.
  3808. + HasInstanceTransformer = RemoveSuperType << 1,
  3809. + };
  3810. +
  3811. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3812. + enum RedefinitionPolicy {
  3813. + StaticCheck,
  3814. + DynamicCheck,
  3815. + AccessDeletedMembers,
  3816. + AccessOldMembers
  3817. + };
  3818. +
  3819. protected:
  3820. //
  3821. // The oop block. All oop fields must be declared here and only oop fields
  3822. @@ -242,6 +276,10 @@
  3823. oop _java_mirror;
  3824. // Superclass
  3825. klassOop _super;
  3826. + // Old class
  3827. + klassOop _old_version;
  3828. + // New class
  3829. + klassOop _new_version;
  3830. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3831. klassOop _subklass;
  3832. // Sibling link (or NULL); links all subklasses of a klass
  3833. @@ -254,6 +292,19 @@
  3834. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3835. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3836. + // (tw) Non-oop fields for enhanced class redefinition
  3837. + jint _revision_number; // The revision number for redefined classes
  3838. + jint _redefinition_index; // Index of this class when performing the redefinition
  3839. + bool _subtype_changed;
  3840. + int _redefinition_flags; // Level of class redefinition
  3841. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3842. + int * _update_information; // Update information
  3843. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3844. + char _method_redefinition_policy;
  3845. + char _field_redefinition_policy;
  3846. + char _static_field_redefinition_policy;
  3847. + bool _is_redefining;
  3848. +
  3849. #ifndef PRODUCT
  3850. int _verify_count; // to avoid redundant verifies
  3851. #endif
  3852. @@ -302,6 +353,99 @@
  3853. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3854. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3855. + // BEGIN class redefinition utilities
  3856. +
  3857. + // double links between new and old version of a class
  3858. + klassOop old_version() const { return _old_version; }
  3859. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3860. + klassOop new_version() const { return _new_version; }
  3861. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3862. +
  3863. + // A subtype of this class is no longer a subtype
  3864. + bool has_subtype_changed() const { return _subtype_changed; }
  3865. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3866. + _subtype_changed = b; }
  3867. + // state of being redefined
  3868. + int redefinition_index() const { return _redefinition_index; }
  3869. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3870. + void set_redefining(bool b) { _is_redefining = b; }
  3871. + bool is_redefining() const { return _is_redefining; }
  3872. + int redefinition_flags() const { return _redefinition_flags; }
  3873. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3874. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3875. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3876. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3877. +
  3878. + // update information
  3879. + int *update_information() const { return _update_information; }
  3880. + void set_update_information(int *info) { _update_information = info; }
  3881. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3882. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3883. +
  3884. + bool is_same_or_older_version(klassOop klass) const {
  3885. + if (Klass::cast(klass) == this) { return true; }
  3886. + else if (_old_version == NULL) { return false; }
  3887. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3888. + }
  3889. +
  3890. + // Revision number for redefined classes, -1 for originally loaded classes
  3891. + jint revision_number() const {
  3892. + return _revision_number;
  3893. + }
  3894. +
  3895. + bool was_redefined() const {
  3896. + return _revision_number != -1;
  3897. + }
  3898. +
  3899. + void set_revision_number(jint number) {
  3900. + _revision_number = number;
  3901. + }
  3902. +
  3903. + char method_redefinition_policy() {
  3904. + return _method_redefinition_policy;
  3905. + }
  3906. +
  3907. + void set_method_redefinition_policy(char v) {
  3908. + _method_redefinition_policy = v;
  3909. + }
  3910. +
  3911. + char field_redefinition_policy() {
  3912. + return _field_redefinition_policy;
  3913. + }
  3914. +
  3915. + void set_field_redefinition_policy(char v) {
  3916. + _field_redefinition_policy = v;
  3917. + }
  3918. +
  3919. + char static_field_redefinition_policy() {
  3920. + return _static_field_redefinition_policy;
  3921. + }
  3922. +
  3923. + void set_static_field_redefinition_policy(char v) {
  3924. + _static_field_redefinition_policy = v;
  3925. + }
  3926. +
  3927. + klassOop oldest_version() const {
  3928. + if (_old_version == NULL) { return this->as_klassOop(); }
  3929. + else { return _old_version->klass_part()->oldest_version(); };
  3930. + }
  3931. +
  3932. + klassOop newest_version() const {
  3933. + if (_new_version == NULL) { return this->as_klassOop(); }
  3934. + else { return _new_version->klass_part()->newest_version(); };
  3935. + }
  3936. +
  3937. + klassOop active_version() const {
  3938. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3939. + else { return _new_version->klass_part()->active_version(); };
  3940. + }
  3941. +
  3942. + bool is_newest_version() const {
  3943. + return _new_version == NULL;
  3944. + }
  3945. +
  3946. + // END class redefinition utilities
  3947. +
  3948. objArrayOop secondary_supers() const { return _secondary_supers; }
  3949. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3950. @@ -362,6 +506,8 @@
  3951. void set_next_sibling(klassOop s);
  3952. oop* adr_super() const { return (oop*)&_super; }
  3953. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3954. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3955. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3956. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3957. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3958. @@ -491,6 +637,7 @@
  3959. return search_secondary_supers(k);
  3960. }
  3961. }
  3962. + void update_supers_to_newest_version();
  3963. bool search_secondary_supers(klassOop k) const;
  3964. // Find LCA in class hierarchy
  3965. @@ -818,6 +965,8 @@
  3966. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  3967. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  3968. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  3969. #endif // SHARE_VM_OOPS_KLASS_HPP
  3970. diff -r 882f6c762ac5 src/share/vm/oops/klassKlass.cpp
  3971. --- a/src/share/vm/oops/klassKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  3972. +++ b/src/share/vm/oops/klassKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  3973. @@ -68,6 +68,8 @@
  3974. Klass* k = Klass::cast(klassOop(obj));
  3975. // If we are alive it is valid to keep our superclass and subtype caches alive
  3976. MarkSweep::mark_and_push(k->adr_super());
  3977. + MarkSweep::mark_and_push(k->adr_old_version());
  3978. + MarkSweep::mark_and_push(k->adr_new_version());
  3979. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3980. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3981. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3982. @@ -87,6 +89,8 @@
  3983. Klass* k = Klass::cast(klassOop(obj));
  3984. // If we are alive it is valid to keep our superclass and subtype caches alive
  3985. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3986. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3987. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3988. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3989. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3990. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3991. @@ -106,6 +110,8 @@
  3992. int size = oop_size(obj);
  3993. Klass* k = Klass::cast(klassOop(obj));
  3994. blk->do_oop(k->adr_super());
  3995. + blk->do_oop(k->adr_old_version());
  3996. + blk->do_oop(k->adr_new_version());
  3997. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3998. blk->do_oop(k->adr_primary_supers()+i);
  3999. blk->do_oop(k->adr_secondary_super_cache());
  4000. @@ -134,6 +140,10 @@
  4001. oop* adr;
  4002. adr = k->adr_super();
  4003. if (mr.contains(adr)) blk->do_oop(adr);
  4004. + adr = k->adr_old_version();
  4005. + if (mr.contains(adr)) blk->do_oop(adr);
  4006. + adr = k->adr_new_version();
  4007. + if (mr.contains(adr)) blk->do_oop(adr);
  4008. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4009. adr = k->adr_primary_supers()+i;
  4010. if (mr.contains(adr)) blk->do_oop(adr);
  4011. @@ -147,6 +157,8 @@
  4012. // The following are "weak links" in the perm gen and are
  4013. // treated specially in a later phase of a perm gen collection.
  4014. assert(oop(k)->is_perm(), "should be in perm");
  4015. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4016. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4017. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4018. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4019. if (blk->should_remember_klasses()
  4020. @@ -167,6 +179,8 @@
  4021. Klass* k = Klass::cast(klassOop(obj));
  4022. MarkSweep::adjust_pointer(k->adr_super());
  4023. + MarkSweep::adjust_pointer(k->adr_new_version());
  4024. + MarkSweep::adjust_pointer(k->adr_old_version());
  4025. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4026. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4027. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4028. diff -r 882f6c762ac5 src/share/vm/oops/klassOop.hpp
  4029. --- a/src/share/vm/oops/klassOop.hpp Thu Jul 09 23:10:04 2015 -0700
  4030. +++ b/src/share/vm/oops/klassOop.hpp Thu Jul 09 23:18:17 2015 -0700
  4031. @@ -41,8 +41,10 @@
  4032. // returns the Klass part containing dispatching behavior
  4033. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4034. - // Convenience wrapper
  4035. + // Convenience wrappers
  4036. inline oop java_mirror() const;
  4037. + inline klassOop old_version() const;
  4038. + inline klassOop new_version() const;
  4039. private:
  4040. // These have no implementation since klassOop should never be accessed in this fashion
  4041. diff -r 882f6c762ac5 src/share/vm/oops/klassVtable.cpp
  4042. --- a/src/share/vm/oops/klassVtable.cpp Thu Jul 09 23:10:04 2015 -0700
  4043. +++ b/src/share/vm/oops/klassVtable.cpp Thu Jul 09 23:18:17 2015 -0700
  4044. @@ -97,7 +97,8 @@
  4045. vtable_length = Universe::base_vtable_size();
  4046. }
  4047. - if (super == NULL && !Universe::is_bootstrapping() &&
  4048. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4049. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4050. vtable_length != Universe::base_vtable_size()) {
  4051. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4052. // only way this should happen is from
  4053. @@ -107,9 +108,9 @@
  4054. vtable_length = Universe::base_vtable_size();
  4055. }
  4056. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4057. - "bad vtable size for class Object");
  4058. + "bad vtable size for class Object");*/
  4059. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4060. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4061. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4062. }
  4063. int klassVtable::index_of(methodOop m, int len) const {
  4064. @@ -678,20 +679,6 @@
  4065. return true;
  4066. }
  4067. -void klassVtable::dump_vtable() {
  4068. - tty->print_cr("vtable dump --");
  4069. - for (int i = 0; i < length(); i++) {
  4070. - methodOop m = unchecked_method_at(i);
  4071. - if (m != NULL) {
  4072. - tty->print(" (%5d) ", i);
  4073. - m->access_flags().print_on(tty);
  4074. - tty->print(" -- ");
  4075. - m->print_name(tty);
  4076. - tty->cr();
  4077. - }
  4078. - }
  4079. -}
  4080. -
  4081. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4082. void klassVtable::clear_vtable() {
  4083. for (int i = 0; i < _length; i++) table()[i].clear();
  4084. @@ -1262,6 +1249,7 @@
  4085. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4086. vtableEntry* vte = &vt->table()[index];
  4087. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4088. if (vte->method()->name() != table()[index].method()->name() ||
  4089. vte->method()->signature() != table()[index].method()->signature()) {
  4090. fatal("mismatched name/signature of vtable entries");
  4091. @@ -1281,6 +1269,8 @@
  4092. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4093. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4094. + // (tw) TODO: Check: Does not hold?
  4095. + if (method() != NULL) {
  4096. assert(method() != NULL, "must have set method");
  4097. method()->verify();
  4098. // we sub_type, because it could be a miranda method
  4099. @@ -1288,7 +1278,13 @@
  4100. #ifndef PRODUCT
  4101. print();
  4102. #endif
  4103. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4104. + klassOop first_klass = vt->klass()();
  4105. + klassOop second_klass = method()->method_holder();
  4106. + // (tw) the following fatal does not work for old versions of classes
  4107. + if (first_klass->klass_part()->is_newest_version()) {
  4108. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4109. + }
  4110. + }
  4111. }
  4112. }
  4113. @@ -1296,7 +1292,7 @@
  4114. void vtableEntry::print() {
  4115. ResourceMark rm;
  4116. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4117. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4118. if (Verbose) {
  4119. tty->print("m %#lx ", (address)method());
  4120. }
  4121. @@ -1363,6 +1359,33 @@
  4122. tty->print_cr("%6d bytes total", total);
  4123. }
  4124. +bool klassVtable::check_no_old_entries() {
  4125. + // Check that there really is no entry
  4126. + for (int i = 0; i < length(); i++) {
  4127. + methodOop m = unchecked_method_at(i);
  4128. + if (m != NULL) {
  4129. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4130. + return false;
  4131. + }
  4132. + }
  4133. + }
  4134. + return true;
  4135. +}
  4136. +
  4137. +void klassVtable::dump_vtable() {
  4138. + tty->print_cr("vtable dump --");
  4139. + for (int i = 0; i < length(); i++) {
  4140. + methodOop m = unchecked_method_at(i);
  4141. + if (m != NULL) {
  4142. + tty->print(" (%5d) ", i);
  4143. + m->access_flags().print_on(tty);
  4144. + tty->print(" -- ");
  4145. + m->print_name(tty);
  4146. + tty->cr();
  4147. + }
  4148. + }
  4149. +}
  4150. +
  4151. int klassItable::_total_classes; // Total no. of classes with itables
  4152. long klassItable::_total_size; // Total no. of bytes used for itables
  4153. diff -r 882f6c762ac5 src/share/vm/oops/klassVtable.hpp
  4154. --- a/src/share/vm/oops/klassVtable.hpp Thu Jul 09 23:10:04 2015 -0700
  4155. +++ b/src/share/vm/oops/klassVtable.hpp Thu Jul 09 23:18:17 2015 -0700
  4156. @@ -100,6 +100,7 @@
  4157. int methods_length, bool * trace_name_printed);
  4158. bool check_no_old_or_obsolete_entries();
  4159. void dump_vtable();
  4160. + bool check_no_old_entries();
  4161. // Garbage collection
  4162. void oop_follow_contents();
  4163. diff -r 882f6c762ac5 src/share/vm/oops/methodKlass.cpp
  4164. --- a/src/share/vm/oops/methodKlass.cpp Thu Jul 09 23:10:04 2015 -0700
  4165. +++ b/src/share/vm/oops/methodKlass.cpp Thu Jul 09 23:18:17 2015 -0700
  4166. @@ -93,6 +93,10 @@
  4167. m->set_adapter_entry(NULL);
  4168. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4169. + m->set_forward_method(NULL);
  4170. + m->set_new_version(NULL);
  4171. + m->set_old_version(NULL);
  4172. +
  4173. if (access_flags.is_native()) {
  4174. m->clear_native_function();
  4175. m->set_signature_handler(NULL);
  4176. @@ -122,6 +126,9 @@
  4177. // Performance tweak: We skip iterating over the klass pointer since we
  4178. // know that Universe::methodKlassObj never moves.
  4179. MarkSweep::mark_and_push(m->adr_constMethod());
  4180. + MarkSweep::mark_and_push(m->adr_forward_method());
  4181. + MarkSweep::mark_and_push(m->adr_new_version());
  4182. + MarkSweep::mark_and_push(m->adr_old_version());
  4183. if (m->method_data() != NULL) {
  4184. MarkSweep::mark_and_push(m->adr_method_data());
  4185. }
  4186. @@ -135,6 +142,9 @@
  4187. // Performance tweak: We skip iterating over the klass pointer since we
  4188. // know that Universe::methodKlassObj never moves.
  4189. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4190. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4191. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4192. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4193. #ifdef COMPILER2
  4194. if (m->method_data() != NULL) {
  4195. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4196. @@ -152,6 +162,9 @@
  4197. // Performance tweak: We skip iterating over the klass pointer since we
  4198. // know that Universe::methodKlassObj never moves
  4199. blk->do_oop(m->adr_constMethod());
  4200. + blk->do_oop(m->adr_forward_method());
  4201. + blk->do_oop(m->adr_new_version());
  4202. + blk->do_oop(m->adr_old_version());
  4203. if (m->method_data() != NULL) {
  4204. blk->do_oop(m->adr_method_data());
  4205. }
  4206. @@ -170,6 +183,12 @@
  4207. oop* adr;
  4208. adr = m->adr_constMethod();
  4209. if (mr.contains(adr)) blk->do_oop(adr);
  4210. + adr = m->adr_new_version();
  4211. + if (mr.contains(adr)) blk->do_oop(adr);
  4212. + adr = m->adr_forward_method();
  4213. + if (mr.contains(adr)) blk->do_oop(adr);
  4214. + adr = m->adr_old_version();
  4215. + if (mr.contains(adr)) blk->do_oop(adr);
  4216. if (m->method_data() != NULL) {
  4217. adr = m->adr_method_data();
  4218. if (mr.contains(adr)) blk->do_oop(adr);
  4219. @@ -187,6 +206,9 @@
  4220. // Performance tweak: We skip iterating over the klass pointer since we
  4221. // know that Universe::methodKlassObj never moves.
  4222. MarkSweep::adjust_pointer(m->adr_constMethod());
  4223. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4224. + MarkSweep::adjust_pointer(m->adr_new_version());
  4225. + MarkSweep::adjust_pointer(m->adr_old_version());
  4226. if (m->method_data() != NULL) {
  4227. MarkSweep::adjust_pointer(m->adr_method_data());
  4228. }
  4229. @@ -202,6 +224,9 @@
  4230. assert(obj->is_method(), "should be method");
  4231. methodOop m = methodOop(obj);
  4232. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4233. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4234. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4235. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4236. #ifdef COMPILER2
  4237. if (m->method_data() != NULL) {
  4238. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4239. @@ -222,7 +247,18 @@
  4240. methodOop m = methodOop(obj);
  4241. // get the effect of PrintOopAddress, always, for methods:
  4242. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4243. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4244. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4245. +
  4246. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4247. + st->print(" (old)");
  4248. + }
  4249. + st->cr();
  4250. +
  4251. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4252. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4253. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4254. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4255. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4256. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4257. m->constants()->print_value_on(st); st->cr();
  4258. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4259. diff -r 882f6c762ac5 src/share/vm/oops/methodOop.cpp
  4260. --- a/src/share/vm/oops/methodOop.cpp Thu Jul 09 23:10:04 2015 -0700
  4261. +++ b/src/share/vm/oops/methodOop.cpp Thu Jul 09 23:18:17 2015 -0700
  4262. @@ -328,6 +328,70 @@
  4263. }
  4264. +bool methodOopDesc::is_in_code_section(int bci) {
  4265. + // There is no table => every bci is in the code section table.
  4266. + if (!constMethod()->has_code_section_table()) return true;
  4267. +
  4268. + constMethodOop m = constMethod();
  4269. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4270. + u2 new_index = m->code_section_new_index_at(i);
  4271. + u2 length = m->code_section_length_at(i);
  4272. + if (bci >= new_index && bci < new_index + length) {
  4273. + // We are in a specified code section.
  4274. + return true;
  4275. + }
  4276. + }
  4277. +
  4278. + return false;
  4279. +}
  4280. +
  4281. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4282. + int original_bci = -1;
  4283. + if (constMethod()->has_code_section_table()) {
  4284. + assert(is_in_code_section(bci), "can only forward in section");
  4285. + // First calculate back to original bci.
  4286. + constMethodOop m = constMethod();
  4287. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4288. + u2 new_index = m->code_section_new_index_at(i);
  4289. + u2 original_index = m->code_section_original_index_at(i);
  4290. + u2 length = m->code_section_length_at(i);
  4291. + if (bci >= new_index && bci < new_index + length) {
  4292. + // We are in a specified code section.
  4293. + original_bci = bci - new_index + original_index;
  4294. + break;
  4295. + }
  4296. + }
  4297. + assert (original_bci != -1, "must have been in code section");
  4298. + } else {
  4299. + // No code sections specified => we are in an original method.
  4300. + original_bci = bci;
  4301. + }
  4302. +
  4303. + // We know the original bci => match to new method.
  4304. + int new_bci = -1;
  4305. + if (new_method->constMethod()->has_code_section_table()) {
  4306. + // Map to new bci.
  4307. + constMethodOop m = new_method->constMethod();
  4308. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4309. + u2 new_index = m->code_section_new_index_at(i);
  4310. + u2 original_index = m->code_section_original_index_at(i);
  4311. + u2 length = m->code_section_length_at(i);
  4312. + if (original_bci >= original_index && original_bci < original_index + length) {
  4313. + new_bci = original_bci - original_index + new_index;
  4314. + break;
  4315. + }
  4316. + }
  4317. + assert (new_bci != -1, "must have found new code section");
  4318. +
  4319. + } else {
  4320. + // We are in an original method.
  4321. + new_bci = original_bci;
  4322. + }
  4323. +
  4324. + return new_bci;
  4325. +}
  4326. +
  4327. +
  4328. int methodOopDesc::extra_stack_words() {
  4329. // not an inline function, to avoid a header dependency on Interpreter
  4330. return extra_stack_entries() * Interpreter::stackElementSize;
  4331. @@ -1061,6 +1125,9 @@
  4332. // Reset correct method/const method, method size, and parameter info
  4333. newm->set_constMethod(newcm);
  4334. + newm->set_forward_method(newm->forward_method());
  4335. + newm->set_new_version(newm->new_version());
  4336. + newm->set_old_version(newm->old_version());
  4337. newm->constMethod()->set_code_size(new_code_length);
  4338. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4339. newm->set_method_size(new_method_size);
  4340. diff -r 882f6c762ac5 src/share/vm/oops/methodOop.hpp
  4341. --- a/src/share/vm/oops/methodOop.hpp Thu Jul 09 23:10:04 2015 -0700
  4342. +++ b/src/share/vm/oops/methodOop.hpp Thu Jul 09 23:18:17 2015 -0700
  4343. @@ -114,6 +114,11 @@
  4344. AccessFlags _access_flags; // Access flags
  4345. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4346. // note: can have vtables with >2**16 elements (because of inheritance)
  4347. + // (tw) Newer version of method available?
  4348. + methodOop _forward_method;
  4349. + methodOop _new_version;
  4350. + methodOop _old_version;
  4351. +
  4352. #ifdef CC_INTERP
  4353. int _result_index; // C++ interpreter needs for converting results to/from stack
  4354. #endif
  4355. @@ -175,6 +180,32 @@
  4356. int name_index() const { return constMethod()->name_index(); }
  4357. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4358. + methodOop forward_method() const {return _forward_method; }
  4359. + void set_forward_method(methodOop m) { _forward_method = m; }
  4360. + bool has_forward_method() const { return forward_method() != NULL; }
  4361. + methodOop new_version() const {return _new_version; }
  4362. + void set_new_version(methodOop m) { _new_version = m; }
  4363. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4364. +
  4365. + methodOop old_version() const {return _old_version; };
  4366. + void set_old_version(methodOop m) {
  4367. + if (m == NULL) {
  4368. + _old_version = NULL;
  4369. + return;
  4370. + }
  4371. +
  4372. + assert(_old_version == NULL, "may only be set once");
  4373. + assert(this->code_size() == m->code_size(), "must have same code length");
  4374. + _old_version = m;
  4375. + }
  4376. +
  4377. + methodOop oldest_version() const {
  4378. + if(_old_version == NULL) return (methodOop)this;
  4379. + else {
  4380. + return old_version()->oldest_version();
  4381. + }
  4382. + }
  4383. +
  4384. // signature
  4385. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4386. int signature_index() const { return constMethod()->signature_index(); }
  4387. @@ -670,6 +701,10 @@
  4388. // Inline cache support
  4389. void cleanup_inline_caches();
  4390. + // (tw) Method forwarding support.
  4391. + bool is_in_code_section(int bci);
  4392. + int calculate_forward_bci(int bci, methodOop new_method);
  4393. +
  4394. // Find if klass for method is loaded
  4395. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4396. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4397. @@ -734,6 +769,9 @@
  4398. // Garbage collection support
  4399. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4400. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4401. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4402. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4403. oop* adr_method_data() const { return (oop*)&_method_data; }
  4404. };
  4405. diff -r 882f6c762ac5 src/share/vm/oops/oop.hpp
  4406. --- a/src/share/vm/oops/oop.hpp Thu Jul 09 23:10:04 2015 -0700
  4407. +++ b/src/share/vm/oops/oop.hpp Thu Jul 09 23:18:17 2015 -0700
  4408. @@ -95,6 +95,7 @@
  4409. narrowOop* compressed_klass_addr();
  4410. void set_klass(klassOop k);
  4411. + void set_klass_no_check(klassOop k);
  4412. // For klass field compression
  4413. int klass_gap() const;
  4414. @@ -135,6 +136,7 @@
  4415. bool is_array() const;
  4416. bool is_objArray() const;
  4417. bool is_klass() const;
  4418. + bool is_instanceKlass() const;
  4419. bool is_thread() const;
  4420. bool is_method() const;
  4421. bool is_constMethod() const;
  4422. diff -r 882f6c762ac5 src/share/vm/oops/oop.inline.hpp
  4423. --- a/src/share/vm/oops/oop.inline.hpp Thu Jul 09 23:10:04 2015 -0700
  4424. +++ b/src/share/vm/oops/oop.inline.hpp Thu Jul 09 23:18:17 2015 -0700
  4425. @@ -123,6 +123,14 @@
  4426. }
  4427. }
  4428. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4429. + if (UseCompressedOops) {
  4430. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4431. + } else {
  4432. + oop_store_without_check(klass_addr(), (oop) k);
  4433. + }
  4434. +}
  4435. +
  4436. inline int oopDesc::klass_gap() const {
  4437. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4438. }
  4439. @@ -156,6 +164,7 @@
  4440. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4441. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4442. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4443. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4444. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4445. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4446. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4447. diff -r 882f6c762ac5 src/share/vm/prims/jni.cpp
  4448. --- a/src/share/vm/prims/jni.cpp Thu Jul 09 23:10:04 2015 -0700
  4449. +++ b/src/share/vm/prims/jni.cpp Thu Jul 09 23:18:17 2015 -0700
  4450. @@ -406,7 +406,7 @@
  4451. }
  4452. }
  4453. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4454. - Handle(), &st, true,
  4455. + Handle(), &st, true, KlassHandle(),
  4456. CHECK_NULL);
  4457. if (TraceClassResolution && k != NULL) {
  4458. diff -r 882f6c762ac5 src/share/vm/prims/jvm.cpp
  4459. --- a/src/share/vm/prims/jvm.cpp Thu Jul 09 23:10:04 2015 -0700
  4460. +++ b/src/share/vm/prims/jvm.cpp Thu Jul 09 23:18:17 2015 -0700
  4461. @@ -932,7 +932,7 @@
  4462. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4463. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4464. protection_domain, &st,
  4465. - verify != 0,
  4466. + verify != 0, KlassHandle(),
  4467. CHECK_NULL);
  4468. if (TraceClassResolution && k != NULL) {
  4469. diff -r 882f6c762ac5 src/share/vm/prims/jvmtiEnv.cpp
  4470. --- a/src/share/vm/prims/jvmtiEnv.cpp Thu Jul 09 23:10:04 2015 -0700
  4471. +++ b/src/share/vm/prims/jvmtiEnv.cpp Thu Jul 09 23:18:17 2015 -0700
  4472. @@ -290,7 +290,10 @@
  4473. class_definitions[index].klass = jcls;
  4474. }
  4475. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4476. - VMThread::execute(&op);
  4477. + {
  4478. + MutexLocker sd_mutex(RedefineClasses_lock);
  4479. + VMThread::execute(&op);
  4480. + }
  4481. return (op.check_error());
  4482. } /* end RetransformClasses */
  4483. @@ -299,9 +302,12 @@
  4484. // class_definitions - pre-checked for NULL
  4485. jvmtiError
  4486. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4487. -//TODO: add locking
  4488. +
  4489. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4490. - VMThread::execute(&op);
  4491. + {
  4492. + MutexLocker sd_mutex(RedefineClasses_lock);
  4493. + VMThread::execute(&op);
  4494. + }
  4495. return (op.check_error());
  4496. } /* end RedefineClasses */
  4497. diff -r 882f6c762ac5 src/share/vm/prims/jvmtiExport.cpp
  4498. --- a/src/share/vm/prims/jvmtiExport.cpp Thu Jul 09 23:10:04 2015 -0700
  4499. +++ b/src/share/vm/prims/jvmtiExport.cpp Thu Jul 09 23:18:17 2015 -0700
  4500. @@ -2296,7 +2296,7 @@
  4501. // iterate over any code blob descriptors collected and post a
  4502. // DYNAMIC_CODE_GENERATED event to the profiler.
  4503. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4504. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4505. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4506. // iterate over any code blob descriptors that we collected
  4507. if (_code_blobs != NULL) {
  4508. for (int i=0; i<_code_blobs->length(); i++) {
  4509. diff -r 882f6c762ac5 src/share/vm/prims/jvmtiImpl.cpp
  4510. --- a/src/share/vm/prims/jvmtiImpl.cpp Thu Jul 09 23:10:04 2015 -0700
  4511. +++ b/src/share/vm/prims/jvmtiImpl.cpp Thu Jul 09 23:18:17 2015 -0700
  4512. @@ -286,6 +286,8 @@
  4513. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4514. ((methodOopDesc*)_method->*meth_act)(_bci);
  4515. + // DCEVM: TODO: Check how we can implement this differently here!
  4516. +
  4517. // add/remove breakpoint to/from versions of the method that
  4518. // are EMCP. Directly or transitively obsolete methods are
  4519. // not saved in the PreviousVersionInfo.
  4520. diff -r 882f6c762ac5 src/share/vm/prims/jvmtiRedefineClasses.cpp
  4521. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Jul 09 23:10:04 2015 -0700
  4522. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Jul 09 23:18:17 2015 -0700
  4523. @@ -1,5 +1,5 @@
  4524. /*
  4525. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  4526. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4527. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4528. *
  4529. * This code is free software; you can redistribute it and/or modify it
  4530. @@ -30,581 +30,637 @@
  4531. #include "interpreter/rewriter.hpp"
  4532. #include "memory/gcLocker.hpp"
  4533. #include "memory/universe.inline.hpp"
  4534. +#include "memory/cardTableRS.hpp"
  4535. +#include "oops/klassVtable.hpp"
  4536. #include "oops/fieldStreams.hpp"
  4537. -#include "oops/klassVtable.hpp"
  4538. #include "prims/jvmtiImpl.hpp"
  4539. #include "prims/jvmtiRedefineClasses.hpp"
  4540. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4541. #include "prims/methodComparator.hpp"
  4542. -#include "prims/methodHandles.hpp"
  4543. #include "runtime/deoptimization.hpp"
  4544. #include "runtime/relocator.hpp"
  4545. #include "utilities/bitMap.inline.hpp"
  4546. +#include "compiler/compileBroker.hpp"
  4547. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4548. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4549. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4550. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4551. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4552. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4553. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4554. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4555. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4556. +int* VM_RedefineClasses::_added_methods = NULL;
  4557. int VM_RedefineClasses::_matching_methods_length = 0;
  4558. int VM_RedefineClasses::_deleted_methods_length = 0;
  4559. int VM_RedefineClasses::_added_methods_length = 0;
  4560. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4561. -
  4562. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4563. - const jvmtiClassDefinition *class_defs,
  4564. - JvmtiClassLoadKind class_load_kind) {
  4565. +// Holds the revision number of the current class redefinition
  4566. +int VM_RedefineClasses::_revision_number = -1;
  4567. +
  4568. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4569. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4570. + RC_TIMER_START(_timer_total);
  4571. _class_count = class_count;
  4572. _class_defs = class_defs;
  4573. _class_load_kind = class_load_kind;
  4574. - _res = JVMTI_ERROR_NONE;
  4575. + _updated_oops = NULL;
  4576. + _result = JVMTI_ERROR_NONE;
  4577. }
  4578. +VM_RedefineClasses::~VM_RedefineClasses() {
  4579. + {
  4580. + MonitorLockerEx ml(RedefinitionSync_lock);
  4581. + Threads::set_wait_at_instrumentation_entry(false);
  4582. + ml.notify_all();
  4583. + }
  4584. +
  4585. + unlock_threads();
  4586. + RC_TIMER_STOP(_timer_total);
  4587. +
  4588. + if (TimeRedefineClasses) {
  4589. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4590. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4591. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4592. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4593. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4594. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4595. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4596. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4597. + tty->print_cr("------------------------------------------------------------------");
  4598. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4599. + }
  4600. +}
  4601. +
  4602. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4603. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4604. +
  4605. + // Create array with all classes for which the redefine command was given
  4606. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4607. + for (int i=0; i<_class_count; i++) {
  4608. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4609. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4610. + klasses_to_redefine.append(klass_handle);
  4611. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4612. + }
  4613. +
  4614. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4615. + GrowableArray<instanceKlassHandle> affected_classes;
  4616. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4617. +
  4618. + // Trace affected classes
  4619. + if (RC_TRACE_ENABLED(0x00000001)) {
  4620. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4621. + affected_classes.length()));
  4622. + for (int i=0; i<affected_classes.length(); i++) {
  4623. + RC_TRACE(0x00000001, ("%s",
  4624. + affected_classes.at(i)->name()->as_C_string()));
  4625. + }
  4626. + }
  4627. +
  4628. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4629. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4630. + all_affected_klasses->appendAll(&affected_classes);
  4631. +
  4632. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4633. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4634. + if (RC_TRACE_ENABLED(0x00000001)) {
  4635. + RC_TRACE(0x00000001, ("Redefine order: "));
  4636. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4637. + RC_TRACE(0x00000001, ("%s",
  4638. + all_affected_klasses->at(i)->name()->as_C_string()));
  4639. + }
  4640. + }
  4641. +
  4642. + return result;
  4643. +}
  4644. +
  4645. +// Searches for the class bytes of the given class and returns them as a byte array.
  4646. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4647. +
  4648. + *not_changed = false;
  4649. +
  4650. + // Search for the index in the redefinition array that corresponds to the current class
  4651. + int j;
  4652. + for (j=0; j<_class_count; j++) {
  4653. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4654. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4655. + if (the_class_oop == the_class()) {
  4656. + break;
  4657. + }
  4658. + }
  4659. +
  4660. + if (j == _class_count) {
  4661. +
  4662. + *not_changed = true;
  4663. +
  4664. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4665. + // so the user did not specify a different bytecode for that class.
  4666. +
  4667. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4668. + // not cached, we need to reconstitute the class file from VM representation
  4669. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4670. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4671. +
  4672. + JvmtiClassFileReconstituter reconstituter(the_class);
  4673. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4674. + return reconstituter.get_error();
  4675. + }
  4676. +
  4677. + *class_byte_count = (jint)reconstituter.class_file_size();
  4678. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4679. +
  4680. + } else {
  4681. +
  4682. + // it is cached, get it from the cache
  4683. + *class_byte_count = the_class->get_cached_class_file_len();
  4684. + *class_bytes = the_class->get_cached_class_file_bytes();
  4685. + }
  4686. +
  4687. + } else {
  4688. +
  4689. + // Redefine with bytecodes at index j
  4690. + *class_bytes = _class_defs[j].class_bytes;
  4691. + *class_byte_count = _class_defs[j].class_byte_count;
  4692. + }
  4693. +
  4694. + return JVMTI_ERROR_NONE;
  4695. +}
  4696. +
  4697. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4698. bool VM_RedefineClasses::doit_prologue() {
  4699. - if (_class_count == 0) {
  4700. - _res = JVMTI_ERROR_NONE;
  4701. +
  4702. + _revision_number++;
  4703. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4704. +
  4705. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4706. + RC_TIMER_START(_timer_prologue);
  4707. +
  4708. + if (!check_arguments()) {
  4709. + RC_TIMER_STOP(_timer_prologue);
  4710. return false;
  4711. }
  4712. - if (_class_defs == NULL) {
  4713. - _res = JVMTI_ERROR_NULL_POINTER;
  4714. +
  4715. + // We first load new class versions in the prologue, because somewhere down the
  4716. + // call chain it is required that the current thread is a Java thread.
  4717. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4718. + _result = load_new_class_versions(Thread::current());
  4719. +
  4720. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4721. + if (_result != JVMTI_ERROR_NONE) {
  4722. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4723. + delete _new_classes;
  4724. + _new_classes = NULL;
  4725. + RC_TIMER_STOP(_timer_prologue);
  4726. return false;
  4727. }
  4728. +
  4729. + RC_TRACE(0x00000001, ("nearly finished"));
  4730. + VM_GC_Operation::doit_prologue();
  4731. + RC_TIMER_STOP(_timer_prologue);
  4732. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4733. + return true;
  4734. +}
  4735. +
  4736. +// Checks basic properties of the arguments of the redefinition command.
  4737. +bool VM_RedefineClasses::check_arguments() {
  4738. +
  4739. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4740. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4741. for (int i = 0; i < _class_count; i++) {
  4742. - if (_class_defs[i].klass == NULL) {
  4743. - _res = JVMTI_ERROR_INVALID_CLASS;
  4744. - return false;
  4745. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4746. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4747. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4748. + }
  4749. +
  4750. + return true;
  4751. +}
  4752. +
  4753. +jvmtiError VM_RedefineClasses::check_exception() const {
  4754. + Thread* THREAD = Thread::current();
  4755. + if (HAS_PENDING_EXCEPTION) {
  4756. +
  4757. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4758. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4759. + ex_name->as_C_string()));
  4760. + if (TraceRedefineClasses >= 1) {
  4761. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4762. + tty->print_cr("");
  4763. }
  4764. - if (_class_defs[i].class_byte_count == 0) {
  4765. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4766. - return false;
  4767. - }
  4768. - if (_class_defs[i].class_bytes == NULL) {
  4769. - _res = JVMTI_ERROR_NULL_POINTER;
  4770. - return false;
  4771. + CLEAR_PENDING_EXCEPTION;
  4772. +
  4773. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4774. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4775. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4776. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4777. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4778. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4779. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4780. + // The message will be "XXX (wrong name: YYY)"
  4781. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4782. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4783. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4784. + } else {
  4785. + // Just in case more exceptions can be thrown..
  4786. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4787. }
  4788. }
  4789. - // Start timer after all the sanity checks; not quite accurate, but
  4790. - // better than adding a bunch of stop() calls.
  4791. - RC_TIMER_START(_timer_vm_op_prologue);
  4792. -
  4793. - // We first load new class versions in the prologue, because somewhere down the
  4794. - // call chain it is required that the current thread is a Java thread.
  4795. - _res = load_new_class_versions(Thread::current());
  4796. - if (_res != JVMTI_ERROR_NONE) {
  4797. - // Free os::malloc allocated memory in load_new_class_version.
  4798. - os::free(_scratch_classes);
  4799. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4800. - return false;
  4801. + return JVMTI_ERROR_NONE;
  4802. +}
  4803. +
  4804. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4805. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4806. +
  4807. + ResourceMark rm(THREAD);
  4808. +
  4809. + RC_TRACE(0x00000001, ("==================================================================="));
  4810. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  4811. + _class_count));
  4812. +
  4813. + // Retrieve an array of all classes that need to be redefined
  4814. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4815. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4816. + if (err != JVMTI_ERROR_NONE) {
  4817. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  4818. + (int)err));
  4819. + return err;
  4820. }
  4821. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4822. - return true;
  4823. -}
  4824. -
  4825. -void VM_RedefineClasses::doit() {
  4826. - Thread *thread = Thread::current();
  4827. -
  4828. - if (UseSharedSpaces) {
  4829. - // Sharing is enabled so we remap the shared readonly space to
  4830. - // shared readwrite, private just in case we need to redefine
  4831. - // a shared class. We do the remap during the doit() phase of
  4832. - // the safepoint to be safer.
  4833. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4834. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4835. - ("failed to remap shared readonly space to readwrite, private"));
  4836. - _res = JVMTI_ERROR_INTERNAL;
  4837. - return;
  4838. +
  4839. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4840. +
  4841. + _max_redefinition_flags = Klass::NoRedefinition;
  4842. + jvmtiError result = JVMTI_ERROR_NONE;
  4843. +
  4844. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4845. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  4846. + i+1, all_affected_klasses.length()));
  4847. +
  4848. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4849. + RC_TRACE(0x00000002, ("name=%s",
  4850. + the_class->name()->as_C_string()));
  4851. +
  4852. + the_class->link_class(THREAD);
  4853. + result = check_exception();
  4854. + if (result != JVMTI_ERROR_NONE) break;
  4855. +
  4856. + // Find new class bytes
  4857. + const unsigned char* class_bytes;
  4858. + jint class_byte_count;
  4859. + jvmtiError error;
  4860. + jboolean not_changed;
  4861. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4862. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  4863. + (int)error));
  4864. + result = error;
  4865. + break;
  4866. }
  4867. - }
  4868. -
  4869. - for (int i = 0; i < _class_count; i++) {
  4870. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4871. - }
  4872. - // Disable any dependent concurrent compilations
  4873. - SystemDictionary::notice_modification();
  4874. -
  4875. - // Set flag indicating that some invariants are no longer true.
  4876. - // See jvmtiExport.hpp for detailed explanation.
  4877. - JvmtiExport::set_has_redefined_a_class();
  4878. -
  4879. -// check_class() is optionally called for product bits, but is
  4880. -// always called for non-product bits.
  4881. -#ifdef PRODUCT
  4882. - if (RC_TRACE_ENABLED(0x00004000)) {
  4883. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4884. +
  4885. +
  4886. + // Set redefined class handle in JvmtiThreadState class.
  4887. + // This redefined class is sent to agent event handler for class file
  4888. + // load hook event.
  4889. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4890. +
  4891. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  4892. +
  4893. + RC_TIMER_STOP(_timer_prologue);
  4894. + RC_TIMER_START(_timer_class_loading);
  4895. +
  4896. +
  4897. + // Parse the stream.
  4898. + Handle the_class_loader(THREAD, the_class->class_loader());
  4899. + Handle protection_domain(THREAD, the_class->protection_domain());
  4900. + Symbol* the_class_sym = the_class->name();
  4901. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4902. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  4903. + the_class_loader,
  4904. + protection_domain,
  4905. + &st,
  4906. + true,
  4907. + the_class,
  4908. + THREAD));
  4909. +
  4910. + not_changed = false;
  4911. +
  4912. + RC_TIMER_STOP(_timer_class_loading);
  4913. + RC_TIMER_START(_timer_prologue);
  4914. +
  4915. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  4916. + // Clear class_being_redefined just to be sure.
  4917. + state->clear_class_being_redefined();
  4918. +
  4919. + result = check_exception();
  4920. + if (result != JVMTI_ERROR_NONE) break;
  4921. +
  4922. +#ifdef ASSERT
  4923. +
  4924. + assert(new_class() != NULL, "Class could not be loaded!");
  4925. + assert(new_class() != the_class(), "must be different");
  4926. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4927. +
  4928. +
  4929. + objArrayOop k_interfaces = new_class->local_interfaces();
  4930. + for (int j=0; j<k_interfaces->length(); j++) {
  4931. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4932. + }
  4933. +
  4934. + if (!THREAD->is_Compiler_thread()) {
  4935. +
  4936. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  4937. + the_class->name()->as_C_string(),
  4938. + (address)(the_class->class_loader()),
  4939. + (address)(the_class->protection_domain())));
  4940. + // If we are on the compiler thread, we must not try to resolve a class.
  4941. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4942. +
  4943. + if (systemLookup != NULL) {
  4944. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4945. +
  4946. +
  4947. + Klass *subklass = new_class()->klass_part()->subklass();
  4948. + while (subklass != NULL) {
  4949. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4950. + subklass = subklass->next_sibling();
  4951. + }
  4952. + } else {
  4953. + // This can happen for reflection generated classes.. ?
  4954. + CLEAR_PENDING_EXCEPTION;
  4955. + }
  4956. + }
  4957. +
  4958. #endif
  4959. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4960. - SystemDictionary::classes_do(check_class, thread);
  4961. -#ifdef PRODUCT
  4962. - }
  4963. -#endif
  4964. -}
  4965. -
  4966. -void VM_RedefineClasses::doit_epilogue() {
  4967. - // Free os::malloc allocated memory.
  4968. - // The memory allocated in redefine will be free'ed in next VM operation.
  4969. - os::free(_scratch_classes);
  4970. -
  4971. - if (RC_TRACE_ENABLED(0x00000004)) {
  4972. - // Used to have separate timers for "doit" and "all", but the timer
  4973. - // overhead skewed the measurements.
  4974. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4975. - _timer_rsc_phase2.milliseconds();
  4976. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4977. -
  4978. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4979. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4980. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4981. - RC_TRACE(0x00000004,
  4982. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4983. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4984. - }
  4985. -}
  4986. -
  4987. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4988. - // classes for primitives cannot be redefined
  4989. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4990. - return false;
  4991. - }
  4992. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4993. - // classes for arrays cannot be redefined
  4994. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4995. - return false;
  4996. - }
  4997. - return true;
  4998. -}
  4999. -
  5000. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  5001. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  5002. -// direct CP entries, there is just the current entry to append. For
  5003. -// indirect and double-indirect CP entries, there are zero or more
  5004. -// referenced CP entries along with the current entry to append.
  5005. -// Indirect and double-indirect CP entries are handled by recursive
  5006. -// calls to append_entry() as needed. The referenced CP entries are
  5007. -// always appended to *merge_cp_p before the referee CP entry. These
  5008. -// referenced CP entries may already exist in *merge_cp_p in which case
  5009. -// there is nothing extra to append and only the current entry is
  5010. -// appended.
  5011. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  5012. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  5013. - TRAPS) {
  5014. -
  5015. - // append is different depending on entry tag type
  5016. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5017. -
  5018. - // The old verifier is implemented outside the VM. It loads classes,
  5019. - // but does not resolve constant pool entries directly so we never
  5020. - // see Class entries here with the old verifier. Similarly the old
  5021. - // verifier does not like Class entries in the input constant pool.
  5022. - // The split-verifier is implemented in the VM so it can optionally
  5023. - // and directly resolve constant pool entries to load classes. The
  5024. - // split-verifier can accept either Class entries or UnresolvedClass
  5025. - // entries in the input constant pool. We revert the appended copy
  5026. - // back to UnresolvedClass so that either verifier will be happy
  5027. - // with the constant pool entry.
  5028. - case JVM_CONSTANT_Class:
  5029. - {
  5030. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5031. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  5032. - scratch_cp->klass_name_at(scratch_i));
  5033. -
  5034. - if (scratch_i != *merge_cp_length_p) {
  5035. - // The new entry in *merge_cp_p is at a different index than
  5036. - // the new entry in scratch_cp so we need to map the index values.
  5037. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5038. +
  5039. + if (RC_TRACE_ENABLED(0x00000001)) {
  5040. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5041. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5042. + new_class->name()->as_C_string(),
  5043. + new_class->layout_helper(),
  5044. + the_class->layout_helper()));
  5045. }
  5046. - (*merge_cp_length_p)++;
  5047. - } break;
  5048. -
  5049. - // these are direct CP entries so they can be directly appended,
  5050. - // but double and long take two constant pool entries
  5051. - case JVM_CONSTANT_Double: // fall through
  5052. - case JVM_CONSTANT_Long:
  5053. - {
  5054. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5055. - THREAD);
  5056. -
  5057. - if (scratch_i != *merge_cp_length_p) {
  5058. - // The new entry in *merge_cp_p is at a different index than
  5059. - // the new entry in scratch_cp so we need to map the index values.
  5060. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5061. - }
  5062. - (*merge_cp_length_p) += 2;
  5063. - } break;
  5064. -
  5065. - // these are direct CP entries so they can be directly appended
  5066. - case JVM_CONSTANT_Float: // fall through
  5067. - case JVM_CONSTANT_Integer: // fall through
  5068. - case JVM_CONSTANT_Utf8: // fall through
  5069. -
  5070. - // This was an indirect CP entry, but it has been changed into
  5071. - // an interned string so this entry can be directly appended.
  5072. - case JVM_CONSTANT_String: // fall through
  5073. -
  5074. - // These were indirect CP entries, but they have been changed into
  5075. - // Symbol*s so these entries can be directly appended.
  5076. - case JVM_CONSTANT_UnresolvedClass: // fall through
  5077. - case JVM_CONSTANT_UnresolvedString:
  5078. - {
  5079. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5080. - THREAD);
  5081. -
  5082. - if (scratch_i != *merge_cp_length_p) {
  5083. - // The new entry in *merge_cp_p is at a different index than
  5084. - // the new entry in scratch_cp so we need to map the index values.
  5085. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5086. - }
  5087. - (*merge_cp_length_p)++;
  5088. - } break;
  5089. -
  5090. - // this is an indirect CP entry so it needs special handling
  5091. - case JVM_CONSTANT_NameAndType:
  5092. - {
  5093. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  5094. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  5095. - merge_cp_length_p, THREAD);
  5096. -
  5097. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5098. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  5099. - merge_cp_p, merge_cp_length_p,
  5100. - THREAD);
  5101. -
  5102. - // If the referenced entries already exist in *merge_cp_p, then
  5103. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5104. - // In that case, all we are appending is the current entry.
  5105. - if (new_name_ref_i != name_ref_i) {
  5106. - RC_TRACE(0x00080000,
  5107. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5108. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5109. - }
  5110. - if (new_signature_ref_i != signature_ref_i) {
  5111. - RC_TRACE(0x00080000,
  5112. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5113. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5114. - }
  5115. -
  5116. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5117. - new_name_ref_i, new_signature_ref_i);
  5118. - if (scratch_i != *merge_cp_length_p) {
  5119. - // The new entry in *merge_cp_p is at a different index than
  5120. - // the new entry in scratch_cp so we need to map the index values.
  5121. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5122. - }
  5123. - (*merge_cp_length_p)++;
  5124. - } break;
  5125. -
  5126. - // this is a double-indirect CP entry so it needs special handling
  5127. - case JVM_CONSTANT_Fieldref: // fall through
  5128. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5129. - case JVM_CONSTANT_Methodref:
  5130. - {
  5131. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5132. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  5133. - merge_cp_p, merge_cp_length_p, THREAD);
  5134. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5135. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  5136. - merge_cp_p, merge_cp_length_p, THREAD);
  5137. -
  5138. - const char *entry_name;
  5139. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5140. - case JVM_CONSTANT_Fieldref:
  5141. - entry_name = "Fieldref";
  5142. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5143. - new_name_and_type_ref_i);
  5144. - break;
  5145. - case JVM_CONSTANT_InterfaceMethodref:
  5146. - entry_name = "IFMethodref";
  5147. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5148. - new_klass_ref_i, new_name_and_type_ref_i);
  5149. - break;
  5150. - case JVM_CONSTANT_Methodref:
  5151. - entry_name = "Methodref";
  5152. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5153. - new_name_and_type_ref_i);
  5154. - break;
  5155. - default:
  5156. - guarantee(false, "bad switch");
  5157. + }
  5158. +
  5159. + // Set the new version of the class
  5160. + new_class->set_revision_number(_revision_number);
  5161. + new_class->set_redefinition_index(i);
  5162. + the_class->set_new_version(new_class());
  5163. + _new_classes->append(new_class);
  5164. +
  5165. + assert(new_class->new_version() == NULL, "");
  5166. +
  5167. + int redefinition_flags = Klass::NoRedefinition;
  5168. +
  5169. + if (not_changed) {
  5170. + redefinition_flags = Klass::NoRedefinition;
  5171. + } else if (AllowAdvancedClassRedefinition) {
  5172. + redefinition_flags = calculate_redefinition_flags(new_class);
  5173. + } else {
  5174. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5175. + if (allowed != JVMTI_ERROR_NONE) {
  5176. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5177. + result = allowed;
  5178. break;
  5179. }
  5180. -
  5181. - if (klass_ref_i != new_klass_ref_i) {
  5182. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5183. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5184. + redefinition_flags = Klass::ModifyClass;
  5185. + }
  5186. +
  5187. + if (new_class->super() != NULL) {
  5188. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5189. + }
  5190. +
  5191. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5192. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5193. + }
  5194. +
  5195. + new_class->set_redefinition_flags(redefinition_flags);
  5196. +
  5197. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5198. +
  5199. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5200. + // TODO: Check if watch access flags of static fields are updated correctly.
  5201. + calculate_instance_update_information(_new_classes->at(i)());
  5202. + } else {
  5203. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5204. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5205. +
  5206. + fieldDescriptor fd_new;
  5207. + fieldDescriptor fd_old;
  5208. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5209. + fd_new.initialize(new_class(), fs.index());
  5210. + fd_old.initialize(new_class->old_version(), fs.index());
  5211. + transfer_special_access_flags(&fd_old, &fd_new);
  5212. }
  5213. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5214. - RC_TRACE(0x00080000,
  5215. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5216. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5217. - new_name_and_type_ref_i));
  5218. + }
  5219. +
  5220. + if (RC_TRACE_ENABLED(0x00000008)) {
  5221. + if (new_class->super() != NULL) {
  5222. + RC_TRACE(0x00000008, ("Super class is %s",
  5223. + new_class->super()->klass_part()->name()->as_C_string()));
  5224. }
  5225. -
  5226. - if (scratch_i != *merge_cp_length_p) {
  5227. - // The new entry in *merge_cp_p is at a different index than
  5228. - // the new entry in scratch_cp so we need to map the index values.
  5229. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5230. + }
  5231. +
  5232. +#ifdef ASSERT
  5233. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5234. +
  5235. + the_class->vtable()->verify(tty);
  5236. + new_class->vtable()->verify(tty);
  5237. +#endif
  5238. +
  5239. + RC_TRACE(0x00000002, ("Verification done!"));
  5240. +
  5241. + if (i == all_affected_klasses.length() - 1) {
  5242. +
  5243. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5244. +
  5245. + RC_TIMER_STOP(_timer_prologue);
  5246. + lock_threads();
  5247. + RC_TIMER_START(_timer_prologue);
  5248. +
  5249. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5250. +
  5251. + klassOop initial_klass = all_affected_klasses.at(j)();
  5252. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5253. + Klass *cur_klass = initial_subklass;
  5254. + while(cur_klass != NULL) {
  5255. +
  5256. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5257. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5258. + if (!all_affected_klasses.contains(handle)) {
  5259. +
  5260. + int k = i + 1;
  5261. + for (; k<all_affected_klasses.length(); k++) {
  5262. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5263. + break;
  5264. + }
  5265. + }
  5266. + all_affected_klasses.insert_before(k, handle);
  5267. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5268. + cur_klass->name()->as_C_string()));
  5269. + }
  5270. + }
  5271. +
  5272. + cur_klass = cur_klass->next_sibling();
  5273. + }
  5274. }
  5275. - (*merge_cp_length_p)++;
  5276. - } break;
  5277. -
  5278. - // this is an indirect CP entry so it needs special handling
  5279. - case JVM_CONSTANT_MethodType:
  5280. - {
  5281. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  5282. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5283. - merge_cp_length_p, THREAD);
  5284. - if (new_ref_i != ref_i) {
  5285. - RC_TRACE(0x00080000,
  5286. - ("MethodType entry@%d ref_index change: %d to %d",
  5287. - *merge_cp_length_p, ref_i, new_ref_i));
  5288. - }
  5289. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  5290. - if (scratch_i != *merge_cp_length_p) {
  5291. - // The new entry in *merge_cp_p is at a different index than
  5292. - // the new entry in scratch_cp so we need to map the index values.
  5293. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5294. - }
  5295. - (*merge_cp_length_p)++;
  5296. - } break;
  5297. -
  5298. - // this is an indirect CP entry so it needs special handling
  5299. - case JVM_CONSTANT_MethodHandle:
  5300. - {
  5301. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  5302. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  5303. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5304. - merge_cp_length_p, THREAD);
  5305. - if (new_ref_i != ref_i) {
  5306. - RC_TRACE(0x00080000,
  5307. - ("MethodHandle entry@%d ref_index change: %d to %d",
  5308. - *merge_cp_length_p, ref_i, new_ref_i));
  5309. - }
  5310. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  5311. - if (scratch_i != *merge_cp_length_p) {
  5312. - // The new entry in *merge_cp_p is at a different index than
  5313. - // the new entry in scratch_cp so we need to map the index values.
  5314. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5315. - }
  5316. - (*merge_cp_length_p)++;
  5317. - } break;
  5318. -
  5319. - // this is an indirect CP entry so it needs special handling
  5320. - case JVM_CONSTANT_InvokeDynamic:
  5321. - {
  5322. - // Index of the bootstrap specifier in the operands array
  5323. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  5324. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  5325. - merge_cp_length_p, THREAD);
  5326. - // The bootstrap method NameAndType_info index
  5327. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  5328. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5329. - merge_cp_length_p, THREAD);
  5330. - if (new_bs_i != old_bs_i) {
  5331. - RC_TRACE(0x00080000,
  5332. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  5333. - *merge_cp_length_p, old_bs_i, new_bs_i));
  5334. - }
  5335. - if (new_ref_i != old_ref_i) {
  5336. - RC_TRACE(0x00080000,
  5337. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  5338. - *merge_cp_length_p, old_ref_i, new_ref_i));
  5339. - }
  5340. -
  5341. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  5342. - if (scratch_i != *merge_cp_length_p) {
  5343. - // The new entry in *merge_cp_p is at a different index than
  5344. - // the new entry in scratch_cp so we need to map the index values.
  5345. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5346. - }
  5347. - (*merge_cp_length_p)++;
  5348. - } break;
  5349. -
  5350. - // At this stage, Class or UnresolvedClass could be here, but not
  5351. - // ClassIndex
  5352. - case JVM_CONSTANT_ClassIndex: // fall through
  5353. -
  5354. - // Invalid is used as the tag for the second constant pool entry
  5355. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5356. - // not be seen by itself.
  5357. - case JVM_CONSTANT_Invalid: // fall through
  5358. -
  5359. - // At this stage, String or UnresolvedString could be here, but not
  5360. - // StringIndex
  5361. - case JVM_CONSTANT_StringIndex: // fall through
  5362. -
  5363. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5364. - // here
  5365. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5366. -
  5367. - default:
  5368. - {
  5369. - // leave a breadcrumb
  5370. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5371. - ShouldNotReachHere();
  5372. - } break;
  5373. - } // end switch tag value
  5374. -} // end append_entry()
  5375. -
  5376. -
  5377. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  5378. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5379. -
  5380. - int new_ref_i = ref_i;
  5381. - bool match = (ref_i < *merge_cp_length_p) &&
  5382. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  5383. -
  5384. - if (!match) {
  5385. - // forward reference in *merge_cp_p or not a direct match
  5386. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  5387. - if (found_i != 0) {
  5388. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  5389. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  5390. - new_ref_i = found_i;
  5391. - map_index(scratch_cp, ref_i, found_i);
  5392. - } else {
  5393. - // no match found so we have to append this entry to *merge_cp_p
  5394. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  5395. - // The above call to append_entry() can only append one entry
  5396. - // so the post call query of *merge_cp_length_p is only for
  5397. - // the sake of consistency.
  5398. - new_ref_i = *merge_cp_length_p - 1;
  5399. - }
  5400. - }
  5401. -
  5402. - return new_ref_i;
  5403. -} // end find_or_append_indirect_entry()
  5404. -
  5405. -
  5406. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  5407. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  5408. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  5409. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  5410. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5411. -
  5412. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  5413. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5414. - merge_cp_length_p, THREAD);
  5415. - if (new_ref_i != old_ref_i) {
  5416. - RC_TRACE(0x00080000,
  5417. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  5418. - _operands_cur_length, old_ref_i, new_ref_i));
  5419. - }
  5420. -
  5421. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  5422. - int new_bs_i = _operands_cur_length;
  5423. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  5424. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  5425. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  5426. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  5427. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  5428. -
  5429. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  5430. - merge_ops->short_at_put(new_base++, new_ref_i);
  5431. - merge_ops->short_at_put(new_base++, argc);
  5432. -
  5433. - for (int i = 0; i < argc; i++) {
  5434. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  5435. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  5436. - merge_cp_length_p, THREAD);
  5437. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  5438. - if (new_arg_ref_i != old_arg_ref_i) {
  5439. - RC_TRACE(0x00080000,
  5440. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  5441. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  5442. - }
  5443. - }
  5444. - if (old_bs_i != _operands_cur_length) {
  5445. - // The bootstrap specifier in *merge_cp_p is at a different index than
  5446. - // that in scratch_cp so we need to map the index values.
  5447. - map_operand_index(old_bs_i, new_bs_i);
  5448. - }
  5449. - _operands_cur_length++;
  5450. -} // end append_operand()
  5451. -
  5452. -
  5453. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  5454. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5455. -
  5456. - int new_bs_i = old_bs_i; // bootstrap specifier index
  5457. - bool match = (old_bs_i < _operands_cur_length) &&
  5458. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  5459. -
  5460. - if (!match) {
  5461. - // forward reference in *merge_cp_p or not a direct match
  5462. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  5463. - _operands_cur_length, THREAD);
  5464. - if (found_i != -1) {
  5465. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  5466. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  5467. - new_bs_i = found_i;
  5468. - map_operand_index(old_bs_i, found_i);
  5469. - } else {
  5470. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  5471. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  5472. - new_bs_i = _operands_cur_length - 1;
  5473. - }
  5474. - }
  5475. - return new_bs_i;
  5476. -} // end find_or_append_operand()
  5477. -
  5478. -
  5479. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  5480. - if (merge_cp->operands() == NULL) {
  5481. - return;
  5482. - }
  5483. - // Shrink the merge_cp operands
  5484. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  5485. -
  5486. - if (RC_TRACE_ENABLED(0x00040000)) {
  5487. - // don't want to loop unless we are tracing
  5488. - int count = 0;
  5489. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  5490. - int value = _operands_index_map_p->at(i);
  5491. - if (value != -1) {
  5492. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5493. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  5494. - count++;
  5495. +
  5496. + int new_count = all_affected_klasses.length() - 1 - i;
  5497. + if (new_count != 0) {
  5498. +
  5499. + unlock_threads();
  5500. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5501. + new_count));
  5502. }
  5503. }
  5504. }
  5505. - // Clean-up
  5506. - _operands_index_map_p = NULL;
  5507. - _operands_cur_length = 0;
  5508. - _operands_index_map_count = 0;
  5509. -} // end finalize_operands_merge()
  5510. -
  5511. -
  5512. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5513. - typeArrayOop save;
  5514. -
  5515. - save = scratch_class->get_method_annotations_of(i);
  5516. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5517. - scratch_class->set_method_annotations_of(j, save);
  5518. -
  5519. - save = scratch_class->get_method_parameter_annotations_of(i);
  5520. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5521. - scratch_class->set_method_parameter_annotations_of(j, save);
  5522. -
  5523. - save = scratch_class->get_method_default_annotations_of(i);
  5524. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5525. - scratch_class->set_method_default_annotations_of(j, save);
  5526. +
  5527. + if (result != JVMTI_ERROR_NONE) {
  5528. + rollback();
  5529. + return result;
  5530. + }
  5531. +
  5532. + RC_TIMER_STOP(_timer_prologue);
  5533. + RC_TIMER_START(_timer_class_linking);
  5534. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5535. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5536. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5537. + instanceKlassHandle new_class(the_class->new_version());
  5538. +
  5539. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5540. + i,
  5541. + all_affected_klasses.length(),
  5542. + the_class->name()->as_C_string()));
  5543. + new_class->link_class(THREAD);
  5544. +
  5545. + result = check_exception();
  5546. + if (result != JVMTI_ERROR_NONE) break;
  5547. + }
  5548. + RC_TIMER_STOP(_timer_class_linking);
  5549. + RC_TIMER_START(_timer_prologue);
  5550. +
  5551. + if (result != JVMTI_ERROR_NONE) {
  5552. + rollback();
  5553. + return result;
  5554. + }
  5555. +
  5556. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5557. +
  5558. +#ifdef ASSERT
  5559. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5560. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5561. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5562. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5563. + assert(new_version->new_version() == NULL, "Must be newest version");
  5564. +
  5565. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5566. + new_version()->print();
  5567. + new_version->super()->print();
  5568. + }
  5569. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5570. + }
  5571. +
  5572. + SystemDictionary::classes_do(check_class, THREAD);
  5573. +
  5574. +#endif
  5575. +
  5576. + RC_TRACE(0x00000001, ("Finished verification!"));
  5577. + return JVMTI_ERROR_NONE;
  5578. }
  5579. -
  5580. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5581. - instanceKlassHandle the_class,
  5582. - instanceKlassHandle scratch_class) {
  5583. +void VM_RedefineClasses::lock_threads() {
  5584. +
  5585. + RC_TIMER_START(_timer_wait_for_locks);
  5586. +
  5587. +
  5588. + JavaThread *javaThread = Threads::first();
  5589. + while (javaThread != NULL) {
  5590. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5591. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5592. + compilerThread->set_should_bailout(true);
  5593. + }
  5594. + javaThread = javaThread->next();
  5595. + }
  5596. +
  5597. + int cnt = 0;
  5598. + javaThread = Threads::first();
  5599. + while (javaThread != NULL) {
  5600. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5601. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5602. + compilerThread->compilation_mutex()->lock();
  5603. + cnt++;
  5604. + }
  5605. + javaThread = javaThread->next();
  5606. + }
  5607. +
  5608. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5609. +
  5610. + cnt = 0;
  5611. + javaThread = Threads::first();
  5612. + while (javaThread != NULL) {
  5613. + if (javaThread != Thread::current()) {
  5614. + javaThread->redefine_classes_mutex()->lock();
  5615. + }
  5616. + javaThread = javaThread->next();
  5617. + }
  5618. +
  5619. +
  5620. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5621. +
  5622. + RC_TIMER_STOP(_timer_wait_for_locks);
  5623. +}
  5624. +
  5625. +void VM_RedefineClasses::unlock_threads() {
  5626. +
  5627. + int cnt = 0;
  5628. + JavaThread *javaThread = Threads::first();
  5629. + Thread *thread = Thread::current();
  5630. + while (javaThread != NULL) {
  5631. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5632. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5633. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5634. + compilerThread->compilation_mutex()->unlock();
  5635. + cnt++;
  5636. + }
  5637. + }
  5638. + javaThread = javaThread->next();
  5639. + }
  5640. +
  5641. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5642. +
  5643. + cnt = 0;
  5644. + javaThread = Threads::first();
  5645. + while (javaThread != NULL) {
  5646. + if (javaThread != Thread::current()) {
  5647. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5648. + javaThread->redefine_classes_mutex()->unlock();
  5649. + }
  5650. + }
  5651. + javaThread = javaThread->next();
  5652. + }
  5653. +
  5654. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5655. +}
  5656. +
  5657. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5658. +
  5659. +
  5660. +
  5661. + // Compatibility mode => check for unsupported modification
  5662. +
  5663. +
  5664. + assert(scratch_class->old_version() != NULL, "must have old version");
  5665. + instanceKlassHandle the_class(scratch_class->old_version());
  5666. +
  5667. int i;
  5668. // Check superclasses, or rather their names, since superclasses themselves can be
  5669. // requested to replace.
  5670. // Check for NULL superclass first since this might be java.lang.Object
  5671. if (the_class->super() != scratch_class->super() &&
  5672. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5673. - Klass::cast(the_class->super())->name() !=
  5674. - Klass::cast(scratch_class->super())->name())) {
  5675. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5676. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5677. + Klass::cast(the_class->super())->name() !=
  5678. + Klass::cast(scratch_class->super())->name())) {
  5679. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5680. }
  5681. // Check if the number, names and order of directly implemented interfaces are the same.
  5682. @@ -622,8 +678,8 @@
  5683. }
  5684. for (i = 0; i < n_intfs; i++) {
  5685. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5686. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5687. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5688. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5689. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5690. }
  5691. }
  5692. @@ -772,12 +828,8 @@
  5693. idnum_owner->set_method_idnum(new_num);
  5694. }
  5695. k_new_method->set_method_idnum(old_num);
  5696. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5697. }
  5698. }
  5699. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5700. - k_new_method->name_and_sig_as_C_string(), ni,
  5701. - k_old_method->name_and_sig_as_C_string(), oi));
  5702. // advance to next pair of methods
  5703. ++oi;
  5704. ++ni;
  5705. @@ -786,11 +838,11 @@
  5706. // method added, see if it is OK
  5707. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5708. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5709. - // hack: private should be treated as final, but alas
  5710. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5711. - ) {
  5712. - // new methods must be private
  5713. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5714. + // hack: private should be treated as final, but alas
  5715. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5716. + ) {
  5717. + // new methods must be private
  5718. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5719. }
  5720. {
  5721. u2 num = the_class->next_method_idnum();
  5722. @@ -805,24 +857,19 @@
  5723. idnum_owner->set_method_idnum(new_num);
  5724. }
  5725. k_new_method->set_method_idnum(num);
  5726. - swap_all_method_annotations(new_num, num, scratch_class);
  5727. }
  5728. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5729. - k_new_method->name_and_sig_as_C_string(), ni));
  5730. ++ni; // advance to next new method
  5731. break;
  5732. case deleted:
  5733. // method deleted, see if it is OK
  5734. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5735. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5736. - // hack: private should be treated as final, but alas
  5737. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5738. - ) {
  5739. - // deleted methods must be private
  5740. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5741. + // hack: private should be treated as final, but alas
  5742. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5743. + ) {
  5744. + // deleted methods must be private
  5745. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5746. }
  5747. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5748. - k_old_method->name_and_sig_as_C_string(), oi));
  5749. ++oi; // advance to next old method
  5750. break;
  5751. default:
  5752. @@ -833,2121 +880,2266 @@
  5753. return JVMTI_ERROR_NONE;
  5754. }
  5755. -
  5756. -// Find new constant pool index value for old constant pool index value
  5757. -// by seaching the index map. Returns zero (0) if there is no mapped
  5758. -// value for the old constant pool index.
  5759. -int VM_RedefineClasses::find_new_index(int old_index) {
  5760. - if (_index_map_count == 0) {
  5761. - // map is empty so nothing can be found
  5762. - return 0;
  5763. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5764. +
  5765. + int result = Klass::NoRedefinition;
  5766. +
  5767. +
  5768. +
  5769. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5770. + new_class->name()->as_C_string()));
  5771. +
  5772. + assert(new_class->old_version() != NULL, "must have old version");
  5773. + instanceKlassHandle the_class(new_class->old_version());
  5774. +
  5775. + // Check whether class is in the error init state.
  5776. + if (the_class->is_in_error_state()) {
  5777. + // TBD #5057930: special error code is needed in 1.6
  5778. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5779. }
  5780. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5781. - // The old_index is out of range so it is not mapped. This should
  5782. - // not happen in regular constant pool merging use, but it can
  5783. - // happen if a corrupt annotation is processed.
  5784. - return 0;
  5785. + int i;
  5786. +
  5787. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5788. + // Check superclasses
  5789. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5790. + if (the_class->super() != new_class->super()) {
  5791. + // Super class changed
  5792. +
  5793. + klassOop cur_klass = the_class->super();
  5794. + while (cur_klass != NULL) {
  5795. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5796. + RC_TRACE(0x00000002, ("Removed super class %s",
  5797. + cur_klass->klass_part()->name()->as_C_string()));
  5798. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5799. +
  5800. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5801. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5802. + cur_klass->klass_part()->name()->as_C_string()));
  5803. + cur_klass->klass_part()->set_subtype_changed(true);
  5804. + }
  5805. + }
  5806. +
  5807. + cur_klass = cur_klass->klass_part()->super();
  5808. + }
  5809. +
  5810. + cur_klass = new_class->super();
  5811. + while (cur_klass != NULL) {
  5812. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5813. + RC_TRACE(0x00000002, ("Added super class %s",
  5814. + cur_klass->klass_part()->name()->as_C_string()));
  5815. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5816. + }
  5817. + cur_klass = cur_klass->klass_part()->super();
  5818. + }
  5819. }
  5820. - int value = _index_map_p->at(old_index);
  5821. - if (value == -1) {
  5822. - // the old_index is not mapped
  5823. - return 0;
  5824. - }
  5825. -
  5826. - return value;
  5827. -} // end find_new_index()
  5828. -
  5829. -
  5830. -// Find new bootstrap specifier index value for old bootstrap specifier index
  5831. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  5832. -// value for the old bootstrap specifier index.
  5833. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  5834. - if (_operands_index_map_count == 0) {
  5835. - // map is empty so nothing can be found
  5836. - return -1;
  5837. - }
  5838. -
  5839. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  5840. - // The old_index is out of range so it is not mapped.
  5841. - // This should not happen in regular constant pool merging use.
  5842. - return -1;
  5843. - }
  5844. -
  5845. - int value = _operands_index_map_p->at(old_index);
  5846. -
  5847. - return value;
  5848. -} // end find_new_operand_index()
  5849. -
  5850. -
  5851. -// Returns true if the current mismatch is due to a resolved/unresolved
  5852. -// class pair. Otherwise, returns false.
  5853. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5854. - int index1, constantPoolHandle cp2, int index2) {
  5855. -
  5856. - jbyte t1 = cp1->tag_at(index1).value();
  5857. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5858. - return false; // wrong entry type; not our special case
  5859. - }
  5860. -
  5861. - jbyte t2 = cp2->tag_at(index2).value();
  5862. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5863. - return false; // wrong entry type; not our special case
  5864. - }
  5865. -
  5866. - if (t1 == t2) {
  5867. - return false; // not a mismatch; not our special case
  5868. - }
  5869. -
  5870. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5871. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5872. - if (strcmp(s1, s2) != 0) {
  5873. - return false; // strings don't match; not our special case
  5874. - }
  5875. -
  5876. - return true; // made it through the gauntlet; this is our special case
  5877. -} // end is_unresolved_class_mismatch()
  5878. -
  5879. -
  5880. -// Returns true if the current mismatch is due to a resolved/unresolved
  5881. -// string pair. Otherwise, returns false.
  5882. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5883. - int index1, constantPoolHandle cp2, int index2) {
  5884. -
  5885. - jbyte t1 = cp1->tag_at(index1).value();
  5886. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5887. - return false; // wrong entry type; not our special case
  5888. - }
  5889. -
  5890. - jbyte t2 = cp2->tag_at(index2).value();
  5891. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5892. - return false; // wrong entry type; not our special case
  5893. - }
  5894. -
  5895. - if (t1 == t2) {
  5896. - return false; // not a mismatch; not our special case
  5897. - }
  5898. -
  5899. - char *s1 = cp1->string_at_noresolve(index1);
  5900. - char *s2 = cp2->string_at_noresolve(index2);
  5901. - if (strcmp(s1, s2) != 0) {
  5902. - return false; // strings don't match; not our special case
  5903. - }
  5904. -
  5905. - return true; // made it through the gauntlet; this is our special case
  5906. -} // end is_unresolved_string_mismatch()
  5907. -
  5908. -
  5909. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5910. - // For consistency allocate memory using os::malloc wrapper.
  5911. - _scratch_classes = (instanceKlassHandle *)
  5912. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5913. - if (_scratch_classes == NULL) {
  5914. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5915. - }
  5916. -
  5917. - ResourceMark rm(THREAD);
  5918. -
  5919. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5920. - // state can only be NULL if the current thread is exiting which
  5921. - // should not happen since we're trying to do a RedefineClasses
  5922. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5923. - for (int i = 0; i < _class_count; i++) {
  5924. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5925. - // classes for primitives cannot be redefined
  5926. - if (!is_modifiable_class(mirror)) {
  5927. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5928. - }
  5929. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5930. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5931. - Symbol* the_class_sym = the_class->name();
  5932. -
  5933. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5934. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5935. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5936. - the_class->external_name(), _class_load_kind,
  5937. - os::available_memory() >> 10));
  5938. -
  5939. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5940. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5941. -
  5942. - // Parse the stream.
  5943. - Handle the_class_loader(THREAD, the_class->class_loader());
  5944. - Handle protection_domain(THREAD, the_class->protection_domain());
  5945. - // Set redefined class handle in JvmtiThreadState class.
  5946. - // This redefined class is sent to agent event handler for class file
  5947. - // load hook event.
  5948. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5949. -
  5950. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5951. - the_class_loader,
  5952. - protection_domain,
  5953. - &st,
  5954. - THREAD);
  5955. - // Clear class_being_redefined just to be sure.
  5956. - state->clear_class_being_redefined();
  5957. -
  5958. - // TODO: if this is retransform, and nothing changed we can skip it
  5959. -
  5960. - instanceKlassHandle scratch_class (THREAD, k);
  5961. -
  5962. - if (HAS_PENDING_EXCEPTION) {
  5963. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5964. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5965. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5966. - ex_name->as_C_string()));
  5967. - CLEAR_PENDING_EXCEPTION;
  5968. -
  5969. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5970. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5971. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5972. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5973. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5974. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5975. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5976. - // The message will be "XXX (wrong name: YYY)"
  5977. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5978. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5979. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5980. - } else { // Just in case more exceptions can be thrown..
  5981. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5982. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5983. + // Check interfaces
  5984. +
  5985. + // Interfaces removed?
  5986. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5987. + for (i = 0; i<old_interfaces->length(); i++) {
  5988. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5989. + if (!new_class->implements_interface_any_version(old_interface())) {
  5990. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5991. + RC_TRACE(0x00000002, ("Removed interface %s",
  5992. + old_interface->name()->as_C_string()));
  5993. +
  5994. + if (!old_interface->has_subtype_changed()) {
  5995. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5996. + old_interface->name()->as_C_string()));
  5997. + old_interface->set_subtype_changed(true);
  5998. }
  5999. }
  6000. -
  6001. - // Ensure class is linked before redefine
  6002. - if (!the_class->is_linked()) {
  6003. - the_class->link_class(THREAD);
  6004. - if (HAS_PENDING_EXCEPTION) {
  6005. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6006. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6007. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  6008. - ex_name->as_C_string()));
  6009. - CLEAR_PENDING_EXCEPTION;
  6010. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6011. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6012. + }
  6013. +
  6014. + // Interfaces added?
  6015. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  6016. + for (i = 0; i<new_interfaces->length(); i++) {
  6017. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  6018. + result = result | Klass::ModifyClass;
  6019. + RC_TRACE(0x00000002, ("Added interface %s",
  6020. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  6021. + }
  6022. + }
  6023. +
  6024. +
  6025. + // Check whether class modifiers are the same.
  6026. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  6027. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  6028. + if (old_flags != new_flags) {
  6029. + // TODO (tw): Can this have any effects?
  6030. + }
  6031. +
  6032. + // Check if the number, names, types and order of fields declared in these classes
  6033. + // are the same.
  6034. + JavaFieldStream old_fs(the_class);
  6035. + JavaFieldStream new_fs(new_class);
  6036. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  6037. + // access
  6038. + old_flags = old_fs.access_flags().as_short();
  6039. + new_flags = new_fs.access_flags().as_short();
  6040. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  6041. + // (tw) Can this have any effects?
  6042. + }
  6043. + // offset
  6044. + if (old_fs.offset() != new_fs.offset()) {
  6045. + result = result | Klass::ModifyInstances;
  6046. + }
  6047. + // name and signature
  6048. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  6049. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  6050. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  6051. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  6052. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  6053. + result = result | Klass::ModifyInstances;
  6054. + }
  6055. + }
  6056. +
  6057. + if (!old_fs.done() || !new_fs.done()) {
  6058. + result = result | Klass::ModifyInstances;
  6059. + }
  6060. +
  6061. + // Do a parallel walk through the old and new methods. Detect
  6062. + // cases where they match (exist in both), have been added in
  6063. + // the new methods, or have been deleted (exist only in the
  6064. + // old methods). The class file parser places methods in order
  6065. + // by method name, but does not order overloaded methods by
  6066. + // signature. In order to determine what fate befell the methods,
  6067. + // this code places the overloaded new methods that have matching
  6068. + // old methods in the same order as the old methods and places
  6069. + // new overloaded methods at the end of overloaded methods of
  6070. + // that name. The code for this order normalization is adapted
  6071. + // from the algorithm used in instanceKlass::find_method().
  6072. + // Since we are swapping out of order entries as we find them,
  6073. + // we only have to search forward through the overloaded methods.
  6074. + // Methods which are added and have the same name as an existing
  6075. + // method (but different signature) will be put at the end of
  6076. + // the methods with that name, and the name mismatch code will
  6077. + // handle them.
  6078. + objArrayHandle k_old_methods(the_class->methods());
  6079. + objArrayHandle k_new_methods(new_class->methods());
  6080. + int n_old_methods = k_old_methods->length();
  6081. + int n_new_methods = k_new_methods->length();
  6082. +
  6083. + int ni = 0;
  6084. + int oi = 0;
  6085. + while (true) {
  6086. + methodOop k_old_method;
  6087. + methodOop k_new_method;
  6088. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6089. +
  6090. + if (oi >= n_old_methods) {
  6091. + if (ni >= n_new_methods) {
  6092. + break; // we've looked at everything, done
  6093. + }
  6094. + // New method at the end
  6095. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6096. + method_was = added;
  6097. + } else if (ni >= n_new_methods) {
  6098. + // Old method, at the end, is deleted
  6099. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6100. + method_was = deleted;
  6101. + } else {
  6102. + // There are more methods in both the old and new lists
  6103. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6104. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6105. + if (k_old_method->name() != k_new_method->name()) {
  6106. + // Methods are sorted by method name, so a mismatch means added
  6107. + // or deleted
  6108. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6109. + method_was = added;
  6110. } else {
  6111. - return JVMTI_ERROR_INTERNAL;
  6112. + method_was = deleted;
  6113. + }
  6114. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6115. + // Both the name and signature match
  6116. + method_was = matched;
  6117. + } else {
  6118. + // The name matches, but the signature doesn't, which means we have to
  6119. + // search forward through the new overloaded methods.
  6120. + int nj; // outside the loop for post-loop check
  6121. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6122. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6123. + if (k_old_method->name() != m->name()) {
  6124. + // reached another method name so no more overloaded methods
  6125. + method_was = deleted;
  6126. + break;
  6127. + }
  6128. + if (k_old_method->signature() == m->signature()) {
  6129. + // found a match so swap the methods
  6130. + k_new_methods->obj_at_put(ni, m);
  6131. + k_new_methods->obj_at_put(nj, k_new_method);
  6132. + k_new_method = m;
  6133. + method_was = matched;
  6134. + break;
  6135. + }
  6136. + }
  6137. +
  6138. + if (nj >= n_new_methods) {
  6139. + // reached the end without a match; so method was deleted
  6140. + method_was = deleted;
  6141. }
  6142. }
  6143. }
  6144. - // Do the validity checks in compare_and_normalize_class_versions()
  6145. - // before verifying the byte codes. By doing these checks first, we
  6146. - // limit the number of functions that require redirection from
  6147. - // the_class to scratch_class. In particular, we don't have to
  6148. - // modify JNI GetSuperclass() and thus won't change its performance.
  6149. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6150. - scratch_class);
  6151. - if (res != JVMTI_ERROR_NONE) {
  6152. - return res;
  6153. + switch (method_was) {
  6154. + case matched:
  6155. + // methods match, be sure modifiers do too
  6156. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6157. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6158. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6159. + // (tw) Can this have any effects? Probably yes on vtables?
  6160. + result = result | Klass::ModifyClass;
  6161. }
  6162. -
  6163. - // verify what the caller passed us
  6164. {
  6165. - // The bug 6214132 caused the verification to fail.
  6166. - // Information about the_class and scratch_class is temporarily
  6167. - // recorded into jvmtiThreadState. This data is used to redirect
  6168. - // the_class to scratch_class in the JVM_* functions called by the
  6169. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6170. - // description.
  6171. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6172. - Verifier::verify(
  6173. - scratch_class, Verifier::ThrowException, true, THREAD);
  6174. - }
  6175. -
  6176. - if (HAS_PENDING_EXCEPTION) {
  6177. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6178. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6179. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6180. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6181. - CLEAR_PENDING_EXCEPTION;
  6182. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6183. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6184. - } else {
  6185. - // tell the caller the bytecodes are bad
  6186. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6187. + u2 new_num = k_new_method->method_idnum();
  6188. + u2 old_num = k_old_method->method_idnum();
  6189. + if (new_num != old_num) {
  6190. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6191. + if (idnum_owner != NULL) {
  6192. + // There is already a method assigned this idnum -- switch them
  6193. + idnum_owner->set_method_idnum(new_num);
  6194. + }
  6195. + k_new_method->set_method_idnum(old_num);
  6196. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6197. + new_num,
  6198. + old_num));
  6199. + // swap_all_method_annotations(old_num, new_num, new_class);
  6200. }
  6201. }
  6202. -
  6203. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6204. - if (res != JVMTI_ERROR_NONE) {
  6205. - return res;
  6206. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6207. + k_new_method->name_and_sig_as_C_string(), ni,
  6208. + k_old_method->name_and_sig_as_C_string(), oi));
  6209. + // advance to next pair of methods
  6210. + ++oi;
  6211. + ++ni;
  6212. + break;
  6213. + case added:
  6214. + // method added, see if it is OK
  6215. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6216. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6217. + // hack: private should be treated as final, but alas
  6218. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6219. + ) {
  6220. + // new methods must be private
  6221. + result = result | Klass::ModifyClass;
  6222. }
  6223. -
  6224. - if (VerifyMergedCPBytecodes) {
  6225. - // verify what we have done during constant pool merging
  6226. - {
  6227. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6228. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6229. + {
  6230. + u2 num = the_class->next_method_idnum();
  6231. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6232. + // cannot add any more methods
  6233. + result = result | Klass::ModifyClass;
  6234. }
  6235. -
  6236. - if (HAS_PENDING_EXCEPTION) {
  6237. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6238. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6239. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6240. - ("verify_byte_codes post merge-CP exception: '%s'",
  6241. - ex_name->as_C_string()));
  6242. - CLEAR_PENDING_EXCEPTION;
  6243. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6244. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6245. - } else {
  6246. - // tell the caller that constant pool merging screwed up
  6247. - return JVMTI_ERROR_INTERNAL;
  6248. + u2 new_num = k_new_method->method_idnum();
  6249. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6250. + if (idnum_owner != NULL) {
  6251. + // There is already a method assigned this idnum -- switch them
  6252. + idnum_owner->set_method_idnum(new_num);
  6253. + }
  6254. + k_new_method->set_method_idnum(num);
  6255. + //swap_all_method_annotations(new_num, num, new_class);
  6256. + }
  6257. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6258. + k_new_method->name_and_sig_as_C_string(), ni));
  6259. + ++ni; // advance to next new method
  6260. + break;
  6261. + case deleted:
  6262. + // method deleted, see if it is OK
  6263. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6264. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6265. + // hack: private should be treated as final, but alas
  6266. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6267. + ) {
  6268. + // deleted methods must be private
  6269. + result = result | Klass::ModifyClass;
  6270. + }
  6271. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6272. + k_old_method->name_and_sig_as_C_string(), oi));
  6273. + ++oi; // advance to next old method
  6274. + break;
  6275. + default:
  6276. + ShouldNotReachHere();
  6277. + }
  6278. + }
  6279. +
  6280. + if (new_class()->size() != new_class->old_version()->size()) {
  6281. + result |= Klass::ModifyClassSize;
  6282. + }
  6283. +
  6284. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6285. + result |= Klass::ModifyInstanceSize;
  6286. + }
  6287. +
  6288. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6289. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6290. + result |= Klass::HasInstanceTransformer;
  6291. + }
  6292. +
  6293. + // (tw) Check method bodies to be able to return NoChange?
  6294. + return result;
  6295. +}
  6296. +
  6297. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6298. +
  6299. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6300. +
  6301. + private:
  6302. +
  6303. + GrowableArray<int> info;
  6304. + int curPosition;
  6305. + bool copy_backwards;
  6306. +
  6307. + public:
  6308. +
  6309. + bool does_copy_backwards() {
  6310. + return copy_backwards;
  6311. + }
  6312. +
  6313. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6314. +
  6315. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6316. +
  6317. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6318. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6319. + }
  6320. +
  6321. + info.append(base_offset);
  6322. + info.append(0);
  6323. + curPosition = base_offset;
  6324. + copy_backwards = false;
  6325. + }
  6326. +
  6327. + GrowableArray<int> &finish() {
  6328. + info.append(0);
  6329. + return info;
  6330. + }
  6331. +
  6332. + virtual void do_new_field(fieldDescriptor* fd){
  6333. + int alignment = fd->offset() - curPosition;
  6334. + if (alignment > 0) {
  6335. + // This field was aligned, so we need to make sure that we fill the gap
  6336. + fill(alignment);
  6337. + }
  6338. +
  6339. + int size = size_of_type(fd->field_type());
  6340. + fill(size);
  6341. + }
  6342. +
  6343. + private:
  6344. +
  6345. + void fill(int size) {
  6346. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6347. + (*info.adr_at(info.length() - 1)) -= size;
  6348. + } else {
  6349. + info.append(-size);
  6350. + }
  6351. +
  6352. + curPosition += size;
  6353. + }
  6354. +
  6355. + int size_of_type(BasicType type) {
  6356. + int size = 0;
  6357. + switch(type) {
  6358. + case T_BOOLEAN:
  6359. + size = sizeof(jboolean);
  6360. + break;
  6361. +
  6362. + case T_CHAR:
  6363. + size = (sizeof(jchar));
  6364. + break;
  6365. +
  6366. + case T_FLOAT:
  6367. + size = (sizeof(jfloat));
  6368. + break;
  6369. +
  6370. + case T_DOUBLE:
  6371. + size = (sizeof(jdouble));
  6372. + break;
  6373. +
  6374. + case T_BYTE:
  6375. + size = (sizeof(jbyte));
  6376. + break;
  6377. +
  6378. + case T_SHORT:
  6379. + size = (sizeof(jshort));
  6380. + break;
  6381. +
  6382. + case T_INT:
  6383. + size = (sizeof(jint));
  6384. + break;
  6385. +
  6386. + case T_LONG:
  6387. + size = (sizeof(jlong));
  6388. + break;
  6389. +
  6390. + case T_OBJECT:
  6391. + case T_ARRAY:
  6392. + if (UseCompressedOops) {
  6393. + size = sizeof(narrowOop);
  6394. + } else {
  6395. + size = (sizeof(oop));
  6396. + }
  6397. + break;
  6398. +
  6399. + default:
  6400. + ShouldNotReachHere();
  6401. + }
  6402. +
  6403. + assert(size > 0, "");
  6404. + return size;
  6405. +
  6406. + }
  6407. +
  6408. + public:
  6409. +
  6410. + virtual void do_old_field(fieldDescriptor* fd){}
  6411. +
  6412. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6413. +
  6414. + int alignment = new_fd->offset() - curPosition;
  6415. + if (alignment > 0) {
  6416. + // This field was aligned, so we need to make sure that we fill the gap
  6417. + fill(alignment);
  6418. + }
  6419. +
  6420. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6421. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6422. +
  6423. + int offset = old_fd->offset();
  6424. + int size = size_of_type(old_fd->field_type());
  6425. +
  6426. + int prevEnd = -1;
  6427. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6428. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6429. + }
  6430. +
  6431. + if (prevEnd == offset) {
  6432. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6433. + } else {
  6434. + info.append(size);
  6435. + info.append(offset);
  6436. + }
  6437. +
  6438. + if (old_fd->offset() < new_fd->offset()) {
  6439. + copy_backwards = true;
  6440. + }
  6441. +
  6442. + transfer_special_access_flags(old_fd, new_fd);
  6443. +
  6444. + curPosition += size;
  6445. + }
  6446. + };
  6447. +
  6448. + UpdateFieldsEvolutionClosure cl(new_version);
  6449. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6450. +
  6451. + GrowableArray<int> result = cl.finish();
  6452. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6453. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6454. +
  6455. + if (RC_TRACE_ENABLED(0x00000002)) {
  6456. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6457. + new_version->klass_part()->name()->as_C_string()));
  6458. + if (cl.does_copy_backwards()) {
  6459. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6460. + }
  6461. + for (int i=0; i<result.length(); i++) {
  6462. + int curNum = result.at(i);
  6463. + if (curNum < 0) {
  6464. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6465. + } else if (curNum > 0) {
  6466. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6467. + i++;
  6468. + } else {
  6469. + RC_TRACE(0x00000002, ("\tEND"));
  6470. + }
  6471. + }
  6472. + }
  6473. +}
  6474. +
  6475. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6476. + assert(FieldType::is_obj(signature), "");
  6477. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6478. +}
  6479. +
  6480. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6481. + if (klass->klass_part()->is_redefining()) {
  6482. + klass = klass->klass_part()->old_version();
  6483. + }
  6484. +
  6485. + // We found an instance klass!
  6486. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6487. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6488. +
  6489. + class MyFieldClosure : public FieldClosure {
  6490. +
  6491. + public:
  6492. +
  6493. + GrowableArray< Pair<int, klassOop> > *_arr;
  6494. +
  6495. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6496. + _arr = arr;
  6497. + }
  6498. +
  6499. + virtual void do_field(fieldDescriptor* fd) {
  6500. + if (fd->field_type() == T_OBJECT) {
  6501. + Symbol* signature = fd->signature();
  6502. + if (FieldType::is_obj(signature)) {
  6503. + Symbol* name = signature_to_class_name(signature);
  6504. + klassOop field_klass;
  6505. + if (is_field_dangerous(name, fd, field_klass)) {
  6506. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6507. + fd->name()->as_C_string(),
  6508. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6509. + name->as_C_string()));
  6510. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6511. + }
  6512. + }
  6513. +
  6514. + // Array fields can never be a problem!
  6515. + }
  6516. + }
  6517. +
  6518. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6519. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6520. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6521. + if(field_klass != NULL) {
  6522. + if (field_klass->klass_part()->is_redefining()) {
  6523. + field_klass = field_klass->klass_part()->old_version();
  6524. + }
  6525. + if (field_klass->klass_part()->has_subtype_changed()) {
  6526. + return true;
  6527. + }
  6528. + }
  6529. + return false;
  6530. + }
  6531. + };
  6532. +
  6533. + MyFieldClosure fieldClosure(&type_check_information);
  6534. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6535. +
  6536. + if (type_check_information.length() > 0) {
  6537. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6538. + cur_instance_klass->store_type_check_information(type_check_information);
  6539. + }
  6540. +}
  6541. +
  6542. +bool VM_RedefineClasses::check_field_value_types() {
  6543. +
  6544. + Thread *THREAD = Thread::current();
  6545. + class CheckFieldTypesClosure : public ObjectClosure {
  6546. +
  6547. + private:
  6548. +
  6549. + bool _result;
  6550. +
  6551. + public:
  6552. +
  6553. + CheckFieldTypesClosure() {
  6554. + _result = true;
  6555. + }
  6556. +
  6557. + bool result() { return _result; }
  6558. +
  6559. + virtual void do_object(oop obj) {
  6560. +
  6561. + if (!_result) {
  6562. + return;
  6563. + }
  6564. +
  6565. + if (obj->is_objArray()) {
  6566. +
  6567. + objArrayOop array = objArrayOop(obj);
  6568. +
  6569. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6570. +
  6571. + if (element_klass->klass_part()->has_subtype_changed()) {
  6572. + int length = array->length();
  6573. + for (int i=0; i<length; i++) {
  6574. + oop element = array->obj_at(i);
  6575. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6576. + // Check subtype relationship to static type of array
  6577. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6578. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6579. + element_klass->klass_part()->name()->as_C_string(),
  6580. + i,
  6581. + element->blueprint()->name()->as_C_string()));
  6582. + _result = false;
  6583. + break;
  6584. + }
  6585. + }
  6586. + }
  6587. + }
  6588. +
  6589. + } else {
  6590. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6591. + if (cur != NULL) {
  6592. + // Type check information exists for this oop
  6593. + while ((*cur).left() != -1) {
  6594. + check_field(obj, (*cur).left(), (*cur).right());
  6595. + cur++;
  6596. + }
  6597. }
  6598. }
  6599. }
  6600. - Rewriter::rewrite(scratch_class, THREAD);
  6601. - if (!HAS_PENDING_EXCEPTION) {
  6602. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6603. - }
  6604. - if (HAS_PENDING_EXCEPTION) {
  6605. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6606. - CLEAR_PENDING_EXCEPTION;
  6607. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6608. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6609. - } else {
  6610. - return JVMTI_ERROR_INTERNAL;
  6611. - }
  6612. - }
  6613. -
  6614. - _scratch_classes[i] = scratch_class;
  6615. -
  6616. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6617. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6618. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6619. - the_class->external_name(), os::available_memory() >> 10));
  6620. - }
  6621. -
  6622. - return JVMTI_ERROR_NONE;
  6623. -}
  6624. -
  6625. -
  6626. -// Map old_index to new_index as needed. scratch_cp is only needed
  6627. -// for RC_TRACE() calls.
  6628. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6629. - int old_index, int new_index) {
  6630. - if (find_new_index(old_index) != 0) {
  6631. - // old_index is already mapped
  6632. - return;
  6633. - }
  6634. -
  6635. - if (old_index == new_index) {
  6636. - // no mapping is needed
  6637. - return;
  6638. - }
  6639. -
  6640. - _index_map_p->at_put(old_index, new_index);
  6641. - _index_map_count++;
  6642. -
  6643. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6644. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6645. -} // end map_index()
  6646. -
  6647. -
  6648. -// Map old_index to new_index as needed.
  6649. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  6650. - if (find_new_operand_index(old_index) != -1) {
  6651. - // old_index is already mapped
  6652. - return;
  6653. - }
  6654. -
  6655. - if (old_index == new_index) {
  6656. - // no mapping is needed
  6657. - return;
  6658. - }
  6659. -
  6660. - _operands_index_map_p->at_put(old_index, new_index);
  6661. - _operands_index_map_count++;
  6662. -
  6663. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  6664. -} // end map_index()
  6665. -
  6666. -
  6667. -// Merge old_cp and scratch_cp and return the results of the merge via
  6668. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6669. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6670. -// in *merge_cp_p. Also creates a map of indices from entries in
  6671. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6672. -// entries are only created for entries in scratch_cp that occupy a
  6673. -// different location in *merged_cp_p.
  6674. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6675. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6676. - int *merge_cp_length_p, TRAPS) {
  6677. -
  6678. - if (merge_cp_p == NULL) {
  6679. - assert(false, "caller must provide scatch constantPool");
  6680. - return false; // robustness
  6681. - }
  6682. - if (merge_cp_length_p == NULL) {
  6683. - assert(false, "caller must provide scatch CP length");
  6684. - return false; // robustness
  6685. - }
  6686. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6687. - // but the caller might be smart so make sure we have at least
  6688. - // the minimum.
  6689. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6690. - assert(false, "merge area too small");
  6691. - return false; // robustness
  6692. - }
  6693. -
  6694. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6695. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6696. - scratch_cp->length()));
  6697. -
  6698. - {
  6699. - // Pass 0:
  6700. - // The old_cp is copied to *merge_cp_p; this means that any code
  6701. - // using old_cp does not have to change. This work looks like a
  6702. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6703. - // handle one special case:
  6704. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6705. - // This will make verification happy.
  6706. -
  6707. - int old_i; // index into old_cp
  6708. -
  6709. - // index zero (0) is not used in constantPools
  6710. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6711. - // leave debugging crumb
  6712. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6713. - switch (old_tag) {
  6714. - case JVM_CONSTANT_Class:
  6715. - case JVM_CONSTANT_UnresolvedClass:
  6716. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6717. - // May be resolving while calling this so do the same for
  6718. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6719. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6720. - old_cp->klass_name_at(old_i));
  6721. - break;
  6722. -
  6723. - case JVM_CONSTANT_Double:
  6724. - case JVM_CONSTANT_Long:
  6725. - // just copy the entry to *merge_cp_p, but double and long take
  6726. - // two constant pool entries
  6727. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6728. - old_i++;
  6729. - break;
  6730. -
  6731. - default:
  6732. - // just copy the entry to *merge_cp_p
  6733. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6734. - break;
  6735. - }
  6736. - } // end for each old_cp entry
  6737. -
  6738. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  6739. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  6740. -
  6741. - // We don't need to sanity check that *merge_cp_length_p is within
  6742. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6743. - (*merge_cp_length_p) = old_i;
  6744. - }
  6745. -
  6746. - // merge_cp_len should be the same as old_cp->length() at this point
  6747. - // so this trace message is really a "warm-and-breathing" message.
  6748. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6749. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6750. -
  6751. - int scratch_i; // index into scratch_cp
  6752. - {
  6753. - // Pass 1a:
  6754. - // Compare scratch_cp entries to the old_cp entries that we have
  6755. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6756. - // exact duplicates (matching entry at same index) so we only
  6757. - // compare entries in the common indice range.
  6758. - int increment = 1;
  6759. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6760. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6761. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6762. - case JVM_CONSTANT_Double:
  6763. - case JVM_CONSTANT_Long:
  6764. - // double and long take two constant pool entries
  6765. - increment = 2;
  6766. - break;
  6767. -
  6768. - default:
  6769. - increment = 1;
  6770. - break;
  6771. - }
  6772. -
  6773. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6774. - scratch_i, CHECK_0);
  6775. - if (match) {
  6776. - // found a match at the same index so nothing more to do
  6777. - continue;
  6778. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6779. - *merge_cp_p, scratch_i)) {
  6780. - // The mismatch in compare_entry_to() above is because of a
  6781. - // resolved versus unresolved class entry at the same index
  6782. - // with the same string value. Since Pass 0 reverted any
  6783. - // class entries to unresolved class entries in *merge_cp_p,
  6784. - // we go with the unresolved class entry.
  6785. - continue;
  6786. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6787. - *merge_cp_p, scratch_i)) {
  6788. - // The mismatch in compare_entry_to() above is because of a
  6789. - // resolved versus unresolved string entry at the same index
  6790. - // with the same string value. We can live with whichever
  6791. - // happens to be at scratch_i in *merge_cp_p.
  6792. - continue;
  6793. - }
  6794. -
  6795. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6796. - CHECK_0);
  6797. - if (found_i != 0) {
  6798. - guarantee(found_i != scratch_i,
  6799. - "compare_entry_to() and find_matching_entry() do not agree");
  6800. -
  6801. - // Found a matching entry somewhere else in *merge_cp_p so
  6802. - // just need a mapping entry.
  6803. - map_index(scratch_cp, scratch_i, found_i);
  6804. - continue;
  6805. - }
  6806. -
  6807. - // The find_matching_entry() call above could fail to find a match
  6808. - // due to a resolved versus unresolved class or string entry situation
  6809. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6810. - // However, we would have to call is_unresolved_*_mismatch() over
  6811. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6812. - // worth the time.
  6813. -
  6814. - // No match found so we have to append this entry and any unique
  6815. - // referenced entries to *merge_cp_p.
  6816. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6817. - CHECK_0);
  6818. - }
  6819. - }
  6820. -
  6821. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6822. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6823. - *merge_cp_length_p, scratch_i, _index_map_count));
  6824. -
  6825. - if (scratch_i < scratch_cp->length()) {
  6826. - // Pass 1b:
  6827. - // old_cp is smaller than scratch_cp so there are entries in
  6828. - // scratch_cp that we have not yet processed. We take care of
  6829. - // those now.
  6830. - int increment = 1;
  6831. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6832. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6833. - case JVM_CONSTANT_Double:
  6834. - case JVM_CONSTANT_Long:
  6835. - // double and long take two constant pool entries
  6836. - increment = 2;
  6837. - break;
  6838. -
  6839. - default:
  6840. - increment = 1;
  6841. - break;
  6842. - }
  6843. -
  6844. - int found_i =
  6845. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6846. - if (found_i != 0) {
  6847. - // Found a matching entry somewhere else in *merge_cp_p so
  6848. - // just need a mapping entry.
  6849. - map_index(scratch_cp, scratch_i, found_i);
  6850. - continue;
  6851. - }
  6852. -
  6853. - // No match found so we have to append this entry and any unique
  6854. - // referenced entries to *merge_cp_p.
  6855. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6856. - CHECK_0);
  6857. - }
  6858. -
  6859. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6860. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6861. - *merge_cp_length_p, scratch_i, _index_map_count));
  6862. - }
  6863. - finalize_operands_merge(*merge_cp_p, THREAD);
  6864. -
  6865. - return true;
  6866. -} // end merge_constant_pools()
  6867. -
  6868. -
  6869. -// Merge constant pools between the_class and scratch_class and
  6870. -// potentially rewrite bytecodes in scratch_class to use the merged
  6871. -// constant pool.
  6872. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6873. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6874. - TRAPS) {
  6875. - // worst case merged constant pool length is old and new combined
  6876. - int merge_cp_length = the_class->constants()->length()
  6877. - + scratch_class->constants()->length();
  6878. -
  6879. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6880. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6881. -
  6882. - // Constant pools are not easily reused so we allocate a new one
  6883. - // each time.
  6884. - // merge_cp is created unsafe for concurrent GC processing. It
  6885. - // should be marked safe before discarding it. Even though
  6886. - // garbage, if it crosses a card boundary, it may be scanned
  6887. - // in order to find the start of the first complete object on the card.
  6888. - constantPoolHandle merge_cp(THREAD,
  6889. - oopFactory::new_constantPool(merge_cp_length,
  6890. - oopDesc::IsUnsafeConc,
  6891. - THREAD));
  6892. - int orig_length = old_cp->orig_length();
  6893. - if (orig_length == 0) {
  6894. - // This old_cp is an actual original constant pool. We save
  6895. - // the original length in the merged constant pool so that
  6896. - // merge_constant_pools() can be more efficient. If a constant
  6897. - // pool has a non-zero orig_length() value, then that constant
  6898. - // pool was created by a merge operation in RedefineClasses.
  6899. - merge_cp->set_orig_length(old_cp->length());
  6900. - } else {
  6901. - // This old_cp is a merged constant pool from a previous
  6902. - // RedefineClasses() calls so just copy the orig_length()
  6903. - // value.
  6904. - merge_cp->set_orig_length(old_cp->orig_length());
  6905. - }
  6906. -
  6907. - ResourceMark rm(THREAD);
  6908. - _index_map_count = 0;
  6909. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6910. -
  6911. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6912. - _operands_index_map_count = 0;
  6913. - _operands_index_map_p = new intArray(
  6914. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6915. -
  6916. - // reference to the cp holder is needed for copy_operands()
  6917. - merge_cp->set_pool_holder(scratch_class());
  6918. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6919. - &merge_cp_length, THREAD);
  6920. - merge_cp->set_pool_holder(NULL);
  6921. -
  6922. - if (!result) {
  6923. - // The merge can fail due to memory allocation failure or due
  6924. - // to robustness checks.
  6925. - return JVMTI_ERROR_INTERNAL;
  6926. - }
  6927. -
  6928. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6929. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6930. -
  6931. - if (_index_map_count == 0) {
  6932. - // there is nothing to map between the new and merged constant pools
  6933. -
  6934. - if (old_cp->length() == scratch_cp->length()) {
  6935. - // The old and new constant pools are the same length and the
  6936. - // index map is empty. This means that the three constant pools
  6937. - // are equivalent (but not the same). Unfortunately, the new
  6938. - // constant pool has not gone through link resolution nor have
  6939. - // the new class bytecodes gone through constant pool cache
  6940. - // rewriting so we can't use the old constant pool with the new
  6941. - // class.
  6942. -
  6943. - merge_cp()->set_is_conc_safe(true);
  6944. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6945. - } else if (old_cp->length() < scratch_cp->length()) {
  6946. - // The old constant pool has fewer entries than the new constant
  6947. - // pool and the index map is empty. This means the new constant
  6948. - // pool is a superset of the old constant pool. However, the old
  6949. - // class bytecodes have already gone through constant pool cache
  6950. - // rewriting so we can't use the new constant pool with the old
  6951. - // class.
  6952. -
  6953. - merge_cp()->set_is_conc_safe(true);
  6954. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6955. - } else {
  6956. - // The old constant pool has more entries than the new constant
  6957. - // pool and the index map is empty. This means that both the old
  6958. - // and merged constant pools are supersets of the new constant
  6959. - // pool.
  6960. -
  6961. - // Replace the new constant pool with a shrunken copy of the
  6962. - // merged constant pool; the previous new constant pool will
  6963. - // get GCed.
  6964. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6965. - THREAD);
  6966. - // drop local ref to the merged constant pool
  6967. - merge_cp()->set_is_conc_safe(true);
  6968. - merge_cp = constantPoolHandle();
  6969. - }
  6970. - } else {
  6971. - if (RC_TRACE_ENABLED(0x00040000)) {
  6972. - // don't want to loop unless we are tracing
  6973. - int count = 0;
  6974. - for (int i = 1; i < _index_map_p->length(); i++) {
  6975. - int value = _index_map_p->at(i);
  6976. -
  6977. - if (value != -1) {
  6978. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6979. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6980. - count++;
  6981. + void check_field(oop obj, int offset, klassOop static_type) {
  6982. + oop field_value = obj->obj_field(offset);
  6983. + if (field_value != NULL) {
  6984. + // Field is not null
  6985. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6986. + // We are OK
  6987. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6988. + obj->klass()->klass_part()->name()->as_C_string(),
  6989. + static_type->klass_part()->name()->as_C_string(),
  6990. + offset,
  6991. + field_value->klass()->klass_part()->name()->as_C_string()));
  6992. + } else {
  6993. + // Failure!
  6994. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6995. + obj->klass()->klass_part()->name()->as_C_string(),
  6996. + static_type->klass_part()->name()->as_C_string(),
  6997. + offset,
  6998. + field_value->klass()->klass_part()->name()->as_C_string()));
  6999. + _result = false;
  7000. }
  7001. }
  7002. }
  7003. -
  7004. - // We have entries mapped between the new and merged constant pools
  7005. - // so we have to rewrite some constant pool references.
  7006. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  7007. - return JVMTI_ERROR_INTERNAL;
  7008. + };
  7009. +
  7010. + CheckFieldTypesClosure myObjectClosure;
  7011. +
  7012. + // make sure that heap is parsable (fills TLABs with filler objects)
  7013. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  7014. +
  7015. + // do the iteration
  7016. + // If this operation encounters a bad object when using CMS,
  7017. + // consider using safe_object_iterate() which avoids perm gen
  7018. + // objects that may contain bad references.
  7019. + Universe::heap()->object_iterate(&myObjectClosure);
  7020. +
  7021. + // when sharing is enabled we must iterate over the shared spaces
  7022. + if (UseSharedSpaces) {
  7023. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  7024. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  7025. + gen->ro_space()->object_iterate(&myObjectClosure);
  7026. + gen->rw_space()->object_iterate(&myObjectClosure);
  7027. + }
  7028. +
  7029. + return myObjectClosure.result();
  7030. +}
  7031. +
  7032. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  7033. + if (k->klass_part()->is_redefining()) {
  7034. + k = k->klass_part()->old_version();
  7035. + }
  7036. +
  7037. + // We found an instance klass!
  7038. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  7039. + cur_instance_klass->clear_type_check_information();
  7040. +}
  7041. +
  7042. +void VM_RedefineClasses::update_active_methods() {
  7043. +
  7044. + RC_TRACE(0x00000002, ("Updating active methods"));
  7045. + JavaThread *java_thread = Threads::first();
  7046. + while (java_thread != NULL) {
  7047. +
  7048. + int stack_depth = 0;
  7049. + if (java_thread->has_last_Java_frame()) {
  7050. +
  7051. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  7052. +
  7053. + // vframes are resource allocated
  7054. + Thread* current_thread = Thread::current();
  7055. + ResourceMark rm(current_thread);
  7056. + HandleMark hm(current_thread);
  7057. +
  7058. + RegisterMap reg_map(java_thread);
  7059. + frame f = java_thread->last_frame();
  7060. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7061. + frame* last_entry_frame = NULL;
  7062. +
  7063. + while (vf != NULL) {
  7064. + if (vf->is_java_frame()) {
  7065. + // java frame (interpreted, compiled, ...)
  7066. + javaVFrame *jvf = javaVFrame::cast(vf);
  7067. +
  7068. + if (!(jvf->method()->is_native())) {
  7069. + int bci = jvf->bci();
  7070. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  7071. + ResourceMark rm(Thread::current());
  7072. + HandleMark hm;
  7073. + instanceKlassHandle klass(jvf->method()->method_holder());
  7074. +
  7075. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  7076. +
  7077. +
  7078. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  7079. + jvf->method()->name_and_sig_as_C_string()));
  7080. +
  7081. + if (RC_TRACE_ENABLED(0x01000000)) {
  7082. + int code_size = jvf->method()->code_size();
  7083. + char *code_base_old = (char*)jvf->method()->code_base();
  7084. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  7085. + for (int i=0; i<code_size; i++) {
  7086. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  7087. + }
  7088. + jvf->method()->print_codes_on(tty);
  7089. + jvf->method()->new_version()->print_codes_on(tty);
  7090. + }
  7091. +
  7092. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  7093. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  7094. +
  7095. +
  7096. + if (RC_TRACE_ENABLED(0x01000000)) {
  7097. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  7098. + tty->print_cr("old cp");
  7099. + for (int i=0; i<cp_old->length(); i++) {
  7100. + cp_old->entry_at(i)->print(tty, i);
  7101. + }
  7102. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  7103. + tty->print_cr("new cp");
  7104. + for (int i=0; i<cp_new->length(); i++) {
  7105. + cp_new->entry_at(i)->print(tty, i);
  7106. + }
  7107. + }
  7108. +
  7109. + iframe->set_method(jvf->method()->new_version(), bci);
  7110. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  7111. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  7112. +
  7113. + }
  7114. + }
  7115. + }
  7116. + vf = vf->sender();
  7117. + }
  7118. }
  7119. - // Replace the new constant pool with a shrunken copy of the
  7120. - // merged constant pool so now the rewritten bytecodes have
  7121. - // valid references; the previous new constant pool will get
  7122. - // GCed.
  7123. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  7124. - THREAD);
  7125. - merge_cp()->set_is_conc_safe(true);
  7126. + // Advance to next thread
  7127. + java_thread = java_thread->next();
  7128. }
  7129. - assert(old_cp()->is_conc_safe(), "Just checking");
  7130. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7131. -
  7132. - return JVMTI_ERROR_NONE;
  7133. -} // end merge_cp_and_rewrite()
  7134. -
  7135. -
  7136. -// Rewrite constant pool references in klass scratch_class.
  7137. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  7138. - TRAPS) {
  7139. -
  7140. - // rewrite constant pool references in the methods:
  7141. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  7142. - // propagate failure back to caller
  7143. +}
  7144. +
  7145. +void VM_RedefineClasses::method_forwarding() {
  7146. +
  7147. + int forwarding_count = 0;
  7148. + JavaThread *java_thread = Threads::first();
  7149. + while (java_thread != NULL) {
  7150. +
  7151. + int stack_depth = 0;
  7152. + if (java_thread->has_last_Java_frame()) {
  7153. +
  7154. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7155. +
  7156. + // vframes are resource allocated
  7157. + Thread* current_thread = Thread::current();
  7158. + ResourceMark rm(current_thread);
  7159. + HandleMark hm(current_thread);
  7160. +
  7161. + RegisterMap reg_map(java_thread);
  7162. + frame f = java_thread->last_frame();
  7163. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7164. + frame* last_entry_frame = NULL;
  7165. +
  7166. + while (vf != NULL) {
  7167. + if (vf->is_java_frame()) {
  7168. + // java frame (interpreted, compiled, ...)
  7169. + javaVFrame *jvf = javaVFrame::cast(vf);
  7170. +
  7171. + if (!(jvf->method()->is_native())) {
  7172. + RC_TRACE(0x00008000, ("found method: %s",
  7173. + jvf->method()->name()->as_C_string()));
  7174. + ResourceMark rm(Thread::current());
  7175. + HandleMark hm;
  7176. + instanceKlassHandle klass(jvf->method()->method_holder());
  7177. + methodOop m = jvf->method();
  7178. + int bci = jvf->bci();
  7179. + RC_TRACE(0x00008000, ("klass redef %d",
  7180. + klass->is_redefining()));
  7181. +
  7182. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7183. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7184. + m->name()->as_C_string()));
  7185. +
  7186. + klassOop new_klass = klass->newest_version();
  7187. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7188. + RC_TRACE(0x00000002, ("%d %d",
  7189. + new_method,
  7190. + new_method->constMethod()->has_code_section_table()));
  7191. +
  7192. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7193. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7194. + new_method->name()->as_C_string()));
  7195. + m->set_forward_method(new_method);
  7196. + if (new_method->max_locals() != m->max_locals()) {
  7197. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7198. + }
  7199. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7200. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7201. + if (jvf->is_interpreted_frame()) {
  7202. + if (m->is_in_code_section(bci)) {
  7203. + // We must transfer now and cannot delay until next NOP.
  7204. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7205. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7206. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7207. + new_method->name()->as_C_string(),
  7208. + bci,
  7209. + new_bci));
  7210. + iframe->set_method(new_method, new_bci);
  7211. + } else {
  7212. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7213. + new_method->name()->as_C_string(),
  7214. + bci));
  7215. + }
  7216. + } else {
  7217. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7218. + new_method->name()->as_C_string()));
  7219. + }
  7220. + }
  7221. + }
  7222. + }
  7223. + }
  7224. + vf = vf->sender();
  7225. + }
  7226. + }
  7227. +
  7228. + // Advance to next thread
  7229. + java_thread = java_thread->next();
  7230. + }
  7231. +
  7232. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7233. + forwarding_count));
  7234. +}
  7235. +
  7236. +bool VM_RedefineClasses::check_method_stacks() {
  7237. +
  7238. + JavaThread *java_thread = Threads::first();
  7239. + while (java_thread != NULL) {
  7240. +
  7241. + int stack_depth = 0;
  7242. + if (java_thread->has_last_Java_frame()) {
  7243. +
  7244. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7245. +
  7246. + // vframes are resource allocated
  7247. + Thread* current_thread = Thread::current();
  7248. + ResourceMark rm(current_thread);
  7249. + HandleMark hm(current_thread);
  7250. +
  7251. + RegisterMap reg_map(java_thread);
  7252. + frame f = java_thread->last_frame();
  7253. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7254. + frame* last_entry_frame = NULL;
  7255. +
  7256. + while (vf != NULL) {
  7257. + if (vf->is_java_frame()) {
  7258. + // java frame (interpreted, compiled, ...)
  7259. + javaVFrame *jvf = javaVFrame::cast(vf);
  7260. +
  7261. + if (!(jvf->method()->is_native())) {
  7262. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7263. + ResourceMark rm(Thread::current());
  7264. + HandleMark hm;
  7265. + instanceKlassHandle klass(jvf->method()->method_holder());
  7266. +
  7267. + StackValueCollection *locals = jvf->locals();
  7268. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7269. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7270. +
  7271. + for (int i=0; i<locals->size(); i++) {
  7272. + StackValue *stack_value = locals->at(i);
  7273. + if (stack_value->type() == T_OBJECT) {
  7274. + Handle obj = stack_value->get_obj();
  7275. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7276. +
  7277. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7278. + bool result = false;
  7279. + methodOop method = jvf->method();
  7280. + if (method->has_localvariable_table()) {
  7281. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7282. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7283. +
  7284. + if (elem->slot == i) {
  7285. +
  7286. + // Matching index found
  7287. +
  7288. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7289. +
  7290. + // Also in range!!
  7291. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7292. + Symbol* klass_name = signature_to_class_name(signature);
  7293. +
  7294. + 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();
  7295. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7296. +
  7297. + // Field is not null
  7298. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7299. + // We are OK
  7300. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7301. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7302. + result = true;
  7303. + } else {
  7304. + // Failure!
  7305. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7306. + local_klass->klass_part()->name()->as_C_string(),
  7307. + cur->klass_part()->name()->as_C_string()));
  7308. + return false;
  7309. + }
  7310. + }
  7311. + }
  7312. +
  7313. + elem++;
  7314. + }
  7315. + } else {
  7316. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7317. + method->name_and_sig_as_C_string()));
  7318. + }
  7319. +
  7320. + if (!result) {
  7321. + return false;
  7322. + }
  7323. +
  7324. + RC_TRACE(0x00008000, ("Verifying class %s",
  7325. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7326. +
  7327. + Symbol* exception_name;
  7328. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7329. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7330. +
  7331. + Thread::current()->set_pretend_new_universe(true);
  7332. + ClassVerifier split_verifier(klass, Thread::current());
  7333. + split_verifier.verify_method(jvf->method(), Thread::current());
  7334. + exception_name = split_verifier.result();
  7335. + Thread::current()->set_pretend_new_universe(false);
  7336. +
  7337. + if (exception_name != NULL) {
  7338. +
  7339. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7340. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7341. + RC_TRACE(0x00000001, ("Exception: %s",
  7342. + exception_name->as_C_string()));
  7343. + RC_TRACE(0x00000001, ("Message: %s",
  7344. + message_buffer));
  7345. + Thread::current()->clear_pending_exception();
  7346. + return false;
  7347. + }
  7348. +
  7349. + }
  7350. + }
  7351. + }
  7352. + }
  7353. + }
  7354. + vf = vf->sender();
  7355. + }
  7356. + }
  7357. +
  7358. + // Advance to next thread
  7359. + java_thread = java_thread->next();
  7360. + }
  7361. +
  7362. + return true;
  7363. +}
  7364. +
  7365. +bool VM_RedefineClasses::check_method(methodOop method) {
  7366. +
  7367. +
  7368. + return true;
  7369. +}
  7370. +
  7371. +// Warning: destroys redefinition level values of klasses.
  7372. +bool VM_RedefineClasses::check_loaded_methods() {
  7373. +
  7374. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7375. +
  7376. + private:
  7377. +
  7378. + bool _result;
  7379. + GrowableArray<klassOop> *_dangerous_klasses;
  7380. +
  7381. + public:
  7382. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7383. + _result = true;
  7384. + _dangerous_klasses = dangerous_klasses;
  7385. + }
  7386. +
  7387. + bool result() {
  7388. + return _result;
  7389. + }
  7390. +
  7391. + bool is_class_dangerous(klassOop k) {
  7392. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7393. + }
  7394. +
  7395. + bool can_be_affected(instanceKlass *klass) {
  7396. +
  7397. + constantPoolOop cp = klass->constants();
  7398. +
  7399. + Thread *THREAD = Thread::current();
  7400. + klassOop k;
  7401. + Symbol* symbol;
  7402. +
  7403. + for (int i=1; i<cp->length(); i++) {
  7404. + jbyte tag = cp->tag_at(i).value();
  7405. + switch(tag) {
  7406. + case JVM_CONSTANT_Long:
  7407. + case JVM_CONSTANT_Double:
  7408. + i++;
  7409. + break;
  7410. +
  7411. + case JVM_CONSTANT_Utf8:
  7412. + case JVM_CONSTANT_Unicode:
  7413. + case JVM_CONSTANT_Integer:
  7414. + case JVM_CONSTANT_Float:
  7415. + case JVM_CONSTANT_String:
  7416. + case JVM_CONSTANT_Fieldref:
  7417. + case JVM_CONSTANT_Methodref:
  7418. + case JVM_CONSTANT_InterfaceMethodref:
  7419. + case JVM_CONSTANT_ClassIndex:
  7420. + case JVM_CONSTANT_UnresolvedString:
  7421. + case JVM_CONSTANT_StringIndex:
  7422. + case JVM_CONSTANT_UnresolvedClassInError:
  7423. + case JVM_CONSTANT_Object:
  7424. + // do nothing
  7425. + break;
  7426. +
  7427. + case JVM_CONSTANT_Class:
  7428. + k = cp->klass_at(i, CHECK_(true));
  7429. + if (is_class_dangerous(k)) {
  7430. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7431. + klass->name()->as_C_string(),
  7432. + i,
  7433. + k->klass_part()->name()->as_C_string()));
  7434. + return true;
  7435. + }
  7436. + break;
  7437. +
  7438. + case JVM_CONSTANT_NameAndType:
  7439. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7440. + if (symbol->byte_at(0) == '(') {
  7441. + // This must be a method
  7442. + SignatureStream signatureStream(symbol);
  7443. + while (true) {
  7444. +
  7445. + if (signatureStream.is_array()) {
  7446. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7447. + if (is_type_signature_dangerous(cur_signature)) {
  7448. + return true;
  7449. + }
  7450. + } else if (signatureStream.is_object()) {
  7451. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7452. + return true;
  7453. + }
  7454. + }
  7455. +
  7456. + if (signatureStream.at_return_type()) {
  7457. + break;
  7458. + }
  7459. +
  7460. + signatureStream.next();
  7461. + }
  7462. +
  7463. + } else if (is_type_signature_dangerous(symbol)) {
  7464. + return true;
  7465. + }
  7466. + break;
  7467. +
  7468. + case JVM_CONSTANT_UnresolvedClass:
  7469. + symbol = cp->unresolved_klass_at(i);
  7470. + if (is_symbol_dangerous(symbol)) {
  7471. + return true;
  7472. + }
  7473. + break;
  7474. +
  7475. + default:
  7476. + ShouldNotReachHere();
  7477. + }
  7478. + }
  7479. +
  7480. + return false;
  7481. + }
  7482. +
  7483. + bool is_type_signature_dangerous(Symbol* signature) {
  7484. + // This must be a field type
  7485. + if (FieldType::is_obj(signature)) {
  7486. + Symbol* name = signature_to_class_name(signature);
  7487. + if (is_symbol_dangerous(name)) {
  7488. + return true;
  7489. + }
  7490. + } else if (FieldType::is_array(signature)) {
  7491. + //jint dimension;
  7492. + //Symbol* object_key;
  7493. + FieldArrayInfo fd;
  7494. + FieldType::get_array_info(signature, fd, Thread::current());
  7495. + if (is_symbol_dangerous(fd.object_key())) {
  7496. + return true;
  7497. + }
  7498. + }
  7499. + return false;
  7500. + }
  7501. +
  7502. + bool is_symbol_dangerous(Symbol* symbol) {
  7503. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7504. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7505. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7506. + i,
  7507. + symbol->as_C_string()));
  7508. + return true;
  7509. + }
  7510. + }
  7511. + return false;
  7512. + }
  7513. +
  7514. + virtual void do_object(oop obj) {
  7515. +
  7516. + if (!_result) return;
  7517. +
  7518. + klassOop klassObj = (klassOop)obj;
  7519. + Thread *THREAD = Thread::current();
  7520. +
  7521. + // We found an instance klass!
  7522. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7523. + instanceKlassHandle handle(klassObj);
  7524. +
  7525. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7526. +
  7527. + if (!can_be_affected(klass)) {
  7528. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7529. + return;
  7530. + }
  7531. +
  7532. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7533. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7534. + _result = false;
  7535. + return;
  7536. + }
  7537. +
  7538. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7539. +
  7540. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7541. +
  7542. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7543. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7544. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7545. + //PENDING_EXCEPTION->print();
  7546. + CLEAR_PENDING_EXCEPTION;
  7547. + _result = false;
  7548. + }
  7549. +
  7550. + /*int method_count = klass->methods()->length();
  7551. + for (int i=0; i<method_count; i++) {
  7552. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7553. + if (!check_method(cur_method)) {
  7554. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7555. + }
  7556. + }*/
  7557. + }
  7558. + };
  7559. +
  7560. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7561. +
  7562. + GrowableArray<klassOop> dangerous_klasses;
  7563. + for (int i=0; i<_new_classes->length(); i++) {
  7564. + instanceKlassHandle handle = _new_classes->at(i);
  7565. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7566. + dangerous_klasses.append(handle());
  7567. + }
  7568. + }
  7569. +
  7570. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7571. + Thread::current()->set_pretend_new_universe(true);
  7572. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7573. + Thread::current()->set_pretend_new_universe(false);
  7574. +
  7575. +
  7576. + return checkLoadedMethodsClosure.result();
  7577. +}
  7578. +
  7579. +bool VM_RedefineClasses::check_type_consistency() {
  7580. +
  7581. + Universe::set_verify_in_progress(true);
  7582. +
  7583. + SystemDictionary::classes_do(calculate_type_check_information);
  7584. + bool result = check_field_value_types();
  7585. + SystemDictionary::classes_do(clear_type_check_information);
  7586. + if (!result) {
  7587. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7588. + Universe::set_verify_in_progress(false);
  7589. return false;
  7590. }
  7591. - // rewrite constant pool references in the class_annotations:
  7592. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  7593. - // propagate failure back to caller
  7594. + result = check_method_stacks();
  7595. + if (!result) {
  7596. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7597. + Universe::set_verify_in_progress(false);
  7598. return false;
  7599. }
  7600. - // rewrite constant pool references in the fields_annotations:
  7601. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  7602. - // propagate failure back to caller
  7603. + result = check_loaded_methods();
  7604. + if (!result) {
  7605. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7606. + Universe::set_verify_in_progress(false);
  7607. return false;
  7608. }
  7609. - // rewrite constant pool references in the methods_annotations:
  7610. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  7611. - // propagate failure back to caller
  7612. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7613. + Universe::set_verify_in_progress(false);
  7614. + return true;
  7615. +}
  7616. +
  7617. +void VM_RedefineClasses::rollback() {
  7618. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7619. + SystemDictionary::rollback_redefinition();
  7620. +
  7621. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7622. + for (int i=0; i<_new_classes->length(); i++) {
  7623. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7624. + }
  7625. +
  7626. + for (int i=0; i<_new_classes->length(); i++) {
  7627. + instanceKlassHandle new_class = _new_classes->at(i);
  7628. + new_class->set_redefining(false);
  7629. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7630. + new_class->set_old_version(NULL);
  7631. + }
  7632. +
  7633. +}
  7634. +
  7635. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7636. + T heap_oop = oopDesc::load_heap_oop(p);
  7637. + if (!oopDesc::is_null(heap_oop)) {
  7638. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7639. + if (obj->is_instanceKlass()) {
  7640. + klassOop klass = (klassOop)obj;
  7641. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7642. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7643. + obj = klass->klass_part()->new_version();
  7644. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7645. + }
  7646. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7647. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7648. + // java.lang.Class instances.
  7649. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7650. + if (klass_oop != NULL) {
  7651. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7652. + obj = klass_oop->new_version()->java_mirror();
  7653. + } else if (klass_oop->klass_part()->is_redefining()) {
  7654. + obj = klass_oop->java_mirror();
  7655. + }
  7656. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7657. +
  7658. +
  7659. + // FIXME: DCEVM: better implementation?
  7660. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7661. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7662. + // case we need to run write barrier to make sure card table is properly updated. This will
  7663. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7664. + if (Universe::heap()->is_in_reserved(p)) {
  7665. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7666. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7667. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7668. + CardTableRS* _rs = (CardTableRS*)rs;
  7669. + _rs->inline_write_ref_field_gc(p, obj);
  7670. + }
  7671. + }
  7672. + }
  7673. + }
  7674. + }
  7675. +}
  7676. +
  7677. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7678. + markOop first_mark = first->mark();
  7679. + markOop second_mark = second->mark();
  7680. + first->set_mark(second_mark);
  7681. + second->set_mark(first_mark);
  7682. +}
  7683. +
  7684. +void VM_RedefineClasses::doit() {
  7685. + Thread *thread = Thread::current();
  7686. +
  7687. + RC_TRACE(0x00000001, ("Entering doit!"));
  7688. +
  7689. +
  7690. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7691. +
  7692. + RC_TIMER_START(_timer_check_type);
  7693. +
  7694. + if (!check_type_consistency()) {
  7695. + // (tw) TODO: Rollback the class redefinition
  7696. + rollback();
  7697. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7698. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7699. + RC_TIMER_STOP(_timer_check_type);
  7700. + return;
  7701. + }
  7702. +
  7703. + RC_TIMER_STOP(_timer_check_type);
  7704. +
  7705. + } else {
  7706. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7707. + }
  7708. +
  7709. + if (UseMethodForwardPoints) {
  7710. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7711. + method_forwarding();
  7712. + }
  7713. +
  7714. + if (UseSharedSpaces) {
  7715. + // Sharing is enabled so we remap the shared readonly space to
  7716. + // shared readwrite, private just in case we need to redefine
  7717. + // a shared class. We do the remap during the doit() phase of
  7718. + // the safepoint to be safer.
  7719. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7720. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7721. + _result = JVMTI_ERROR_INTERNAL;
  7722. + return;
  7723. + }
  7724. + }
  7725. +
  7726. + RC_TIMER_START(_timer_prepare_redefinition);
  7727. + for (int i = 0; i < _new_classes->length(); i++) {
  7728. + redefine_single_class(_new_classes->at(i), thread);
  7729. + }
  7730. +
  7731. + // Deoptimize all compiled code that depends on this class
  7732. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7733. +
  7734. + // Adjust constantpool caches and vtables for all classes
  7735. + // that reference methods of the evolved class.
  7736. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7737. +
  7738. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7739. + RC_TIMER_START(_timer_redefinition);
  7740. +
  7741. + class ChangePointersOopClosure : public OopClosure {
  7742. + virtual void do_oop(oop* o) {
  7743. + do_oop_work(o);
  7744. + }
  7745. +
  7746. + virtual void do_oop(narrowOop* o) {
  7747. + do_oop_work(o);
  7748. + }
  7749. + };
  7750. +
  7751. + class ChangePointersObjectClosure : public ObjectClosure {
  7752. +
  7753. + private:
  7754. +
  7755. + OopClosure *_closure;
  7756. + bool _needs_instance_update;
  7757. + GrowableArray<oop> *_updated_oops;
  7758. +
  7759. + public:
  7760. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7761. +
  7762. + bool needs_instance_update() {
  7763. + return _needs_instance_update;
  7764. + }
  7765. +
  7766. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7767. +
  7768. + virtual void do_object(oop obj) {
  7769. + if (!obj->is_instanceKlass()) {
  7770. + obj->oop_iterate(_closure);
  7771. +
  7772. + if (obj->blueprint()->is_redefining()) {
  7773. +
  7774. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7775. + if (_updated_oops == NULL) {
  7776. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  7777. + }
  7778. + _updated_oops->append(obj);
  7779. + }
  7780. +
  7781. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7782. +
  7783. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7784. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7785. +
  7786. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7787. + // We need an instance update => set back to old klass
  7788. + _needs_instance_update = true;
  7789. +
  7790. + } else {
  7791. + MarkSweep::update_fields(obj, obj);
  7792. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7793. + }
  7794. + }
  7795. + }
  7796. +
  7797. + } else {
  7798. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  7799. + if (klass->is_redefining()) {
  7800. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  7801. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  7802. + old_klass->constants()->set_pool_holder(klass->old_version());
  7803. +
  7804. + // Initialize the new class! Special static initialization that does not execute the
  7805. + // static constructor but copies static field values from the old class if name
  7806. + // and signature of a static field match.
  7807. + klass->initialize_redefined_class();
  7808. + }
  7809. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  7810. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  7811. + // idubrov: will get new version of that class
  7812. + //klass->iterate_static_fields(_closure);
  7813. + }
  7814. + }
  7815. + };
  7816. +
  7817. + ChangePointersOopClosure oopClosure;
  7818. + ChangePointersObjectClosure objectClosure(&oopClosure);
  7819. +
  7820. + {
  7821. + SharedHeap::heap()->gc_prologue(true);
  7822. + Universe::root_oops_do(&oopClosure);
  7823. + Universe::heap()->object_iterate(&objectClosure);
  7824. + SharedHeap::heap()->gc_epilogue(false);
  7825. + }
  7826. +
  7827. + // Swap marks to have same hashcodes
  7828. + for (int i=0; i<_new_classes->length(); i++) {
  7829. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  7830. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  7831. + }
  7832. +
  7833. + _updated_oops = objectClosure.updated_oops();
  7834. +
  7835. + if (objectClosure.needs_instance_update()){
  7836. +
  7837. + // Do a full garbage collection to update the instance sizes accordingly
  7838. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  7839. + Universe::set_redefining_gc_run(true);
  7840. + JvmtiGCMarker jgcm;
  7841. + notify_gc_begin(true);
  7842. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  7843. + notify_gc_end();
  7844. + Universe::set_redefining_gc_run(false);
  7845. + RC_TRACE(0x00000001, ("GC done!"));
  7846. + }
  7847. +
  7848. +
  7849. + if (RC_TRACE_ENABLED(0x00000001)) {
  7850. + if (_updated_oops != NULL) {
  7851. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  7852. + } else {
  7853. + RC_TRACE(0x00000001, ("No objects updated!"));
  7854. + }
  7855. + }
  7856. +
  7857. + // Unmark klassOops as "redefining"
  7858. + for (int i=0; i<_new_classes->length(); i++) {
  7859. + klassOop cur = _new_classes->at(i)();
  7860. + _new_classes->at(i)->set_redefining(false);
  7861. + _new_classes->at(i)->clear_update_information();
  7862. + _new_classes->at(i)->update_supers_to_newest_version();
  7863. +
  7864. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  7865. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7866. +
  7867. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  7868. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7869. +
  7870. + oop new_mirror = _new_classes->at(i)->java_mirror();
  7871. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  7872. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  7873. + }
  7874. + }
  7875. +
  7876. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  7877. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  7878. + }
  7879. +
  7880. + // Disable any dependent concurrent compilations
  7881. + SystemDictionary::notice_modification();
  7882. +
  7883. + // Set flag indicating that some invariants are no longer true.
  7884. + // See jvmtiExport.hpp for detailed explanation.
  7885. + JvmtiExport::set_has_redefined_a_class();
  7886. +
  7887. + // Clean up caches in the compiler interface and compiler threads
  7888. + CompileBroker::cleanup_after_redefinition();
  7889. +
  7890. +#ifdef ASSERT
  7891. +
  7892. + // Universe::verify();
  7893. + // JNIHandles::verify();
  7894. +
  7895. + SystemDictionary::classes_do(check_class, thread);
  7896. +#endif
  7897. +
  7898. + update_active_methods();
  7899. + RC_TIMER_STOP(_timer_redefinition);
  7900. +
  7901. +}
  7902. +
  7903. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  7904. +
  7905. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  7906. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  7907. +
  7908. +
  7909. + while (curArrayKlass != NULL) {
  7910. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  7911. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  7912. + curArrayKlass->update_supers_to_newest_version();
  7913. +
  7914. + curArrayKlass = NULL;
  7915. + if (higher_dimension != NULL) {
  7916. + curArrayKlass = arrayKlass::cast(higher_dimension);
  7917. + }
  7918. + }
  7919. +
  7920. +}
  7921. +
  7922. +void VM_RedefineClasses::doit_epilogue() {
  7923. +
  7924. + RC_TIMER_START(_timer_vm_op_epilogue);
  7925. +
  7926. + unlock_threads();
  7927. +
  7928. + ResourceMark mark;
  7929. +
  7930. + VM_GC_Operation::doit_epilogue();
  7931. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  7932. +
  7933. + GrowableArray<methodHandle> instanceTransformerMethods;
  7934. +
  7935. + // Call static transformers
  7936. + for (int i=0; i<_new_classes->length(); i++) {
  7937. +
  7938. + instanceKlassHandle klass = _new_classes->at(i);
  7939. +
  7940. + // Transfer init state
  7941. + if (klass->old_version() != NULL) {
  7942. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  7943. + if (state > instanceKlass::linked) {
  7944. + klass->initialize(Thread::current());
  7945. + }
  7946. + }
  7947. +
  7948. + // Find instance transformer method
  7949. +
  7950. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7951. +
  7952. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  7953. + klassOop cur_klass = klass();
  7954. + while (cur_klass != NULL) {
  7955. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  7956. + if (method != NULL) {
  7957. + methodHandle instanceTransformerMethod(method);
  7958. + instanceTransformerMethods.append(instanceTransformerMethod);
  7959. + break;
  7960. + } else {
  7961. + cur_klass = cur_klass->klass_part()->super();
  7962. + }
  7963. + }
  7964. + assert(cur_klass != NULL, "must have instance transformer method");
  7965. + } else {
  7966. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  7967. + }
  7968. + }
  7969. +
  7970. +
  7971. + // Call instance transformers
  7972. + if (_updated_oops != NULL) {
  7973. +
  7974. + for (int i=0; i<_updated_oops->length(); i++) {
  7975. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  7976. + Handle cur(_updated_oops->at(i));
  7977. + instanceKlassHandle klass(cur->klass());
  7978. +
  7979. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7980. +
  7981. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  7982. +
  7983. + RC_TRACE(0x00008000, ("executing transformer method"));
  7984. +
  7985. + Thread *__the_thread__ = Thread::current();
  7986. + JavaValue result(T_VOID);
  7987. + JavaCallArguments args(cur);
  7988. + JavaCalls::call(&result,
  7989. + method,
  7990. + &args,
  7991. + THREAD);
  7992. +
  7993. + // TODO: What to do with an exception here?
  7994. + if (HAS_PENDING_EXCEPTION) {
  7995. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7996. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  7997. + ex_name->as_C_string()));
  7998. + CLEAR_PENDING_EXCEPTION;
  7999. + }
  8000. + }
  8001. + }
  8002. +
  8003. + delete _updated_oops;
  8004. + _updated_oops = NULL;
  8005. + }
  8006. +
  8007. + // Free the array of scratch classes
  8008. + delete _new_classes;
  8009. + _new_classes = NULL;
  8010. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  8011. +
  8012. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  8013. +}
  8014. +
  8015. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  8016. + // classes for primitives cannot be redefined
  8017. + if (java_lang_Class::is_primitive(klass_mirror)) {
  8018. return false;
  8019. }
  8020. -
  8021. - // rewrite constant pool references in the methods_parameter_annotations:
  8022. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  8023. - THREAD)) {
  8024. - // propagate failure back to caller
  8025. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  8026. + // classes for arrays cannot be redefined
  8027. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  8028. return false;
  8029. }
  8030. -
  8031. - // rewrite constant pool references in the methods_default_annotations:
  8032. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  8033. - THREAD)) {
  8034. - // propagate failure back to caller
  8035. - return false;
  8036. + return true;
  8037. +}
  8038. +
  8039. +#ifdef ASSERT
  8040. +
  8041. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8042. + klassOop k_oop = k_oop_latest;
  8043. + while (k_oop != NULL) {
  8044. +
  8045. + instanceKlassHandle k_handle(THREAD, k_oop);
  8046. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  8047. + k_oop = k_oop->klass_part()->old_version();
  8048. }
  8049. -
  8050. - return true;
  8051. -} // end rewrite_cp_refs()
  8052. -
  8053. -
  8054. -// Rewrite constant pool references in the methods.
  8055. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  8056. - instanceKlassHandle scratch_class, TRAPS) {
  8057. -
  8058. - objArrayHandle methods(THREAD, scratch_class->methods());
  8059. -
  8060. - if (methods.is_null() || methods->length() == 0) {
  8061. - // no methods so nothing to do
  8062. - return true;
  8063. - }
  8064. -
  8065. - // rewrite constant pool references in the methods:
  8066. - for (int i = methods->length() - 1; i >= 0; i--) {
  8067. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8068. - methodHandle new_method;
  8069. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  8070. - if (!new_method.is_null()) {
  8071. - // the method has been replaced so save the new method version
  8072. - methods->obj_at_put(i, new_method());
  8073. +}
  8074. +
  8075. +#endif
  8076. +
  8077. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  8078. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  8079. +// do that, they assume that cache entry is resolved already.
  8080. +static void unpatch_bytecode(methodOop method) {
  8081. + RawBytecodeStream bcs(method);
  8082. + Bytecodes::Code code;
  8083. + Bytecodes::Code java_code;
  8084. + while (!bcs.is_last_bytecode()) {
  8085. + code = bcs.raw_next();
  8086. + address bcp = bcs.bcp();
  8087. +
  8088. + if (code == Bytecodes::_breakpoint) {
  8089. + int bci = method->bci_from(bcp);
  8090. + code = method->orig_bytecode_at(bci);
  8091. + java_code = Bytecodes::java_code(code);
  8092. + if (code != java_code &&
  8093. + (java_code == Bytecodes::_getfield ||
  8094. + java_code == Bytecodes::_putfield ||
  8095. + java_code == Bytecodes::_aload_0)) {
  8096. + // Let breakpoint table handling unpatch bytecode
  8097. + method->set_orig_bytecode_at(bci, java_code);
  8098. + }
  8099. + } else {
  8100. + java_code = Bytecodes::java_code(code);
  8101. + if (code != java_code &&
  8102. + (java_code == Bytecodes::_getfield ||
  8103. + java_code == Bytecodes::_putfield ||
  8104. + java_code == Bytecodes::_aload_0)) {
  8105. + *bcp = java_code;
  8106. + }
  8107. + }
  8108. +
  8109. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  8110. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  8111. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  8112. + assert(code2 == Bytecodes::_fast_igetfield ||
  8113. + code2 == Bytecodes::_fast_agetfield ||
  8114. + code2 == Bytecodes::_fast_fgetfield, "");
  8115. + *(bcp + 1) = Bytecodes::java_code(code2);
  8116. }
  8117. }
  8118. -
  8119. - return true;
  8120. }
  8121. -
  8122. -// Rewrite constant pool references in the specific method. This code
  8123. -// was adapted from Rewriter::rewrite_method().
  8124. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  8125. - methodHandle *new_method_p, TRAPS) {
  8126. -
  8127. - *new_method_p = methodHandle(); // default is no new method
  8128. -
  8129. - // We cache a pointer to the bytecodes here in code_base. If GC
  8130. - // moves the methodOop, then the bytecodes will also move which
  8131. - // will likely cause a crash. We create a No_Safepoint_Verifier
  8132. - // object to detect whether we pass a possible safepoint in this
  8133. - // code block.
  8134. - No_Safepoint_Verifier nsv;
  8135. -
  8136. - // Bytecodes and their length
  8137. - address code_base = method->code_base();
  8138. - int code_length = method->code_size();
  8139. -
  8140. - int bc_length;
  8141. - for (int bci = 0; bci < code_length; bci += bc_length) {
  8142. - address bcp = code_base + bci;
  8143. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  8144. -
  8145. - bc_length = Bytecodes::length_for(c);
  8146. - if (bc_length == 0) {
  8147. - // More complicated bytecodes report a length of zero so
  8148. - // we have to try again a slightly different way.
  8149. - bc_length = Bytecodes::length_at(method(), bcp);
  8150. - }
  8151. -
  8152. - assert(bc_length != 0, "impossible bytecode length");
  8153. -
  8154. - switch (c) {
  8155. - case Bytecodes::_ldc:
  8156. - {
  8157. - int cp_index = *(bcp + 1);
  8158. - int new_index = find_new_index(cp_index);
  8159. -
  8160. - if (StressLdcRewrite && new_index == 0) {
  8161. - // If we are stressing ldc -> ldc_w rewriting, then we
  8162. - // always need a new_index value.
  8163. - new_index = cp_index;
  8164. - }
  8165. - if (new_index != 0) {
  8166. - // the original index is mapped so we have more work to do
  8167. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  8168. - // The new value can still use ldc instead of ldc_w
  8169. - // unless we are trying to stress ldc -> ldc_w rewriting
  8170. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8171. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  8172. - bcp, cp_index, new_index));
  8173. - *(bcp + 1) = new_index;
  8174. - } else {
  8175. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8176. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  8177. - Bytecodes::name(c), bcp, cp_index, new_index));
  8178. - // the new value needs ldc_w instead of ldc
  8179. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  8180. - bcp = (address)inst_buffer;
  8181. - // construct new instruction sequence
  8182. - *bcp = Bytecodes::_ldc_w;
  8183. - bcp++;
  8184. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  8185. - // See comment below for difference between put_Java_u2()
  8186. - // and put_native_u2().
  8187. - Bytes::put_Java_u2(bcp, new_index);
  8188. -
  8189. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  8190. - methodHandle m;
  8191. - {
  8192. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  8193. -
  8194. - // ldc is 2 bytes and ldc_w is 3 bytes
  8195. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  8196. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  8197. - guarantee(false, "insert_space_at() failed");
  8198. - }
  8199. - }
  8200. -
  8201. - // return the new method so that the caller can update
  8202. - // the containing class
  8203. - *new_method_p = method = m;
  8204. - // switch our bytecode processing loop from the old method
  8205. - // to the new method
  8206. - code_base = method->code_base();
  8207. - code_length = method->code_size();
  8208. - bcp = code_base + bci;
  8209. - c = (Bytecodes::Code)(*bcp);
  8210. - bc_length = Bytecodes::length_for(c);
  8211. - assert(bc_length != 0, "sanity check");
  8212. - } // end we need ldc_w instead of ldc
  8213. - } // end if there is a mapped index
  8214. - } break;
  8215. -
  8216. - // these bytecodes have a two-byte constant pool index
  8217. - case Bytecodes::_anewarray : // fall through
  8218. - case Bytecodes::_checkcast : // fall through
  8219. - case Bytecodes::_getfield : // fall through
  8220. - case Bytecodes::_getstatic : // fall through
  8221. - case Bytecodes::_instanceof : // fall through
  8222. - case Bytecodes::_invokedynamic : // fall through
  8223. - case Bytecodes::_invokeinterface: // fall through
  8224. - case Bytecodes::_invokespecial : // fall through
  8225. - case Bytecodes::_invokestatic : // fall through
  8226. - case Bytecodes::_invokevirtual : // fall through
  8227. - case Bytecodes::_ldc_w : // fall through
  8228. - case Bytecodes::_ldc2_w : // fall through
  8229. - case Bytecodes::_multianewarray : // fall through
  8230. - case Bytecodes::_new : // fall through
  8231. - case Bytecodes::_putfield : // fall through
  8232. - case Bytecodes::_putstatic :
  8233. - {
  8234. - address p = bcp + 1;
  8235. - int cp_index = Bytes::get_Java_u2(p);
  8236. - int new_index = find_new_index(cp_index);
  8237. - if (new_index != 0) {
  8238. - // the original index is mapped so update w/ new value
  8239. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8240. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  8241. - bcp, cp_index, new_index));
  8242. - // Rewriter::rewrite_method() uses put_native_u2() in this
  8243. - // situation because it is reusing the constant pool index
  8244. - // location for a native index into the constantPoolCache.
  8245. - // Since we are updating the constant pool index prior to
  8246. - // verification and constantPoolCache initialization, we
  8247. - // need to keep the new index in Java byte order.
  8248. - Bytes::put_Java_u2(p, new_index);
  8249. - }
  8250. - } break;
  8251. - }
  8252. - } // end for each bytecode
  8253. -} // end rewrite_cp_refs_in_method()
  8254. -
  8255. -
  8256. -// Rewrite constant pool references in the class_annotations field.
  8257. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  8258. - instanceKlassHandle scratch_class, TRAPS) {
  8259. -
  8260. - typeArrayHandle class_annotations(THREAD,
  8261. - scratch_class->class_annotations());
  8262. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  8263. - // no class_annotations so nothing to do
  8264. - return true;
  8265. - }
  8266. -
  8267. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8268. - ("class_annotations length=%d", class_annotations->length()));
  8269. -
  8270. - int byte_i = 0; // byte index into class_annotations
  8271. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  8272. - THREAD);
  8273. -}
  8274. -
  8275. -
  8276. -// Rewrite constant pool references in an annotations typeArray. This
  8277. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  8278. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  8279. -//
  8280. -// annotations_typeArray {
  8281. -// u2 num_annotations;
  8282. -// annotation annotations[num_annotations];
  8283. -// }
  8284. -//
  8285. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  8286. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8287. -
  8288. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8289. - // not enough room for num_annotations field
  8290. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8291. - ("length() is too small for num_annotations field"));
  8292. - return false;
  8293. - }
  8294. -
  8295. - u2 num_annotations = Bytes::get_Java_u2((address)
  8296. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8297. - byte_i_ref += 2;
  8298. -
  8299. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8300. - ("num_annotations=%d", num_annotations));
  8301. -
  8302. - int calc_num_annotations = 0;
  8303. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  8304. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8305. - byte_i_ref, THREAD)) {
  8306. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8307. - ("bad annotation_struct at %d", calc_num_annotations));
  8308. - // propagate failure back to caller
  8309. - return false;
  8310. - }
  8311. - }
  8312. - assert(num_annotations == calc_num_annotations, "sanity check");
  8313. -
  8314. - return true;
  8315. -} // end rewrite_cp_refs_in_annotations_typeArray()
  8316. -
  8317. -
  8318. -// Rewrite constant pool references in the annotation struct portion of
  8319. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  8320. -// the 2nd-edition of the VM spec:
  8321. -//
  8322. -// struct annotation {
  8323. -// u2 type_index;
  8324. -// u2 num_element_value_pairs;
  8325. -// {
  8326. -// u2 element_name_index;
  8327. -// element_value value;
  8328. -// } element_value_pairs[num_element_value_pairs];
  8329. -// }
  8330. -//
  8331. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  8332. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8333. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  8334. - // not enough room for smallest annotation_struct
  8335. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8336. - ("length() is too small for annotation_struct"));
  8337. - return false;
  8338. - }
  8339. -
  8340. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  8341. - byte_i_ref, "mapped old type_index=%d", THREAD);
  8342. -
  8343. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  8344. - annotations_typeArray->byte_at_addr(
  8345. - byte_i_ref));
  8346. - byte_i_ref += 2;
  8347. -
  8348. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8349. - ("type_index=%d num_element_value_pairs=%d", type_index,
  8350. - num_element_value_pairs));
  8351. -
  8352. - int calc_num_element_value_pairs = 0;
  8353. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  8354. - calc_num_element_value_pairs++) {
  8355. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8356. - // not enough room for another element_name_index, let alone
  8357. - // the rest of another component
  8358. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8359. - ("length() is too small for element_name_index"));
  8360. - return false;
  8361. - }
  8362. -
  8363. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  8364. - annotations_typeArray, byte_i_ref,
  8365. - "mapped old element_name_index=%d", THREAD);
  8366. -
  8367. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8368. - ("element_name_index=%d", element_name_index));
  8369. -
  8370. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  8371. - byte_i_ref, THREAD)) {
  8372. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8373. - ("bad element_value at %d", calc_num_element_value_pairs));
  8374. - // propagate failure back to caller
  8375. - return false;
  8376. - }
  8377. - } // end for each component
  8378. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  8379. - "sanity check");
  8380. -
  8381. - return true;
  8382. -} // end rewrite_cp_refs_in_annotation_struct()
  8383. -
  8384. -
  8385. -// Rewrite a constant pool reference at the current position in
  8386. -// annotations_typeArray if needed. Returns the original constant
  8387. -// pool reference if a rewrite was not needed or the new constant
  8388. -// pool reference if a rewrite was needed.
  8389. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  8390. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  8391. - const char * trace_mesg, TRAPS) {
  8392. -
  8393. - address cp_index_addr = (address)
  8394. - annotations_typeArray->byte_at_addr(byte_i_ref);
  8395. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  8396. - u2 new_cp_index = find_new_index(old_cp_index);
  8397. - if (new_cp_index != 0) {
  8398. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  8399. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  8400. - old_cp_index = new_cp_index;
  8401. - }
  8402. - byte_i_ref += 2;
  8403. - return old_cp_index;
  8404. -}
  8405. -
  8406. -
  8407. -// Rewrite constant pool references in the element_value portion of an
  8408. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  8409. -// the 2nd-edition of the VM spec:
  8410. -//
  8411. -// struct element_value {
  8412. -// u1 tag;
  8413. -// union {
  8414. -// u2 const_value_index;
  8415. -// {
  8416. -// u2 type_name_index;
  8417. -// u2 const_name_index;
  8418. -// } enum_const_value;
  8419. -// u2 class_info_index;
  8420. -// annotation annotation_value;
  8421. -// struct {
  8422. -// u2 num_values;
  8423. -// element_value values[num_values];
  8424. -// } array_value;
  8425. -// } value;
  8426. -// }
  8427. -//
  8428. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  8429. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8430. -
  8431. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  8432. - // not enough room for a tag let alone the rest of an element_value
  8433. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8434. - ("length() is too small for a tag"));
  8435. - return false;
  8436. - }
  8437. -
  8438. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  8439. - byte_i_ref++;
  8440. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  8441. -
  8442. - switch (tag) {
  8443. - // These BaseType tag values are from Table 4.2 in VM spec:
  8444. - case 'B': // byte
  8445. - case 'C': // char
  8446. - case 'D': // double
  8447. - case 'F': // float
  8448. - case 'I': // int
  8449. - case 'J': // long
  8450. - case 'S': // short
  8451. - case 'Z': // boolean
  8452. -
  8453. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  8454. - // the VM spec:
  8455. - case 's':
  8456. - {
  8457. - // For the above tag values (including the BaseType values),
  8458. - // value.const_value_index is right union field.
  8459. -
  8460. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8461. - // not enough room for a const_value_index
  8462. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8463. - ("length() is too small for a const_value_index"));
  8464. - return false;
  8465. - }
  8466. -
  8467. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8468. - annotations_typeArray, byte_i_ref,
  8469. - "mapped old const_value_index=%d", THREAD);
  8470. -
  8471. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8472. - ("const_value_index=%d", const_value_index));
  8473. - } break;
  8474. -
  8475. - case 'e':
  8476. - {
  8477. - // for the above tag value, value.enum_const_value is right union field
  8478. -
  8479. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8480. - // not enough room for a enum_const_value
  8481. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8482. - ("length() is too small for a enum_const_value"));
  8483. - return false;
  8484. - }
  8485. -
  8486. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8487. - annotations_typeArray, byte_i_ref,
  8488. - "mapped old type_name_index=%d", THREAD);
  8489. -
  8490. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8491. - annotations_typeArray, byte_i_ref,
  8492. - "mapped old const_name_index=%d", THREAD);
  8493. -
  8494. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8495. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8496. - const_name_index));
  8497. - } break;
  8498. -
  8499. - case 'c':
  8500. - {
  8501. - // for the above tag value, value.class_info_index is right union field
  8502. -
  8503. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8504. - // not enough room for a class_info_index
  8505. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8506. - ("length() is too small for a class_info_index"));
  8507. - return false;
  8508. - }
  8509. -
  8510. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8511. - annotations_typeArray, byte_i_ref,
  8512. - "mapped old class_info_index=%d", THREAD);
  8513. -
  8514. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8515. - ("class_info_index=%d", class_info_index));
  8516. - } break;
  8517. -
  8518. - case '@':
  8519. - // For the above tag value, value.attr_value is the right union
  8520. - // field. This is a nested annotation.
  8521. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8522. - byte_i_ref, THREAD)) {
  8523. - // propagate failure back to caller
  8524. - return false;
  8525. - }
  8526. - break;
  8527. -
  8528. - case '[':
  8529. - {
  8530. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8531. - // not enough room for a num_values field
  8532. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8533. - ("length() is too small for a num_values field"));
  8534. - return false;
  8535. - }
  8536. -
  8537. - // For the above tag value, value.array_value is the right union
  8538. - // field. This is an array of nested element_value.
  8539. - u2 num_values = Bytes::get_Java_u2((address)
  8540. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8541. - byte_i_ref += 2;
  8542. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8543. -
  8544. - int calc_num_values = 0;
  8545. - for (; calc_num_values < num_values; calc_num_values++) {
  8546. - if (!rewrite_cp_refs_in_element_value(
  8547. - annotations_typeArray, byte_i_ref, THREAD)) {
  8548. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8549. - ("bad nested element_value at %d", calc_num_values));
  8550. - // propagate failure back to caller
  8551. - return false;
  8552. - }
  8553. - }
  8554. - assert(num_values == calc_num_values, "sanity check");
  8555. - } break;
  8556. -
  8557. - default:
  8558. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8559. - return false;
  8560. - } // end decode tag field
  8561. -
  8562. - return true;
  8563. -} // end rewrite_cp_refs_in_element_value()
  8564. -
  8565. -
  8566. -// Rewrite constant pool references in a fields_annotations field.
  8567. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8568. - instanceKlassHandle scratch_class, TRAPS) {
  8569. -
  8570. - objArrayHandle fields_annotations(THREAD,
  8571. - scratch_class->fields_annotations());
  8572. -
  8573. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8574. - // no fields_annotations so nothing to do
  8575. - return true;
  8576. - }
  8577. -
  8578. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8579. - ("fields_annotations length=%d", fields_annotations->length()));
  8580. -
  8581. - for (int i = 0; i < fields_annotations->length(); i++) {
  8582. - typeArrayHandle field_annotations(THREAD,
  8583. - (typeArrayOop)fields_annotations->obj_at(i));
  8584. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8585. - // this field does not have any annotations so skip it
  8586. - continue;
  8587. - }
  8588. -
  8589. - int byte_i = 0; // byte index into field_annotations
  8590. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8591. - THREAD)) {
  8592. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8593. - ("bad field_annotations at %d", i));
  8594. - // propagate failure back to caller
  8595. - return false;
  8596. - }
  8597. - }
  8598. -
  8599. - return true;
  8600. -} // end rewrite_cp_refs_in_fields_annotations()
  8601. -
  8602. -
  8603. -// Rewrite constant pool references in a methods_annotations field.
  8604. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8605. - instanceKlassHandle scratch_class, TRAPS) {
  8606. -
  8607. - objArrayHandle methods_annotations(THREAD,
  8608. - scratch_class->methods_annotations());
  8609. -
  8610. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8611. - // no methods_annotations so nothing to do
  8612. - return true;
  8613. - }
  8614. -
  8615. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8616. - ("methods_annotations length=%d", methods_annotations->length()));
  8617. -
  8618. - for (int i = 0; i < methods_annotations->length(); i++) {
  8619. - typeArrayHandle method_annotations(THREAD,
  8620. - (typeArrayOop)methods_annotations->obj_at(i));
  8621. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8622. - // this method does not have any annotations so skip it
  8623. - continue;
  8624. - }
  8625. -
  8626. - int byte_i = 0; // byte index into method_annotations
  8627. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8628. - THREAD)) {
  8629. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8630. - ("bad method_annotations at %d", i));
  8631. - // propagate failure back to caller
  8632. - return false;
  8633. - }
  8634. - }
  8635. -
  8636. - return true;
  8637. -} // end rewrite_cp_refs_in_methods_annotations()
  8638. -
  8639. -
  8640. -// Rewrite constant pool references in a methods_parameter_annotations
  8641. -// field. This "structure" is adapted from the
  8642. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8643. -// 4.8.17 of the 2nd-edition of the VM spec:
  8644. -//
  8645. -// methods_parameter_annotations_typeArray {
  8646. -// u1 num_parameters;
  8647. -// {
  8648. -// u2 num_annotations;
  8649. -// annotation annotations[num_annotations];
  8650. -// } parameter_annotations[num_parameters];
  8651. -// }
  8652. -//
  8653. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8654. - instanceKlassHandle scratch_class, TRAPS) {
  8655. -
  8656. - objArrayHandle methods_parameter_annotations(THREAD,
  8657. - scratch_class->methods_parameter_annotations());
  8658. -
  8659. - if (methods_parameter_annotations.is_null()
  8660. - || methods_parameter_annotations->length() == 0) {
  8661. - // no methods_parameter_annotations so nothing to do
  8662. - return true;
  8663. - }
  8664. -
  8665. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8666. - ("methods_parameter_annotations length=%d",
  8667. - methods_parameter_annotations->length()));
  8668. -
  8669. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8670. - typeArrayHandle method_parameter_annotations(THREAD,
  8671. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8672. - if (method_parameter_annotations.is_null()
  8673. - || method_parameter_annotations->length() == 0) {
  8674. - // this method does not have any parameter annotations so skip it
  8675. - continue;
  8676. - }
  8677. -
  8678. - if (method_parameter_annotations->length() < 1) {
  8679. - // not enough room for a num_parameters field
  8680. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8681. - ("length() is too small for a num_parameters field at %d", i));
  8682. - return false;
  8683. - }
  8684. -
  8685. - int byte_i = 0; // byte index into method_parameter_annotations
  8686. -
  8687. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8688. - byte_i++;
  8689. -
  8690. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8691. - ("num_parameters=%d", num_parameters));
  8692. -
  8693. - int calc_num_parameters = 0;
  8694. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8695. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8696. - method_parameter_annotations, byte_i, THREAD)) {
  8697. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8698. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8699. - // propagate failure back to caller
  8700. - return false;
  8701. - }
  8702. - }
  8703. - assert(num_parameters == calc_num_parameters, "sanity check");
  8704. - }
  8705. -
  8706. - return true;
  8707. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8708. -
  8709. -
  8710. -// Rewrite constant pool references in a methods_default_annotations
  8711. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8712. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8713. -//
  8714. -// methods_default_annotations_typeArray {
  8715. -// element_value default_value;
  8716. -// }
  8717. -//
  8718. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8719. - instanceKlassHandle scratch_class, TRAPS) {
  8720. -
  8721. - objArrayHandle methods_default_annotations(THREAD,
  8722. - scratch_class->methods_default_annotations());
  8723. -
  8724. - if (methods_default_annotations.is_null()
  8725. - || methods_default_annotations->length() == 0) {
  8726. - // no methods_default_annotations so nothing to do
  8727. - return true;
  8728. - }
  8729. -
  8730. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8731. - ("methods_default_annotations length=%d",
  8732. - methods_default_annotations->length()));
  8733. -
  8734. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8735. - typeArrayHandle method_default_annotations(THREAD,
  8736. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8737. - if (method_default_annotations.is_null()
  8738. - || method_default_annotations->length() == 0) {
  8739. - // this method does not have any default annotations so skip it
  8740. - continue;
  8741. - }
  8742. -
  8743. - int byte_i = 0; // byte index into method_default_annotations
  8744. -
  8745. - if (!rewrite_cp_refs_in_element_value(
  8746. - method_default_annotations, byte_i, THREAD)) {
  8747. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8748. - ("bad default element_value at %d", i));
  8749. - // propagate failure back to caller
  8750. - return false;
  8751. - }
  8752. - }
  8753. -
  8754. - return true;
  8755. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8756. -
  8757. -
  8758. -// Rewrite constant pool references in the method's stackmap table.
  8759. -// These "structures" are adapted from the StackMapTable_attribute that
  8760. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8761. -// (dated 2005.10.26):
  8762. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8763. -//
  8764. -// stack_map {
  8765. -// u2 number_of_entries;
  8766. -// stack_map_frame entries[number_of_entries];
  8767. -// }
  8768. -//
  8769. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8770. - methodHandle method, TRAPS) {
  8771. -
  8772. - if (!method->has_stackmap_table()) {
  8773. - return;
  8774. - }
  8775. -
  8776. - typeArrayOop stackmap_data = method->stackmap_data();
  8777. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8778. - address stackmap_end = stackmap_p + stackmap_data->length();
  8779. -
  8780. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8781. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8782. - stackmap_p += 2;
  8783. -
  8784. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8785. - ("number_of_entries=%u", number_of_entries));
  8786. -
  8787. - // walk through each stack_map_frame
  8788. - u2 calc_number_of_entries = 0;
  8789. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8790. - // The stack_map_frame structure is a u1 frame_type followed by
  8791. - // 0 or more bytes of data:
  8792. - //
  8793. - // union stack_map_frame {
  8794. - // same_frame;
  8795. - // same_locals_1_stack_item_frame;
  8796. - // same_locals_1_stack_item_frame_extended;
  8797. - // chop_frame;
  8798. - // same_frame_extended;
  8799. - // append_frame;
  8800. - // full_frame;
  8801. - // }
  8802. -
  8803. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8804. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8805. - // issues the following warning for the first if-statement below:
  8806. - //
  8807. - // "warning: comparison is always true due to limited range of data type"
  8808. - //
  8809. - u4 frame_type = *stackmap_p;
  8810. - stackmap_p++;
  8811. -
  8812. - // same_frame {
  8813. - // u1 frame_type = SAME; /* 0-63 */
  8814. - // }
  8815. - if (frame_type >= 0 && frame_type <= 63) {
  8816. - // nothing more to do for same_frame
  8817. - }
  8818. -
  8819. - // same_locals_1_stack_item_frame {
  8820. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8821. - // verification_type_info stack[1];
  8822. - // }
  8823. - else if (frame_type >= 64 && frame_type <= 127) {
  8824. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8825. - calc_number_of_entries, frame_type, THREAD);
  8826. - }
  8827. -
  8828. - // reserved for future use
  8829. - else if (frame_type >= 128 && frame_type <= 246) {
  8830. - // nothing more to do for reserved frame_types
  8831. - }
  8832. -
  8833. - // same_locals_1_stack_item_frame_extended {
  8834. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8835. - // u2 offset_delta;
  8836. - // verification_type_info stack[1];
  8837. - // }
  8838. - else if (frame_type == 247) {
  8839. - stackmap_p += 2;
  8840. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8841. - calc_number_of_entries, frame_type, THREAD);
  8842. - }
  8843. -
  8844. - // chop_frame {
  8845. - // u1 frame_type = CHOP; /* 248-250 */
  8846. - // u2 offset_delta;
  8847. - // }
  8848. - else if (frame_type >= 248 && frame_type <= 250) {
  8849. - stackmap_p += 2;
  8850. - }
  8851. -
  8852. - // same_frame_extended {
  8853. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8854. - // u2 offset_delta;
  8855. - // }
  8856. - else if (frame_type == 251) {
  8857. - stackmap_p += 2;
  8858. - }
  8859. -
  8860. - // append_frame {
  8861. - // u1 frame_type = APPEND; /* 252-254 */
  8862. - // u2 offset_delta;
  8863. - // verification_type_info locals[frame_type - 251];
  8864. - // }
  8865. - else if (frame_type >= 252 && frame_type <= 254) {
  8866. - assert(stackmap_p + 2 <= stackmap_end,
  8867. - "no room for offset_delta");
  8868. - stackmap_p += 2;
  8869. - u1 len = frame_type - 251;
  8870. - for (u1 i = 0; i < len; i++) {
  8871. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8872. - calc_number_of_entries, frame_type, THREAD);
  8873. - }
  8874. - }
  8875. -
  8876. - // full_frame {
  8877. - // u1 frame_type = FULL_FRAME; /* 255 */
  8878. - // u2 offset_delta;
  8879. - // u2 number_of_locals;
  8880. - // verification_type_info locals[number_of_locals];
  8881. - // u2 number_of_stack_items;
  8882. - // verification_type_info stack[number_of_stack_items];
  8883. - // }
  8884. - else if (frame_type == 255) {
  8885. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8886. - "no room for smallest full_frame");
  8887. - stackmap_p += 2;
  8888. -
  8889. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8890. - stackmap_p += 2;
  8891. -
  8892. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8893. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8894. - calc_number_of_entries, frame_type, THREAD);
  8895. - }
  8896. -
  8897. - // Use the largest size for the number_of_stack_items, but only get
  8898. - // the right number of bytes.
  8899. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8900. - stackmap_p += 2;
  8901. -
  8902. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8903. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8904. - calc_number_of_entries, frame_type, THREAD);
  8905. - }
  8906. - }
  8907. - } // end while there is a stack_map_frame
  8908. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8909. -} // end rewrite_cp_refs_in_stack_map_table()
  8910. -
  8911. -
  8912. -// Rewrite constant pool references in the verification type info
  8913. -// portion of the method's stackmap table. These "structures" are
  8914. -// adapted from the StackMapTable_attribute that is described in
  8915. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8916. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8917. -//
  8918. -// The verification_type_info structure is a u1 tag followed by 0 or
  8919. -// more bytes of data:
  8920. -//
  8921. -// union verification_type_info {
  8922. -// Top_variable_info;
  8923. -// Integer_variable_info;
  8924. -// Float_variable_info;
  8925. -// Long_variable_info;
  8926. -// Double_variable_info;
  8927. -// Null_variable_info;
  8928. -// UninitializedThis_variable_info;
  8929. -// Object_variable_info;
  8930. -// Uninitialized_variable_info;
  8931. -// }
  8932. -//
  8933. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8934. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8935. - u1 frame_type, TRAPS) {
  8936. -
  8937. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8938. - u1 tag = *stackmap_p_ref;
  8939. - stackmap_p_ref++;
  8940. -
  8941. - switch (tag) {
  8942. - // Top_variable_info {
  8943. - // u1 tag = ITEM_Top; /* 0 */
  8944. - // }
  8945. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8946. - case 0: // fall through
  8947. -
  8948. - // Integer_variable_info {
  8949. - // u1 tag = ITEM_Integer; /* 1 */
  8950. - // }
  8951. - case ITEM_Integer: // fall through
  8952. -
  8953. - // Float_variable_info {
  8954. - // u1 tag = ITEM_Float; /* 2 */
  8955. - // }
  8956. - case ITEM_Float: // fall through
  8957. -
  8958. - // Double_variable_info {
  8959. - // u1 tag = ITEM_Double; /* 3 */
  8960. - // }
  8961. - case ITEM_Double: // fall through
  8962. -
  8963. - // Long_variable_info {
  8964. - // u1 tag = ITEM_Long; /* 4 */
  8965. - // }
  8966. - case ITEM_Long: // fall through
  8967. -
  8968. - // Null_variable_info {
  8969. - // u1 tag = ITEM_Null; /* 5 */
  8970. - // }
  8971. - case ITEM_Null: // fall through
  8972. -
  8973. - // UninitializedThis_variable_info {
  8974. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8975. - // }
  8976. - case ITEM_UninitializedThis:
  8977. - // nothing more to do for the above tag types
  8978. - break;
  8979. -
  8980. - // Object_variable_info {
  8981. - // u1 tag = ITEM_Object; /* 7 */
  8982. - // u2 cpool_index;
  8983. - // }
  8984. - case ITEM_Object:
  8985. - {
  8986. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8987. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8988. - u2 new_cp_index = find_new_index(cpool_index);
  8989. - if (new_cp_index != 0) {
  8990. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8991. - ("mapped old cpool_index=%d", cpool_index));
  8992. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8993. - cpool_index = new_cp_index;
  8994. - }
  8995. - stackmap_p_ref += 2;
  8996. -
  8997. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8998. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8999. - frame_type, cpool_index));
  9000. - } break;
  9001. -
  9002. - // Uninitialized_variable_info {
  9003. - // u1 tag = ITEM_Uninitialized; /* 8 */
  9004. - // u2 offset;
  9005. - // }
  9006. - case ITEM_Uninitialized:
  9007. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  9008. - stackmap_p_ref += 2;
  9009. - break;
  9010. -
  9011. - default:
  9012. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  9013. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  9014. - ShouldNotReachHere();
  9015. - break;
  9016. - } // end switch (tag)
  9017. -} // end rewrite_cp_refs_in_verification_type_info()
  9018. -
  9019. -
  9020. -// Change the constant pool associated with klass scratch_class to
  9021. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  9022. -// are copied from scratch_cp to a smaller constant pool and the
  9023. -// smaller constant pool is associated with scratch_class.
  9024. -void VM_RedefineClasses::set_new_constant_pool(
  9025. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  9026. - int scratch_cp_length, TRAPS) {
  9027. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  9028. -
  9029. - // scratch_cp is a merged constant pool and has enough space for a
  9030. - // worst case merge situation. We want to associate the minimum
  9031. - // sized constant pool with the klass to save space.
  9032. - constantPoolHandle smaller_cp(THREAD,
  9033. - oopFactory::new_constantPool(scratch_cp_length,
  9034. - oopDesc::IsUnsafeConc,
  9035. - THREAD));
  9036. - // preserve orig_length() value in the smaller copy
  9037. - int orig_length = scratch_cp->orig_length();
  9038. - assert(orig_length != 0, "sanity check");
  9039. - smaller_cp->set_orig_length(orig_length);
  9040. -
  9041. - // attach klass to new constant pool
  9042. - // reference to the cp holder is needed for copy_operands()
  9043. - smaller_cp->set_pool_holder(scratch_class());
  9044. -
  9045. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  9046. - scratch_cp = smaller_cp;
  9047. - smaller_cp()->set_is_conc_safe(true);
  9048. -
  9049. - // attach new constant pool to klass
  9050. - scratch_class->set_constants(scratch_cp());
  9051. -
  9052. - int i; // for portability
  9053. -
  9054. - // update each field in klass to use new constant pool indices as needed
  9055. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  9056. - jshort cur_index = fs.name_index();
  9057. - jshort new_index = find_new_index(cur_index);
  9058. - if (new_index != 0) {
  9059. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9060. - ("field-name_index change: %d to %d", cur_index, new_index));
  9061. - fs.set_name_index(new_index);
  9062. - }
  9063. - cur_index = fs.signature_index();
  9064. - new_index = find_new_index(cur_index);
  9065. - if (new_index != 0) {
  9066. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9067. - ("field-signature_index change: %d to %d", cur_index, new_index));
  9068. - fs.set_signature_index(new_index);
  9069. - }
  9070. - cur_index = fs.initval_index();
  9071. - new_index = find_new_index(cur_index);
  9072. - if (new_index != 0) {
  9073. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9074. - ("field-initval_index change: %d to %d", cur_index, new_index));
  9075. - fs.set_initval_index(new_index);
  9076. - }
  9077. - cur_index = fs.generic_signature_index();
  9078. - new_index = find_new_index(cur_index);
  9079. - if (new_index != 0) {
  9080. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9081. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  9082. - fs.set_generic_signature_index(new_index);
  9083. - }
  9084. - } // end for each field
  9085. -
  9086. - // Update constant pool indices in the inner classes info to use
  9087. - // new constant indices as needed. The inner classes info is a
  9088. - // quadruple:
  9089. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  9090. - InnerClassesIterator iter(scratch_class);
  9091. - for (; !iter.done(); iter.next()) {
  9092. - int cur_index = iter.inner_class_info_index();
  9093. - if (cur_index == 0) {
  9094. - continue; // JVM spec. allows null inner class refs so skip it
  9095. - }
  9096. - int new_index = find_new_index(cur_index);
  9097. - if (new_index != 0) {
  9098. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9099. - ("inner_class_info change: %d to %d", cur_index, new_index));
  9100. - iter.set_inner_class_info_index(new_index);
  9101. - }
  9102. - cur_index = iter.outer_class_info_index();
  9103. - new_index = find_new_index(cur_index);
  9104. - if (new_index != 0) {
  9105. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9106. - ("outer_class_info change: %d to %d", cur_index, new_index));
  9107. - iter.set_outer_class_info_index(new_index);
  9108. - }
  9109. - cur_index = iter.inner_name_index();
  9110. - new_index = find_new_index(cur_index);
  9111. - if (new_index != 0) {
  9112. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9113. - ("inner_name change: %d to %d", cur_index, new_index));
  9114. - iter.set_inner_name_index(new_index);
  9115. - }
  9116. - } // end for each inner class
  9117. -
  9118. - // Attach each method in klass to the new constant pool and update
  9119. - // to use new constant pool indices as needed:
  9120. - objArrayHandle methods(THREAD, scratch_class->methods());
  9121. - for (i = methods->length() - 1; i >= 0; i--) {
  9122. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  9123. - method->set_constants(scratch_cp());
  9124. -
  9125. - int new_index = find_new_index(method->name_index());
  9126. - if (new_index != 0) {
  9127. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9128. - ("method-name_index change: %d to %d", method->name_index(),
  9129. - new_index));
  9130. - method->set_name_index(new_index);
  9131. - }
  9132. - new_index = find_new_index(method->signature_index());
  9133. - if (new_index != 0) {
  9134. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9135. - ("method-signature_index change: %d to %d",
  9136. - method->signature_index(), new_index));
  9137. - method->set_signature_index(new_index);
  9138. - }
  9139. - new_index = find_new_index(method->generic_signature_index());
  9140. - if (new_index != 0) {
  9141. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9142. - ("method-generic_signature_index change: %d to %d",
  9143. - method->generic_signature_index(), new_index));
  9144. - method->set_generic_signature_index(new_index);
  9145. - }
  9146. -
  9147. - // Update constant pool indices in the method's checked exception
  9148. - // table to use new constant indices as needed.
  9149. - int cext_length = method->checked_exceptions_length();
  9150. - if (cext_length > 0) {
  9151. - CheckedExceptionElement * cext_table =
  9152. - method->checked_exceptions_start();
  9153. - for (int j = 0; j < cext_length; j++) {
  9154. - int cur_index = cext_table[j].class_cp_index;
  9155. - int new_index = find_new_index(cur_index);
  9156. - if (new_index != 0) {
  9157. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9158. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  9159. - cext_table[j].class_cp_index = (u2)new_index;
  9160. - }
  9161. - } // end for each checked exception table entry
  9162. - } // end if there are checked exception table entries
  9163. -
  9164. - // Update each catch type index in the method's exception table
  9165. - // to use new constant pool indices as needed. The exception table
  9166. - // holds quadruple entries of the form:
  9167. - // (beg_bci, end_bci, handler_bci, klass_index)
  9168. -
  9169. - ExceptionTable ex_table(method());
  9170. - int ext_length = ex_table.length();
  9171. -
  9172. - for (int j = 0; j < ext_length; j ++) {
  9173. - int cur_index = ex_table.catch_type_index(j);
  9174. - int new_index = find_new_index(cur_index);
  9175. - if (new_index != 0) {
  9176. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9177. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  9178. - ex_table.set_catch_type_index(j, new_index);
  9179. - }
  9180. - } // end for each exception table entry
  9181. -
  9182. - // Update constant pool indices in the method's local variable
  9183. - // table to use new constant indices as needed. The local variable
  9184. - // table hold sextuple entries of the form:
  9185. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  9186. - int lvt_length = method->localvariable_table_length();
  9187. - if (lvt_length > 0) {
  9188. - LocalVariableTableElement * lv_table =
  9189. - method->localvariable_table_start();
  9190. - for (int j = 0; j < lvt_length; j++) {
  9191. - int cur_index = lv_table[j].name_cp_index;
  9192. - int new_index = find_new_index(cur_index);
  9193. - if (new_index != 0) {
  9194. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9195. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  9196. - lv_table[j].name_cp_index = (u2)new_index;
  9197. - }
  9198. - cur_index = lv_table[j].descriptor_cp_index;
  9199. - new_index = find_new_index(cur_index);
  9200. - if (new_index != 0) {
  9201. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9202. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  9203. - new_index));
  9204. - lv_table[j].descriptor_cp_index = (u2)new_index;
  9205. - }
  9206. - cur_index = lv_table[j].signature_cp_index;
  9207. - new_index = find_new_index(cur_index);
  9208. - if (new_index != 0) {
  9209. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9210. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  9211. - lv_table[j].signature_cp_index = (u2)new_index;
  9212. - }
  9213. - } // end for each local variable table entry
  9214. - } // end if there are local variable table entries
  9215. -
  9216. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  9217. - } // end for each method
  9218. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  9219. -} // end set_new_constant_pool()
  9220. -
  9221. -
  9222. -// Unevolving classes may point to methods of the_class directly
  9223. +// Unevolving classes may point to old methods directly
  9224. // from their constant pool caches, itables, and/or vtables. We
  9225. // use the SystemDictionary::classes_do() facility and this helper
  9226. -// to fix up these pointers.
  9227. +// to fix up these pointers. Additional field offsets and vtable indices
  9228. +// in the constant pool cache entries are fixed.
  9229. //
  9230. // Note: We currently don't support updating the vtable in
  9231. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9232. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  9233. - oop initiating_loader, TRAPS) {
  9234. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9235. + klassOop k_oop = k_oop_latest;
  9236. + while (k_oop != NULL) {
  9237. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9238. +/*
  9239. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9240. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9241. +
  9242. + for (int i=0; i<_matching_methods_length; i++) {
  9243. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9244. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9245. + }*/
  9246. +
  9247. + Klass *k = k_oop->klass_part();
  9248. + if (k->oop_is_instance()) {
  9249. + HandleMark hm(THREAD);
  9250. + instanceKlass *ik = (instanceKlass *) k;
  9251. +
  9252. + constantPoolHandle other_cp;
  9253. + constantPoolCacheOop cp_cache;
  9254. +
  9255. + other_cp = constantPoolHandle(ik->constants());
  9256. +
  9257. + for (int i=0; i<other_cp->length(); i++) {
  9258. + if (other_cp->tag_at(i).is_klass()) {
  9259. + klassOop klass = other_cp->klass_at(i, THREAD);
  9260. + if (klass->klass_part()->new_version() != NULL) {
  9261. +
  9262. + // (tw) TODO: check why/if this is necessary
  9263. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9264. + }
  9265. + klass = other_cp->klass_at(i, THREAD);
  9266. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9267. + }
  9268. + }
  9269. +
  9270. + cp_cache = other_cp->cache();
  9271. +
  9272. + if (cp_cache != NULL) {
  9273. + cp_cache->adjust_entries(NULL,
  9274. + NULL,
  9275. + 0);
  9276. + }
  9277. +
  9278. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9279. + if (RewriteBytecodes) {
  9280. + ik->methods_do(unpatch_bytecode);
  9281. + }
  9282. + }
  9283. + k_oop = k_oop->klass_part()->old_version();
  9284. + }
  9285. +}
  9286. +
  9287. +void VM_RedefineClasses::update_jmethod_ids() {
  9288. + for (int j = 0; j < _matching_methods_length; ++j) {
  9289. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9290. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9291. +
  9292. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9293. + if (old_method->new_version() != NULL && jmid == NULL) {
  9294. + // (tw) Have to create jmethodID in this case
  9295. + jmid = old_method->jmethod_id();
  9296. + }
  9297. +
  9298. + if (jmid != NULL) {
  9299. + // There is a jmethodID, change it to point to the new method
  9300. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9301. + if (old_method->new_version() == NULL) {
  9302. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9303. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9304. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9305. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9306. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9307. + } else {
  9308. + jmethodID mid = new_method_h->jmethod_id();
  9309. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9310. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9311. +
  9312. + }
  9313. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9314. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9315. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9316. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9317. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9318. +
  9319. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9320. + }
  9321. + }
  9322. +}
  9323. +
  9324. +
  9325. +// Deoptimize all compiled code that depends on this class.
  9326. +//
  9327. +// If the can_redefine_classes capability is obtained in the onload
  9328. +// phase then the compiler has recorded all dependencies from startup.
  9329. +// In that case we need only deoptimize and throw away all compiled code
  9330. +// that depends on the class.
  9331. +//
  9332. +// If can_redefine_classes is obtained sometime after the onload
  9333. +// phase then the dependency information may be incomplete. In that case
  9334. +// the first call to RedefineClasses causes all compiled code to be
  9335. +// thrown away. As can_redefine_classes has been obtained then
  9336. +// all future compilations will record dependencies so second and
  9337. +// subsequent calls to RedefineClasses need only throw away code
  9338. +// that depends on the class.
  9339. +//
  9340. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9341. + assert_locked_or_safepoint(Compile_lock);
  9342. +
  9343. + // All dependencies have been recorded from startup or this is a second or
  9344. + // subsequent use of RedefineClasses
  9345. +
  9346. + // For now deopt all
  9347. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9348. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9349. + Universe::flush_evol_dependents_on(k_h);
  9350. + } else {
  9351. + CodeCache::mark_all_nmethods_for_deoptimization();
  9352. +
  9353. + ResourceMark rm(THREAD);
  9354. + DeoptimizationMarker dm;
  9355. +
  9356. + // Deoptimize all activations depending on marked nmethods
  9357. + Deoptimization::deoptimize_dependents();
  9358. +
  9359. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9360. + CodeCache::make_marked_nmethods_not_entrant();
  9361. +
  9362. + // From now on we know that the dependency information is complete
  9363. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9364. + }
  9365. +}
  9366. +
  9367. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9368. + methodOop old_method;
  9369. + methodOop new_method;
  9370. +
  9371. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9372. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9373. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9374. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9375. +
  9376. + _matching_methods_length = 0;
  9377. + _deleted_methods_length = 0;
  9378. + _added_methods_length = 0;
  9379. +
  9380. + int nj = 0;
  9381. + int oj = 0;
  9382. + while (true) {
  9383. + if (oj >= _old_methods->length()) {
  9384. + if (nj >= _new_methods->length()) {
  9385. + break; // we've looked at everything, done
  9386. + }
  9387. + // New method at the end
  9388. + new_method = (methodOop) _new_methods->obj_at(nj);
  9389. + _added_methods[_added_methods_length++] = nj;
  9390. + ++nj;
  9391. + } else if (nj >= _new_methods->length()) {
  9392. + // Old method, at the end, is deleted
  9393. + old_method = (methodOop) _old_methods->obj_at(oj);
  9394. + _deleted_methods[_deleted_methods_length++] = oj;
  9395. + ++oj;
  9396. + } else {
  9397. + old_method = (methodOop) _old_methods->obj_at(oj);
  9398. + new_method = (methodOop) _new_methods->obj_at(nj);
  9399. + if (old_method->name() == new_method->name()) {
  9400. + if (old_method->signature() == new_method->signature()) {
  9401. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9402. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9403. + ++nj;
  9404. + ++oj;
  9405. + } else {
  9406. + // added overloaded have already been moved to the end,
  9407. + // so this is a deleted overloaded method
  9408. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9409. + ++oj;
  9410. + }
  9411. + } else { // names don't match
  9412. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9413. + // new method
  9414. + _added_methods[_added_methods_length++] = nj;//new_method;
  9415. + ++nj;
  9416. + } else {
  9417. + // deleted method
  9418. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9419. + ++oj;
  9420. + }
  9421. + }
  9422. + }
  9423. + }
  9424. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9425. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9426. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9427. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9428. +}
  9429. +
  9430. +
  9431. +
  9432. +// Install the redefinition of a class:
  9433. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9434. +// dependent compiled code)
  9435. +// - adjusting constant pool caches and vtables in other classes
  9436. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9437. +
  9438. + ResourceMark rm(THREAD);
  9439. +
  9440. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9441. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9442. +
  9443. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9444. +
  9445. +#ifndef JVMTI_KERNEL
  9446. + // Remove all breakpoints in methods of this class
  9447. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9448. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9449. +#endif // !JVMTI_KERNEL
  9450. +
  9451. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9452. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9453. + // cached and users of the cache care about each active version of
  9454. + // the method so we have to track this previous version.
  9455. + // Do this before methods get switched
  9456. + Universe::reflect_invoke_cache()->add_previous_version(
  9457. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9458. + }
  9459. +
  9460. + _old_methods = the_old_class->methods();
  9461. + _new_methods = the_new_class->methods();
  9462. + _the_class_oop = the_old_class();
  9463. + compute_added_deleted_matching_methods();
  9464. +
  9465. + // track which methods are EMCP for add_previous_version() call below
  9466. +
  9467. + // (tw) TODO: Check if we need the concept of EMCP?
  9468. + BitMap emcp_methods(_old_methods->length());
  9469. + int emcp_method_count = 0;
  9470. + emcp_methods.clear(); // clears 0..(length() - 1)
  9471. +
  9472. + // We need to mark methods as old!!
  9473. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9474. + update_jmethod_ids();
  9475. +
  9476. + // keep track of previous versions of this class
  9477. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9478. + emcp_method_count);
  9479. +
  9480. + // TODO:
  9481. + transfer_old_native_function_registrations(the_old_class);
  9482. +
  9483. +
  9484. +#ifdef ASSERT
  9485. +
  9486. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9487. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9488. +
  9489. + //JNIHandles::verify();
  9490. +
  9491. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9492. +
  9493. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9494. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9495. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9496. +
  9497. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9498. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9499. + }
  9500. +
  9501. + _old_methods->verify();
  9502. + _new_methods->verify();
  9503. +
  9504. + the_new_class->vtable()->verify(tty);
  9505. + the_old_class->vtable()->verify(tty);
  9506. +
  9507. +#endif
  9508. +
  9509. + // increment the classRedefinedCount field in the_class and in any
  9510. + // direct and indirect subclasses of the_class
  9511. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9512. +
  9513. +}
  9514. +
  9515. +
  9516. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9517. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9518. + *emcp_method_count_p = 0;
  9519. + int obsolete_count = 0;
  9520. + int old_index = 0;
  9521. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9522. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9523. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9524. + methodOop old_array_method;
  9525. +
  9526. + // Maintain an old_index into the _old_methods array by skipping
  9527. + // deleted methods
  9528. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9529. + != old_method) {
  9530. + ++old_index;
  9531. + }
  9532. +
  9533. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9534. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9535. + // the same with the exception of constant pool indices which may
  9536. + // differ. However, the constants referred to by those indices
  9537. + // must be the same.
  9538. + //
  9539. + // We use methods_EMCP() for comparison since constant pool
  9540. + // merging can remove duplicate constant pool entries that were
  9541. + // present in the old method and removed from the rewritten new
  9542. + // method. A faster binary comparison function would consider the
  9543. + // old and new methods to be different when they are actually
  9544. + // EMCP.
  9545. +
  9546. + // track which methods are EMCP for add_previous_version() call
  9547. + emcp_methods->set_bit(old_index);
  9548. + (*emcp_method_count_p)++;
  9549. +
  9550. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9551. + // different jmethodID than the current method. An EMCP method
  9552. + // has the same jmethodID as the current method. Having the
  9553. + // same jmethodID for all EMCP versions of a method allows for
  9554. + // a consistent view of the EMCP methods regardless of which
  9555. + // EMCP method you happen to have in hand. For example, a
  9556. + // breakpoint set in one EMCP method will work for all EMCP
  9557. + // versions of the method including the current one.
  9558. +
  9559. + old_method->set_new_version(new_method);
  9560. + new_method->set_old_version(old_method);
  9561. +
  9562. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9563. +
  9564. + // Transfer breakpoints
  9565. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9566. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9567. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9568. + RC_TRACE(0x00000002, ("%d / %d",
  9569. + bp->match(old_method), bp->match(new_method)));
  9570. + if (bp->match(old_method)) {
  9571. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9572. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9573. + new_method->set_breakpoint(bp->bci());
  9574. + }
  9575. + }
  9576. +
  9577. +
  9578. +
  9579. + } else {
  9580. + // mark obsolete methods as such
  9581. + old_method->set_is_obsolete();
  9582. + obsolete_count++;
  9583. +
  9584. + // With tracing we try not to "yack" too much. The position of
  9585. + // this trace assumes there are fewer obsolete methods than
  9586. + // EMCP methods.
  9587. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9588. + old_method->name()->as_C_string(),
  9589. + old_method->signature()->as_C_string()));
  9590. + }
  9591. + old_method->set_is_old();
  9592. + }
  9593. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9594. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9595. +
  9596. + //assert(old_method->vtable_index() < 0,
  9597. + // "cannot delete methods with vtable entries");;
  9598. +
  9599. + // Mark all deleted methods as old and obsolete
  9600. + old_method->set_is_old();
  9601. + old_method->set_is_obsolete();
  9602. + ++obsolete_count;
  9603. + // With tracing we try not to "yack" too much. The position of
  9604. + // this trace assumes there are fewer obsolete methods than
  9605. + // EMCP methods.
  9606. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9607. + old_method->name()->as_C_string(),
  9608. + old_method->signature()->as_C_string()));
  9609. + }
  9610. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9611. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9612. +}
  9613. +
  9614. +// Increment the classRedefinedCount field in the specific instanceKlass
  9615. +// and in all direct and indirect subclasses.
  9616. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9617. + oop class_mirror = ik->java_mirror();
  9618. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9619. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9620. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9621. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9622. +}
  9623. +
  9624. +#ifndef PRODUCT
  9625. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9626. Klass *k = k_oop->klass_part();
  9627. if (k->oop_is_instance()) {
  9628. HandleMark hm(THREAD);
  9629. instanceKlass *ik = (instanceKlass *) k;
  9630. -
  9631. - // HotSpot specific optimization! HotSpot does not currently
  9632. - // support delegation from the bootstrap class loader to a
  9633. - // user-defined class loader. This means that if the bootstrap
  9634. - // class loader is the initiating class loader, then it will also
  9635. - // be the defining class loader. This also means that classes
  9636. - // loaded by the bootstrap class loader cannot refer to classes
  9637. - // loaded by a user-defined class loader. Note: a user-defined
  9638. - // class loader can delegate to the bootstrap class loader.
  9639. - //
  9640. - // If the current class being redefined has a user-defined class
  9641. - // loader as its defining class loader, then we can skip all
  9642. - // classes loaded by the bootstrap class loader.
  9643. - bool is_user_defined =
  9644. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  9645. - if (is_user_defined && ik->class_loader() == NULL) {
  9646. - return;
  9647. - }
  9648. -
  9649. - // This is a very busy routine. We don't want too much tracing
  9650. - // printed out.
  9651. - bool trace_name_printed = false;
  9652. -
  9653. - // Very noisy: only enable this call if you are trying to determine
  9654. - // that a specific class gets found by this routine.
  9655. - // RC_TRACE macro has an embedded ResourceMark
  9656. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  9657. - // ("adjust check: name=%s", ik->external_name()));
  9658. - // trace_name_printed = true;
  9659. -
  9660. - // Fix the vtable embedded in the_class and subclasses of the_class,
  9661. - // if one exists. We discard scratch_class and we don't keep an
  9662. - // instanceKlass around to hold obsolete methods so we don't have
  9663. - // any other instanceKlass embedded vtables to update. The vtable
  9664. - // holds the methodOops for virtual (but not final) methods.
  9665. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  9666. - // ik->vtable() creates a wrapper object; rm cleans it up
  9667. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9668. +
  9669. + if (ik->vtable_length() > 0) {
  9670. ResourceMark rm(THREAD);
  9671. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  9672. - _matching_new_methods,
  9673. - _matching_methods_length,
  9674. - &trace_name_printed);
  9675. - }
  9676. -
  9677. - // If the current class has an itable and we are either redefining an
  9678. - // interface or if the current class is a subclass of the_class, then
  9679. - // we potentially have to fix the itable. If we are redefining an
  9680. - // interface, then we have to call adjust_method_entries() for
  9681. - // every instanceKlass that has an itable since there isn't a
  9682. - // subclass relationship between an interface and an instanceKlass.
  9683. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  9684. - || ik->is_subclass_of(_the_class_oop))) {
  9685. - // ik->itable() creates a wrapper object; rm cleans it up
  9686. - ResourceMark rm(THREAD);
  9687. - ik->itable()->adjust_method_entries(_matching_old_methods,
  9688. - _matching_new_methods,
  9689. - _matching_methods_length,
  9690. - &trace_name_printed);
  9691. - }
  9692. -
  9693. - // The constant pools in other classes (other_cp) can refer to
  9694. - // methods in the_class. We have to update method information in
  9695. - // other_cp's cache. If other_cp has a previous version, then we
  9696. - // have to repeat the process for each previous version. The
  9697. - // constant pool cache holds the methodOops for non-virtual
  9698. - // methods and for virtual, final methods.
  9699. - //
  9700. - // Special case: if the current class is the_class, then new_cp
  9701. - // has already been attached to the_class and old_cp has already
  9702. - // been added as a previous version. The new_cp doesn't have any
  9703. - // cached references to old methods so it doesn't need to be
  9704. - // updated. We can simply start with the previous version(s) in
  9705. - // that case.
  9706. - constantPoolHandle other_cp;
  9707. - constantPoolCacheOop cp_cache;
  9708. -
  9709. - if (k_oop != _the_class_oop) {
  9710. - // this klass' constant pool cache may need adjustment
  9711. - other_cp = constantPoolHandle(ik->constants());
  9712. - cp_cache = other_cp->cache();
  9713. - if (cp_cache != NULL) {
  9714. - cp_cache->adjust_method_entries(_matching_old_methods,
  9715. - _matching_new_methods,
  9716. - _matching_methods_length,
  9717. - &trace_name_printed);
  9718. + if (!ik->vtable()->check_no_old_entries()) {
  9719. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9720. + k_oop->size()));
  9721. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9722. + ik->signature_name()));
  9723. + assert(false, "OLD method found");
  9724. }
  9725. - }
  9726. - {
  9727. - ResourceMark rm(THREAD);
  9728. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9729. - // contain a GrowableArray of handles. We have to clean up the
  9730. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9731. - // has destroyed the handles.
  9732. - {
  9733. - // the previous versions' constant pool caches may need adjustment
  9734. - PreviousVersionWalker pvw(ik);
  9735. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9736. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9737. - other_cp = pv_info->prev_constant_pool_handle();
  9738. - cp_cache = other_cp->cache();
  9739. - if (cp_cache != NULL) {
  9740. - cp_cache->adjust_method_entries(_matching_old_methods,
  9741. - _matching_new_methods,
  9742. - _matching_methods_length,
  9743. - &trace_name_printed);
  9744. - }
  9745. - }
  9746. - } // pvw is cleaned up
  9747. - } // rm is cleaned up
  9748. - }
  9749. -}
  9750. -
  9751. -void VM_RedefineClasses::update_jmethod_ids() {
  9752. - for (int j = 0; j < _matching_methods_length; ++j) {
  9753. - methodOop old_method = _matching_old_methods[j];
  9754. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  9755. - if (jmid != NULL) {
  9756. - // There is a jmethodID, change it to point to the new method
  9757. - methodHandle new_method_h(_matching_new_methods[j]);
  9758. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9759. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9760. - "should be replaced");
  9761. +
  9762. + ik->vtable()->verify(tty, true);
  9763. }
  9764. }
  9765. }
  9766. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9767. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9768. - *emcp_method_count_p = 0;
  9769. - int obsolete_count = 0;
  9770. - int old_index = 0;
  9771. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9772. - methodOop old_method = _matching_old_methods[j];
  9773. - methodOop new_method = _matching_new_methods[j];
  9774. - methodOop old_array_method;
  9775. -
  9776. - // Maintain an old_index into the _old_methods array by skipping
  9777. - // deleted methods
  9778. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9779. - != old_method) {
  9780. - ++old_index;
  9781. +#endif
  9782. +
  9783. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9784. +{
  9785. + assert(original_klasses != NULL && result != NULL, "");
  9786. + this->_original_klasses = original_klasses;
  9787. + this->_result = result;
  9788. + SystemDictionary::classes_do(this);
  9789. +}
  9790. +
  9791. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9792. +{
  9793. + klassOop klass = (klassOop)obj;
  9794. + assert(!_result->contains(klass), "must not occur more than once!");
  9795. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9796. +
  9797. + for(int i=0; i<_original_klasses->length(); i++) {
  9798. + instanceKlassHandle cur = _original_klasses->at(i);
  9799. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9800. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9801. + _result->append(klass);
  9802. + break;
  9803. }
  9804. -
  9805. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9806. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9807. - // the same with the exception of constant pool indices which may
  9808. - // differ. However, the constants referred to by those indices
  9809. - // must be the same.
  9810. - //
  9811. - // We use methods_EMCP() for comparison since constant pool
  9812. - // merging can remove duplicate constant pool entries that were
  9813. - // present in the old method and removed from the rewritten new
  9814. - // method. A faster binary comparison function would consider the
  9815. - // old and new methods to be different when they are actually
  9816. - // EMCP.
  9817. - //
  9818. - // The old and new methods are EMCP and you would think that we
  9819. - // could get rid of one of them here and now and save some space.
  9820. - // However, the concept of EMCP only considers the bytecodes and
  9821. - // the constant pool entries in the comparison. Other things,
  9822. - // e.g., the line number table (LNT) or the local variable table
  9823. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9824. - // method can have a new LNT that we need so we can't just
  9825. - // overwrite the new method with the old method.
  9826. - //
  9827. - // When this routine is called, we have already attached the new
  9828. - // methods to the_class so the old methods are effectively
  9829. - // overwritten. However, if an old method is still executing,
  9830. - // then the old method cannot be collected until sometime after
  9831. - // the old method call has returned. So the overwriting of old
  9832. - // methods by new methods will save us space except for those
  9833. - // (hopefully few) old methods that are still executing.
  9834. - //
  9835. - // A method refers to a constMethodOop and this presents another
  9836. - // possible avenue to space savings. The constMethodOop in the
  9837. - // new method contains possibly new attributes (LNT, LVT, etc).
  9838. - // At first glance, it seems possible to save space by replacing
  9839. - // the constMethodOop in the old method with the constMethodOop
  9840. - // from the new method. The old and new methods would share the
  9841. - // same constMethodOop and we would save the space occupied by
  9842. - // the old constMethodOop. However, the constMethodOop contains
  9843. - // a back reference to the containing method. Sharing the
  9844. - // constMethodOop between two methods could lead to confusion in
  9845. - // the code that uses the back reference. This would lead to
  9846. - // brittle code that could be broken in non-obvious ways now or
  9847. - // in the future.
  9848. - //
  9849. - // Another possibility is to copy the constMethodOop from the new
  9850. - // method to the old method and then overwrite the new method with
  9851. - // the old method. Since the constMethodOop contains the bytecodes
  9852. - // for the method embedded in the oop, this option would change
  9853. - // the bytecodes out from under any threads executing the old
  9854. - // method and make the thread's bcp invalid. Since EMCP requires
  9855. - // that the bytecodes be the same modulo constant pool indices, it
  9856. - // is straight forward to compute the correct new bcp in the new
  9857. - // constMethodOop from the old bcp in the old constMethodOop. The
  9858. - // time consuming part would be searching all the frames in all
  9859. - // of the threads to find all of the calls to the old method.
  9860. - //
  9861. - // It looks like we will have to live with the limited savings
  9862. - // that we get from effectively overwriting the old methods
  9863. - // when the new methods are attached to the_class.
  9864. -
  9865. - // track which methods are EMCP for add_previous_version() call
  9866. - emcp_methods->set_bit(old_index);
  9867. - (*emcp_method_count_p)++;
  9868. -
  9869. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9870. - // different jmethodID than the current method. An EMCP method
  9871. - // has the same jmethodID as the current method. Having the
  9872. - // same jmethodID for all EMCP versions of a method allows for
  9873. - // a consistent view of the EMCP methods regardless of which
  9874. - // EMCP method you happen to have in hand. For example, a
  9875. - // breakpoint set in one EMCP method will work for all EMCP
  9876. - // versions of the method including the current one.
  9877. - } else {
  9878. - // mark obsolete methods as such
  9879. - old_method->set_is_obsolete();
  9880. - obsolete_count++;
  9881. -
  9882. - // obsolete methods need a unique idnum
  9883. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9884. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9885. -// u2 old_num = old_method->method_idnum();
  9886. - old_method->set_method_idnum(num);
  9887. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9888. + }
  9889. +}
  9890. +
  9891. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9892. +{
  9893. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9894. +
  9895. + for (int i=0; i<class_count; i++) {
  9896. +
  9897. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9898. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9899. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9900. + Handle the_class_loader(THREAD, the_class->class_loader());
  9901. + Handle protection_domain(THREAD, the_class->protection_domain());
  9902. +
  9903. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9904. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9905. + ClassFileParser cfp(&st);
  9906. +
  9907. + GrowableArray<Symbol*> symbolArr;
  9908. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9909. + the_class->name()->as_C_string()));
  9910. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9911. +
  9912. + for (int j=0; j<symbolArr.length(); j++) {
  9913. + Symbol* sym = symbolArr.at(j);
  9914. +
  9915. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9916. +
  9917. + for (int k=0; k<arr->length(); k++) {
  9918. + klassOop curOop = arr->at(k)();
  9919. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9920. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9921. + RC_TRACE(0x00000002, ("Found class to link"));
  9922. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9923. + break;
  9924. + }
  9925. }
  9926. - // With tracing we try not to "yack" too much. The position of
  9927. - // this trace assumes there are fewer obsolete methods than
  9928. - // EMCP methods.
  9929. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9930. - old_method->name()->as_C_string(),
  9931. - old_method->signature()->as_C_string()));
  9932. }
  9933. - old_method->set_is_old();
  9934. }
  9935. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9936. - methodOop old_method = _deleted_methods[i];
  9937. -
  9938. - assert(old_method->vtable_index() < 0,
  9939. - "cannot delete methods with vtable entries");;
  9940. -
  9941. - // Mark all deleted methods as old and obsolete
  9942. - old_method->set_is_old();
  9943. - old_method->set_is_obsolete();
  9944. - ++obsolete_count;
  9945. - // With tracing we try not to "yack" too much. The position of
  9946. - // this trace assumes there are fewer obsolete methods than
  9947. - // EMCP methods.
  9948. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9949. - old_method->name()->as_C_string(),
  9950. - old_method->signature()->as_C_string()));
  9951. +
  9952. +
  9953. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9954. +
  9955. + for (int i=0; i<affected->length(); i++) {
  9956. +
  9957. + instanceKlassHandle klass = affected->at(i);
  9958. +
  9959. + klassOop superKlass = klass->super();
  9960. + if (affected->contains(superKlass)) {
  9961. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9962. + }
  9963. +
  9964. + objArrayOop superInterfaces = klass->local_interfaces();
  9965. + for (int j=0; j<superInterfaces->length(); j++) {
  9966. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9967. + if (arr->contains(interfaceKlass)) {
  9968. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9969. + }
  9970. + }
  9971. }
  9972. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9973. - "sanity check");
  9974. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9975. - obsolete_count));
  9976. +
  9977. + if (RC_TRACE_ENABLED(0x00000002)) {
  9978. + RC_TRACE(0x00000002, ("Identified links: "));
  9979. + for (int i=0; i<links->length(); i++) {
  9980. + RC_TRACE(0x00000002, ("%s to %s",
  9981. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9982. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9983. + }
  9984. + }
  9985. +
  9986. + for (int i=0; i<arr->length(); i++) {
  9987. +
  9988. + int j;
  9989. + for (j=i; j<arr->length(); j++) {
  9990. +
  9991. + int k;
  9992. + for (k=0; k<links->length(); k++) {
  9993. +
  9994. + klassOop k1 = links->adr_at(k)->right();
  9995. + klassOop k2 = arr->at(j)();
  9996. + if (k1 == k2) {
  9997. + break;
  9998. + }
  9999. + }
  10000. +
  10001. + if (k == links->length()) {
  10002. + break;
  10003. + }
  10004. + }
  10005. +
  10006. + if (j == arr->length()) {
  10007. + // circle detected
  10008. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  10009. + }
  10010. +
  10011. + for (int k=0; k<links->length(); k++) {
  10012. + if (links->adr_at(k)->left() == arr->at(j)()) {
  10013. + links->at_put(k, links->at(links->length() - 1));
  10014. + links->remove_at(links->length() - 1);
  10015. + k--;
  10016. + }
  10017. + }
  10018. +
  10019. + instanceKlassHandle tmp = arr->at(j);
  10020. + arr->at_put(j, arr->at(i));
  10021. + arr->at_put(i, tmp);
  10022. + }
  10023. +
  10024. + return JVMTI_ERROR_NONE;
  10025. }
  10026. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  10027. +
  10028. + if (_updated_oops != NULL) {
  10029. + for (int i=0; i<_updated_oops->length(); i++) {
  10030. + closure->do_oop(_updated_oops->adr_at(i));
  10031. + }
  10032. + }
  10033. +}
  10034. +
  10035. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  10036. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  10037. + to->set_is_field_access_watched(from->is_field_access_watched());
  10038. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  10039. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  10040. + from->name()->as_C_string()));
  10041. + }
  10042. + update_klass_field_access_flag(to);
  10043. +}
  10044. +
  10045. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  10046. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  10047. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  10048. + fi->set_access_flags(fd->access_flags().as_short());
  10049. +}
  10050. +
  10051. +
  10052. // This internal class transfers the native function registration from old methods
  10053. // to new methods. It is designed to handle both the simple case of unchanged
  10054. // native methods and the complex cases of native method prefixes being added and/or
  10055. @@ -2969,7 +3161,7 @@
  10056. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  10057. //
  10058. class TransferNativeFunctionRegistration {
  10059. - private:
  10060. +private:
  10061. instanceKlassHandle the_class;
  10062. int prefix_count;
  10063. char** prefixes;
  10064. @@ -2982,42 +3174,42 @@
  10065. // (2) with the prefix.
  10066. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  10067. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  10068. - Symbol* signature) {
  10069. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10070. - if (name_symbol != NULL) {
  10071. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  10072. - if (method != NULL) {
  10073. - // Even if prefixed, intermediate methods must exist.
  10074. - if (method->is_native()) {
  10075. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10076. - return method;
  10077. - }
  10078. - if (depth < prefix_count) {
  10079. - // Try applying further prefixes (other than this one).
  10080. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10081. - if (method != NULL) {
  10082. - return method; // found
  10083. + Symbol* signature) {
  10084. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10085. + if (name_symbol != NULL) {
  10086. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10087. + if (method != NULL) {
  10088. + // Even if prefixed, intermediate methods must exist.
  10089. + if (method->is_native()) {
  10090. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10091. + return method;
  10092. }
  10093. -
  10094. - // Try adding this prefix to the method name and see if it matches
  10095. - // another method name.
  10096. - char* prefix = prefixes[depth];
  10097. - size_t prefix_len = strlen(prefix);
  10098. - size_t trial_len = name_len + prefix_len;
  10099. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10100. - strcpy(trial_name_str, prefix);
  10101. - strcat(trial_name_str, name_str);
  10102. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10103. - signature);
  10104. - if (method != NULL) {
  10105. - // If found along this branch, it was prefixed, mark as such
  10106. - method->set_is_prefixed_native();
  10107. - return method; // found
  10108. + if (depth < prefix_count) {
  10109. + // Try applying further prefixes (other than this one).
  10110. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10111. + if (method != NULL) {
  10112. + return method; // found
  10113. + }
  10114. +
  10115. + // Try adding this prefix to the method name and see if it matches
  10116. + // another method name.
  10117. + char* prefix = prefixes[depth];
  10118. + size_t prefix_len = strlen(prefix);
  10119. + size_t trial_len = name_len + prefix_len;
  10120. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10121. + strcpy(trial_name_str, prefix);
  10122. + strcat(trial_name_str, name_str);
  10123. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10124. + signature);
  10125. + if (method != NULL) {
  10126. + // If found along this branch, it was prefixed, mark as such
  10127. + method->set_is_prefixed_native();
  10128. + return method; // found
  10129. + }
  10130. }
  10131. }
  10132. }
  10133. - }
  10134. - return NULL; // This whole branch bore nothing
  10135. + return NULL; // This whole branch bore nothing
  10136. }
  10137. // Return the method name with old prefixes stripped away.
  10138. @@ -3042,10 +3234,10 @@
  10139. ResourceMark rm;
  10140. char* name_str = method_name_without_prefixes(method);
  10141. return search_prefix_name_space(0, name_str, strlen(name_str),
  10142. - method->signature());
  10143. + method->signature());
  10144. }
  10145. - public:
  10146. +public:
  10147. // Construct a native method transfer processor for this class.
  10148. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10149. @@ -3056,9 +3248,9 @@
  10150. }
  10151. // Attempt to transfer any of the old or deleted methods that are native
  10152. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  10153. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10154. for (int j = 0; j < methods_length; j++) {
  10155. - methodOop old_method = old_methods[j];
  10156. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10157. if (old_method->is_native() && old_method->has_native_function()) {
  10158. methodOop new_method = strip_and_search_for_new_native(old_method);
  10159. @@ -3067,7 +3259,9 @@
  10160. // Redefine does not send events (except CFLH), certainly not this
  10161. // behind the scenes re-registration.
  10162. new_method->set_native_function(old_method->native_function(),
  10163. - !methodOopDesc::native_bind_event_is_interesting);
  10164. + !methodOopDesc::native_bind_event_is_interesting);
  10165. +
  10166. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10167. }
  10168. }
  10169. }
  10170. @@ -3075,544 +3269,8 @@
  10171. };
  10172. // Don't lose the association between a native method and its JNI function.
  10173. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  10174. - TransferNativeFunctionRegistration transfer(the_class);
  10175. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  10176. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  10177. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10178. + TransferNativeFunctionRegistration transfer(old_klass);
  10179. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10180. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10181. }
  10182. -
  10183. -// Deoptimize all compiled code that depends on this class.
  10184. -//
  10185. -// If the can_redefine_classes capability is obtained in the onload
  10186. -// phase then the compiler has recorded all dependencies from startup.
  10187. -// In that case we need only deoptimize and throw away all compiled code
  10188. -// that depends on the class.
  10189. -//
  10190. -// If can_redefine_classes is obtained sometime after the onload
  10191. -// phase then the dependency information may be incomplete. In that case
  10192. -// the first call to RedefineClasses causes all compiled code to be
  10193. -// thrown away. As can_redefine_classes has been obtained then
  10194. -// all future compilations will record dependencies so second and
  10195. -// subsequent calls to RedefineClasses need only throw away code
  10196. -// that depends on the class.
  10197. -//
  10198. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  10199. - assert_locked_or_safepoint(Compile_lock);
  10200. -
  10201. - // All dependencies have been recorded from startup or this is a second or
  10202. - // subsequent use of RedefineClasses
  10203. - if (JvmtiExport::all_dependencies_are_recorded()) {
  10204. - Universe::flush_evol_dependents_on(k_h);
  10205. - } else {
  10206. - CodeCache::mark_all_nmethods_for_deoptimization();
  10207. -
  10208. - ResourceMark rm(THREAD);
  10209. - DeoptimizationMarker dm;
  10210. -
  10211. - // Deoptimize all activations depending on marked nmethods
  10212. - Deoptimization::deoptimize_dependents();
  10213. -
  10214. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  10215. - CodeCache::make_marked_nmethods_not_entrant();
  10216. -
  10217. - // From now on we know that the dependency information is complete
  10218. - JvmtiExport::set_all_dependencies_are_recorded(true);
  10219. - }
  10220. -}
  10221. -
  10222. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  10223. - methodOop old_method;
  10224. - methodOop new_method;
  10225. -
  10226. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10227. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10228. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  10229. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10230. -
  10231. - _matching_methods_length = 0;
  10232. - _deleted_methods_length = 0;
  10233. - _added_methods_length = 0;
  10234. -
  10235. - int nj = 0;
  10236. - int oj = 0;
  10237. - while (true) {
  10238. - if (oj >= _old_methods->length()) {
  10239. - if (nj >= _new_methods->length()) {
  10240. - break; // we've looked at everything, done
  10241. - }
  10242. - // New method at the end
  10243. - new_method = (methodOop) _new_methods->obj_at(nj);
  10244. - _added_methods[_added_methods_length++] = new_method;
  10245. - ++nj;
  10246. - } else if (nj >= _new_methods->length()) {
  10247. - // Old method, at the end, is deleted
  10248. - old_method = (methodOop) _old_methods->obj_at(oj);
  10249. - _deleted_methods[_deleted_methods_length++] = old_method;
  10250. - ++oj;
  10251. - } else {
  10252. - old_method = (methodOop) _old_methods->obj_at(oj);
  10253. - new_method = (methodOop) _new_methods->obj_at(nj);
  10254. - if (old_method->name() == new_method->name()) {
  10255. - if (old_method->signature() == new_method->signature()) {
  10256. - _matching_old_methods[_matching_methods_length ] = old_method;
  10257. - _matching_new_methods[_matching_methods_length++] = new_method;
  10258. - ++nj;
  10259. - ++oj;
  10260. - } else {
  10261. - // added overloaded have already been moved to the end,
  10262. - // so this is a deleted overloaded method
  10263. - _deleted_methods[_deleted_methods_length++] = old_method;
  10264. - ++oj;
  10265. - }
  10266. - } else { // names don't match
  10267. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10268. - // new method
  10269. - _added_methods[_added_methods_length++] = new_method;
  10270. - ++nj;
  10271. - } else {
  10272. - // deleted method
  10273. - _deleted_methods[_deleted_methods_length++] = old_method;
  10274. - ++oj;
  10275. - }
  10276. - }
  10277. - }
  10278. - }
  10279. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10280. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10281. -}
  10282. -
  10283. -
  10284. -
  10285. -// Install the redefinition of a class:
  10286. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10287. -// dependent compiled code)
  10288. -// - replacing parts in the_class with parts from scratch_class
  10289. -// - adding a weak reference to track the obsolete but interesting
  10290. -// parts of the_class
  10291. -// - adjusting constant pool caches and vtables in other classes
  10292. -// that refer to methods in the_class. These adjustments use the
  10293. -// SystemDictionary::classes_do() facility which only allows
  10294. -// a helper method to be specified. The interesting parameters
  10295. -// that we would like to pass to the helper method are saved in
  10296. -// static global fields in the VM operation.
  10297. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10298. - instanceKlassHandle scratch_class, TRAPS) {
  10299. -
  10300. - RC_TIMER_START(_timer_rsc_phase1);
  10301. -
  10302. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10303. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10304. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10305. -
  10306. - // Remove all breakpoints in methods of this class
  10307. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10308. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10309. -
  10310. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10311. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10312. - // cached and users of the cache care about each active version of
  10313. - // the method so we have to track this previous version.
  10314. - // Do this before methods get switched
  10315. - Universe::reflect_invoke_cache()->add_previous_version(
  10316. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10317. - }
  10318. -
  10319. - // Deoptimize all compiled code that depends on this class
  10320. - flush_dependent_code(the_class, THREAD);
  10321. -
  10322. - _old_methods = the_class->methods();
  10323. - _new_methods = scratch_class->methods();
  10324. - _the_class_oop = the_class_oop;
  10325. - compute_added_deleted_matching_methods();
  10326. - update_jmethod_ids();
  10327. -
  10328. - // Attach new constant pool to the original klass. The original
  10329. - // klass still refers to the old constant pool (for now).
  10330. - scratch_class->constants()->set_pool_holder(the_class());
  10331. -
  10332. -#if 0
  10333. - // In theory, with constant pool merging in place we should be able
  10334. - // to save space by using the new, merged constant pool in place of
  10335. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10336. - // the klass version we are replacing now and any constant pool(s) in
  10337. - // previous versions of klass. Nice theory, doesn't work in practice.
  10338. - // When this code is enabled, even simple programs throw NullPointer
  10339. - // exceptions. I'm guessing that this is caused by some constant pool
  10340. - // cache difference between the new, merged constant pool and the
  10341. - // constant pool that was just being used by the klass. I'm keeping
  10342. - // this code around to archive the idea, but the code has to remain
  10343. - // disabled for now.
  10344. -
  10345. - // Attach each old method to the new constant pool. This can be
  10346. - // done here since we are past the bytecode verification and
  10347. - // constant pool optimization phases.
  10348. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10349. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10350. - method->set_constants(scratch_class->constants());
  10351. - }
  10352. -
  10353. - {
  10354. - // walk all previous versions of the klass
  10355. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10356. - PreviousVersionWalker pvw(ik);
  10357. - instanceKlassHandle ikh;
  10358. - do {
  10359. - ikh = pvw.next_previous_version();
  10360. - if (!ikh.is_null()) {
  10361. - ik = ikh();
  10362. -
  10363. - // attach previous version of klass to the new constant pool
  10364. - ik->set_constants(scratch_class->constants());
  10365. -
  10366. - // Attach each method in the previous version of klass to the
  10367. - // new constant pool
  10368. - objArrayOop prev_methods = ik->methods();
  10369. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10370. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10371. - method->set_constants(scratch_class->constants());
  10372. - }
  10373. - }
  10374. - } while (!ikh.is_null());
  10375. - }
  10376. -#endif
  10377. -
  10378. - // Replace methods and constantpool
  10379. - the_class->set_methods(_new_methods);
  10380. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10381. - // and to be able to undo operation easily.
  10382. -
  10383. - constantPoolOop old_constants = the_class->constants();
  10384. - the_class->set_constants(scratch_class->constants());
  10385. - scratch_class->set_constants(old_constants); // See the previous comment.
  10386. -#if 0
  10387. - // We are swapping the guts of "the new class" with the guts of "the
  10388. - // class". Since the old constant pool has just been attached to "the
  10389. - // new class", it seems logical to set the pool holder in the old
  10390. - // constant pool also. However, doing this will change the observable
  10391. - // class hierarchy for any old methods that are still executing. A
  10392. - // method can query the identity of its "holder" and this query uses
  10393. - // the method's constant pool link to find the holder. The change in
  10394. - // holding class from "the class" to "the new class" can confuse
  10395. - // things.
  10396. - //
  10397. - // Setting the old constant pool's holder will also cause
  10398. - // verification done during vtable initialization below to fail.
  10399. - // During vtable initialization, the vtable's class is verified to be
  10400. - // a subtype of the method's holder. The vtable's class is "the
  10401. - // class" and the method's holder is gotten from the constant pool
  10402. - // link in the method itself. For "the class"'s directly implemented
  10403. - // methods, the method holder is "the class" itself (as gotten from
  10404. - // the new constant pool). The check works fine in this case. The
  10405. - // check also works fine for methods inherited from super classes.
  10406. - //
  10407. - // Miranda methods are a little more complicated. A miranda method is
  10408. - // provided by an interface when the class implementing the interface
  10409. - // does not provide its own method. These interfaces are implemented
  10410. - // internally as an instanceKlass. These special instanceKlasses
  10411. - // share the constant pool of the class that "implements" the
  10412. - // interface. By sharing the constant pool, the method holder of a
  10413. - // miranda method is the class that "implements" the interface. In a
  10414. - // non-redefine situation, the subtype check works fine. However, if
  10415. - // the old constant pool's pool holder is modified, then the check
  10416. - // fails because there is no class hierarchy relationship between the
  10417. - // vtable's class and "the new class".
  10418. -
  10419. - old_constants->set_pool_holder(scratch_class());
  10420. -#endif
  10421. -
  10422. - // track which methods are EMCP for add_previous_version() call below
  10423. - BitMap emcp_methods(_old_methods->length());
  10424. - int emcp_method_count = 0;
  10425. - emcp_methods.clear(); // clears 0..(length() - 1)
  10426. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10427. - transfer_old_native_function_registrations(the_class);
  10428. -
  10429. - // The class file bytes from before any retransformable agents mucked
  10430. - // with them was cached on the scratch class, move to the_class.
  10431. - // Note: we still want to do this if nothing needed caching since it
  10432. - // should get cleared in the_class too.
  10433. - if (the_class->get_cached_class_file_bytes() == 0) {
  10434. - // the_class doesn't have a cache yet so copy it
  10435. - the_class->set_cached_class_file(
  10436. - scratch_class->get_cached_class_file_bytes(),
  10437. - scratch_class->get_cached_class_file_len());
  10438. - }
  10439. -#ifndef PRODUCT
  10440. - else {
  10441. - assert(the_class->get_cached_class_file_bytes() ==
  10442. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10443. - assert(the_class->get_cached_class_file_len() ==
  10444. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10445. - }
  10446. -#endif
  10447. -
  10448. - // Replace inner_classes
  10449. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10450. - the_class->set_inner_classes(scratch_class->inner_classes());
  10451. - scratch_class->set_inner_classes(old_inner_classes);
  10452. -
  10453. - // Initialize the vtable and interface table after
  10454. - // methods have been rewritten
  10455. - {
  10456. - ResourceMark rm(THREAD);
  10457. - // no exception should happen here since we explicitly
  10458. - // do not check loader constraints.
  10459. - // compare_and_normalize_class_versions has already checked:
  10460. - // - classloaders unchanged, signatures unchanged
  10461. - // - all instanceKlasses for redefined classes reused & contents updated
  10462. - the_class->vtable()->initialize_vtable(false, THREAD);
  10463. - the_class->itable()->initialize_itable(false, THREAD);
  10464. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10465. - }
  10466. -
  10467. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10468. -
  10469. - // Copy the "source file name" attribute from new class version
  10470. - the_class->set_source_file_name(scratch_class->source_file_name());
  10471. -
  10472. - // Copy the "source debug extension" attribute from new class version
  10473. - the_class->set_source_debug_extension(
  10474. - scratch_class->source_debug_extension(),
  10475. - scratch_class->source_debug_extension() == NULL ? 0 :
  10476. - (int)strlen(scratch_class->source_debug_extension()));
  10477. -
  10478. - // Use of javac -g could be different in the old and the new
  10479. - if (scratch_class->access_flags().has_localvariable_table() !=
  10480. - the_class->access_flags().has_localvariable_table()) {
  10481. -
  10482. - AccessFlags flags = the_class->access_flags();
  10483. - if (scratch_class->access_flags().has_localvariable_table()) {
  10484. - flags.set_has_localvariable_table();
  10485. - } else {
  10486. - flags.clear_has_localvariable_table();
  10487. - }
  10488. - the_class->set_access_flags(flags);
  10489. - }
  10490. -
  10491. - // Replace class annotation fields values
  10492. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10493. - the_class->set_class_annotations(scratch_class->class_annotations());
  10494. - scratch_class->set_class_annotations(old_class_annotations);
  10495. -
  10496. - // Replace fields annotation fields values
  10497. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10498. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10499. - scratch_class->set_fields_annotations(old_fields_annotations);
  10500. -
  10501. - // Replace methods annotation fields values
  10502. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10503. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10504. - scratch_class->set_methods_annotations(old_methods_annotations);
  10505. -
  10506. - // Replace methods parameter annotation fields values
  10507. - objArrayOop old_methods_parameter_annotations =
  10508. - the_class->methods_parameter_annotations();
  10509. - the_class->set_methods_parameter_annotations(
  10510. - scratch_class->methods_parameter_annotations());
  10511. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10512. -
  10513. - // Replace methods default annotation fields values
  10514. - objArrayOop old_methods_default_annotations =
  10515. - the_class->methods_default_annotations();
  10516. - the_class->set_methods_default_annotations(
  10517. - scratch_class->methods_default_annotations());
  10518. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10519. -
  10520. - // Replace minor version number of class file
  10521. - u2 old_minor_version = the_class->minor_version();
  10522. - the_class->set_minor_version(scratch_class->minor_version());
  10523. - scratch_class->set_minor_version(old_minor_version);
  10524. -
  10525. - // Replace major version number of class file
  10526. - u2 old_major_version = the_class->major_version();
  10527. - the_class->set_major_version(scratch_class->major_version());
  10528. - scratch_class->set_major_version(old_major_version);
  10529. -
  10530. - // Replace CP indexes for class and name+type of enclosing method
  10531. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10532. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10533. - the_class->set_enclosing_method_indices(
  10534. - scratch_class->enclosing_method_class_index(),
  10535. - scratch_class->enclosing_method_method_index());
  10536. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10537. -
  10538. - // keep track of previous versions of this class
  10539. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10540. - emcp_method_count);
  10541. -
  10542. - RC_TIMER_STOP(_timer_rsc_phase1);
  10543. - RC_TIMER_START(_timer_rsc_phase2);
  10544. -
  10545. - // Adjust constantpool caches and vtables for all classes
  10546. - // that reference methods of the evolved class.
  10547. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10548. -
  10549. - // JSR-292 support
  10550. - MemberNameTable* mnt = the_class->member_names();
  10551. - if (mnt != NULL) {
  10552. - bool trace_name_printed = false;
  10553. - mnt->adjust_method_entries(_matching_old_methods,
  10554. - _matching_new_methods,
  10555. - _matching_methods_length,
  10556. - &trace_name_printed);
  10557. - }
  10558. -
  10559. - if (the_class->oop_map_cache() != NULL) {
  10560. - // Flush references to any obsolete methods from the oop map cache
  10561. - // so that obsolete methods are not pinned.
  10562. - the_class->oop_map_cache()->flush_obsolete_entries();
  10563. - }
  10564. -
  10565. - // increment the classRedefinedCount field in the_class and in any
  10566. - // direct and indirect subclasses of the_class
  10567. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10568. -
  10569. - // RC_TRACE macro has an embedded ResourceMark
  10570. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10571. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10572. - the_class->external_name(),
  10573. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10574. - os::available_memory() >> 10));
  10575. -
  10576. - RC_TIMER_STOP(_timer_rsc_phase2);
  10577. -} // end redefine_single_class()
  10578. -
  10579. -
  10580. -// Increment the classRedefinedCount field in the specific instanceKlass
  10581. -// and in all direct and indirect subclasses.
  10582. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10583. - oop class_mirror = ik->java_mirror();
  10584. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10585. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10586. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10587. -
  10588. - if (class_oop != _the_class_oop) {
  10589. - // _the_class_oop count is printed at end of redefine_single_class()
  10590. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10591. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10592. - }
  10593. -
  10594. - for (Klass *subk = ik->subklass(); subk != NULL;
  10595. - subk = subk->next_sibling()) {
  10596. - if (subk->oop_is_instance()) {
  10597. - // Only update instanceKlasses
  10598. - instanceKlass *subik = (instanceKlass*)subk;
  10599. - // recursively do subclasses of the current subclass
  10600. - increment_class_counter(subik, THREAD);
  10601. - }
  10602. - }
  10603. -}
  10604. -
  10605. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10606. - oop initiating_loader, TRAPS) {
  10607. - Klass *k = k_oop->klass_part();
  10608. - if (k->oop_is_instance()) {
  10609. - HandleMark hm(THREAD);
  10610. - instanceKlass *ik = (instanceKlass *) k;
  10611. - bool no_old_methods = true; // be optimistic
  10612. - ResourceMark rm(THREAD);
  10613. -
  10614. - // a vtable should never contain old or obsolete methods
  10615. - if (ik->vtable_length() > 0 &&
  10616. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  10617. - if (RC_TRACE_ENABLED(0x00004000)) {
  10618. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10619. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  10620. - " -- OLD or OBSOLETE method found -- class: %s",
  10621. - ik->signature_name()));
  10622. - ik->vtable()->dump_vtable();
  10623. - }
  10624. - no_old_methods = false;
  10625. - }
  10626. -
  10627. - // an itable should never contain old or obsolete methods
  10628. - if (ik->itable_length() > 0 &&
  10629. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  10630. - if (RC_TRACE_ENABLED(0x00004000)) {
  10631. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10632. - ("klassItable::check_no_old_or_obsolete_entries failure"
  10633. - " -- OLD or OBSOLETE method found -- class: %s",
  10634. - ik->signature_name()));
  10635. - ik->itable()->dump_itable();
  10636. - }
  10637. - no_old_methods = false;
  10638. - }
  10639. -
  10640. - // the constant pool cache should never contain old or obsolete methods
  10641. - if (ik->constants() != NULL &&
  10642. - ik->constants()->cache() != NULL &&
  10643. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  10644. - if (RC_TRACE_ENABLED(0x00004000)) {
  10645. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10646. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  10647. - " -- OLD or OBSOLETE method found -- class: %s",
  10648. - ik->signature_name()));
  10649. - ik->constants()->cache()->dump_cache();
  10650. - }
  10651. - no_old_methods = false;
  10652. - }
  10653. -
  10654. - if (!no_old_methods) {
  10655. - if (RC_TRACE_ENABLED(0x00004000)) {
  10656. - dump_methods();
  10657. - } else {
  10658. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  10659. - "to see more info about the following guarantee() failure.");
  10660. - }
  10661. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10662. - }
  10663. - }
  10664. -}
  10665. -
  10666. -void VM_RedefineClasses::dump_methods() {
  10667. - int j;
  10668. - RC_TRACE(0x00004000, ("_old_methods --"));
  10669. - for (j = 0; j < _old_methods->length(); ++j) {
  10670. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10671. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10672. - m->access_flags().print_on(tty);
  10673. - tty->print(" -- ");
  10674. - m->print_name(tty);
  10675. - tty->cr();
  10676. - }
  10677. - RC_TRACE(0x00004000, ("_new_methods --"));
  10678. - for (j = 0; j < _new_methods->length(); ++j) {
  10679. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10680. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10681. - m->access_flags().print_on(tty);
  10682. - tty->print(" -- ");
  10683. - m->print_name(tty);
  10684. - tty->cr();
  10685. - }
  10686. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10687. - for (j = 0; j < _matching_methods_length; ++j) {
  10688. - methodOop m = _matching_old_methods[j];
  10689. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10690. - m->access_flags().print_on(tty);
  10691. - tty->print(" -- ");
  10692. - m->print_name(tty);
  10693. - tty->cr();
  10694. - m = _matching_new_methods[j];
  10695. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10696. - m->access_flags().print_on(tty);
  10697. - tty->cr();
  10698. - }
  10699. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10700. - for (j = 0; j < _deleted_methods_length; ++j) {
  10701. - methodOop m = _deleted_methods[j];
  10702. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10703. - m->access_flags().print_on(tty);
  10704. - tty->print(" -- ");
  10705. - m->print_name(tty);
  10706. - tty->cr();
  10707. - }
  10708. - RC_TRACE(0x00004000, ("_added_methods --"));
  10709. - for (j = 0; j < _added_methods_length; ++j) {
  10710. - methodOop m = _added_methods[j];
  10711. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10712. - m->access_flags().print_on(tty);
  10713. - tty->print(" -- ");
  10714. - m->print_name(tty);
  10715. - tty->cr();
  10716. - }
  10717. -}
  10718. diff -r 882f6c762ac5 src/share/vm/prims/jvmtiRedefineClasses.hpp
  10719. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Jul 09 23:10:04 2015 -0700
  10720. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Jul 09 23:18:17 2015 -0700
  10721. @@ -1,26 +1,29 @@
  10722. /*
  10723. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10724. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10725. - *
  10726. - * This code is free software; you can redistribute it and/or modify it
  10727. - * under the terms of the GNU General Public License version 2 only, as
  10728. - * published by the Free Software Foundation.
  10729. - *
  10730. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10731. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10732. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10733. - * version 2 for more details (a copy is included in the LICENSE file that
  10734. - * accompanied this code).
  10735. - *
  10736. - * You should have received a copy of the GNU General Public License version
  10737. - * 2 along with this work; if not, write to the Free Software Foundation,
  10738. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10739. - *
  10740. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10741. - * or visit www.oracle.com if you need additional information or have any
  10742. - * questions.
  10743. - *
  10744. - */
  10745. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10746. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10747. +*
  10748. +* This code is free software; you can redistribute it and/or modify it
  10749. +* under the terms of the GNU General Public License version 2 only, as
  10750. +* published by the Free Software Foundation.
  10751. +*
  10752. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10753. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10754. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10755. +* version 2 for more details (a copy is included in the LICENSE file that
  10756. +* accompanied this code).
  10757. +*
  10758. +* You should have received a copy of the GNU General Public License version
  10759. +* 2 along with this work; if not, write to the Free Software Foundation,
  10760. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10761. +*
  10762. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10763. +* or visit www.oracle.com if you need additional information or have any
  10764. +* questions.
  10765. +*
  10766. +*/
  10767. +
  10768. +// New version that allows arbitrary changes to already loaded classes.
  10769. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10770. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10771. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10772. @@ -32,331 +35,28 @@
  10773. #include "oops/objArrayOop.hpp"
  10774. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10775. #include "runtime/vm_operations.hpp"
  10776. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10777. -// Introduction:
  10778. -//
  10779. -// The RedefineClasses() API is used to change the definition of one or
  10780. -// more classes. While the API supports redefining more than one class
  10781. -// in a single call, in general, the API is discussed in the context of
  10782. -// changing the definition of a single current class to a single new
  10783. -// class. For clarity, the current class is will always be called
  10784. -// "the_class" and the new class will always be called "scratch_class".
  10785. -//
  10786. -// The name "the_class" is used because there is only one structure
  10787. -// that represents a specific class; redefinition does not replace the
  10788. -// structure, but instead replaces parts of the structure. The name
  10789. -// "scratch_class" is used because the structure that represents the
  10790. -// new definition of a specific class is simply used to carry around
  10791. -// the parts of the new definition until they are used to replace the
  10792. -// appropriate parts in the_class. Once redefinition of a class is
  10793. -// complete, scratch_class is thrown away.
  10794. -//
  10795. -//
  10796. -// Implementation Overview:
  10797. -//
  10798. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10799. -// does the real work. The work is split in varying degrees between
  10800. -// doit_prologue(), doit() and doit_epilogue().
  10801. -//
  10802. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10803. -// safepoint. It does parameter verification and loads scratch_class
  10804. -// which involves:
  10805. -// - parsing the incoming class definition using the_class' class
  10806. -// loader and security context
  10807. -// - linking scratch_class
  10808. -// - merging constant pools and rewriting bytecodes as needed
  10809. -// for the merged constant pool
  10810. -// - verifying the bytecodes in scratch_class
  10811. -// - setting up the constant pool cache and rewriting bytecodes
  10812. -// as needed to use the cache
  10813. -// - finally, scratch_class is compared to the_class to verify
  10814. -// that it is a valid replacement class
  10815. -// - if everything is good, then scratch_class is saved in an
  10816. -// instance field in the VM operation for the doit() call
  10817. -//
  10818. -// Note: A JavaThread must do the above work.
  10819. -//
  10820. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10821. -// the new class definition(s) which involves:
  10822. -// - retrieving the scratch_class from the instance field in the
  10823. -// VM operation
  10824. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10825. -// dependent compiled code)
  10826. -// - replacing parts in the_class with parts from scratch_class
  10827. -// - adding weak reference(s) to track the obsolete but interesting
  10828. -// parts of the_class
  10829. -// - adjusting constant pool caches and vtables in other classes
  10830. -// that refer to methods in the_class. These adjustments use the
  10831. -// SystemDictionary::classes_do() facility which only allows
  10832. -// a helper method to be specified. The interesting parameters
  10833. -// that we would like to pass to the helper method are saved in
  10834. -// static global fields in the VM operation.
  10835. -// - telling the SystemDictionary to notice our changes
  10836. -//
  10837. -// Note: the above work must be done by the VMThread to be safe.
  10838. -//
  10839. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10840. -// is finished and the safepoint is done. It simply cleans up
  10841. -// memory allocated in doit_prologue() and used in doit().
  10842. -//
  10843. -//
  10844. -// Constant Pool Details:
  10845. -//
  10846. -// When the_class is redefined, we cannot just replace the constant
  10847. -// pool in the_class with the constant pool from scratch_class because
  10848. -// that could confuse obsolete methods that may still be running.
  10849. -// Instead, the constant pool from the_class, old_cp, is merged with
  10850. -// the constant pool from scratch_class, scratch_cp. The resulting
  10851. -// constant pool, merge_cp, replaces old_cp in the_class.
  10852. -//
  10853. -// The key part of any merging algorithm is the entry comparison
  10854. -// function so we have to know the types of entries in a constant pool
  10855. -// in order to merge two of them together. Constant pools can contain
  10856. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10857. -// is not presently used so we only have to worry about the other 11
  10858. -// entry types. For the purposes of constant pool merging, it is
  10859. -// helpful to know that the 11 entry types fall into 3 different
  10860. -// subtypes: "direct", "indirect" and "double-indirect".
  10861. -//
  10862. -// Direct CP entries contain data and do not contain references to
  10863. -// other CP entries. The following are direct CP entries:
  10864. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10865. -//
  10866. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10867. -// and no other data. The following are indirect CP entries:
  10868. -// JVM_CONSTANT_{Class,NameAndType,String}
  10869. -//
  10870. -// Double-indirect CP entries contain two references to indirect CP
  10871. -// entries and no other data. The following are double-indirect CP
  10872. -// entries:
  10873. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10874. -//
  10875. -// When comparing entries between two constant pools, the entry types
  10876. -// are compared first and if they match, then further comparisons are
  10877. -// made depending on the entry subtype. Comparing direct CP entries is
  10878. -// simply a matter of comparing the data associated with each entry.
  10879. -// Comparing both indirect and double-indirect CP entries requires
  10880. -// recursion.
  10881. -//
  10882. -// Fortunately, the recursive combinations are limited because indirect
  10883. -// CP entries can only refer to direct CP entries and double-indirect
  10884. -// CP entries can only refer to indirect CP entries. The following is
  10885. -// an example illustration of the deepest set of indirections needed to
  10886. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10887. -//
  10888. -// JVM_CONSTANT_Fieldref {
  10889. -// class_index => JVM_CONSTANT_Class {
  10890. -// name_index => JVM_CONSTANT_Utf8 {
  10891. -// <data-1>
  10892. -// }
  10893. -// }
  10894. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10895. -// name_index => JVM_CONSTANT_Utf8 {
  10896. -// <data-2>
  10897. -// }
  10898. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10899. -// <data-3>
  10900. -// }
  10901. -// }
  10902. -// }
  10903. -//
  10904. -// The above illustration is not a data structure definition for any
  10905. -// computer language. The curly braces ('{' and '}') are meant to
  10906. -// delimit the context of the "fields" in the CP entry types shown.
  10907. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10908. -// "=>", e.g., the class_index is used to indirectly reference a
  10909. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10910. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10911. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10912. -// have to do a total of 5 indirections just to get to the CP entries
  10913. -// that contain the interesting pieces of data and then we have to
  10914. -// fetch the three pieces of data. This means we have to do a total of
  10915. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10916. -// entries.
  10917. -//
  10918. -// Here is the indirection, data and dereference count for each entry
  10919. -// type:
  10920. -//
  10921. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10922. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10923. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10924. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10925. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10926. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10927. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10928. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10929. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10930. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10931. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10932. -//
  10933. -// So different subtypes of CP entries require different amounts of
  10934. -// work for a proper comparison.
  10935. -//
  10936. -// Now that we've talked about the different entry types and how to
  10937. -// compare them we need to get back to merging. This is not a merge in
  10938. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10939. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10940. -// preserving entry order. Next we append all the unique entries from
  10941. -// scratch_cp to merge_cp and we track the index changes from the
  10942. -// location in scratch_cp to the possibly new location in merge_cp.
  10943. -// When we are done, any obsolete code that is still running that
  10944. -// uses old_cp should not be able to observe any difference if it
  10945. -// were to use merge_cp. As for the new code in scratch_class, it is
  10946. -// modified to use the appropriate index values in merge_cp before it
  10947. -// is used to replace the code in the_class.
  10948. -//
  10949. -// There is one small complication in copying the entries from old_cp
  10950. -// to merge_cp. Two of the CP entry types are special in that they are
  10951. -// lazily resolved. Before explaining the copying complication, we need
  10952. -// to digress into CP entry resolution.
  10953. -//
  10954. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10955. -// the class file, but are not stored in memory as such until they are
  10956. -// resolved. The entries are not resolved unless they are used because
  10957. -// resolution is expensive. During class file parsing the entries are
  10958. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10959. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10960. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10961. -// have been parsed, but the index values in the entries have not been
  10962. -// validated. After the entire constant pool has been parsed, the index
  10963. -// values can be validated and then the entries are converted into
  10964. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10965. -// entries. During this conversion process, the UTF8 values that are
  10966. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10967. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10968. -// entries are modified to refer to the Symbol*s. This optimization
  10969. -// eliminates one level of indirection for those two CP entry types and
  10970. -// gets the entries ready for verification. During class file parsing
  10971. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10972. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10973. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10974. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10975. -// entries.
  10976. -//
  10977. -// Now we can get back to the copying complication. When we copy
  10978. -// entries from old_cp to merge_cp, we have to revert any
  10979. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10980. -// or verification will fail.
  10981. -//
  10982. -// It is important to explicitly state that the merging algorithm
  10983. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10984. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10985. -// entries in the merge_cp. This is done both to make verification
  10986. -// happy and to avoid adding more brittleness between RedefineClasses
  10987. -// and the constant pool cache. By allowing the constant pool cache
  10988. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10989. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10990. -// about those algorithms in RedefineClasses.
  10991. -//
  10992. -// Appending unique entries from scratch_cp to merge_cp is straight
  10993. -// forward for direct CP entries and most indirect CP entries. For the
  10994. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10995. -// indirect CP entry types, the presence of more than one piece of
  10996. -// interesting data makes appending the entries more complicated.
  10997. -//
  10998. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10999. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  11000. -// If the index in scratch_cp is different than the destination index
  11001. -// in merge_cp, then the change in index value is tracked.
  11002. -//
  11003. -// Note: the above discussion for the direct CP entries also applies
  11004. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  11005. -//
  11006. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  11007. -// one data element at the end of the recursion, we know that we have
  11008. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  11009. -// unique then it is appended to merge_cp before the current entry.
  11010. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  11011. -// is updated to refer to the duplicate entry in merge_cp before it is
  11012. -// appended to merge_cp. Again, any changes in index values are tracked
  11013. -// as needed.
  11014. -//
  11015. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  11016. -// types is theoretical. Since those entry types have already been
  11017. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  11018. -// they are handled as direct CP entries.
  11019. -//
  11020. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  11021. -// data elements at the end of the recursions, we know that we have
  11022. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  11023. -// entries are appended to merge_cp before the current entry. For any
  11024. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  11025. -// updated to refer to the duplicate entry in merge_cp before it is
  11026. -// appended to merge_cp. Again, any changes in index values are tracked
  11027. -// as needed.
  11028. -//
  11029. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  11030. -// types, since there are two indirect CP entries and three data
  11031. -// elements at the end of the recursions, we know that we have between
  11032. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  11033. -// above for an example of all six entries. The uniqueness algorithm
  11034. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  11035. -// covered above. Any unique entries are appended to merge_cp before
  11036. -// the current entry. For any entries that are not unique, the current
  11037. -// entry is updated to refer to the duplicate entry in merge_cp before
  11038. -// it is appended to merge_cp. Again, any changes in index values are
  11039. -// tracked as needed.
  11040. -//
  11041. -//
  11042. -// Other Details:
  11043. -//
  11044. -// Details for other parts of RedefineClasses need to be written.
  11045. -// This is a placeholder section.
  11046. -//
  11047. -//
  11048. -// Open Issues (in no particular order):
  11049. -//
  11050. -// - How do we serialize the RedefineClasses() API without deadlocking?
  11051. -//
  11052. -// - SystemDictionary::parse_stream() was called with a NULL protection
  11053. -// domain since the initial version. This has been changed to pass
  11054. -// the_class->protection_domain(). This change has been tested with
  11055. -// all NSK tests and nothing broke, but what will adding it now break
  11056. -// in ways that we don't test?
  11057. -//
  11058. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  11059. -// (indirect) use of the Relocator class that the max instruction
  11060. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  11061. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  11062. -// what it does to the bytecodes. More investigation is needed.
  11063. -//
  11064. -// - java.lang.Object methods can be called on arrays. This is
  11065. -// implemented via the arrayKlassOop vtable which we don't
  11066. -// update. For example, if we redefine java.lang.Object.toString(),
  11067. -// then the new version of the method will not be called for array
  11068. -// objects.
  11069. -//
  11070. -// - How do we know if redefine_single_class() and the guts of
  11071. -// instanceKlass are out of sync? I don't think this can be
  11072. -// automated, but we should probably order the work in
  11073. -// redefine_single_class() to match the order of field
  11074. -// definitions in instanceKlass. We also need to add some
  11075. -// comments about keeping things in sync.
  11076. -//
  11077. -// - set_new_constant_pool() is huge and we should consider refactoring
  11078. -// it into smaller chunks of work.
  11079. -//
  11080. -// - The exception table update code in set_new_constant_pool() defines
  11081. -// const values that are also defined in a local context elsewhere.
  11082. -// The same literal values are also used in elsewhere. We need to
  11083. -// coordinate a cleanup of these constants with Runtime.
  11084. -//
  11085. +#define RC_ABORT(error) { _result = error; return false; }
  11086. -class VM_RedefineClasses: public VM_Operation {
  11087. +class VM_RedefineClasses: public VM_GC_Operation {
  11088. private:
  11089. +
  11090. // These static fields are needed by SystemDictionary::classes_do()
  11091. // facility and the adjust_cpool_cache_and_vtable() helper:
  11092. static objArrayOop _old_methods;
  11093. static objArrayOop _new_methods;
  11094. - static methodOop* _matching_old_methods;
  11095. - static methodOop* _matching_new_methods;
  11096. - static methodOop* _deleted_methods;
  11097. - static methodOop* _added_methods;
  11098. + static int* _matching_old_methods;
  11099. + static int* _matching_new_methods;
  11100. + static int* _deleted_methods;
  11101. + static int* _added_methods;
  11102. static int _matching_methods_length;
  11103. static int _deleted_methods_length;
  11104. static int _added_methods_length;
  11105. static klassOop _the_class_oop;
  11106. + static int _revision_number;
  11107. +
  11108. // The instance fields are used to pass information from
  11109. // doit_prologue() to doit() and doit_epilogue().
  11110. jint _class_count;
  11111. @@ -370,43 +70,29 @@
  11112. // _index_map_p contains any entries.
  11113. int _index_map_count;
  11114. intArray * _index_map_p;
  11115. -
  11116. - // _operands_index_map_count is just an optimization for knowing if
  11117. - // _operands_index_map_p contains any entries.
  11118. - int _operands_cur_length;
  11119. - int _operands_index_map_count;
  11120. - intArray * _operands_index_map_p;
  11121. -
  11122. - // ptr to _class_count scratch_classes
  11123. - instanceKlassHandle * _scratch_classes;
  11124. - jvmtiError _res;
  11125. + GrowableArray<instanceKlassHandle>* _new_classes;
  11126. + GrowableArray<oop>* _updated_oops;
  11127. + jvmtiError _result;
  11128. + int _max_redefinition_flags;
  11129. // Performance measurement support. These timers do not cover all
  11130. // the work done for JVM/TI RedefineClasses() but they do cover
  11131. // the heavy lifting.
  11132. - elapsedTimer _timer_rsc_phase1;
  11133. - elapsedTimer _timer_rsc_phase2;
  11134. - elapsedTimer _timer_vm_op_prologue;
  11135. + elapsedTimer _timer_total;
  11136. + elapsedTimer _timer_prologue;
  11137. + elapsedTimer _timer_class_linking;
  11138. + elapsedTimer _timer_class_loading;
  11139. + elapsedTimer _timer_check_type;
  11140. + elapsedTimer _timer_prepare_redefinition;
  11141. + elapsedTimer _timer_wait_for_locks;
  11142. + elapsedTimer _timer_redefinition;
  11143. + elapsedTimer _timer_vm_op_epilogue;
  11144. - // These routines are roughly in call order unless otherwise noted.
  11145. -
  11146. - // Load the caller's new class definition(s) into _scratch_classes.
  11147. - // Constant pool merging work is done here as needed. Also calls
  11148. - // compare_and_normalize_class_versions() to verify the class
  11149. - // definition(s).
  11150. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  11151. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  11152. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  11153. jvmtiError load_new_class_versions(TRAPS);
  11154. - // Verify that the caller provided class definition(s) that meet
  11155. - // the restrictions of RedefineClasses. Normalize the order of
  11156. - // overloaded methods as needed.
  11157. - jvmtiError compare_and_normalize_class_versions(
  11158. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  11159. -
  11160. - // Swap annotations[i] with annotations[j]
  11161. - // Used by compare_and_normalize_class_versions() when normalizing
  11162. - // overloaded methods or changing idnum as when adding or deleting methods.
  11163. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  11164. -
  11165. // Figure out which new methods match old methods in name and signature,
  11166. // which methods have been added, and which are no longer present
  11167. void compute_added_deleted_matching_methods();
  11168. @@ -414,103 +100,99 @@
  11169. // Change jmethodIDs to point to the new methods
  11170. void update_jmethod_ids();
  11171. - // In addition to marking methods as obsolete, this routine
  11172. - // records which methods are EMCP (Equivalent Module Constant
  11173. - // Pool) in the emcp_methods BitMap and returns the number of
  11174. - // EMCP methods via emcp_method_count_p. This information is
  11175. - // used when information about the previous version of the_class
  11176. - // is squirreled away.
  11177. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  11178. - int * emcp_method_count_p);
  11179. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11180. + class FindAffectedKlassesClosure : public ObjectClosure {
  11181. - // Unevolving classes may point to methods of the_class directly
  11182. - // from their constant pool caches, itables, and/or vtables. We
  11183. - // use the SystemDictionary::classes_do() facility and this helper
  11184. - // to fix up these pointers.
  11185. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  11186. + private:
  11187. + GrowableArray<instanceKlassHandle> *_original_klasses;
  11188. + GrowableArray<instanceKlassHandle> *_result;
  11189. +
  11190. + public:
  11191. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  11192. +
  11193. + virtual void do_object(oop obj);
  11194. + };
  11195. +
  11196. +
  11197. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  11198. // Install the redefinition of a class
  11199. - void redefine_single_class(jclass the_jclass,
  11200. - instanceKlassHandle scratch_class, TRAPS);
  11201. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  11202. // Increment the classRedefinedCount field in the specific instanceKlass
  11203. // and in all direct and indirect subclasses.
  11204. void increment_class_counter(instanceKlass *ik, TRAPS);
  11205. - // Support for constant pool merging (these routines are in alpha order):
  11206. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  11207. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11208. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11209. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11210. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  11211. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  11212. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11213. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11214. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11215. - int find_new_index(int old_index);
  11216. - int find_new_operand_index(int old_bootstrap_spec_index);
  11217. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  11218. - constantPoolHandle cp2, int index2);
  11219. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  11220. - constantPoolHandle cp2, int index2);
  11221. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  11222. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  11223. - bool merge_constant_pools(constantPoolHandle old_cp,
  11224. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  11225. - int *merge_cp_length_p, TRAPS);
  11226. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  11227. - instanceKlassHandle scratch_class, TRAPS);
  11228. - u2 rewrite_cp_ref_in_annotation_data(
  11229. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  11230. - const char * trace_mesg, TRAPS);
  11231. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  11232. - bool rewrite_cp_refs_in_annotation_struct(
  11233. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11234. - bool rewrite_cp_refs_in_annotations_typeArray(
  11235. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  11236. - bool rewrite_cp_refs_in_class_annotations(
  11237. - instanceKlassHandle scratch_class, TRAPS);
  11238. - bool rewrite_cp_refs_in_element_value(
  11239. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11240. - bool rewrite_cp_refs_in_fields_annotations(
  11241. - instanceKlassHandle scratch_class, TRAPS);
  11242. - void rewrite_cp_refs_in_method(methodHandle method,
  11243. - methodHandle * new_method_p, TRAPS);
  11244. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  11245. - bool rewrite_cp_refs_in_methods_annotations(
  11246. - instanceKlassHandle scratch_class, TRAPS);
  11247. - bool rewrite_cp_refs_in_methods_default_annotations(
  11248. - instanceKlassHandle scratch_class, TRAPS);
  11249. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  11250. - instanceKlassHandle scratch_class, TRAPS);
  11251. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  11252. - void rewrite_cp_refs_in_verification_type_info(
  11253. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  11254. - u1 frame_size, TRAPS);
  11255. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  11256. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  11257. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  11258. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  11259. - static void dump_methods();
  11260. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  11261. +
  11262. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  11263. +
  11264. +#ifdef ASSERT
  11265. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  11266. +#endif
  11267. +
  11268. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  11269. + void calculate_instance_update_information(klassOop new_version);
  11270. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  11271. +
  11272. + static void calculate_type_check_information(klassOop k);
  11273. + static void clear_type_check_information(klassOop k);
  11274. public:
  11275. - VM_RedefineClasses(jint class_count,
  11276. - const jvmtiClassDefinition *class_defs,
  11277. - JvmtiClassLoadKind class_load_kind);
  11278. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  11279. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  11280. + virtual ~VM_RedefineClasses();
  11281. +
  11282. + bool check_arguments();
  11283. bool doit_prologue();
  11284. void doit();
  11285. void doit_epilogue();
  11286. + void rollback();
  11287. - bool allow_nested_vm_operations() const { return true; }
  11288. - jvmtiError check_error() { return _res; }
  11289. + jvmtiError check_exception() const;
  11290. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  11291. + bool skip_operation() const { return false; }
  11292. + bool allow_nested_vm_operations() const { return true; }
  11293. + jvmtiError check_error() { return _result; }
  11294. +
  11295. + void update_active_methods();
  11296. +
  11297. + // Checks for type consistency after hierarchy change
  11298. + bool check_type_consistency();
  11299. + void calculate_type_check_information();
  11300. + bool check_field_value_types();
  11301. + void clear_type_check_information();
  11302. + bool check_method_stacks();
  11303. + bool check_loaded_methods();
  11304. + bool check_method(methodOop method);
  11305. + static Symbol* signature_to_class_name(Symbol* signature);
  11306. +
  11307. + void method_forwarding();
  11308. +
  11309. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11310. // Modifiable test must be shared between IsModifiableClass query
  11311. // and redefine implementation
  11312. static bool is_modifiable_class(oop klass_mirror);
  11313. +
  11314. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11315. + void oops_do(OopClosure* f);
  11316. +
  11317. + // Utility methods for transferring field access flags
  11318. +
  11319. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11320. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11321. +
  11322. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11323. +
  11324. + void lock_threads();
  11325. + void unlock_threads();
  11326. +
  11327. + template <class T> static void do_oop_work(T* p);
  11328. +
  11329. + static void swap_marks(oop first, oop second);
  11330. +
  11331. };
  11332. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11333. diff -r 882f6c762ac5 src/share/vm/prims/methodComparator.cpp
  11334. --- a/src/share/vm/prims/methodComparator.cpp Thu Jul 09 23:10:04 2015 -0700
  11335. +++ b/src/share/vm/prims/methodComparator.cpp Thu Jul 09 23:18:17 2015 -0700
  11336. @@ -65,6 +65,7 @@
  11337. if (! args_same(c_old, c_new))
  11338. return false;
  11339. }
  11340. +
  11341. return true;
  11342. }
  11343. diff -r 882f6c762ac5 src/share/vm/prims/nativeLookup.cpp
  11344. --- a/src/share/vm/prims/nativeLookup.cpp Thu Jul 09 23:10:04 2015 -0700
  11345. +++ b/src/share/vm/prims/nativeLookup.cpp Thu Jul 09 23:18:17 2015 -0700
  11346. @@ -35,6 +35,7 @@
  11347. #include "oops/symbol.hpp"
  11348. #include "prims/jvm_misc.hpp"
  11349. #include "prims/nativeLookup.hpp"
  11350. +#include "prims/jvmtiRedefineClasses.hpp"
  11351. #include "runtime/arguments.hpp"
  11352. #include "runtime/handles.inline.hpp"
  11353. #include "runtime/javaCalls.hpp"
  11354. @@ -53,7 +54,6 @@
  11355. # include "os_bsd.inline.hpp"
  11356. #endif
  11357. -
  11358. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11359. char* bytes = (char*)name->bytes() + begin;
  11360. char* end_bytes = (char*)name->bytes() + end;
  11361. @@ -138,6 +138,40 @@
  11362. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  11363. };
  11364. +// Helper function to call redefineClasses from Java Code
  11365. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11366. + ResourceMark rm(THREAD);
  11367. +
  11368. + JavaThread* current_thread = JavaThread::current();
  11369. + jbyte* bytecodes = NULL;
  11370. + const int class_count = 1;
  11371. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11372. +
  11373. + {
  11374. + ThreadToNativeFromVM ttnfv(thread);
  11375. + jboolean is_copy = JNI_FALSE;
  11376. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11377. + class_definitions[0].klass = target;
  11378. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11379. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11380. + }
  11381. +
  11382. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11383. + VMThread::execute(&op);
  11384. + int result = op.check_error();
  11385. +
  11386. + {
  11387. + ThreadToNativeFromVM ttnfv(thread);
  11388. + if (env->ExceptionOccurred()) {
  11389. + return -1;
  11390. + }
  11391. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11392. + }
  11393. +
  11394. + return result;
  11395. +JVM_END
  11396. +
  11397. +
  11398. static address lookup_special_native(char* jni_name) {
  11399. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11400. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11401. @@ -177,6 +211,9 @@
  11402. return entry;
  11403. }
  11404. }
  11405. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11406. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11407. + }
  11408. // Otherwise call static method findNative in ClassLoader
  11409. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11410. diff -r 882f6c762ac5 src/share/vm/runtime/arguments.cpp
  11411. --- a/src/share/vm/runtime/arguments.cpp Thu Jul 09 23:10:04 2015 -0700
  11412. +++ b/src/share/vm/runtime/arguments.cpp Thu Jul 09 23:18:17 2015 -0700
  11413. @@ -1874,6 +1874,15 @@
  11414. status = false;
  11415. }
  11416. + // (tw) Must use serial GC
  11417. + if (!UseSerialGC && i >= 1) {
  11418. + jio_fprintf(defaultStream::error_stream(),
  11419. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11420. + status = false;
  11421. + } else {
  11422. + UseSerialGC = true;
  11423. + }
  11424. +
  11425. return status;
  11426. }
  11427. diff -r 882f6c762ac5 src/share/vm/runtime/deoptimization.cpp
  11428. --- a/src/share/vm/runtime/deoptimization.cpp Thu Jul 09 23:10:04 2015 -0700
  11429. +++ b/src/share/vm/runtime/deoptimization.cpp Thu Jul 09 23:18:17 2015 -0700
  11430. @@ -599,6 +599,38 @@
  11431. // Cleanup thread deopt data
  11432. cleanup_deopt_info(thread, array);
  11433. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11434. + {
  11435. + ResourceMark res_mark;
  11436. +
  11437. + // Verify that the just-unpacked frames match the interpreter's
  11438. + // notions of expression stack and locals
  11439. + vframeArray* cur_array = thread->vframe_array_last();
  11440. + RegisterMap rm(thread, false);
  11441. + rm.set_include_argument_oops(false);
  11442. + for (int i = 0; i < cur_array->frames(); i++) {
  11443. + vframeArrayElement* el = cur_array->element(i);
  11444. + frame* frame = el->iframe();
  11445. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11446. + RegisterMap reg_map(thread);
  11447. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11448. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11449. + methodOop method = iframe->method();
  11450. + int bci = iframe->bci();
  11451. + method = method->newest_version();
  11452. + iframe->set_method(method, bci);
  11453. +
  11454. + methodOop forward_method = method->forward_method();
  11455. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11456. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11457. + if (TraceRedefineClasses >= 2) {
  11458. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  11459. + }
  11460. + iframe->set_method(forward_method, new_bci);
  11461. + }
  11462. + }
  11463. + }
  11464. +
  11465. #ifndef PRODUCT
  11466. if (VerifyStack) {
  11467. ResourceMark res_mark;
  11468. diff -r 882f6c762ac5 src/share/vm/runtime/frame.cpp
  11469. --- a/src/share/vm/runtime/frame.cpp Thu Jul 09 23:10:04 2015 -0700
  11470. +++ b/src/share/vm/runtime/frame.cpp Thu Jul 09 23:18:17 2015 -0700
  11471. @@ -408,6 +408,12 @@
  11472. *interpreter_frame_method_addr() = method;
  11473. }
  11474. +// (tw) Sets constant pool cache oop
  11475. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11476. + assert(is_interpreted_frame(), "interpreted frame expected");
  11477. + *interpreter_frame_cache_addr() = cp;
  11478. +}
  11479. +
  11480. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11481. assert(is_interpreted_frame(), "Not an interpreted frame");
  11482. if (ProfileInterpreter) {
  11483. @@ -423,19 +429,27 @@
  11484. // The bcx was just converted from bci to bcp.
  11485. // Convert the mdx in parallel.
  11486. methodDataOop mdo = interpreter_frame_method()->method_data();
  11487. - assert(mdo != NULL, "");
  11488. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11489. - address mdp = mdo->di_to_dp(mdi);
  11490. - interpreter_frame_set_mdx((intptr_t)mdp);
  11491. + if (mdo == NULL) {
  11492. + interpreter_frame_set_mdx(0);
  11493. + } else {
  11494. + assert(mdo != NULL, "");
  11495. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11496. + address mdp = mdo->di_to_dp(mdi);
  11497. + interpreter_frame_set_mdx((intptr_t)mdp);
  11498. + }
  11499. }
  11500. } else {
  11501. if (is_now_bci) {
  11502. // The bcx was just converted from bcp to bci.
  11503. // Convert the mdx in parallel.
  11504. methodDataOop mdo = interpreter_frame_method()->method_data();
  11505. - assert(mdo != NULL, "");
  11506. - int mdi = mdo->dp_to_di((address)mdx);
  11507. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11508. + if (mdo == NULL) {
  11509. + interpreter_frame_set_mdx(0);
  11510. + } else {
  11511. + assert(mdo != NULL, "");
  11512. + int mdi = mdo->dp_to_di((address)mdx);
  11513. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11514. + }
  11515. }
  11516. }
  11517. }
  11518. diff -r 882f6c762ac5 src/share/vm/runtime/frame.hpp
  11519. --- a/src/share/vm/runtime/frame.hpp Thu Jul 09 23:10:04 2015 -0700
  11520. +++ b/src/share/vm/runtime/frame.hpp Thu Jul 09 23:18:17 2015 -0700
  11521. @@ -346,6 +346,7 @@
  11522. // Method & constant pool cache
  11523. methodOop interpreter_frame_method() const;
  11524. void interpreter_frame_set_method(methodOop method);
  11525. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11526. methodOop* interpreter_frame_method_addr() const;
  11527. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11528. #ifdef PPC
  11529. diff -r 882f6c762ac5 src/share/vm/runtime/globals.hpp
  11530. --- a/src/share/vm/runtime/globals.hpp Thu Jul 09 23:10:04 2015 -0700
  11531. +++ b/src/share/vm/runtime/globals.hpp Thu Jul 09 23:18:17 2015 -0700
  11532. @@ -1229,9 +1229,23 @@
  11533. product(bool, StressLdcRewrite, false, \
  11534. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11535. \
  11536. + product(bool, UseMethodForwardPoints, false, \
  11537. + "Use method forward points") \
  11538. + \
  11539. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11540. + "Maximum number of locals in forwarding method") \
  11541. + \
  11542. + product(intx, MethodForwardPointsMaxStack, 300, \
  11543. + "Maximum number of stack slots in forwarding method") \
  11544. + \
  11545. product(intx, TraceRedefineClasses, 0, \
  11546. "Trace level for JVMTI RedefineClasses") \
  11547. \
  11548. + product(bool, TimeRedefineClasses, false, \
  11549. + "Measure timing for JVMTI RedefineClasses") \
  11550. + \
  11551. + product(bool, AllowAdvancedClassRedefinition, true, \
  11552. + "Allow advanced class redefinition beyond swapping method bodies")\
  11553. develop(bool, StressMethodComparator, false, \
  11554. "run the MethodComparator on all loaded methods") \
  11555. \
  11556. diff -r 882f6c762ac5 src/share/vm/runtime/interfaceSupport.hpp
  11557. --- a/src/share/vm/runtime/interfaceSupport.hpp Thu Jul 09 23:10:04 2015 -0700
  11558. +++ b/src/share/vm/runtime/interfaceSupport.hpp Thu Jul 09 23:18:17 2015 -0700
  11559. @@ -296,7 +296,7 @@
  11560. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11561. // We are leaving the VM at this point and going directly to native code.
  11562. // Block, if we are in the middle of a safepoint synchronization.
  11563. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11564. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11565. thread->frame_anchor()->make_walkable(thread);
  11566. trans_and_fence(_thread_in_vm, _thread_in_native);
  11567. // Check for pending. async. exceptions or suspends.
  11568. diff -r 882f6c762ac5 src/share/vm/runtime/javaCalls.cpp
  11569. --- a/src/share/vm/runtime/javaCalls.cpp Thu Jul 09 23:10:04 2015 -0700
  11570. +++ b/src/share/vm/runtime/javaCalls.cpp Thu Jul 09 23:18:17 2015 -0700
  11571. @@ -60,7 +60,7 @@
  11572. bool clear_pending_exception = true;
  11573. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11574. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11575. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11576. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11577. _result = result;
  11578. diff -r 882f6c762ac5 src/share/vm/runtime/jniHandles.cpp
  11579. --- a/src/share/vm/runtime/jniHandles.cpp Thu Jul 09 23:10:04 2015 -0700
  11580. +++ b/src/share/vm/runtime/jniHandles.cpp Thu Jul 09 23:18:17 2015 -0700
  11581. @@ -112,6 +112,10 @@
  11582. }
  11583. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11584. + if (mh->newest_version() != mh()) {
  11585. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11586. + return (jmethodID) make_weak_global(mh_new);
  11587. + }
  11588. return (jmethodID) make_weak_global(mh);
  11589. }
  11590. diff -r 882f6c762ac5 src/share/vm/runtime/mutex.cpp
  11591. --- a/src/share/vm/runtime/mutex.cpp Thu Jul 09 23:10:04 2015 -0700
  11592. +++ b/src/share/vm/runtime/mutex.cpp Thu Jul 09 23:18:17 2015 -0700
  11593. @@ -1227,7 +1227,7 @@
  11594. // in increasing rank order (modulo any native ranks)
  11595. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11596. if (tmp->next() != NULL) {
  11597. - assert(tmp->rank() == Mutex::native ||
  11598. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11599. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11600. }
  11601. }
  11602. @@ -1247,7 +1247,7 @@
  11603. // in increasing rank order (modulo any native ranks)
  11604. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11605. if (tmp->next() != NULL) {
  11606. - assert(tmp->rank() == Mutex::native ||
  11607. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11608. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11609. }
  11610. }
  11611. @@ -1310,6 +1310,7 @@
  11612. // already hold Terminator_lock - may happen because of periodic safepoints
  11613. if (this->rank() != Mutex::native &&
  11614. this->rank() != Mutex::suspend_resume &&
  11615. + this->rank() != Mutex::redefine_classes &&
  11616. locks != NULL && locks->rank() <= this->rank() &&
  11617. !SafepointSynchronize::is_at_safepoint() &&
  11618. this != Interrupt_lock &&
  11619. diff -r 882f6c762ac5 src/share/vm/runtime/mutex.hpp
  11620. --- a/src/share/vm/runtime/mutex.hpp Thu Jul 09 23:10:04 2015 -0700
  11621. +++ b/src/share/vm/runtime/mutex.hpp Thu Jul 09 23:18:17 2015 -0700
  11622. @@ -109,7 +109,8 @@
  11623. barrier = safepoint + 1,
  11624. nonleaf = barrier + 1,
  11625. max_nonleaf = nonleaf + 900,
  11626. - native = max_nonleaf + 1
  11627. + native = max_nonleaf + 1,
  11628. + redefine_classes = native + 1
  11629. };
  11630. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11631. diff -r 882f6c762ac5 src/share/vm/runtime/mutexLocker.cpp
  11632. --- a/src/share/vm/runtime/mutexLocker.cpp Thu Jul 09 23:10:04 2015 -0700
  11633. +++ b/src/share/vm/runtime/mutexLocker.cpp Thu Jul 09 23:18:17 2015 -0700
  11634. @@ -49,6 +49,7 @@
  11635. // Consider using GCC's __read_mostly.
  11636. Mutex* Patching_lock = NULL;
  11637. +Mutex* RedefineClasses_lock = NULL;
  11638. Monitor* SystemDictionary_lock = NULL;
  11639. Mutex* PackageTable_lock = NULL;
  11640. Mutex* CompiledIC_lock = NULL;
  11641. @@ -91,6 +92,7 @@
  11642. Mutex* DirtyCardQ_FL_lock = NULL;
  11643. Monitor* DirtyCardQ_CBL_mon = NULL;
  11644. Mutex* Shared_DirtyCardQ_lock = NULL;
  11645. +Monitor* RedefinitionSync_lock = NULL;
  11646. Mutex* ParGCRareEvent_lock = NULL;
  11647. Mutex* EvacFailureStack_lock = NULL;
  11648. Mutex* DerivedPointerTableGC_lock = NULL;
  11649. @@ -208,6 +210,7 @@
  11650. def(HotCardCache_lock , Mutex , special , true );
  11651. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11652. }
  11653. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11654. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11655. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11656. def(CodeCache_lock , Mutex , special, true );
  11657. @@ -283,6 +286,7 @@
  11658. def(Debug3_lock , Mutex , nonleaf+4, true );
  11659. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11660. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11661. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11662. #ifdef INCLUDE_TRACE
  11663. def(JfrMsg_lock , Monitor, leaf, true);
  11664. diff -r 882f6c762ac5 src/share/vm/runtime/mutexLocker.hpp
  11665. --- a/src/share/vm/runtime/mutexLocker.hpp Thu Jul 09 23:10:04 2015 -0700
  11666. +++ b/src/share/vm/runtime/mutexLocker.hpp Thu Jul 09 23:18:17 2015 -0700
  11667. @@ -43,6 +43,8 @@
  11668. // Mutexes used in the VM.
  11669. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11670. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11671. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11672. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11673. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11674. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11675. diff -r 882f6c762ac5 src/share/vm/runtime/reflection.cpp
  11676. --- a/src/share/vm/runtime/reflection.cpp Thu Jul 09 23:10:04 2015 -0700
  11677. +++ b/src/share/vm/runtime/reflection.cpp Thu Jul 09 23:18:17 2015 -0700
  11678. @@ -468,7 +468,8 @@
  11679. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11680. if ( JDK_Version::is_gte_jdk14x_version()
  11681. && UseNewReflection
  11682. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11683. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11684. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11685. return true;
  11686. }
  11687. @@ -519,6 +520,12 @@
  11688. AccessFlags access,
  11689. bool classloader_only,
  11690. bool protected_restriction) {
  11691. +
  11692. + // (tw) Decide accessibility based on active version
  11693. + if (current_class != NULL) {
  11694. + current_class = current_class->klass_part()->active_version();
  11695. + }
  11696. +
  11697. // Verify that current_class can access a field of field_class, where that
  11698. // field's access bits are "access". We assume that we've already verified
  11699. // that current_class can access field_class.
  11700. @@ -560,7 +567,8 @@
  11701. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11702. if ( JDK_Version::is_gte_jdk14x_version()
  11703. && UseNewReflection
  11704. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11705. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11706. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11707. return true;
  11708. }
  11709. diff -r 882f6c762ac5 src/share/vm/runtime/sharedRuntime.cpp
  11710. --- a/src/share/vm/runtime/sharedRuntime.cpp Thu Jul 09 23:10:04 2015 -0700
  11711. +++ b/src/share/vm/runtime/sharedRuntime.cpp Thu Jul 09 23:18:17 2015 -0700
  11712. @@ -1137,7 +1137,20 @@
  11713. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11714. int retry_count = 0;
  11715. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11716. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11717. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11718. +
  11719. + // DCEVM: If we are executing an old method, this is OK!
  11720. + {
  11721. + ResourceMark rm(thread);
  11722. + RegisterMap cbl_map(thread, false);
  11723. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11724. +
  11725. + CodeBlob* caller_cb = caller_frame.cb();
  11726. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11727. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11728. + if (caller_nm->method()->is_old()) break;
  11729. + }
  11730. +
  11731. // If has a pending exception then there is no need to re-try to
  11732. // resolve this method.
  11733. // If the method has been redefined, we need to try again.
  11734. diff -r 882f6c762ac5 src/share/vm/runtime/thread.cpp
  11735. --- a/src/share/vm/runtime/thread.cpp Thu Jul 09 23:10:04 2015 -0700
  11736. +++ b/src/share/vm/runtime/thread.cpp Thu Jul 09 23:18:17 2015 -0700
  11737. @@ -216,6 +216,8 @@
  11738. set_self_raw_id(0);
  11739. set_lgrp_id(-1);
  11740. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11741. +
  11742. // allocated data structures
  11743. set_osthread(NULL);
  11744. set_resource_area(new (mtThread)ResourceArea());
  11745. @@ -249,6 +251,7 @@
  11746. omFreeProvision = 32 ;
  11747. omInUseList = NULL ;
  11748. omInUseCount = 0 ;
  11749. + _pretend_new_universe = false;
  11750. #ifdef ASSERT
  11751. _visited_for_critical_count = false;
  11752. @@ -884,6 +887,15 @@
  11753. return false;
  11754. }
  11755. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11756. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11757. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11758. + return true;
  11759. + }
  11760. + }
  11761. + return false;
  11762. +}
  11763. +
  11764. #endif
  11765. @@ -1637,7 +1649,7 @@
  11766. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11767. assert(JavaThread::current() == this, "sanity check");
  11768. - assert(!Thread::current()->owns_locks(), "sanity check");
  11769. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11770. DTRACE_THREAD_PROBE(start, this);
  11771. @@ -3193,7 +3205,7 @@
  11772. // Create a CompilerThread
  11773. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11774. -: JavaThread(&compiler_thread_entry) {
  11775. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11776. _env = NULL;
  11777. _log = NULL;
  11778. _task = NULL;
  11779. @@ -3201,6 +3213,7 @@
  11780. _counters = counters;
  11781. _buffer_blob = NULL;
  11782. _scanned_nmethod = NULL;
  11783. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11784. #ifndef PRODUCT
  11785. _ideal_graph_printer = NULL;
  11786. @@ -3230,6 +3243,7 @@
  11787. int Threads::_number_of_non_daemon_threads = 0;
  11788. int Threads::_return_code = 0;
  11789. size_t JavaThread::_stack_size_at_create = 0;
  11790. +bool Threads::_wait_at_instrumentation_entry = false;
  11791. // All JavaThreads
  11792. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11793. diff -r 882f6c762ac5 src/share/vm/runtime/thread.hpp
  11794. --- a/src/share/vm/runtime/thread.hpp Thu Jul 09 23:10:04 2015 -0700
  11795. +++ b/src/share/vm/runtime/thread.hpp Thu Jul 09 23:18:17 2015 -0700
  11796. @@ -203,11 +203,14 @@
  11797. void enter_signal_handler() { _num_nested_signal++; }
  11798. void leave_signal_handler() { _num_nested_signal--; }
  11799. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11800. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11801. private:
  11802. // Debug tracing
  11803. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11804. + Mutex* _redefine_classes_mutex;
  11805. +
  11806. // Active_handles points to a block of handles
  11807. JNIHandleBlock* _active_handles;
  11808. @@ -530,10 +533,15 @@
  11809. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11810. int _lgrp_id;
  11811. +
  11812. + bool _pretend_new_universe;
  11813. +
  11814. public:
  11815. // Stack overflow support
  11816. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11817. + 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; } }
  11818. + bool pretend_new_universe() { return _pretend_new_universe; }
  11819. void set_stack_base(address base) { _stack_base = base; }
  11820. size_t stack_size() const { return _stack_size; }
  11821. void set_stack_size(size_t size) { _stack_size = size; }
  11822. @@ -570,6 +578,7 @@
  11823. void print_owned_locks() const { print_owned_locks_on(tty); }
  11824. Monitor* owned_locks() const { return _owned_locks; }
  11825. bool owns_locks() const { return owned_locks() != NULL; }
  11826. + bool owns_locks_but_redefine_classes_lock() const;
  11827. bool owns_locks_but_compiled_lock() const;
  11828. // Deadlock detection
  11829. @@ -1793,6 +1802,8 @@
  11830. CompileTask* _task;
  11831. CompileQueue* _queue;
  11832. BufferBlob* _buffer_blob;
  11833. + bool _should_bailout;
  11834. + Mutex* _compilation_mutex;
  11835. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11836. @@ -1802,12 +1813,16 @@
  11837. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11838. + bool should_bailout() const { return _should_bailout; }
  11839. + void set_should_bailout(bool b) { _should_bailout = false; }
  11840. +
  11841. bool is_Compiler_thread() const { return true; }
  11842. // Hide this compiler thread from external view.
  11843. bool is_hidden_from_external_view() const { return true; }
  11844. CompileQueue* queue() { return _queue; }
  11845. CompilerCounters* counters() { return _counters; }
  11846. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11847. // Get/set the thread's compilation environment.
  11848. ciEnv* env() { return _env; }
  11849. @@ -1862,6 +1877,7 @@
  11850. static int _number_of_threads;
  11851. static int _number_of_non_daemon_threads;
  11852. static int _return_code;
  11853. + static bool _wait_at_instrumentation_entry;
  11854. public:
  11855. // Thread management
  11856. @@ -1873,6 +1889,9 @@
  11857. static JavaThread* first() { return _thread_list; }
  11858. static void threads_do(ThreadClosure* tc);
  11859. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11860. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11861. +
  11862. // Initializes the vm and creates the vm thread
  11863. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11864. static void convert_vm_init_libraries_to_agents();
  11865. diff -r 882f6c762ac5 src/share/vm/runtime/vframe.cpp
  11866. --- a/src/share/vm/runtime/vframe.cpp Thu Jul 09 23:10:04 2015 -0700
  11867. +++ b/src/share/vm/runtime/vframe.cpp Thu Jul 09 23:18:17 2015 -0700
  11868. @@ -253,6 +253,46 @@
  11869. return fr().interpreter_frame_method();
  11870. }
  11871. +// (tw) Sets interpreter frame method.
  11872. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11873. + methodOop old_method = fr().interpreter_frame_method();
  11874. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11875. + if (old_method == new_method) return;
  11876. + u_char *old_bcp = bcp();
  11877. + int old_bci = bci();
  11878. + fr().interpreter_frame_set_method(new_method);
  11879. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11880. + u_char *new_bcp = new_method->code_base() + new_bci;
  11881. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11882. +
  11883. + set_bcp(new_bcp);
  11884. +
  11885. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11886. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11887. +
  11888. + switch (code) {
  11889. + case Bytecodes::_invokevirtual :
  11890. + case Bytecodes::_invokespecial :
  11891. + case Bytecodes::_invokestatic :
  11892. + case Bytecodes::_invokeinterface: {
  11893. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11894. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11895. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11896. + break;
  11897. + }
  11898. +
  11899. + case Bytecodes::_invokedynamic: {
  11900. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11901. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11902. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11903. + break;
  11904. + }
  11905. + }
  11906. +
  11907. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11908. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11909. +}
  11910. +
  11911. StackValueCollection* interpretedVFrame::locals() const {
  11912. int length = method()->max_locals();
  11913. diff -r 882f6c762ac5 src/share/vm/runtime/vframe.hpp
  11914. --- a/src/share/vm/runtime/vframe.hpp Thu Jul 09 23:10:04 2015 -0700
  11915. +++ b/src/share/vm/runtime/vframe.hpp Thu Jul 09 23:18:17 2015 -0700
  11916. @@ -163,6 +163,7 @@
  11917. StackValueCollection* locals() const;
  11918. StackValueCollection* expressions() const;
  11919. GrowableArray<MonitorInfo*>* monitors() const;
  11920. + void set_method(methodOop method, int new_bci);
  11921. void set_locals(StackValueCollection* values) const;
  11922. diff -r 882f6c762ac5 src/share/vm/runtime/vmThread.cpp
  11923. --- a/src/share/vm/runtime/vmThread.cpp Thu Jul 09 23:10:04 2015 -0700
  11924. +++ b/src/share/vm/runtime/vmThread.cpp Thu Jul 09 23:18:17 2015 -0700
  11925. @@ -694,6 +694,10 @@
  11926. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11927. Thread::oops_do(f, cf);
  11928. _vm_queue->oops_do(f);
  11929. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11930. + if (_cur_vm_operation != NULL) {
  11931. + _cur_vm_operation->oops_do(f);
  11932. + }
  11933. }
  11934. //------------------------------------------------------------------------------------------------------------------
  11935. diff -r 882f6c762ac5 src/share/vm/utilities/exceptions.cpp
  11936. --- a/src/share/vm/utilities/exceptions.cpp Thu Jul 09 23:10:04 2015 -0700
  11937. +++ b/src/share/vm/utilities/exceptions.cpp Thu Jul 09 23:18:17 2015 -0700
  11938. @@ -254,6 +254,8 @@
  11939. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11940. assert(!thread->has_pending_exception(), "already has exception");
  11941. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11942. + Thread::current()->set_pretend_new_universe(false);
  11943. Handle h_exception;
  11944. // Resolve exception klass
  11945. @@ -285,6 +287,7 @@
  11946. h_exception = Handle(thread, thread->pending_exception());
  11947. thread->clear_pending_exception();
  11948. }
  11949. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11950. return h_exception;
  11951. }
  11952. @@ -295,6 +298,8 @@
  11953. Symbol* signature, JavaCallArguments *args,
  11954. Handle h_cause,
  11955. Handle h_loader, Handle h_protection_domain) {
  11956. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11957. + Thread::current()->set_pretend_new_universe(false);
  11958. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11959. // Future: object initializer should take a cause argument
  11960. @@ -317,6 +322,8 @@
  11961. h_exception = Handle(thread, thread->pending_exception());
  11962. thread->clear_pending_exception();
  11963. }
  11964. +
  11965. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11966. return h_exception;
  11967. }
  11968. diff -r 882f6c762ac5 src/share/vm/utilities/growableArray.hpp
  11969. --- a/src/share/vm/utilities/growableArray.hpp Thu Jul 09 23:10:04 2015 -0700
  11970. +++ b/src/share/vm/utilities/growableArray.hpp Thu Jul 09 23:18:17 2015 -0700
  11971. @@ -145,6 +145,33 @@
  11972. assert(on_stack(), "fast ResourceObj path only");
  11973. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11974. }
  11975. +
  11976. +};
  11977. +
  11978. +template<class E, class F> class Pair : public StackObj
  11979. +{
  11980. +private:
  11981. + E _left;
  11982. + F _right;
  11983. +
  11984. +public:
  11985. +
  11986. + Pair() {
  11987. +
  11988. + }
  11989. +
  11990. + Pair(E left, F right) {
  11991. + this->_left = left;
  11992. + this->_right = right;
  11993. + }
  11994. +
  11995. + E left() {
  11996. + return _left;
  11997. + }
  11998. +
  11999. + F right() {
  12000. + return _right;
  12001. + }
  12002. };
  12003. template<class E> class GrowableArray : public GenericGrowableArray {